com.elasticpath.persistence.impl
Class HibernatePersistenceEngineImpl

java.lang.Object
  extended by org.springframework.dao.support.DaoSupport
      extended by org.springframework.orm.hibernate3.support.HibernateDaoSupport
          extended by com.elasticpath.persistence.impl.HibernatePersistenceEngineImpl
All Implemented Interfaces:
PersistenceEngine, org.springframework.beans.factory.InitializingBean

public class HibernatePersistenceEngineImpl
extends org.springframework.orm.hibernate3.support.HibernateDaoSupport
implements PersistenceEngine

A wrapper of Hibernate to provide implementation of PersistenceEngine.


Constructor Summary
HibernatePersistenceEngineImpl()
           
 
Method Summary
 int bulkUpdate(java.lang.String query)
          Update/delete all objects according to the given query.
 int bulkUpdate(java.lang.String query, java.lang.Object[] parameters)
          Update/delete all objects according to the given query.
 void clear()
          Clear the cache.
 void delete(Persistence object)
          Delete the given persistent instance.
 int executeSessionUpdate(java.lang.String sql)
          Excute the bulk update with the specified query.
 java.util.List find(java.lang.Class objClass, java.util.List propertyCriteria)
          Retrieve a list of persistent instances of the specified class with the specified property criteria.
 java.util.List find(java.lang.Class objClass, PropertyCriterion propertyCriterion)
          Retrieve a list of persistent instances of the specified class with the specified property criterion.
 java.util.List find(java.lang.Class objClass, RelationCriterion relationCriterion)
          Retrieve a list of persistent instances of the specified class with the specified relation criterion.
 void flush()
          Flush the cache.
 Persistence get(java.lang.Class persistenceClass, long uidPk)
          Get a persistent instance with the given id.
 PersistenceSession getPersistenceSession()
          Returns hibernate session.
 void initialize(java.lang.Object object)
          Initialize the given object.
 Persistence load(java.lang.Class persistenceClass, long uidPk)
          Load a persistent instance with the given id.
 void merge(Persistence object)
          Merge the given persistent instance.
 java.util.List retrieve(java.util.List queries)
          Retrieve a list of persistent instances with the given list of queries.
 java.util.List retrieve(java.util.List queries, java.lang.Object[] parameters)
          Retrieve a list of persistent instances with the given list of queries.
 java.util.List retrieve(java.lang.String query)
          Retrieve a list of persistent instances with the specified query.
 java.util.List retrieve(java.lang.String queryStr, int firstResult, int maxRestuls)
          Retrieve a list of persistent instances with the specified query and bounds, namely, the maximum number of rows to retrieve and / or the first row to retrieve.
 java.util.List retrieve(java.lang.String query, java.lang.Object[] parameters)
          Retrieve a list of persistent instances with the specified query.
 java.util.List retrieve(java.lang.String query, java.lang.Object[] parameters, boolean cacheQuery)
          Retrieve a list of persistent instances with the specified query.
 java.util.List retrieve(java.lang.String queryStr, java.lang.Object[] parameters, int firstResult, int maxRestuls)
          Retrieve a list of persistent instances with the specified query and bounds, namely, the maximum number of rows to retrieve and / or the first row to retrieve.
 void save(Persistence object)
          Persist the given instance.
 void saveOrMerge(Persistence object)
          Save the persistence instance if it's new or merge the persistent instance if it exists.
 void saveOrUpdate(Persistence object)
          Save the persistence instance if it's new or update the persistent instance if it exists.
 void update(Persistence object)
          Update the given persistent instance.
 
Methods inherited from class org.springframework.orm.hibernate3.support.HibernateDaoSupport
getHibernateTemplate, getSessionFactory, setHibernateTemplate, setSessionFactory
 
Methods inherited from class org.springframework.dao.support.DaoSupport
afterPropertiesSet
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HibernatePersistenceEngineImpl

public HibernatePersistenceEngineImpl()
Method Detail

bulkUpdate

public int bulkUpdate(java.lang.String query)
               throws EpPersistenceException
Update/delete all objects according to the given query.

Specified by:
bulkUpdate in interface PersistenceEngine
Parameters:
query - the HQL query
Returns:
the number of instances updated/deleted
Throws:
EpPersistenceException - - in case of persistence errors

