org.norther.tammi.root.hibernate
Class HibernatePersister

java.lang.Object
  extended by org.norther.tammi.root.db.PersisterAdapter
      extended by org.norther.tammi.root.hibernate.HibernatePersister
All Implemented Interfaces:
Persister

public class HibernatePersister
extends PersisterAdapter

Hibernate specific implementation of Persister.

Author:
Ilkka Priha

Constructor Summary
HibernatePersister(String alias, org.hibernate.Session session, Principal princ, MBeanReference pbf)
          Constructs a new persister.
 
Method Summary
 void abortTransaction()
          Aborts a transaction to cancel updates to the repository.
 void beginTransaction()
          Begins a transaction to start updates in the repository.
 DBQuery buildQuery(Class clazz, DBCriteria criteria, boolean distinct)
          Builds a query to a specified criteria for the specified class.
 DBQuery buildQuery(Class clazz, String[] attributes, DBCriteria criteria, boolean distinct)
          Builds a query to a specified criteria for the specified class returning only selected attributes.
 DBQuery buildQuery(Class clazz, String expr, boolean sql)
          Builds a query to a query language expression for the specified class.
 DBQuery buildQuery(Object sample)
          Builds a query to a sample object, an identity or a specific class.
 void clearCache()
          Clears the cache associated to this persister, if any.
 void close()
          Closes the connection to the repository.
 void commitTransaction()
          Commits a transaction to complete updates in the repository.
 void deleteObject(Object object)
          Deletes an object from the repository.
 void deleteObjects(Collection objects)
          Deletes a collection of objects from the repository as one transaction.
 void deleteObjects(DBQuery query)
          Deletes query objects from the repository as one transaction.
 DBCriteria getCriteria()
          Gets implementation specific criteria.
 DBCriteria getCriteria(Object criteria)
          Gets initialized implementation specific criteria.
 String[] getKeyAttributes(String className)
          Gets the primary key attributes of the named class.
 void insertObject(Object object)
          Inserts an object to the repository.
 void insertObjects(Collection objects)
          Inserts a collection of objects to the repository as one transaction.
 boolean isInTransaction()
          Checks whether this persister is performing a transaction.
 boolean isPersistentAttribute(String className, String attribute)
          Checks whether an attribute of the named class is persistent.
 boolean isTransactionsSupported()
          Checks whether this persister implementation supports transactions.
 int queryCount(DBQuery query)
          Queries the count of objects the given query would return.
 QueryIterator queryIterator(DBQuery query)
          Queries an iterator to a collection of objects.
 Object queryObject(DBQuery query)
          Queries an object.
 Collection queryObjects(DBQuery query)
          Queries objects.
 void refreshReference(Object object, String name, boolean force)
          Refreshes a named reference of the specified object.
 void refreshReferences(Object object, boolean force)
          Refreshes references of the specified object.
 void removeFromCache(Object object)
          Removes the specified object from the cache.
 void storeObject(Object object)
          Stores an object to the repository.
 void storeObjects(Collection objects)
          Stores a collection of objects to the repository as one transaction.
 Object toIdentity(Object sample)
          Returns an implementation specific object representing the identity of the specified sample object.
 void updateObject(Object object)
          Updates an object in the repository.
 void updateObjects(Collection objects)
          Updates a collection of objects in the repository as one transaction.
 
Methods inherited from class org.norther.tammi.root.db.PersisterAdapter
buildQuery, buildQuery, buildQuery, deleteObjects, deleteObjects, deleteObjects, deleteObjects, dump, getAdaptee, getConnectionKey, getKeyAttribute, getKeyAttribute, getKeyAttributes, getLocale, getMBeanReferent, getMBeanServer, getPersisterFactory, getPrincipal, getRepository, isClosed, isPersistentAttribute, load, modified, queryBySample, queryCount, queryCount, queryCount, queryCount, queryIterator, queryIterator, queryIterator, queryIterator, queryObject, queryObject, queryObject, queryObject, queryObjects, queryObjects, queryObjects, queryObjects, setLocale, toClass
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HibernatePersister

public HibernatePersister(String alias,
                          org.hibernate.Session session,
                          Principal princ,
                          MBeanReference pbf)
Constructs a new persister.

Parameters:
alias - the connection alias.
session - the session.
princ - the principal.
pbf - the persister factory.
Method Detail

