org.norther.tammi.root.db
Class PersisterAdapter

java.lang.Object
  extended by org.norther.tammi.root.db.PersisterAdapter
All Implemented Interfaces:
Persister
Direct Known Subclasses:
HibernatePersister, OJBPersister, XMLPersister

public abstract class PersisterAdapter
extends Object
implements Persister

An abstract persister adapter.

Author:
Ilkka Priha

Constructor Summary
PersisterAdapter(String key, Object adapt, MBeanReference pbf)
          Constructs a new persister with an adaptee and an MBean server.
PersisterAdapter(String key, Object adapt, Principal princ, MBeanReference ref)
          Constructs a new persister with an adaptee, principal and an MBean server.
 
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(String className, DBCriteria criteria, boolean distinct)
          Builds a query to a specified criteria for the named class.
 DBQuery buildQuery(String className, String[] attributes, DBCriteria criteria, boolean distinct)
          Builds a query to a specified criteria for the named class returning only selected attributes.
 DBQuery buildQuery(String className, String expr, boolean sql)
          Builds a query to a query language expression for the named 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 deleteObjects(Class clazz, DBCriteria criteria)
          Deletes objects of the specified criteria and class as one transaction.
 void deleteObjects(Class clazz, String attribute, Object value, int condition)
          Deletes objects of the specified class from the repository as one transaction.
 void deleteObjects(String className, DBCriteria criteria)
          Deletes objects of the specified criteria and named class as one transaction.
 void deleteObjects(String className, String attribute, Object value, int condition)
          Deletes objects of the named class from the repository as one transaction.
 void dump(Collection objects, File file)
          Dumps a objects into a dump file if this persister supports files.
 Object getAdaptee()
          Gets the implementation specific persister adaptee, if any.
 String getConnectionKey()
          Gets the connection key bound to this persister.
 String getKeyAttribute(Class clazz)
          Gets the primary key attribute of the specified class.
 String getKeyAttribute(String className)
          Gets the primary key attribute of the named class.
 String[] getKeyAttributes(Class clazz)
          Gets the primary key attributes of the specified class.
 String[] getKeyAttributes(String className)
          Gets the primary key attributes of the named class.
 Locale getLocale()
          Gets the locale of this persister.
protected  Object getMBeanReferent(Object object)
          Gets the referent of an MBean reference.
 MBeanServer getMBeanServer()
          Gets the MBean server of this persister.
protected  PersisterFactory getPersisterFactory()
          Gets the persister factory.
 Principal getPrincipal()
          Gets the principal of this persister.
 String getRepository(String className)
          Gets the name of the repository of the named class.
 boolean isClosed()
          Checks whether this persister is closed.
 boolean isInTransaction()
          Checks whether this persister is performing a transaction.
 boolean isPersistentAttribute(Class clazz, String field)
          Checks whether an attribute of the specified class is persistent.
 boolean isPersistentAttribute(String className, String field)
          Checks whether an attribute of the named class is persistent.
 boolean isTransactionsSupported()
          Checks whether this persister implementation supports transactions.
 Collection load(File file)
          Loads objects from a dump file if this persister supports files.
protected  void modified()
          Notifies the persister factory about modifications.
 Object queryBySample(Object identity)
          Queries an object by its properties or identity.
 int queryCount(Class clazz, DBCriteria criteria)
          Queries the count of objects of the specified criteria and class.
 int queryCount(Class clazz, String attribute, Object value, int condition)
          Queries the count of objects of the specified class.
 int queryCount(String className, DBCriteria criteria)
          Queries the count of objects of the specified criteria and named class.
 int queryCount(String className, String attribute, Object value, int condition)
          Queries the count of objects of the named class.
 QueryIterator queryIterator(Class clazz, DBCriteria criteria)
          Queries an iterator to a collection of objects of the specified criteria and class.
 QueryIterator queryIterator(Class clazz, String attribute, Object value, int condition)
          Queries an iterator to a collection of objects of the specified class.
 QueryIterator queryIterator(String className, DBCriteria criteria)
          Queries an iterator to a collection of objects of the specified criteria and named class.
 QueryIterator queryIterator(String className, String attribute, Object value, int condition)
          Queries an iterator to a collection of objects of the named class.
 Object queryObject(Class clazz, Object value)
          Queries an object of the specified class.
 Object queryObject(Class clazz, String attribute, Object value)
          Queries an object of the specified class with the named attribute.
 Object queryObject(String className, Object value)
          Queries an object of the named class.
 Object queryObject(String className, String attribute, Object value)
          Queries an object of the named class with the named attribute.
 Collection queryObjects(Class clazz, DBCriteria criteria)
          Queries objects of the specified criteria and class.
 Collection queryObjects(Class clazz, String attribute, Object value, int condition)
          Queries objects of the specified class.
 Collection queryObjects(String className, DBCriteria criteria)
          Queries objects of the specified criteria and named class.
 Collection queryObjects(String className, String attribute, Object value, int condition)
          Queries objects of the named class.
 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 setLocale(Locale loc)
          Sets the locale of this persister.
