mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-19 21:25:38 +00:00
docs: update service layer
This commit is contained in:
@@ -93,7 +93,7 @@ public abstract class DaoBaseImpl<E extends BaseEntity> implements Dao<E> {
|
||||
@Override
|
||||
public E merge(E entity) {
|
||||
Transaction tx = null;
|
||||
E result = null;
|
||||
E result;
|
||||
try (var session = getSessionFactory().openSession()) {
|
||||
tx = session.beginTransaction();
|
||||
result = (E) session.merge(entity);
|
||||
|
||||
@@ -33,12 +33,16 @@ import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Spell entity.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "SPELL")
|
||||
@Getter
|
||||
@Setter
|
||||
public class Spell extends BaseEntity {
|
||||
|
||||
private String name;
|
||||
@@ -60,30 +64,6 @@ public class Spell extends BaseEntity {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Spellbook getSpellbook() {
|
||||
return spellbook;
|
||||
}
|
||||
|
||||
public void setSpellbook(Spellbook spellbook) {
|
||||
this.spellbook = spellbook;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
|
||||
@@ -38,12 +38,16 @@ import javax.persistence.Id;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Spellbook entity.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "SPELLBOOK")
|
||||
@Getter
|
||||
@Setter
|
||||
public class Spellbook extends BaseEntity {
|
||||
|
||||
@Id
|
||||
@@ -69,38 +73,6 @@ public class Spellbook extends BaseEntity {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Set<Wizard> getWizards() {
|
||||
return wizards;
|
||||
}
|
||||
|
||||
public void setWizards(Set<Wizard> wizards) {
|
||||
this.wizards = wizards;
|
||||
}
|
||||
|
||||
public Set<Spell> getSpells() {
|
||||
return spells;
|
||||
}
|
||||
|
||||
public void setSpells(Set<Spell> spells) {
|
||||
this.spells = spells;
|
||||
}
|
||||
|
||||
public void addSpell(Spell spell) {
|
||||
spell.setSpellbook(this);
|
||||
spells.add(spell);
|
||||
|
||||
@@ -35,12 +35,16 @@ import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Wizard entity.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "WIZARD")
|
||||
@Getter
|
||||
@Setter
|
||||
public class Wizard extends BaseEntity {
|
||||
|
||||
@Id
|
||||
@@ -62,30 +66,6 @@ public class Wizard extends BaseEntity {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Set<Spellbook> getSpellbooks() {
|
||||
return spellbooks;
|
||||
}
|
||||
|
||||
public void setSpellbooks(Set<Spellbook> spellbooks) {
|
||||
this.spellbooks = spellbooks;
|
||||
}
|
||||
|
||||
public void addSpellbook(Spellbook spellbook) {
|
||||
spellbook.getWizards().add(this);
|
||||
spellbooks.add(spellbook);
|
||||
|
||||
+1
-1
@@ -122,7 +122,7 @@ class MagicServiceImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindWizardsWithSpell() throws Exception {
|
||||
void testFindWizardsWithSpell() {
|
||||
final var wizards = Set.of(
|
||||
mock(Wizard.class),
|
||||
mock(Wizard.class),
|
||||
|
||||
Reference in New Issue
Block a user