close

public void close()
Description copied from interface: Persister
Closes the connection to the repository. The persister should not be referred to after closing.

Specified by:
close in interface Persister
Overrides:
close in class PersisterAdapter

clearCache

public void clearCache()
Description copied from interface: Persister
Clears the cache associated to this persister, if any.

Specified by:
clearCache in interface Persister
Overrides:
clearCache in class PersisterAdapter

removeFromCache

public void removeFromCache(Object object)
Description copied from interface: Persister
Removes the specified object from the cache.

Specified by:
removeFromCache in interface Persister
Overrides:
removeFromCache in class PersisterAdapter
Parameters:
object - the object.

refreshReferences

public void refreshReferences(Object object,
                              boolean force)
Description copied from interface: Persister
Refreshes references of the specified object.

Specified by:
refreshReferences in interface Persister
Overrides:
refreshReferences in class PersisterAdapter
Parameters:
object - the object.
force - force the refresh if true, otherwise false.

refreshReference

public void refreshReference(Object object,
                             String name,
                             boolean force)
Description copied from interface: Persister
Refreshes a named reference of the specified object.

Specified by:
refreshReference in interface Persister
Overrides:
refreshReference in class PersisterAdapter
Parameters:
object - the object.
name - the reference attribute.
force - force the refresh if true, otherwise false.

toIdentity

public Object toIdentity(Object sample)
Description copied from interface: Persister
Returns an implementation specific object representing the identity of the specified sample object.

Parameters:
sample - the sample object.
Returns:
the identity object.

getKeyAttributes

public String[] getKeyAttributes(String className)
Description copied from interface: Persister
Gets the primary key attributes of the named class.

Specified by:
getKeyAttributes in interface Persister
Overrides:
getKeyAttributes in class PersisterAdapter
Parameters:
className - the class name.
Returns:
the primary key attributes or null.

isPersistentAttribute

public boolean isPersistentAttribute(String className,
                                     String attribute)
Description copied from interface: Persister
Checks whether an attribute of the named class is persistent.

Specified by:
isPersistentAttribute in interface Persister
Overrides:
isPersistentAttribute in class PersisterAdapter
Parameters:
className - the class name.
attribute - the field.
Returns:
true for a persistent attribute, false otherwise.

getCriteria

public DBCriteria getCriteria()
Description copied from interface: Persister
Gets implementation specific criteria.

Returns:
ampty criteria.

getCriteria

public DBCriteria getCriteria(Object criteria)
Description copied from interface: Persister
Gets initialized implementation specific criteria.

Parameters:
criteria - the initial criteria.
Returns:
initialized criteria.

buildQuery

public DBQuery buildQuery(Object sample)
Description copied from interface: Persister
Builds a query to a sample object, an identity or a specific class.

Parameters:
sample - the sample, identity or class.
Returns:
the corresponding query.

buildQuery

public DBQuery buildQuery(Class clazz,
                          String expr,
                          boolean sql)
Description copied from interface: Persister
Builds a query to a query language expression for the specified class.

Parameters:
clazz - the class to query.
expr - the query expression.
sql - the SQL flag.
Returns:
the corresponding query.

buildQuery

public DBQuery buildQuery(Class clazz,
                          DBCriteria criteria,
                          boolean distinct)
Description copied from interface: Persister
Builds a query to a specified criteria for the specified class.

Parameters:
clazz - the class to query.
criteria - an implementation specific criteria.
distinct - a flag to indicate a distinct query.
Returns:
the corresponding query.

buildQuery

public DBQuery buildQuery(Class clazz,
                          String[] attributes,
                          DBCriteria criteria,
                          boolean distinct)
Description copied from interface: Persister
Builds a query to a specified criteria for the specified class returning only selected attributes.

Parameters:
clazz - the class to query.
attributes - the attributes to return.
criteria - in implementation specific criteria.
distinct - a flag to indicate a distinct query.
Returns:
the corresponding query.

queryObject

public Object queryObject(DBQuery query)
                   throws PersisterException
Description copied from interface: Persister
Queries an object. The specified query should identify only one unique object as implementations may throw an exception for multiple matches.

Parameters:
query - the query.
Returns:
the found object or null.
Throws:
PersisterException - on errors.

queryObjects