bulkUpdate

public int bulkUpdate(java.lang.String query,
                      java.lang.Object[] parameters)
               throws EpPersistenceException
Update/delete all objects according to the given query.

Specified by:
bulkUpdate in interface PersistenceEngine
Parameters:
query - the HQL query
parameters - the prameters to be used with the criteria
Returns:
the number of instances updated/deleted
Throws:
EpPersistenceException - - in case of persistence errors

clear

public void clear()
Clear the cache.

Specified by:
clear in interface PersistenceEngine

delete

public void delete(Persistence object)
            throws EpPersistenceException
Delete the given persistent instance.

Specified by:
delete in interface PersistenceEngine
Parameters:
object - the instance to delete
Throws:
EpPersistenceException - - in case of persistence errors

executeSessionUpdate

public int executeSessionUpdate(java.lang.String sql)
                         throws EpPersistenceException
Excute the bulk update with the specified query.

Parameters:
sql - the HQL sql statement
Returns:
the number of entities effective by the operation.
Throws:
EpPersistenceException - - in case of persistence errors

find

public java.util.List find(java.lang.Class objClass,
                           java.util.List propertyCriteria)
                    throws EpPersistenceException
Retrieve a list of persistent instances of the specified class with the specified property criteria.

Specified by:
find in interface PersistenceEngine
Parameters:
objClass - Class of the object
propertyCriteria - property criteria for retrieving
Returns:
list of persistence instatnce
Throws:
EpPersistenceException - - in case of persistence errors

find

public java.util.List find(java.lang.Class objClass,
                           PropertyCriterion propertyCriterion)
                    throws EpPersistenceException
Retrieve a list of persistent instances of the specified class with the specified property criterion.

Specified by:
find in interface PersistenceEngine
Parameters:
objClass - Class of the object
propertyCriterion - property criterion for retrieving
Returns:
list of persistence instatnce
Throws:
EpPersistenceException - - in case of persistence errors

find

public java.util.List find(java.lang.Class objClass,
                           RelationCriterion relationCriterion)
                    throws EpPersistenceException
Retrieve a list of persistent instances of the specified class with the specified relation criterion.

Specified by:
find in interface PersistenceEngine
Parameters:
objClass - Class of the object
relationCriterion - relation criterion for retrieving
Returns:
list of persistence instatnce
Throws:
EpPersistenceException - - in case of persistence errors

flush

public void flush()
Flush the cache.

Specified by:
flush in interface PersistenceEngine

get

public Persistence get(java.lang.Class persistenceClass,
                       long uidPk)
                throws EpPersistenceException
Get a persistent instance with the given id. Return null if no matching record exists.

Specified by:
get in interface PersistenceEngine
Parameters:
persistenceClass - the persistent class of the given id.
uidPk - the persistent instance id.
Returns:
the persistent instance
Throws:
EpPersistenceException - - in case of persistence errors

getPersistenceSession

public PersistenceSession getPersistenceSession()
Returns hibernate session.

Specified by:
getPersistenceSession in interface PersistenceEngine
Returns:
hibernate session

initialize

public void initialize(java.lang.Object object)
Initialize the given object.

Specified by:
initialize in interface PersistenceEngine
Parameters:
object - the object to initialize.

load

public Persistence load(java.lang.Class persistenceClass,
                        long uidPk)
                 throws EpPersistenceException
Load a persistent instance with the given id. Throw an unrecoverable exception if there is no matching database row.

Specified by:
load in interface PersistenceEngine
Parameters:
persistenceClass - the persistent class of the given id.
uidPk - The persistent instance id.
Returns:
the persistent instance
Throws:
EpPersistenceException - - in case of persistence errors

merge

public void merge(Persistence object)
           throws EpPersistenceException
Merge the given persistent instance.

Specified by:
merge in interface PersistenceEngine
Parameters:
object - the instance to merge
Throws:
EpPersistenceException - - in case of persistence errors

retrieve

public java.util.List retrieve(java.util.List queries)
                        throws EpPersistenceException
Retrieve a list of persistent instances with the given list of queries.

Note: all queries must return the same type of data. Their results will be merged into the list returned by this method.

Specified by:
retrieve in interface PersistenceEngine
Parameters:
queries - the list of queries
Returns:
a list of persistent instances.
Throws:
EpPersistenceException - - in case of persistence errors