protected  Class toClass(String className)
          Returns the class instance of the named class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.norther.tammi.root.db.Persister
buildQuery, buildQuery, buildQuery, buildQuery, deleteObject, deleteObjects, deleteObjects, getCriteria, getCriteria, insertObject, insertObjects, queryCount, queryIterator, queryObject, queryObjects, storeObject, storeObjects, toIdentity, updateObject, updateObjects
 

Constructor Detail

PersisterAdapter

public PersisterAdapter(String key,
                        Object adapt,
                        MBeanReference pbf)
Constructs a new persister with an adaptee and an MBean server.

Parameters:
key - the connector key.
adapt - the persister adaptee.
pbf - the persister factory.
Throws:
NullPointerException - if key is null.

PersisterAdapter

public PersisterAdapter(String key,
                        Object adapt,
                        Principal princ,
                        MBeanReference ref)
Constructs a new persister with an adaptee, principal and an MBean server.

Parameters:
key - the connector key.
adapt - the persister adaptee.
princ - the principal.
ref - the persister factory.
Throws:
NullPointerException - if key is null.
Method Detail

getConnectionKey

public String getConnectionKey()
Description copied from interface: Persister
Gets the connection key bound to this persister.

Specified by:
getConnectionKey in interface Persister
Returns:
the connection key.

getAdaptee

public Object getAdaptee()
Description copied from interface: Persister
Gets the implementation specific persister adaptee, if any.

Specified by:
getAdaptee in interface Persister
Returns:
the adaptee or null.

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

isClosed

public boolean isClosed()
Description copied from interface: Persister
Checks whether this persister is closed.

Specified by:
isClosed in interface Persister
Returns:
true if closed, otherwise false.

clearCache

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

Specified by:
clearCache in interface Persister

removeFromCache

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

Specified by:
removeFromCache in interface Persister
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
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
Parameters:
object - the object.
name - the reference attribute.
force - force the refresh if true, otherwise false.

getKeyAttribute

public String getKeyAttribute(Class clazz)
Description copied from interface: Persister
Gets the primary key attribute of the specified class.

Specified by:
getKeyAttribute in interface Persister
Parameters:
clazz - the class.
Returns:
the primary key attribute or null.

getKeyAttribute

public String getKeyAttribute(String className)
Description copied from interface: Persister
Gets the primary key attribute of the named class.

Specified by:
getKeyAttribute in interface Persister
Parameters:
className - the class name.
Returns:
the primary key attribute or null.

getKeyAttributes

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

Specified by:
getKeyAttributes in interface Persister
Parameters:
clazz - the class.
Returns:
the primary key attributes or null.

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
Parameters:
className - the class name.
Returns:
the primary key attributes or null.

isPersistentAttribute

public boolean isPersistentAttribute(Class clazz,
                                     String field)
Description copied from interface: Persister
Checks whether an attribute of the specified class is persistent.

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

isPersistentAttribute

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

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

buildQuery

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

Specified by:
buildQuery in interface Persister
Parameters:
className - the class name to query.
expr - the query expression.
sql - the SQL flag.
Returns:
the corresponding query.

buildQuery

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

Specified by:
buildQuery in interface Persister
Parameters:
className - the class name to query.
criteria - an implementation specific criteria.
distinct - a flag to indicate a distinct query.
Returns:
the corresponding query.

buildQuery

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

Specified by:
buildQuery in interface Persister
Parameters:
className - the class name to query.
attributes - the attributes to return.
criteria - in implementation specific criteria.
distinct - a flag to indicate a distinct query.
Returns:
the corresponding query.

queryBySample

public Object queryBySample(Object identity)
                     throws PersisterException
Description copied from interface: Persister
Queries an object by its properties or identity.

Specified by:
queryBySample in interface Persister
Parameters:
identity - the sample object of identity.
Returns:
the found object or null.
Throws:
PersisterException - on errors.

queryObject

public Object queryObject(Class clazz,
                          Object value)
                   throws PersisterException
Description copied from interface: Persister
Queries an object of the specified class.

Specified by:
queryObject in interface Persister
Parameters:
clazz - the class to query.
value - the PK of the object.
Returns:
the found object or null.
Throws:
PersisterException - on errors.

queryObject

public Object queryObject(String className,
                          Object value)
                   throws PersisterException
Description copied from interface: Persister
Queries an object of the named class.