public Collection queryObjects(DBQuery query)
                        throws PersisterException
Description copied from interface: Persister
Queries objects. All matchings objects are returned.

Parameters:
query - the query.
Returns:
a collection of objects.
Throws:
PersisterException - on errors.

queryIterator

public QueryIterator queryIterator(DBQuery query)
                            throws PersisterException
Description copied from interface: Persister
Queries an iterator to a collection of objects.

Parameters:
query - the query.
Returns:
an iterator to a collection of objects.
Throws:
PersisterException - on errors.

queryCount

public int queryCount(DBQuery query)
Description copied from interface: Persister
Queries the count of objects the given query would return.

Parameters:
query - the query.
Returns:
the count of objects or -1 if the query fails.

storeObject

public void storeObject(Object object)
                 throws PersisterException
Description copied from interface: Persister
Stores an object to the repository.

Parameters:
object - the object to store.
Throws:
PersisterException - on errors.

storeObjects

public void storeObjects(Collection objects)
                  throws PersisterException
Description copied from interface: Persister
Stores a collection of objects to the repository as one transaction. If storing of any of the objects fails, the transaction is aborted.

Parameters:
objects - the objects to store.
Throws:
PersisterException - on errors.

insertObject

public void insertObject(Object object)
                  throws PersisterException
Description copied from interface: Persister
Inserts an object to the repository.

Parameters:
object - the object to insert.
Throws:
PersisterException - on errors.

insertObjects

public void insertObjects(Collection objects)
                   throws PersisterException
Description copied from interface: Persister
Inserts a collection of objects to the repository as one transaction. If insertion of any of the objects fails, the transaction is aborted.

Parameters:
objects - the objects to insert.
Throws:
PersisterException - on errors.

updateObject

public void updateObject(Object object)
                  throws PersisterException
Description copied from interface: Persister
Updates an object in the repository.

Parameters:
object - the object to update.
Throws:
PersisterException - on errors.

updateObjects

public void updateObjects(Collection objects)
                   throws PersisterException
Description copied from interface: Persister
Updates a collection of objects in the repository as one transaction. If update of any of the objects fails, the transaction is aborted.

Parameters:
objects - the objects to update.
Throws:
PersisterException - on errors.

deleteObject

public void deleteObject(Object object)
                  throws PersisterException
Description copied from interface: Persister
Deletes an object from the repository.

Parameters:
object - the object to delete.
Throws:
PersisterException - on errors.

deleteObjects

public void deleteObjects(Collection objects)
                   throws PersisterException
Description copied from interface: Persister
Deletes a collection of objects from the repository as one transaction.

Parameters:
objects - the objects to delete.
Throws:
PersisterException - on errors.

deleteObjects

public void deleteObjects(DBQuery query)
                   throws PersisterException
Description copied from interface: Persister
Deletes query objects from the repository as one transaction.

Parameters:
query - the query.
Throws:
PersisterException - on errors.

isTransactionsSupported

public boolean isTransactionsSupported()
Description copied from interface: Persister
Checks whether this persister implementation supports transactions.

Specified by:
isTransactionsSupported in interface Persister
Overrides:
isTransactionsSupported in class PersisterAdapter
Returns:
true if transactions are supported, otherwise false.

isInTransaction

public boolean isInTransaction()
Description copied from interface: Persister
Checks whether this persister is performing a transaction.

Specified by:
isInTransaction in interface Persister
Overrides:
isInTransaction in class PersisterAdapter
Returns:
true if in transaction, otherwise false.

beginTransaction

public void beginTransaction()
Description copied from interface: Persister
Begins a transaction to start updates in the repository.

No-op if transactions are not supported.

Specified by:
beginTransaction in interface Persister
Overrides:
beginTransaction in class PersisterAdapter

abortTransaction

public void abortTransaction()
Description copied from interface: Persister
Aborts a transaction to cancel updates to the repository.

No-op if transactions are not supported.

Specified by:
abortTransaction in interface Persister
Overrides:
abortTransaction in class PersisterAdapter

commitTransaction

public void commitTransaction()
Description copied from interface: Persister
Commits a transaction to complete updates in the repository.

No-op if transactions are not supported.

Specified by:
commitTransaction in interface Persister
Overrides:
commitTransaction in class PersisterAdapter


Copyright © 2004 The Norther Organization. All rights reserved.