Skip to content

Commit 3d38289

Browse files
committed
Added findAll methods to service level.
1 parent 281f225 commit 3d38289

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

service-layer/src/main/java/com/iluwatar/App.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,18 @@ public static void initData() {
113113
}
114114

115115
public static void queryData() {
116+
MagicService service = new MagicServiceImpl(new WizardDaoImpl(), new SpellbookDaoImpl(), new SpellDaoImpl());
117+
System.out.println("Enumerating all wizards");
118+
for (Wizard w: service.findAllWizards()) {
119+
System.out.println(w.getName());
120+
}
121+
System.out.println("Enumerating all spellbooks");
122+
for (Spellbook s: service.findAllSpellbooks()) {
123+
System.out.println(s.getName());
124+
}
125+
System.out.println("Enumerating all spells");
126+
for (Spell s: service.findAllSpells()) {
127+
System.out.println(s.getName());
128+
}
116129
}
117130
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
package com.iluwatar;
22

3+
import java.util.List;
4+
35

46
public interface MagicService {
7+
8+
List<Wizard> findAllWizards();
9+
10+
List<Spellbook> findAllSpellbooks();
11+
12+
List<Spell> findAllSpells();
513

614
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
package com.iluwatar;
22

3+
import java.util.List;
4+
35
public class MagicServiceImpl implements MagicService {
6+
7+
private WizardDao wizardDao;
8+
private SpellbookDao spellbookDao;
9+
private SpellDao spellDao;
10+
11+
public MagicServiceImpl(WizardDao wizardDao, SpellbookDao spellbookDao, SpellDao spellDao) {
12+
this.wizardDao = wizardDao;
13+
this.spellbookDao = spellbookDao;
14+
this.spellDao = spellDao;
15+
}
16+
17+
@Override
18+
public List<Wizard> findAllWizards() {
19+
return wizardDao.findAll();
20+
}
21+
22+
@Override
23+
public List<Spellbook> findAllSpellbooks() {
24+
return spellbookDao.findAll();
25+
}
426

27+
@Override
28+
public List<Spell> findAllSpells() {
29+
return spellDao.findAll();
30+
}
531
}

service-layer/src/main/java/com/iluwatar/Wizard.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public void setId(Long id) {
4242
@ManyToMany(cascade = CascadeType.ALL)
4343
private Set<Spellbook> spellbooks;
4444

45-
public String getFirstName() {
45+
public String getName() {
4646
return name;
4747
}
4848

49-
public void setFirstName(String firstName) {
50-
this.name = firstName;
49+
public void setName(String name) {
50+
this.name = name;
5151
}
5252

5353
public Set<Spellbook> getSpellbooks() {

0 commit comments

Comments
 (0)