it.amattioli.dominate.hibernate
Class AbstractHibernateRepository<I extends Serializable,T extends Entity<I>>

Show UML class diagram
java.lang.Object
  extended by it.amattioli.dominate.hibernate.AbstractHibernateRepository<I,T>
All Implemented Interfaces:
Repository<I,T>, Cloneable
Direct Known Subclasses:
ClassHibernateRepository, CollectionHibernateRepository

public abstract class AbstractHibernateRepository<I extends Serializable,T extends Entity<I>>
extends Object
implements Repository<I,T>

Abstract class that implements basic methods for a repository whose content is persisted on a relational database using Hibernate.

That sort of repository needs a Session object to do its job. To retrieve such an object it will use a HibernateSessionManager that must be injected in the repository. After the injection the repository can use getHibernateSession() to retrieve the session from the session manager. If no HibernateSessionManager has been injected the SessionManagerRegistry will be used to get one.

Author:
a.mattioli

Constructor Summary
AbstractHibernateRepository()
           
 
Method Summary
 void addOrder(String property, boolean reverse)
          Add an order property for the lists retrieved using Repository.list() and Repository.list(Specification).
protected  AbstractHibernateRepository<I,T> clone()
           
 T getByPropertyValue(String propertyName, Object value)
          Retrieves the object contained in this repository that has a specified property equals to a certain value.
 int getFirst()
          Retrieves the index of the first object that will be retrieved by Repository.list() e Repository.list(Filter).
 org.hibernate.Session getHibernateSession()
          Retrieves a Hibernate session
protected  String getHqlOrder()
          Builds the "order by" clause of an HQL query using the informations set with setOrder(String, boolean).
 int getLast()
          Retrieves the index of the last object that will be retrieved by Repository.list() e Repository.list(Specification).
 String getOrderProperty()
          Retrieves the name of the property used for ordering the result of the Repository.list() and Repository.list(Specification) methods.
protected  List<Order> getOrders()
           
 SessionManager getSessionManager()
          Retrieves the session manager set by #setSessionManager(HibernateSessionManager).
 boolean isReverseOrder()
          Returns true if the order of the result of the Repository.list() and Repository.list(Specification) methods is ascending, false otherwise.
 void removeLastOrder()
          Remove the last added order property.
 void setFirst(int first)
          Set the index of the first object that will be retrieved by Repository.list() and Repository.list(Filter) when value 0 has been set for 'first' in the filter.
 void setLast(int last)
          Set the index of the last object that will be retrieved by Repository.list() e Repository.list(Filter) when value 0 has been set for 'first' in the filter.
 void setOrder(String property, boolean reverse)
          Set the order for the lists retrieved using Repository.list() and Repository.list(Specification).
 void setSessionManager(SessionManager newSessionMgr)
          Set the session manager that will be used by getHibernateSession().
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface it.amattioli.dominate.Repository
fillCollection, fillCollection, get, getDetailRepository, isRemoveAllowed, list, list, list, put, refresh, refresh, remove, remove
 

Constructor Detail

AbstractHibernateRepository

public AbstractHibernateRepository()
Method Detail

setFirst

public void setFirst(int first)
Description copied from interface: Repository
Set the index of the first object that will be retrieved by Repository.list() and Repository.list(Filter) when value 0 has been set for 'first' in the filter.

The value in the filter, if different than 0, will always superseed this value.

Specified by:
setFirst in interface Repository<I extends Serializable,T extends Entity<I>>
Parameters:
first - the index of the first object that will be retrieved by Repository.list() e Repository.list(Filter)

getFirst

public int getFirst()
Description copied from interface: Repository
Retrieves the index of the first object that will be retrieved by Repository.list() e Repository.list(Filter).

Specified by:
getFirst in interface Repository<I extends Serializable,T extends Entity<I>>
Returns:
the index of the first object that will be retrieved by Repository.list() e Repository.list(Filter)

setLast

public void setLast(int last)
Description copied from interface: Repository
Set the index of the last object that will be retrieved by Repository.list() e Repository.list(Filter) when value 0 has been set for 'first' in the filter.

The value in the filter, if different than 0, will always superseed this value.