Specified by:
queryObject in interface Persister
Parameters:
className - the class name to query.
value - the PK of the object.
Returns:
the found object or null.
Throws:
PersisterException - on errors.

queryObject

public Object queryObject(Class clazz,
                          String attribute,
                          Object value)
                   throws PersisterException
Description copied from interface: Persister
Queries an object of the specified class with the named attribute.

Specified by:
queryObject in interface Persister
Parameters:
clazz - the class to query.
attribute - the name of the attribute.
value - the value of the attribute.
Returns:
the found object or null.
Throws:
PersisterException - on errors.

queryObject

public Object queryObject(String className,
                          String attribute,
                          Object value)
                   throws PersisterException
Description copied from interface: Persister
Queries an object of the named class with the named attribute.

Specified by:
queryObject in interface Persister
Parameters:
className - the class name to query.
attribute - the name of the attribute.
value - the value of the attribute.
Returns:
the found object or null.
Throws:
PersisterException - on errors.

queryObjects

public Collection queryObjects(Class clazz,
                               DBCriteria criteria)
                        throws PersisterException
Description copied from interface: Persister
Queries objects of the specified criteria and class.

Specified by:
queryObjects in interface Persister
Parameters:
clazz - the class to query.
criteria - the criteria to apply.
Returns:
a collection of objects.
Throws:
PersisterException - on errors.

queryObjects

public Collection queryObjects(String className,
                               DBCriteria criteria)
                        throws PersisterException
Description copied from interface: Persister
Queries objects of the specified criteria and named class.

Specified by:
queryObjects in interface Persister
Parameters:
className - the class name to query.
criteria - the criteria to apply.
Returns:
a collection of objects.
Throws:
PersisterException - on errors.

queryObjects

public Collection queryObjects(Class clazz,
                               String attribute,
                               Object value,
                               int condition)
                        throws PersisterException
Description copied from interface: Persister
Queries objects of the specified class.

Specified by:
queryObjects in interface Persister
Parameters:
clazz - the class to query.
attribute - the name of the attribute.
value - the value of the attribute.
condition - the condition for the criteria.
Returns:
a collection of objects.
Throws:
PersisterException - on errors.

queryObjects

public Collection queryObjects(String className,
                               String attribute,
                               Object value,
                               int condition)
                        throws PersisterException
Description copied from interface: Persister
Queries objects of the named class.

Specified by:
queryObjects in interface Persister
Parameters:
className - the class name to query.
attribute - the name of the attribute.
value - the value of the attribute.
condition - the condition for the criteria.
Returns:
a collection of objects.
Throws:
PersisterException - on errors.

queryIterator

public QueryIterator queryIterator(Class clazz,
                                   DBCriteria criteria)
                            throws PersisterException
Description copied from interface: Persister
Queries an iterator to a collection of objects of the specified criteria and class.

Specified by:
queryIterator in interface Persister
Parameters:
clazz - the class to query.
criteria - the criteria to apply.
Returns:
a collection of objects.
Throws:
PersisterException - on errors.

queryIterator

public QueryIterator queryIterator(String className,
                                   DBCriteria criteria)
                            throws PersisterException
Description copied from interface: Persister
Queries an iterator to a collection of objects of the specified criteria and named class.

Specified by:
queryIterator in interface Persister
Parameters:
className - the class name to query.
criteria - the criteria to apply.
Returns:
a collection of objects.
Throws:
PersisterException - on errors.

queryIterator

public QueryIterator queryIterator(Class clazz,
                                   String attribute,
                                   Object value,
                                   int condition)
                            throws PersisterException
Description copied from interface: Persister
Queries an iterator to a collection of objects of the specified class.

Specified by:
queryIterator in interface Persister
Parameters:
clazz - the class to query.
attribute - the name of the attribute.
value - the value of the attribute.
condition - the condition for the criteria.
Returns:
a collection of objects.
Throws:
PersisterException - on errors.

queryIterator

public QueryIterator queryIterator(String className,
                                   String attribute,
                                   Object value,
                                   int condition)
                            throws PersisterException
Description copied from interface: Persister
Queries an iterator to a collection of objects of the named class.

Specified by:
queryIterator in interface Persister
Parameters:
className - the class name to query.
attribute - the name of the attribute.
value - the value of the attribute.
condition - the condition for the criterion attribute.
Returns:
a collection of objects.
Throws:
PersisterException - on errors.

queryCount

public int queryCount(Class clazz,
                      DBCriteria criteria)
Description copied from interface: Persister
Queries the count of objects of the specified criteria and class.

Specified by:
queryCount in interface Persister
Parameters:
clazz - the class to query.
criteria - the criteria to apply.
Returns:
a collection of objects.

queryCount

public int queryCount(String className,
                      DBCriteria criteria)
Description copied from interface: Persister
Queries the count of objects of the specified criteria and named class.

