org.norther.tammi.root.ojb
Class OJBPersister

java.lang.Object
  extended by org.norther.tammi.root.db.PersisterAdapter<PersistenceBroker>
      extended by org.norther.tammi.root.ojb.OJBPersister
All Implemented Interfaces:
Cloneable, Traceable, Persister

public class OJBPersister
extends PersisterAdapter<PersistenceBroker>

OJB specific implementation of Persister.

Version:
$Id: OJBPersister.java,v 1.93 2010-05-25 06:53:51 cvsimp Exp $
Author:
Ilkka Priha

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.norther.tammi.root.db.Persister
Persister.Action, Persister.Script
 
Field Summary
 
Fields inherited from class org.norther.tammi.root.db.PersisterAdapter
factory
 
Constructor Summary
OJBPersister(String alias, String provider, PersistenceBroker pb, Principal principal, MBeanReference<OJBFactory> pbf)
          Constructs a new persister.
 
Method Summary
 boolean abortTransaction()
          Aborts a transaction to cancel updates to the repository.
 boolean beginTransaction()
          Begins a transaction to start updates in the repository.
<T> DBQuery<T>
buildQuery(Class<T> clazz, String expr, Persister.Script type)
          Builds a query to a query language expression for the specified class.
 DBQuery<Object[]> buildQuery(DBCriteria<?> criteria, String[] attributes, boolean distinct, Object... clazz)
          Builds a query to a specified criteria returning only selected attributes.
<T> DBQuery<T>
buildQuery(DBCriteria<T> criteria, boolean distinct, Object... clazz)
          Builds a query to a specified criteria.
<T> DBQuery<T>
buildQuery(Object sample, DBCriteria<?>... criteria)
          Builds a query to a sample object, an identity or a specific class.
 void clearCache()
          Clears the cache associated to this persister, if any.
 Object clone()
          Returns a clone.
 void close()
          Closes the connection to the repository.
 boolean commitTransaction()
          Commits a transaction to complete updates in the repository.
<T> DBCriteria<T>
createCriteria(Class<T> clazz)
          Creates implementation specific query criteria for the specified class.
 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.
 void execute(String sql)
          Executes an SQL statement.
 void execute(String[] sql)
          Executes SQL statements as a batch.
 String[] getIdentityAttributes(Object sample, String... classNames)
          Gets the identity attributes of the specified sample object.
 String[] getPersistentAttributes(Object sample, String... classNames)
          Gets the persistent attributes of the specified sample object.
 String getPersistentColumn(Object sample, String attribute, String... classNames)
          Gets the persistent column of an attribute of the specified sample object.
 String getPersistentTable(Object sample, String... classNames)
          Gets the persistent table of the specified sample object.
 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.
protected  boolean isAutoIncrementalAttribute(String className, String field)
          Checks whether the specified field if auto incremental.
 boolean isInTransaction()
          Checks whether this persister is performing a transaction.
protected  boolean isMandatoryAttribute(String className, String field)
          Checks whether the specified field if mandatory.
 boolean isRelationAttribute(Object sample, String attribute, String... classNames)
          Checks whether an attribute of the specified sample object is relative.
 boolean isTransactionsSupported()
          Checks whether this persister implementation supports transactions.
 int queryCount(DBQuery<?> query)
          Queries the count of objects the given query would return.
<T> QueryIterator<T>
queryIterator(DBQuery<T> query)
          Queries an iterator to a collection of objects.
<T> T
queryObject(DBQuery<T> query)
          Queries an object.
<T> Collection<T>
queryObjects(DBQuery<T> query)
          Queries objects.
 boolean refreshLocators(Object object, String... classNames)
          Refreshes locators of the specified object.
 boolean refreshReference(Object object, String reference, String... classNames)
          Refreshes a named reference of the specified object.
 boolean refreshReferences(Object object, String... classNames)
          Refreshes references of the specified object.
 void removeFromCache(Object object)
          Removes the specified object from the cache.
 void retrieveReference(Object object, String reference, String... classNames)
          Retrieves a named reference of the specified object.
 void retrieveReferences(Object object, String... classNames)
          Retrieves references of the specified object.
 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.
 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
addTraceListener, buildQuery, clearLastModified, clearTraceListeners, createCriteria, deleteObjects, deleteObjects, deleteObjects, deleteObjects, deleteObjects, deleteReferences, dump, exists, exportReferences, getAttributeValue, getAttributeValues, getConnectionAlias, getGroupId, getIdentityAttribute, getIdentityValue, getIdentityValues, getLastModified, getLastModified, getLocale, getMBeanReferent, getMBeanServer, getObject, getPersister, getPersisterFactory, getPrincipal, getProviderAlias, getReferenceValue, getReferenceValues, getRootGroupId, getUserId, getValidatedValue, importReferences, insertReferences, isClosed, isGloballyStaleReference, isGloballyStaleReferences, isLocallyStaleReference, isLocallyStaleReferences, isPersistentAttribute, isPersistentClass, isPersistentObject, load, mergeObject, mergeReferences, mergeReferences, modified, persisted, queryBySample, queryCount, queryCount, queryCount, queryCount, queryCount, queryIterator, queryIterator, queryIterator, queryIterator, queryIterator, queryObject, queryObject, queryObject, queryObject, queryObject, queryObjects, queryObjects, queryObjects, queryObjects, queryObjects, removeTraceListener, resetIdentityValues, setAttributeValue, setIdentityValue, setIdentityValues, setLastModified, setLocale, setValidatedValue, storeReferences, toClass, updateReferences
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OJBPersister