If the repository contains less objects than the indicated index, all the objects will be retrieved.

Specified by:
setLast in interface Repository<I extends Serializable,T extends Entity<I>>
Parameters:
last - the index of the last object that will be retrieved by Repository.list() and Repository.list(Specification)

getLast

public int getLast()
Description copied from interface: Repository
Retrieves the index of the last object that will be retrieved by Repository.list() e Repository.list(Specification). This method will retrieve the same number that has been set using Repository.setLast(int) independently of the repository content size.

Specified by:
getLast in interface Repository<I extends Serializable,T extends Entity<I>>
Returns:
the index of the last object that will be retrieved by Repository.list() and Repository.list(Filter)

setOrder

public void setOrder(String property,
                     boolean reverse)
Description copied from interface: Repository
Set the order for the lists retrieved using Repository.list() and Repository.list(Specification). If a previous order property was set it will be replaced.

Specified by:
setOrder in interface Repository<I extends Serializable,T extends Entity<I>>
Parameters:
property - the name of the property that will be used to order the lists
reverse - if this parameter is true the order will be ascendant, otherwise it will be descendant

addOrder

public void addOrder(String property,
                     boolean reverse)
Description copied from interface: Repository
Add an order property for the lists retrieved using Repository.list() and Repository.list(Specification). If a previous order property was set it will remain in place and the new property will be added to the list.

Specified by:
addOrder in interface Repository<I extends Serializable,T extends Entity<I>>
Parameters:
property - the name of the property that will be used to order the lists
reverse - if this parameter is true the order will be ascendant, otherwise it will be descendant

removeLastOrder

public void removeLastOrder()
Description copied from interface: Repository
Remove the last added order property. If no order was set nothing will happen.

Specified by:
removeLastOrder in interface Repository<I extends Serializable,T extends Entity<I>>

getOrderProperty

public String getOrderProperty()
Description copied from interface: Repository
Retrieves the name of the property used for ordering the result of the Repository.list() and Repository.list(Specification) methods.

Specified by:
getOrderProperty in interface Repository<I extends Serializable,T extends Entity<I>>
Returns:
the name of the property used for ordering

isReverseOrder

public boolean isReverseOrder()
Description copied from interface: Repository
Returns true if the order of the result of the Repository.list() and Repository.list(Specification) methods is ascending, false otherwise.

Specified by:
isReverseOrder in interface Repository<I extends Serializable,T extends Entity<I>>
Returns:

getOrders

protected List<Order> getOrders()

getHqlOrder

protected String getHqlOrder()
Builds the "order by" clause of an HQL query using the informations set with setOrder(String, boolean). Subclasses can use this method in Repository.list() and Repository#list(it.maticasrl.appctrl.persistence.Filter) if they need to implement them using HQL.

Returns:
the "order by" clause of a HQL query

setSessionManager

public void setSessionManager(SessionManager newSessionMgr)
Set the session manager that will be used by getHibernateSession().

Parameters:
newSessionMgr - the session manager that will be used by getHibernateSession()

getSessionManager

public SessionManager getSessionManager()
Retrieves the session manager set by #setSessionManager(HibernateSessionManager). If no session manager has been set an instance of SessionManagerRegistry will be used to get one.

Returns:
the session manager to use to get a Hibernate session

getHibernateSession

public org.hibernate.Session getHibernateSession()
Retrieves a Hibernate session

Returns:
a Hibernate session

clone

protected AbstractHibernateRepository<I,T> clone()
                                                                                 throws CloneNotSupportedException
Overrides:
clone in class Object
Throws:
CloneNotSupportedException

getByPropertyValue

public T getByPropertyValue(String propertyName,
                            Object value)
Description copied from interface: Repository
Retrieves the object contained in this repository that has a specified property equals to a certain value.

This method makes sense only if the specified property has distinct values for each entity.

If there is no entity in this repository that has the specified value, null is returned.

if there is more than one entity in this repository that has the specified value, one of them is returned.

Specified by:
getByPropertyValue in interface Repository<I extends Serializable,T extends Entity<I>>
Parameters:
propertyName - the name of the property
value - the property value
Returns:


Copyright © 2011. All Rights Reserved.