Added findAll methods to service level.

This commit is contained in:
Ilkka Seppala 2015-04-15 21:39:31 +03:00
parent 281f225a54
commit 3d3828933c
4 changed files with 51 additions and 4 deletions

View File

@ -113,5 +113,18 @@ public class App {
}
public static void queryData() {
MagicService service = new MagicServiceImpl(new WizardDaoImpl(), new SpellbookDaoImpl(), new SpellDaoImpl());
System.out.println("Enumerating all wizards");
for (Wizard w: service.findAllWizards()) {
System.out.println(w.getName());
}
System.out.println("Enumerating all spellbooks");
for (Spellbook s: service.findAllSpellbooks()) {
System.out.println(s.getName());
}
System.out.println("Enumerating all spells");
for (Spell s: service.findAllSpells()) {
System.out.println(s.getName());
}
}
}

View File

@ -1,6 +1,14 @@
package com.iluwatar;
import java.util.List;
public interface MagicService {
List<Wizard> findAllWizards();
List<Spellbook> findAllSpellbooks();
List<Spell> findAllSpells();
}

View File

@ -1,5 +1,31 @@
package com.iluwatar;
public class MagicServiceImpl implements MagicService {
import java.util.List;
public class MagicServiceImpl implements MagicService {
private WizardDao wizardDao;
private SpellbookDao spellbookDao;
private SpellDao spellDao;
public MagicServiceImpl(WizardDao wizardDao, SpellbookDao spellbookDao, SpellDao spellDao) {
this.wizardDao = wizardDao;
this.spellbookDao = spellbookDao;
this.spellDao = spellDao;
}
@Override
public List<Wizard> findAllWizards() {
return wizardDao.findAll();
}
@Override
public List<Spellbook> findAllSpellbooks() {
return spellbookDao.findAll();
}
@Override
public List<Spell> findAllSpells() {
return spellDao.findAll();
}
}

View File

@ -42,12 +42,12 @@ public class Wizard extends BaseEntity {
@ManyToMany(cascade = CascadeType.ALL)
private Set<Spellbook> spellbooks;
public String getFirstName() {
public String getName() {
return name;
}
public void setFirstName(String firstName) {
this.name = firstName;
public void setName(String name) {
this.name = name;
}
public Set<Spellbook> getSpellbooks() {