public OJBPersister(String alias,
                    String provider,
                    PersistenceBroker pb,
                    Principal principal,
                    MBeanReference<OJBFactory> pbf)
Constructs a new persister.

Parameters:
alias - the connection alias.
provider - the provider alias.
pb - the persistence broker.
principal - the principal.
pbf - the persister factory.
Method Detail

clone

public Object clone()
Description copied from interface: Persister
Returns a clone.

Specified by:
clone in interface Persister
Overrides:
clone in class PersisterAdapter<PersistenceBroker>
Returns:
a copy of this persister.

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<PersistenceBroker>

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<PersistenceBroker>

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<PersistenceBroker>
Parameters:
object - the object.

retrieveReferences

public void retrieveReferences(Object object,
                               String... classNames)
Description copied from interface: Persister
Retrieves references of the specified object.

Note that if dependent class names are not given, only the current class of the object is considered as a dependent class.

Parameters:
object - the object.
classNames - dependent class names.

retrieveReference

public void retrieveReference(Object object,
                              String reference,
                              String... classNames)
Description copied from interface: Persister
Retrieves a named reference of the specified object.

Note that if dependent class names are not given, only the current class of the object is considered as a dependent class.

Parameters:
object - the object.
reference - the reference attribute.
classNames - dependent class names.

refreshReferences

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

Note that if dependent class names are not given, only the current class of the object is considered as a dependent class.

Specified by:
refreshReferences in interface Persister
Overrides:
refreshReferences in class PersisterAdapter<PersistenceBroker>
Parameters:
object - the object.
classNames - dependent class names.
Returns:
true if refreshed, false otherwise.

refreshReference

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

Note that if dependent class names are not given, only the current class of the object is considered as a dependent class.

Specified by:
refreshReference in interface Persister
Overrides:
refreshReference in class PersisterAdapter<PersistenceBroker>
Parameters:
object - the object.
reference - the reference attribute.
classNames - dependent class names.
Returns:
true if refreshed, false otherwise.

refreshLocators

public boolean refreshLocators(Object object,
                               String... classNames)
Description copied from interface: Persister
Refreshes locators of the specified object.

Note that if dependent class names are not given, only the current class of the object is considered as a dependent class.

Parameters:
object - the object.
classNames - dependent class names.
Returns:
true if refreshed, false otherwise.

getIdentityAttributes

public String[] getIdentityAttributes(Object sample,
                                      String... classNames)
Description copied from interface: Persister
Gets the identity attributes of the specified sample object.

Parameters:
sample - the sample object.
classNames - the dependent class names.
Returns:
the identity attributes or null.

getPersistentAttributes

public String[] getPersistentAttributes(Object sample,
                                        String... classNames)
Description copied from interface: Persister
Gets the persistent attributes of the specified sample object.

Parameters:
sample - the sample object.
classNames - the dependent class names.
Returns:
the attributes or null.

isRelationAttribute

public boolean isRelationAttribute(Object sample,
                                   String attribute,
                                   String... classNames)
Description copied from interface: Persister
Checks whether an attribute of the specified sample object is relative.

Parameters:
sample - the sample object.
attribute - the field.
classNames - the dependent class names.
Returns:
true for a relation attribute, false otherwise.

getPersistentTable

public String getPersistentTable(Object sample,
                                 String... classNames)
Description copied from interface: Persister
Gets the persistent table of the specified sample object.

Parameters:
sample - the sample object.
classNames - the dependent class names.
Returns:
the persistent table or null.

getPersistentColumn

public String getPersistentColumn(Object sample,
                                  String attribute,
                                  String... classNames)
Description copied from interface: Persister
Gets the persistent column of an attribute of the specified sample object.

Parameters:
sample - the sample object.
attribute - the field.
classNames - the dependent class names.
Returns:
the persistent column or null.

createCriteria

public <T> DBCriteria<T> createCriteria(Class<T> clazz)
Description copied from interface: Persister
Creates implementation specific query criteria for the specified class.

Type Parameters:
T - the criteria type.
Parameters:
clazz - the class type.
Returns:
empty criteria.

buildQuery

public <T> DBQuery<T> buildQuery(Object sample,
                                 DBCriteria<?>... criteria)
Description copied from interface: Persister
Builds a query to a sample object, an identity or a specific class. The query type is on caller's response.

