|
1 | 1 | package com.iluwatar; |
2 | 2 |
|
| 3 | +import java.util.List; |
3 | 4 |
|
4 | | - |
| 5 | +/** |
| 6 | + * |
| 7 | + * |
| 8 | + * |
| 9 | + */ |
5 | 10 | public class App { |
| 11 | + |
6 | 12 | public static void main( String[] args ) { |
7 | | - WizardDaoImpl dao = new WizardDaoImpl(); |
8 | | - persistData(dao); |
| 13 | + initData(); |
9 | 14 | queryData(); |
10 | 15 | } |
11 | 16 |
|
12 | | - public static void persistData(WizardDaoImpl dao) { |
13 | | - Spell spell = new Spell("Fireball"); |
14 | | - Spellbook spellbook = new Spellbook("Book of fire"); |
15 | | - spell.setSpellbook(spellbook); |
16 | | - spellbook.getSpells().add(spell); |
17 | | - Wizard wizard = new Wizard("Jugga"); |
18 | | - spellbook.setWizard(wizard); |
19 | | - wizard.getSpellbooks().add(spellbook); |
20 | | - dao.persist(wizard); |
| 17 | + public static void initData() { |
| 18 | + Spell spell1 = new Spell("Ice dart"); |
| 19 | + Spell spell2 = new Spell("Invisibility"); |
| 20 | + Spell spell3 = new Spell("Stun bolt"); |
| 21 | + Spell spell4 = new Spell("Confusion"); |
| 22 | + Spell spell5 = new Spell("Darkness"); |
| 23 | + Spell spell6 = new Spell("Fireball"); |
| 24 | + Spell spell7 = new Spell("Enchant weapon"); |
| 25 | + Spell spell8 = new Spell("Rock armour"); |
| 26 | + Spell spell9 = new Spell("Light"); |
| 27 | + Spell spell10 = new Spell("Bee swarm"); |
| 28 | + Spell spell11 = new Spell("Haste"); |
| 29 | + Spell spell12 = new Spell("Levitation"); |
| 30 | + Spell spell13 = new Spell("Magic lock"); |
| 31 | + Spell spell14 = new Spell("Summon hell bat"); |
| 32 | + Spell spell15 = new Spell("Water walking"); |
| 33 | + Spell spell16 = new Spell("Magic storm"); |
| 34 | + Spell spell17 = new Spell("Entangle"); |
| 35 | + SpellDao spellDao = new SpellDaoImpl(); |
| 36 | + spellDao.persist(spell1); |
| 37 | + spellDao.persist(spell2); |
| 38 | + spellDao.persist(spell3); |
| 39 | + spellDao.persist(spell4); |
| 40 | + spellDao.persist(spell5); |
| 41 | + spellDao.persist(spell6); |
| 42 | + spellDao.persist(spell7); |
| 43 | + spellDao.persist(spell8); |
| 44 | + spellDao.persist(spell9); |
| 45 | + spellDao.persist(spell10); |
| 46 | + spellDao.persist(spell11); |
| 47 | + spellDao.persist(spell12); |
| 48 | + spellDao.persist(spell13); |
| 49 | + spellDao.persist(spell14); |
| 50 | + spellDao.persist(spell15); |
| 51 | + spellDao.persist(spell16); |
| 52 | + spellDao.persist(spell17); |
| 53 | + |
| 54 | + SpellbookDao spellbookDao = new SpellbookDaoImpl(); |
| 55 | + Spellbook spellbook1 = new Spellbook("Book of Orgymon"); |
| 56 | + spellbookDao.persist(spellbook1); |
| 57 | + spellbook1.addSpell(spell1); |
| 58 | + spellbook1.addSpell(spell2); |
| 59 | + spellbook1.addSpell(spell3); |
| 60 | + spellbook1.addSpell(spell4); |
| 61 | + spellbookDao.merge(spellbook1); |
| 62 | + Spellbook spellbook2 = new Spellbook("Book of Aras"); |
| 63 | + spellbookDao.persist(spellbook2); |
| 64 | + spellbook2.addSpell(spell5); |
| 65 | + spellbook2.addSpell(spell6); |
| 66 | + spellbookDao.merge(spellbook2); |
| 67 | + Spellbook spellbook3 = new Spellbook("Book of Kritior"); |
| 68 | + spellbookDao.persist(spellbook3); |
| 69 | + spellbook3.addSpell(spell7); |
| 70 | + spellbook3.addSpell(spell8); |
| 71 | + spellbook3.addSpell(spell9); |
| 72 | + spellbookDao.merge(spellbook3); |
| 73 | + Spellbook spellbook4 = new Spellbook("Book of Tamaex"); |
| 74 | + spellbookDao.persist(spellbook4); |
| 75 | + spellbook4.addSpell(spell10); |
| 76 | + spellbook4.addSpell(spell11); |
| 77 | + spellbook4.addSpell(spell12); |
| 78 | + spellbookDao.merge(spellbook4); |
| 79 | + Spellbook spellbook5 = new Spellbook("Book of Idores"); |
| 80 | + spellbookDao.persist(spellbook5); |
| 81 | + spellbook5.addSpell(spell13); |
| 82 | + spellbookDao.merge(spellbook5); |
| 83 | + Spellbook spellbook6 = new Spellbook("Book of Opaen"); |
| 84 | + spellbookDao.persist(spellbook6); |
| 85 | + spellbook6.addSpell(spell14); |
| 86 | + spellbook6.addSpell(spell15); |
| 87 | + spellbookDao.merge(spellbook6); |
| 88 | + Spellbook spellbook7 = new Spellbook("Book of Kihione"); |
| 89 | + spellbookDao.persist(spellbook7); |
| 90 | + spellbook7.addSpell(spell16); |
| 91 | + spellbook7.addSpell(spell17); |
| 92 | + spellbookDao.merge(spellbook7); |
| 93 | + |
| 94 | + WizardDao wizardDao = new WizardDaoImpl(); |
| 95 | + Wizard wizard1 = new Wizard("Aderlard Boud"); |
| 96 | + wizardDao.persist(wizard1); |
| 97 | +// wizard1.addSpellbook(spellbook1); |
| 98 | +// wizard1.addSpellbook(spellbook2); |
| 99 | + wizardDao.merge(wizard1); |
| 100 | + Wizard wizard2 = new Wizard("Anaxis Bajraktari"); |
| 101 | + wizardDao.persist(wizard2); |
| 102 | +// wizard2.addSpellbook(spellbook3); |
| 103 | +// wizard2.addSpellbook(spellbook4); |
| 104 | + wizardDao.merge(wizard2); |
| 105 | + Wizard wizard3 = new Wizard("Xuban Munoa"); |
| 106 | + wizardDao.persist(wizard3); |
| 107 | +// wizard3.addSpellbook(spellbook5); |
| 108 | +// wizard3.addSpellbook(spellbook6); |
| 109 | + wizardDao.merge(wizard3); |
| 110 | + Wizard wizard4 = new Wizard("Blasius Dehooge"); |
| 111 | + wizardDao.persist(wizard4); |
| 112 | +// wizard4.addSpellbook(spellbook7); |
| 113 | + wizardDao.merge(wizard4); |
21 | 114 | } |
22 | 115 |
|
23 | 116 | public static void queryData() { |
24 | | - MagicService magicService = new MagicServiceImpl(); |
25 | | - for (Wizard w: magicService.findAllWizards()) { |
26 | | - System.out.println(w); |
27 | | - } |
28 | 117 | } |
29 | 118 | } |
0 commit comments