2015-09-18 19:59:52 +03:00
|
|
|
package com.iluwatar.servicelayer.spell;
|
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;
|
2015-04-16 07:44:07 +03:00
|
|
|
import org.hibernate.criterion.Restrictions;
|
2015-04-15 21:11:12 +03:00
|
|
|
|
2015-05-31 11:55:18 +03:00
|
|
|
import com.iluwatar.servicelayer.common.DaoBaseImpl;
|
2015-04-15 21:45:14 +03:00
|
|
|
|
2015-04-15 22:29:04 +03:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* SpellDao implementation.
|
|
|
|
*
|
|
|
|
*/
|
2015-04-14 23:38:50 +03:00
|
|
|
public class SpellDaoImpl extends DaoBaseImpl<Spell> implements SpellDao {
|
2015-04-13 22:36:52 +03:00
|
|
|
|
2015-04-15 21:11:12 +03:00
|
|
|
@Override
|
|
|
|
public Spell findByName(String name) {
|
|
|
|
Session session = getSession();
|
|
|
|
Transaction tx = null;
|
|
|
|
Spell result = null;
|
|
|
|
try {
|
|
|
|
tx = session.beginTransaction();
|
|
|
|
Criteria criteria = session.createCriteria(persistentClass);
|
2015-04-16 07:44:07 +03:00
|
|
|
criteria.add(Restrictions.eq("name", name));
|
2015-04-15 21:11:12 +03:00
|
|
|
result = (Spell) criteria.uniqueResult();
|
2015-04-15 22:29:04 +03:00
|
|
|
result.getSpellbook().getWizards().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
|
|
|
}
|