Specified by:
queryCount in interface Persister
Parameters:
className - the class name to query.
criteria - the criteria to apply.
Returns:
a collection of objects.

queryCount

public int queryCount(Class clazz,
                      String attribute,
                      Object value,
                      int condition)
Description copied from interface: Persister
Queries the count of objects of the specified class.

Specified by:
queryCount in interface Persister
Parameters:
clazz - the class to query.
attribute - the name of the attribute.
value - the value of the attribute.
condition - the condition for the criteria.
Returns:
the count of objects or -1 if the query fails.

queryCount

public int queryCount(String className,
                      String attribute,
                      Object value,
                      int condition)
Description copied from interface: Persister
Queries the count of objects of the named class.

Specified by:
queryCount in interface Persister
Parameters:
className - the class name to query.
attribute - the name of the attribute.
value - the value of the attribute.
condition - the condition for the criterion attribute.
Returns:
the count of objects or -1 if the query fails.

deleteObjects

public void deleteObjects(Class clazz,
                          DBCriteria criteria)
                   throws PersisterException
Description copied from interface: Persister
Deletes objects of the specified criteria and class as one transaction.

Specified by:
deleteObjects in interface Persister
Parameters:
clazz - the class to query.
criteria - the criteria to apply.
Throws:
PersisterException - on errors.

deleteObjects

public void deleteObjects(String className,
                          DBCriteria criteria)
                   throws PersisterException
Description copied from interface: Persister
Deletes objects of the specified criteria and named class as one transaction.

Specified by:
deleteObjects in interface Persister
Parameters:
className - the class name to query.
criteria - the criteria to apply.
Throws:
PersisterException - on errors.

deleteObjects

public void deleteObjects(Class clazz,
                          String attribute,
                          Object value,
                          int condition)
                   throws PersisterException
Description copied from interface: Persister
Deletes objects of the specified class from the repository as one transaction.

Specified by:
deleteObjects in interface Persister
Parameters:
clazz - the class to delete.
attribute - the name of the attribute.
value - the value of the attribute.
condition - the condition for the criteria.
Throws:
PersisterException - on errors.

deleteObjects

public void deleteObjects(String className,
                          String attribute,
                          Object value,
                          int condition)
                   throws PersisterException
Description copied from interface: Persister
Deletes objects of the named class from the repository as one transaction.

Specified by:
deleteObjects in interface Persister
Parameters:
className - the class name to delete.
attribute - the name of the attribute.
value - the value of the attribute.
condition - the condition for the criteria.
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
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
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

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

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

getRepository

public String getRepository(String className)
Description copied from interface: Persister
Gets the name of the repository of the named class.

Specified by:
getRepository in interface Persister
Parameters:
className - the class name.
Returns:
the name of the repository or null.

load

public Collection load(File file)
                throws PersisterException
Description copied from interface: Persister
Loads objects from a dump file if this persister supports files.

Specified by:
load in interface Persister
Parameters:
file - the dump file.
Returns:
a collection of loaded objects.
Throws:
PersisterException - for loading errors.

dump

public void dump(Collection objects,
                 File file)
          throws PersisterException
Description copied from interface: Persister
Dumps a objects into a dump file if this persister supports files.

Specified by:
dump in interface Persister
Parameters:
objects - a collection of objects to dump.
file - the dump file.
Throws:
PersisterException - for dumping errors.

getLocale

public Locale getLocale()
Description copied from interface: Persister
Gets the locale of this persister.

Specified by:
getLocale in interface Persister
Returns:
the locale or the default.

setLocale

public void setLocale(Locale loc)
Description copied from interface: Persister
Sets the locale of this persister.

Specified by:
setLocale in interface Persister
Parameters:
loc - the locale.

getPrincipal

public Principal getPrincipal()
Description copied from interface: Persister
Gets the principal of this persister.

Specified by:
getPrincipal in interface Persister
Returns:
the principal or null.

getMBeanServer

public MBeanServer getMBeanServer()
Description copied from interface: Persister
Gets the MBean server of this persister.

Specified by:
getMBeanServer in interface Persister
Returns:
the MBean server.

getPersisterFactory

protected PersisterFactory getPersisterFactory()
Gets the persister factory.

Returns:
the persister factory.

getMBeanReferent

protected Object getMBeanReferent(Object object)
Gets the referent of an MBean reference.

Parameters:
object - the reference.
Returns:
the found referent.

modified

protected void modified()
Notifies the persister factory about modifications.


toClass

protected Class toClass(String className)
                 throws ClassNotFoundException
Returns the class instance of the named class.

Parameters:
className - the class name to load.
Returns:
the loaded class.
Throws:
ClassNotFoundException - if the loading fails.


Copyright © 2004 The Norther Organiz