Type Parameters:
T - the query type.
Parameters:
sample - the sample, identity or class.
criteria - optional criteria.
Returns:
the corresponding query.

buildQuery

public <T> DBQuery<T> buildQuery(Class<T> clazz,
                                 String expr,
                                 Persister.Script type)
Description copied from interface: Persister
Builds a query to a query language expression for the specified class.

Type Parameters:
T - the class type.
Parameters:
clazz - the class to query.
expr - the query expression.
type - the query type.
Returns:
the corresponding query.

buildQuery

public <T> DBQuery<T> buildQuery(DBCriteria<T> criteria,
                                 boolean distinct,
                                 Object... clazz)
Description copied from interface: Persister
Builds a query to a specified criteria.

Note that the signature must differ from that of a sample query to avoid conflicts.

Type Parameters:
T - the class type.
Parameters:
criteria - an implementation specific criteria.
distinct - true for a distinct query, false otherwise.
clazz - an alternate class or class name.
Returns:
the corresponding query.

buildQuery

public DBQuery<Object[]> buildQuery(DBCriteria<?> criteria,
                                    String[] attributes,
                                    boolean distinct,
                                    Object... clazz)
Description copied from interface: Persister
Builds a query to a specified criteria returning only selected attributes.

Parameters:
criteria - in implementation specific criteria.
attributes - the attributes to return.
distinct - true for a distinct query, false otherwise.
clazz - an alternate class or class name.
Returns:
the corresponding query.

queryObject

public <T> T queryObject(DBQuery<T> query)
              throws PersistenceException
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.

Type Parameters:
T - the query type.
Parameters:
query - the query.
Returns:
the found object or null.
Throws:
PersistenceException - on errors.

queryObjects

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

Type Parameters:
T - the query type.
Parameters:
query - the query.
Returns:
a collection of objects.
Throws:
PersistenceException - on errors.

queryIterator

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

Type Parameters:
T - the query type.
Parameters:
query - the query.
Returns:
an iterator to a collection of objects.
Throws:
PersistenceException - 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 PersistenceException
Description copied from interface: Persister
Stores an object to the repository.

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

storeObjects

public void storeObjects(Collection<?> objects)
                  throws PersistenceException
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:
PersistenceException - on errors.

insertObject

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

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

insertObjects

public void insertObjects(Collection<?> objects)
                   throws PersistenceException
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:
PersistenceException - on errors.

updateObject

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

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

updateObjects

public void updateObjects(Collection<?> objects)
                   throws PersistenceException
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:
PersistenceException - on errors.

deleteObject

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

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

deleteObjects

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

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

deleteObjects

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

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

execute

public void execute(String sql)
             throws PersistenceException
Description copied from interface: Persister
Executes an SQL statement.

Note that open transactions may be committed as a side effect.

Parameters:
sql - the statement.
Throws:
PersistenceException - on errors.

execute

public void execute(String[] sql)
             throws PersistenceException
Description copied from interface: Persister
Executes SQL statements as a batch.

Note that open transactions may be committed as a side effect.

Parameters:
sql - the statements.
Throws:
PersistenceException - 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<PersistenceBroker>
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<PersistenceBroker>
Returns:
true if in transaction, otherwise false.

beginTransaction

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

Nop if transactions are not supported.

Specified by:
beginTransaction in interface Persister
Overrides:
beginTransaction in class PersisterAdapter<PersistenceBroker>
Returns:
true if a new transaction is started, false if an existing transaction was already open.

abortTransaction

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

Nop if transactions are not supported.

Specified by:
abortTransaction in interface Persister
Overrides:
abortTransaction in class PersisterAdapter<PersistenceBroker>
Returns:
true if a transaction is aborted, false if no transaction was open to be aborted.

commitTransaction

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

Nop if transactions are not supported.

Specified by:
commitTransaction in interface Persister
Overrides:
commitTransaction in class PersisterAdapter<PersistenceBroker>
Returns:
true if a transaction is commited, false if no transaction was open to be committed.

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
Overrides:
getRepository in class PersisterAdapter<PersistenceBroker>
Parameters:
className - the class name.
Returns:
the name of the repository or null.

isMandatoryAttribute

protected boolean isMandatoryAttribute(String className,
                                       String field)
Description copied from class: PersisterAdapter
Checks whether the specified field if mandatory.

Specified by:
isMandatoryAttribute in class PersisterAdapter<PersistenceBroker>
Parameters:
className - the class name.
field - the field name.
Returns:
true if mandatory, false otherwise.

isAutoIncrementalAttribute

protected boolean isAutoIncrementalAttribute(String className,
                                             String field)
Description copied from class: PersisterAdapter
Checks whether the specified field if auto incremental.

Specified by:
isAutoIncrementalAttribute in class PersisterAdapter<PersistenceBroker>
Parameters:
className - the class name.
field - the field name.
Returns:
true if auto incremental, false otherwise.


Copyright © 2004 The Norther Organization. All rights reserved.