43 lines
982 B
Java
Raw Normal View History

package com.iluwatar.servicelayer.wizard;
2015-04-13 22:36:52 +03:00
2015-04-15 21:11:12 +03:00
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;
2015-04-15 21:11:12 +03:00
import com.iluwatar.servicelayer.common.DaoBaseImpl;
import com.iluwatar.servicelayer.spellbook.Spellbook;
2015-04-15 21:45:14 +03:00
2015-04-15 22:29:04 +03:00
/**
*
* WizardDao implementation.
*
*/
2015-04-14 23:38:50 +03:00
public class WizardDaoImpl extends DaoBaseImpl<Wizard> implements WizardDao {
2015-04-13 22:36:52 +03:00
2015-04-15 21:11:12 +03:00
@Override
public Wizard findByName(String name) {
Session session = getSession();
Transaction tx = null;
Wizard result = null;
try {
tx = session.beginTransaction();
Criteria criteria = session.createCriteria(persistentClass);
criteria.add(Restrictions.eq("name", name));
2015-04-15 21:11:12 +03:00
result = (Wizard) criteria.uniqueResult();
2015-04-15 22:29:04 +03:00
for (Spellbook s: result.getSpellbooks()) {
s.getSpells().size();
}
2015-04-15 21:11:12 +03:00
tx.commit();
}
catch (Exception e) {
if (tx!=null) tx.rollback();
throw e;
}
finally {
session.close();
}
return result;
}
2015-04-13 22:36:52 +03:00
}