org.domdrides.hibernate.repository
Class HibernateRepository<EntityType extends Entity<IdType>,IdType extends Serializable>

java.lang.Object
  extended by org.springframework.dao.support.DaoSupport
      extended by org.springframework.orm.hibernate3.support.HibernateDaoSupport
          extended by org.domdrides.hibernate.repository.HibernateRepository<EntityType,IdType>
All Implemented Interfaces:
PageableRepository<EntityType,IdType>, Repository<EntityType,IdType>, org.springframework.beans.factory.InitializingBean
Direct Known Subclasses:
HibernatePersonRepository

@Repository
public abstract class HibernateRepository<EntityType extends Entity<IdType>,IdType extends Serializable>
extends org.springframework.orm.hibernate3.support.HibernateDaoSupport
implements PageableRepository<EntityType,IdType>

A Hibernate-based repository implementation.

Since:
1.0
Author:
James Carman

Field Summary
static String UNCHECKED
           
 
Fields inherited from class org.springframework.dao.support.DaoSupport
logger
 
Constructor Summary
protected HibernateRepository(Class<EntityType> entityClass)
          Constructs a repository which supports entityClass.
 
Method Summary
 EntityType add(EntityType entity)
          Adds the entity to this repository.
 boolean contains(EntityType entity)
          Returns whether or not the entity is contained within the repository.
protected  org.hibernate.Criteria createCriteria()
          Creates a Criteria object which returns the entity type.
 Set<EntityType> getAll()
          Returns all entities in this repository as a set.
 EntityType getById(IdType id)
          Returns the entity with the given id.
protected  List<EntityType> list(org.hibernate.Criteria criteria)
          Returns a list of entities based on the provided criteria.
 List<EntityType> list(int first, int max, String sortProperty, boolean ascending)
          Returns one page of data from this repository.
protected  List<EntityType> list(org.hibernate.Query query)
          Returns a list of entities based on the provided query.
 void remove(EntityType entity)
          Removes the entity from this repository.
protected  Set<EntityType> set(org.hibernate.Criteria criteria)
          Returns a set of entities based on the provided criteria.
protected  Set<EntityType> set(org.hibernate.Query query)
          Returns a set of entities based on the provided query.
 int size()
          Returns the size of the repository.
protected  EntityType uniqueResult(org.hibernate.Criteria criteria)
          Returns a unique result based on the provided criteria.
protected  EntityType uniqueResult(org.hibernate.Query query)
          Returns a unique result based on the provided query.
 EntityType update(EntityType entity)
          Updates an entity within this repository.
 
Methods inherited from class org.springframework.orm.hibernate3.support.HibernateDaoSupport
checkDaoConfig, convertHibernateAccessException, createHibernateTemplate, getHibernateTemplate, getSession, getSession, getSessionFactory, releaseSession, setHibernateTemplate, setSessionFactory
 
Methods inherited from class org.springframework.dao.support.DaoSupport
afterPropertiesSet, initDao
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNCHECKED

public static final String UNCHECKED
See Also:
Constant Field Values
Constructor Detail

HibernateRepository

protected HibernateRepository(Class<EntityType> entityClass)
Constructs a repository which supports entityClass.

Parameters:
entityClass - the entity class
Method Detail

list

@Transactional(readOnly=true)
public List<EntityType> list(int first,
                                           int max,
                                           String sortProperty,
                                           boolean ascending)
Returns one page of data from this repository.

Specified by:
list in interface PageableRepository<EntityType extends Entity<IdType>,IdType extends Serializable>
Parameters:
first - the first entity to return
max - the maximum number of entities to return
sortProperty - the property to sort by
ascending - whether or not the sorting is asceding
Returns:
one page of data from this repository

add

@Transactional
public EntityType add(EntityType entity)
Description copied from interface: Repository
Adds the entity to this repository.

Specified by:
add in interface Repository<EntityType extends Entity<IdType>,IdType extends Serializable>
Parameters:
entity - the entity
Returns:
the entity (useful if adding entity to repository changes the entity, e.g. creates oid)

contains

@Transactional(readOnly=true)
public boolean contains(EntityType entity)
Description copied from interface: Repository
Returns whether or not the entity is contained within the repository.

Specified by:
contains in interface Repository<EntityType extends Entity<IdType>,IdType extends Serializable>
Parameters:
entity - the entity
Returns:
whether or not the entity is contained within the repository

getAll

@Transactional(readOnly=true)
public Set<EntityType> getAll()
Description copied from interface: Repository
Returns all entities in this repository as a set.

Specified by:
getAll in interface Repository<EntityType extends Entity<IdType>,IdType extends Serializable>
Returns:
all entities in this repository as a set

getById

@Transactional(readOnly=true)
public EntityType getById(IdType id)
Description copied from interface: Repository
Returns the entity with the given id.

Specified by:
getById in interface Repository<EntityType extends Entity<IdType>,IdType extends Serializable>
Parameters:
id - the id
Returns:
the entity with the given id

remove

@Transactional
public void remove(EntityType entity)
Description copied from interface: Repository
Removes the entity from this repository.

Specified by:
remove in interface Repository<EntityType extends Entity<IdType>,IdType extends Serializable>
Parameters:
entity - the entity

size

@Transactional(readOnly=true)
public int size()
Description copied from interface: Repository
Returns the size of the repository.

Specified by:
size in interface Repository<EntityType extends Entity<IdType>,IdType extends Serializable>
Returns:
the size of the repository

update

@Transactional
public EntityType update(EntityType entity)
Description copied from interface: Repository
Updates an entity within this repository.

Specified by:
update in interface Repository<EntityType extends Entity<IdType>,IdType extends Serializable>
Parameters:
entity - the entity
Returns:
the entity (useful if adding entity to repository changes the entity, e.g. creates oid)

createCriteria

protected org.hibernate.Criteria createCriteria()
Creates a Criteria object which returns the entity type.

Returns:
a Criteria object which returns the entity type

list

@Transactional(readOnly=true)
protected List<EntityType> list(org.hibernate.Criteria criteria)
Returns a list of entities based on the provided criteria.

Parameters:
criteria - the criteria
Returns:
a list of entities based on the provided criteria

list

@Transactional(readOnly=true)
protected List<EntityType> list(org.hibernate.Query query)
Returns a list of entities based on the provided query.

Parameters:
query - the query
Returns:
a list of entities based on the provided query

set

@Transactional(readOnly=true)
protected Set<EntityType> set(org.hibernate.Criteria criteria)
Returns a set of entities based on the provided criteria.

Parameters:
criteria - the criteria
Returns:
a set of entities based on the provided criteria

set

@Transactional(readOnly=true)
protected Set<EntityType> set(org.hibernate.Query query)
Returns a set of entities based on the provided query.

Parameters:
query - the query
Returns:
a set of entities based on the provided query

uniqueResult

@Transactional(readOnly=true)
protected EntityType uniqueResult(org.hibernate.Criteria criteria)
Returns a unique result based on the provided criteria.

Parameters:
criteria - the criteria
Returns:
a unique result based on the provided criteria

uniqueResult

@Transactional(readOnly=true)
protected EntityType uniqueResult(org.hibernate.Query query)
Returns a unique result based on the provided query.

Parameters:
query - the query
Returns:
a unique result based on the provided query


Copyright © 2013. All Rights Reserved.