All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jlot.hibernate.repository.RootEntityRepositoryHibernate Maven / Gradle / Ivy

There is a newer version: 1.2
Show newest version
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 persitableEntityClass )
	{
		Criteria criteria = getSession().createCriteria(persitableEntityClass);
		criteria.add(Restrictions.eq(propertyName, value));
		return criteria.uniqueResult();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy