org.norther.tammi.root.db
Interface Persister

All Known Implementing Classes:
HibernatePersister, OJBPersister, PersisterAdapter, XMLPersister

public interface Persister

An interface to classes providing access to the persistent layer.

Author:
Marketta Priha

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.
 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 deleteObject(Object object)
          Deletes an object from 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(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.
 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.
 DBCriteria getCriteria()
          Gets implementation specific criteria.
 DBCriteria getCriteria(Object criteria)
          Gets initialized implementation specific criteria.
 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.
 MBeanServer getMBeanServer()
          Gets the MBean server of this persister.
 Principal getPrincipal()
          Gets the principal of this persister.
 String getRepository(String className)
          Gets the name of the repository 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 isClosed()
          Checks whether this persister is closed.
 boolean isInTransaction()
          Checks whether this persister is performing a transaction.
 boolean isPersistentAttribute(Class clazz, String attribute)
          Checks whether an attribute of the specified class is persistent.
 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.
 Collection load(File file)
          Loads objects from a dump file if this persister supports files.
 Object queryBySample(Object sample)
          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(DBQuery query)
          Queries the count of objects the given query would return.
 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(DBQuery query)
          Queries an iterator to a collection of objects.
 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(DBQuery query)
          Queries an object.
 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(DBQuery query)
          Queries objects.
 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.
 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.
 

Method Detail

getConnectionKey

String getConnectionKey()
Gets the connection key bound to this persister.

Returns:
the connection key.

getAdaptee

Object getAdaptee()
Gets the implementation specific persister adaptee, if any.

Returns:
the adaptee or null.

close

void close()
Closes the connection to the repository. The persister should not be referred to after closing.


isClosed

boolean isClosed()
Checks whether this persister is closed.

Returns:
true if closed, otherwise false.

clearCache

void clearCache()
Clears the cache associated to this persister, if any.


removeFromCache

void removeFromCache(Object object)
Removes the specified object from the cache.

Parameters:
object - the object.

refreshReferences

void refreshReferences(Object object,
                       boolean force)
Refreshes references of the specified object.

Parameters:
object - the object.
force - force the refresh if true, otherwise false.

refreshReference

void refreshReference(Object object,
                      String name,
                      boolean force)
Refreshes a named reference of the specified object.

Parameters:
object - the object.
name - the reference attribute.
force - force the refresh if true, otherwise false.

toIdentity

Object toIdentity(Object sample)
Returns an implementation specific object representing the identity of the specified sample object.

Parameters:
sample - the sample object.
Returns:
the identity object.
Throws:
UnsupportedOperationException - if the sample can't be identified.

getKeyAttribute

String getKeyAttribute(Class clazz)
Gets the primary key attribute of the specified class.

Parameters:
clazz - the class.
Returns:
the primary key attribute or null.

getKeyAttribute

String getKeyAttribute(String className)
Gets the primary key attribute of the named class.

Parameters:
className - the class name.
Returns:
the primary key attribute or null.

getKeyAttributes

String[] getKeyAttributes(Class clazz)
Gets the primary key attributes of the specified class.

Parameters:
clazz - the class.
Returns:
the primary key attributes or null.

getKeyAttributes

String[] getKeyAttributes(String className)
Gets the primary key attributes of the named class.

Parameters:
className - the class name.
Returns:
the primary key attributes or null.

isPersistentAttribute

boolean isPersistentAttribute(Class clazz,
                              String attribute)
Checks whether an attribute of the specified class is persistent.

Parameters:
clazz - the class.
attribute - the field.
Returns:
true for a persistent attribute, false otherwise.

isPersistentAttribute

boolean isPersistentAttribute(String className,
                              String attribute)
Checks whether an attribute of the named class is persistent.

Parameters:
className - the class name.
attribute - the field.
Returns:
true for a persistent attribute, false otherwise.

getCriteria

DBCriteria getCriteria()
Gets implementation specific criteria.

Returns:
ampty criteria.

getCriteria

DBCriteria getCriteria(Object criteria)
Gets initialized implementation specific criteria.

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

buildQuery

DBQuery buildQuery(Object sample)
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

DBQuery buildQuery(Class clazz,
                   String expr,
                   boolean sql)
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

DBQuery buildQuery(String className,
                   String expr,
                   boolean sql)
Builds a query to a query language expression for the named class.

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

buildQuery

DBQuery buildQuery(Class clazz,
                   DBCriteria criteria,
                   boolean distinct)
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

DBQuery buildQuery(String className,
                   DBCriteria criteria,
                   boolean distinct)
Builds a query to a specified criteria for the named class.

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

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.

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.

buildQuery

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.

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

Object queryBySample(Object sample)
                     throws PersisterException
Queries an object by its properties or identity.

Parameters:
sample - the sample object of identity.
Returns:
the found object or null.
Throws:
PersisterException - on errors.

queryObject

Object queryObject(DBQuery query)
                   throws PersisterException
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.

queryObject

Object queryObject(Class clazz,
                   Object value)
                   throws PersisterException
Queries an object of the specified class.

Parameters:
clazz - the class to query.
value - the PK of the object.
Returns:
the found object or null.
Throws:
PersisterException - on errors.

queryObject

Object queryObject(String className,
                   Object value)
                   throws PersisterException
Queries an object of the named class.

Parameters:
className - the class name to query.
value - the PK of the object.
Returns:
the found object or null.
Throws:
PersisterException - on errors.

queryObject

Object queryObject(Class clazz,
                   String attribute,
                   Object value)
                   throws PersisterException
Queries an object of the specified class with the named attribute.

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

Object queryObject(String className,
                   String attribute,
                   Object value)
                   throws PersisterException
Queries an object of the named class with the named attribute.

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

Collection queryObjects(DBQuery query)
                        throws PersisterException
Queries objects. All matchings objects are returned.

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

queryObjects

Collection queryObjects(Class clazz,
                        DBCriteria criteria)
                        throws PersisterException
Queries objects of the specified criteria and class.

Parameters:
clazz - the class to query.
criteria - the criteria to apply.
Returns:
a collection of objects.
Throws:
PersisterException - on errors.

queryObjects

Collection queryObjects(String className,
                        DBCriteria criteria)
                        throws PersisterException
Queries objects of the specified criteria and named class.

Parameters:
className - the class name to query.
criteria - the criteria to apply.
Returns:
a collection of objects.
Throws:
PersisterException - on errors.

queryObjects

Collection queryObjects(Class clazz,
                        String attribute,
                        Object value,
                        int condition)
                        throws PersisterException
Queries objects of the specified class.

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

Collection queryObjects(String className,
                        String attribute,
                        Object value,
                        int condition)
                        throws PersisterException
Queries objects of the named class.

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

QueryIterator queryIterator(DBQuery query)
                            throws PersisterException
Queries an iterator to a collection of objects.

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

queryIterator

QueryIterator queryIterator(Class clazz,
                            DBCriteria criteria)
                            throws PersisterException
Queries an iterator to a collection of objects of the specified criteria and class.

Parameters:
clazz - the class to query.
criteria - the criteria to apply.
Returns:
a collection of objects.
Throws:
PersisterException - on errors.

queryIterator

QueryIterator queryIterator(String className,
                            DBCriteria criteria)
                            throws PersisterException
Queries an iterator to a collection of objects of the specified criteria and named class.

Parameters:
className - the class name to query.
criteria - the criteria to apply.
Returns:
a collection of objects.
Throws:
PersisterException - on errors.

queryIterator

QueryIterator queryIterator(Class clazz,
                            String attribute,
                            Object value,
                            int condition)
                            throws PersisterException
Queries an iterator to a collection of objects of the specified class.

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

QueryIterator queryIterator(String className,
                            String attribute,
                            Object value,
                            int condition)
                            throws PersisterException
Queries an iterator to a collection of objects of the named class.

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

int queryCount(DBQuery query)
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.

queryCount

int queryCount(Class clazz,
               DBCriteria criteria)
               throws PersisterException
Queries the count of objects of the specified criteria and class.

Parameters:
clazz - the class to query.
criteria - the criteria to apply.
Returns:
a collection of objects.
Throws:
PersisterException - on errors.

queryCount

int queryCount(String className,
               DBCriteria criteria)
               throws PersisterException
Queries the count of objects of the specified criteria and named class.

Parameters:
className - the class name to query.
criteria - the criteria to apply.
Returns:
a collection of objects.
Throws:
PersisterException - on errors.

queryCount

int queryCount(Class clazz,
               String attribute,
               Object value,
               int condition)
Queries the count of objects of the specified class.

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

int queryCount(String className,
               String attribute,
               Object value,
               int condition)
Queries the count of objects of the named class.

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.

storeObject

void storeObject(Object object)
                 throws PersisterException
Stores an object to the repository.

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

storeObjects

void storeObjects(Collection objects)
                  throws PersisterException
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

void insertObject(Object object)
                  throws PersisterException
Inserts an object to the repository.

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

insertObjects

void insertObjects(Collection objects)
                   throws PersisterException
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

void updateObject(Object object)
                  throws PersisterException
Updates an object in the repository.

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

updateObjects

void updateObjects(Collection objects)
                   throws PersisterException
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

void deleteObject(Object object)
                  throws PersisterException
Deletes an object from the repository.

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

deleteObjects

void deleteObjects(Collection objects)
                   throws PersisterException
Deletes a collection of objects from the repository as one transaction.

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

deleteObjects

void deleteObjects(DBQuery query)
                   throws PersisterException
Deletes query objects from the repository as one transaction.

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

deleteObjects

void deleteObjects(Class clazz,
                   DBCriteria criteria)
                   throws PersisterException
Deletes objects of the specified criteria and class as one transaction.

Parameters:
clazz - the class to query.
criteria - the criteria to apply.
Throws:
PersisterException - on errors.

deleteObjects

void deleteObjects(String className,
                   DBCriteria criteria)
                   throws PersisterException
Deletes objects of the specified criteria and named class as one transaction.

Parameters:
className - the class name to query.
criteria - the criteria to apply.
Throws:
PersisterException - on errors.

deleteObjects

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

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

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

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

boolean isTransactionsSupported()
Checks whether this persister implementation supports transactions.

Returns:
true if transactions are supported, otherwise false.

isInTransaction

boolean isInTransaction()
Checks whether this persister is performing a transaction.

Returns:
true if in transaction, otherwise false.

beginTransaction

void beginTransaction()
Begins a transaction to start updates in the repository.

No-op if transactions are not supported.


abortTransaction

void abortTransaction()
Aborts a transaction to cancel updates to the repository.

No-op if transactions are not supported.


commitTransaction

void commitTransaction()
Commits a transaction to complete updates in the repository.

No-op if transactions are not supported.


getRepository

String getRepository(String className)
Gets the name of the repository of the named class.

Parameters:
className - the class name.
Returns:
the name of the repository or null.

load

Collection load(File file)
                throws PersisterException
Loads objects from a dump file if this persister supports files.

Parameters:
file - the dump file.
Returns:
a collection of loaded objects.
Throws:
PersisterException - for loading errors.
UnsupportedOperationException - if not supported.

dump

void dump(Collection objects,
          File file)
          throws PersisterException
Dumps a objects into a dump file if this persister supports files.

Parameters:
objects - a collection of objects to dump.
file - the dump file.
Throws:
PersisterException - for dumping errors.
UnsupportedOperationException - if not supported.

getLocale

Locale getLocale()
Gets the locale of this persister.

Returns:
the locale or the default.

setLocale

void setLocale(Locale loc)
Sets the locale of this persister.

Parameters:
loc - the locale.

getPrincipal

Principal getPrincipal()
Gets the principal of this persister.

Returns:
the principal or null.

getMBeanServer

MBeanServer getMBeanServer()
Gets the MBean server of this persister.

Returns:
the MBean server.


Copyright © 2004 The Norther Organization. All rights reserved.