org.jlot.hibernate.repository.RootEntityRepositoryHibernate Maven / Gradle / Ivy
package org.jlot.hibernate.repository;
import java.util.Collections;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.jlot.hibernate.orm.PersistableEntity;
import org.jlot.hibernate.repository.api.RootEntityRepository;
public abstract class RootEntityRepositoryHibernate extends EntityRepositoryHibernate implements RootEntityRepository
{
@Override
public void save ( T persistableEntity )
{
getSession().save(persistableEntity);
}
@Override
public void delete ( T persistableEntity )
{
getSession().delete(persistableEntity);
}
protected List getPersistableEntitiesByEqualRestriction ( String propertyName, Object value, Class persitableEntityClass )
{
Criteria criteria = getSession().createCriteria(persitableEntityClass);
criteria.add(Restrictions.eq(propertyName, value));
@SuppressWarnings("unchecked")
List persitableEntities = criteria.list();
Collections.sort(persitableEntities);
return persitableEntities;
}
protected Object getUniquePersistableEntityByEqualRestriction ( String propertyName, Object value, Class extends PersistableEntity> persitableEntityClass )
{
Criteria criteria = getSession().createCriteria(persitableEntityClass);
criteria.add(Restrictions.eq(propertyName, value));
return criteria.uniqueResult();
}
}