40 lines
948 B
Java
Raw Normal View History

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;
import org.hibernate.criterion.Restrictions;
2015-04-15 21:11:12 +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
@Override
public Spell findByName(String name) {
Session session = getSession();
Transaction tx = null;
Spell result = null;
try {
tx = session.beginTransaction();
Criteria criteria = session.createCriteria(persistentClass);
criteria.add(Restrictions.eq("name", name));
result = (Spell) criteria.uniqueResult();
result.getSpellbook().getWizards().size();
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
}