retrieve

public java.util.List retrieve(java.util.List queries,
                               java.lang.Object[] parameters)
                        throws EpPersistenceException
Retrieve a list of persistent instances with the given list of queries.

Note: all queries must return the same type of data. Their results will be merged into the list returned by this method.

Specified by:
retrieve in interface PersistenceEngine
Parameters:
queries - the list of queries
parameters - the prameters to be used with the given query
Returns:
a list of persistent instances.
Throws:
EpPersistenceException - - in case of persistence errors

retrieve

public java.util.List retrieve(java.lang.String query)
                        throws EpPersistenceException
Retrieve a list of persistent instances with the specified query.

Specified by:
retrieve in interface PersistenceEngine
Parameters:
query - the HQL query
Returns:
a list of persistent instances.
Throws:
EpPersistenceException - - in case of persistence errors

retrieve

public java.util.List retrieve(java.lang.String queryStr,
                               int firstResult,
                               int maxRestuls)
                        throws EpPersistenceException
Retrieve a list of persistent instances with the specified query and bounds, namely, the maximum number of rows to retrieve and / or the first row to retrieve. This help to support pagination.

Specified by:
retrieve in interface PersistenceEngine
Parameters:
queryStr - the HQL query string to be executed.
firstResult - the first row to retrieve.
maxRestuls - the maximum number of rows to retrieve.
Returns:
a list of persistent instances.
Throws:
EpPersistenceException - - in case of persistence errors

retrieve

public java.util.List retrieve(java.lang.String query,
                               java.lang.Object[] parameters)
                        throws EpPersistenceException
Retrieve a list of persistent instances with the specified query.

Specified by:
retrieve in interface PersistenceEngine
Parameters:
query - the HQL query
parameters - the prameters to be used with the criteria
Returns:
a list of persistent instances.
Throws:
EpPersistenceException - - in case of persistence errors

retrieve

public java.util.List retrieve(java.lang.String query,
                               java.lang.Object[] parameters,
                               boolean cacheQuery)
                        throws EpPersistenceException
Retrieve a list of persistent instances with the specified query.

Specified by:
retrieve in interface PersistenceEngine
Parameters:
query - the HQL query
parameters - the prameters to be used with the criteria
cacheQuery - set it to true to cache the query result
Returns:
a list of persistent instances.
Throws:
EpPersistenceException - - in case of persistence errors

retrieve

public java.util.List retrieve(java.lang.String queryStr,
                               java.lang.Object[] parameters,
                               int firstResult,
                               int maxRestuls)
                        throws EpPersistenceException
Retrieve a list of persistent instances with the specified query and bounds, namely, the maximum number of rows to retrieve and / or the first row to retrieve. This help to support pagination.

Specified by:
retrieve in interface PersistenceEngine
Parameters:
queryStr - the HQL query string to be executed.
firstResult - the first row to retrieve.
maxRestuls - the maximum number of rows to retrieve.
parameters - the prameters to be used with the criteria
Returns:
a list of persistent instances.
Throws:
EpPersistenceException - - in case of persistence errors

save

public void save(Persistence object)
          throws EpPersistenceException
Persist the given instance.

Specified by:
save in interface PersistenceEngine
Parameters:
object - the instance to save.
Throws:
EpPersistenceException - - in case of persistence errors

saveOrMerge

public void saveOrMerge(Persistence object)
                 throws EpPersistenceException
Save the persistence instance if it's new or merge the persistent instance if it exists.

Specified by:
saveOrMerge in interface PersistenceEngine
Parameters:
object - the instance to save or merge
Throws:
EpPersistenceException - - in case of persistence errors

saveOrUpdate

public void saveOrUpdate(Persistence object)
                  throws EpPersistenceException
Save the persistence instance if it's new or update the persistent instance if it exists.

Specified by:
saveOrUpdate in interface PersistenceEngine
Parameters:
object - the instance to save or update
Throws:
EpPersistenceException - - in case of persistence errors

update

public void update(Persistence object)
            throws EpPersistenceException
Update the given persistent instance.

Specified by:
update in interface PersistenceEngine
Parameters:
object - the instance to update
Throws:
EpPersistenceException - - in case of persistence errors