org.springframework.orm.toplink
Class TopLinkTemplate

java.lang.Object
  extended by org.springframework.orm.toplink.TopLinkAccessor
      extended by org.springframework.orm.toplink.TopLinkTemplate
All Implemented Interfaces:
InitializingBean, TopLinkOperations

public class TopLinkTemplate
extends TopLinkAccessor
implements TopLinkOperations

Helper class that simplifies TopLink data access code, and converts TopLinkExceptions into unchecked DataAccessExceptions, following the org.springframework.dao exception hierarchy. Uses the same SQLExceptionTranslator mechanism as JdbcTemplate.

Typically used to implement data access or business logic services that use TopLink within their implementation but are TopLink-agnostic in their interface. The latter or code calling the latter only have to deal with business objects, query objects, and org.springframework.dao exceptions.

The central method is execute, supporting TopLink code implementing the TopLinkCallback interface. It provides TopLink Session handling such that neither the TopLinkCallback implementation nor the calling code needs to explicitly care about retrieving/closing TopLink Sessions, or handling Session lifecycle exceptions. For typical single step actions, there are various convenience methods (read, readAll, merge, delete, etc).

Can be used within a service implementation via direct instantiation with a SessionFactory reference, or get prepared in an application context and given to services as bean reference. Note: The SessionFactory should always be configured as bean in the application context, in the first case given to the service directly, in the second case to the prepared template.

This class can be considered as direct alternative to working with the raw TopLink Session API (through SessionFactoryUtils.getSession()). The major advantage is its automatic conversion to DataAccessExceptions, the major disadvantage that no checked application exceptions can get thrown from within data access code. Corresponding checks and the actual throwing of such exceptions can often be deferred to after callback execution, though.

Note that even if TopLinkTransactionManager is used for transaction demarcation in higher-level services, all those services above the data access layer don't need need to be TopLink-aware. Setting such a special PlatformTransactionManager is a configuration issue, without introducing code dependencies. For example, switching to JTA is just a matter of Spring configuration (use JtaTransactionManager instead) and TopLink session configuration, neither affecting application code.

LocalSessionFactoryBean is the preferred way of obtaining a reference to a specific TopLink SessionFactory. It will usually be configured to create ClientSessions for a ServerSession held by it, allowing for seamless multi-threaded execution.

Thanks to Slavik Markovich for implementing the initial TopLink support prototype!

Since:
1.2
Author:
Juergen Hoeller, James Clark
See Also:
TopLinkAccessor.setSessionFactory(org.springframework.orm.toplink.SessionFactory), TopLinkCallback, Session, TopLinkInterceptor, LocalSessionFactoryBean, TopLinkTransactionManager, JtaTransactionManager

Field Summary
 
Fields inherited from class org.springframework.orm.toplink.TopLinkAccessor
logger
 
Constructor Summary
TopLinkTemplate()
          Create a new TopLinkTemplate instance.
TopLinkTemplate(SessionFactory sessionFactory)
          Create a new TopLinkTemplate instance.
TopLinkTemplate(SessionFactory sessionFactory, boolean allowCreate)
          Create a new TopLinkTemplate instance.
 
Method Summary
 Object copy(Object entity)
          Create a detached copy of the given entity object, using TopLink's default ObjectCopyingPolicy.
 Object copy(Object entity, oracle.toplink.sessions.ObjectCopyingPolicy copyingPolicy)
          Create a detached copy of the given entity object.
 List copyAll(Collection entities)
          Create detached copies of all given entity objects, using TopLink's default ObjectCopyingPolicy.
 List copyAll(Collection entities, oracle.toplink.sessions.ObjectCopyingPolicy copyingPolicy)
          Create detached copies of all given entity objects.
 Object deepMerge(Object entity)
          Reassociate the given entity copy with the current UnitOfWork, using deep merging of all contained entities.
 void delete(Object entity)
          Delete the given entity.
 void deleteAll(Collection entities)
          Delete all given entities.
 Object execute(TopLinkCallback action)
          Execute the action specified by the given action object within a TopLink Session.
 List executeFind(TopLinkCallback action)
          Execute the specified action assuming that the result object is a Collection.
 Object executeNamedQuery(Class entityClass, String queryName)
          Execute a given named query with the given arguments.
 Object executeNamedQuery(Class entityClass, String queryName, boolean enforceReadOnly)
          Execute a given named query with the given arguments.
 Object executeNamedQuery(Class entityClass, String queryName, Object[] args)
          Execute a given named query with the given arguments.
 Object executeNamedQuery(Class entityClass, String queryName, Object[] args, boolean enforceReadOnly)
          Execute a given named query with the given arguments.
 Object executeQuery(oracle.toplink.queryframework.DatabaseQuery query)
          Execute the given query object with the given arguments.
 Object executeQuery(oracle.toplink.queryframework.DatabaseQuery query, boolean enforceReadOnly)
          Execute the given query object with the given arguments.
 Object executeQuery(oracle.toplink.queryframework.DatabaseQuery query, Object[] args)
          Execute the given query object with the given arguments.
 Object executeQuery(oracle.toplink.queryframework.DatabaseQuery query, Object[] args, boolean enforceReadOnly)
          Execute the given query object with the given arguments.
 boolean isAllowCreate()
          Return if a new Session should be created if no thread-bound found.
 Object merge(Object entity)
          Reassociate the given entity copy with the current UnitOfWork, using simple merging.
 Object mergeWithReferences(Object entity)
          Reassociate the given entity copy with the current UnitOfWork, using merging with all references from this clone.
 Object read(Class entityClass, oracle.toplink.queryframework.Call call)
          Read an entity instance of the given class, as returned by the given call.
 Object read(Class entityClass, oracle.toplink.queryframework.Call call, boolean enforceReadOnly)
          Read an entity instance of the given class, as returned by the given call.
 Object read(Class entityClass, oracle.toplink.expressions.Expression expression)
          Read an entity instance of the given class that matches the given expression.
 Object read(Class entityClass, oracle.toplink.expressions.Expression expression, boolean enforceReadOnly)
          Read an entity instance of the given class that matches the given expression.
 List readAll(Class entityClass)
          Read all entity instances of the given class.
 List readAll(Class entityClass, boolean enforceReadOnly)
          Read all entity instances of the given class.
 List readAll(Class entityClass, oracle.toplink.queryframework.Call call)
          Read all entity instances of the given class, as returned by the given call.
 List readAll(Class entityClass, oracle.toplink.queryframework.Call call, boolean enforceReadOnly)
          Read all entity instances of the given class, as returned by the given call.
 List readAll(Class entityClass, oracle.toplink.expressions.Expression expression)
          Read all entity instances of the given class that match the given expression.
 List readAll(Class entityClass, oracle.toplink.expressions.Expression expression, boolean enforceReadOnly)
          Read all entity instances of the given class that match the given expression.
 Object readAndCopy(Class entityClass, Object id)
          Read the entity instance of the given class with the given id, throwing an exception if not found.
 Object readAndCopy(Class entityClass, Object[] keys)
          Read the entity instance of the given class with the given composite id, throwing an exception if not found.
 Object readAndCopy(Class entityClass, Object[] keys, boolean enforceReadOnly)
          Read the entity instance of the given class with the given composite id, throwing an exception if not found.
 Object readAndCopy(Class entityClass, Object id, boolean enforceReadOnly)
          Read the entity instance of the given class with the given id, throwing an exception if not found.
 Object readById(Class entityClass, Object id)
          Read the entity instance of the given class with the given id, throwing an exception if not found.
 Object readById(Class entityClass, Object[] keys)
          Read the entity instance of the given class with the given composite id, throwing an exception if not found.
 Object readById(Class entityClass, Object[] keys, boolean enforceReadOnly)
          Read the entity instance of the given class with the given composite id, throwing an exception if not found.
 Object readById(Class entityClass, Object id, boolean enforceReadOnly)
          Read the entity instance of the given class with the given id, throwing an exception if not found.
 Object refresh(Object entity)
          Refresh the given entity object, returning the refreshed object.
 Object refresh(Object entity, boolean enforceReadOnly)
          Refresh the given entity object, returning the refreshed object.
 List refreshAll(Collection entities)
          Refresh the given entity objects, returning the corresponding refreshed objects.
 List refreshAll(Collection entities, boolean enforceReadOnly)
          Refresh the given entity objects, returning the corresponding refreshed objects.
 Object register(Object entity)
          Register the given (new or existing) entity with the current UnitOfWork.
 List registerAll(Collection entities)
          Register all given entities with the current UnitOfWork.
 Object registerExisting(Object entity)
          Register the given existing entity with the current UnitOfWork.
 void registerNew(Object entity)
          Register the given new entity with the current UnitOfWork.
 void setAllowCreate(boolean allowCreate)
          Set if a new Session should be created when no transactional Session can be found for the current thread.
 Object shallowMerge(Object entity)
          Reassociate the given entity copy with the current UnitOfWork, using shallow merging of the entity instance.
 
Methods inherited from class org.springframework.orm.toplink.TopLinkAccessor
afterPropertiesSet, convertJdbcAccessException, convertTopLinkAccessException, getJdbcExceptionTranslator, getSessionFactory, setJdbcExceptionTranslator, setSessionFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TopLinkTemplate

public TopLinkTemplate()
Create a new TopLinkTemplate instance.


TopLinkTemplate

public TopLinkTemplate(SessionFactory sessionFactory)
Create a new TopLinkTemplate instance.


TopLinkTemplate

public TopLinkTemplate(SessionFactory sessionFactory,
                       boolean allowCreate)
Create a new TopLinkTemplate instance.

Parameters:
allowCreate - if a new Session should be created if no thread-bound found
Method Detail

setAllowCreate

public void setAllowCreate(boolean allowCreate)
Set if a new Session should be created when no transactional Session can be found for the current thread.

TopLinkTemplate is aware of a corresponding Session bound to the current thread, for example when using TopLinkTransactionManager. If allowCreate is true, a new non-transactional Session will be created if none found, which needs to be closed at the end of the operation. If false, an IllegalStateException will get thrown in this case.

See Also:
SessionFactoryUtils.getSession(SessionFactory, boolean)

isAllowCreate

public boolean isAllowCreate()
Return if a new Session should be created if no thread-bound found.


execute

public Object execute(TopLinkCallback action)
               throws DataAccessException
Description copied from interface: TopLinkOperations
Execute the action specified by the given action object within a TopLink Session. Application exceptions thrown by the action object get propagated to the caller (can only be unchecked). TopLink exceptions are transformed into appropriate DAO ones. Allows for returning a result object, i.e. a domain object or a collection of domain objects.

Note: Callback code is not supposed to handle transactions itself! Use an appropriate transaction manager like TopLinkTransactionManager.

Specified by:
execute in interface TopLinkOperations
Parameters:
action - callback object that specifies the TopLink action
Returns:
a result object returned by the action, or null
Throws:
DataAccessException - in case of TopLink errors
See Also:
TopLinkTransactionManager, org.springframework.dao, org.springframework.transaction, Session

executeFind

public List executeFind(TopLinkCallback action)
                 throws DataAccessException
Description copied from interface: TopLinkOperations
Execute the specified action assuming that the result object is a Collection. This is a convenience method for executing TopLink queries within an action.

Specified by:
executeFind in interface TopLinkOperations
Parameters:
action - callback object that specifies the TopLink action
Returns:
a Collection result returned by the action, or null
Throws:
DataAccessException - in case of TopLink errors

executeNamedQuery

public Object executeNamedQuery(Class entityClass,
                                String queryName)
                         throws DataAccessException
Description copied from interface: TopLinkOperations
Execute a given named query with the given arguments.

Retrieves read-write objects from the TopLink UnitOfWork in case of a non-read-only transaction, and read-only objects else.

Specified by:
executeNamedQuery in interface TopLinkOperations
Parameters:
entityClass - the entity class that has the named query descriptor
queryName - the name of the query
Returns:
the result object or list of result objects for the query (can be cast to the entity class or Collection/List, respectively)
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.executeQuery(String, Class)

executeNamedQuery

public Object executeNamedQuery(Class entityClass,
                                String queryName,
                                boolean enforceReadOnly)
                         throws DataAccessException
Description copied from interface: TopLinkOperations
Execute a given named query with the given arguments.

Specified by:
executeNamedQuery in interface TopLinkOperations
Parameters:
entityClass - the entity class that has the named query descriptor
queryName - the name of the query
enforceReadOnly - whether to always retrieve read-only objects from the plain TopLink Session (else, read-write objects will be retrieved from the TopLink UnitOfWork in case of a non-read-only transaction)
Returns:
the result object or list of result objects for the query (can be cast to the entity class or Collection/List, respectively)
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.executeQuery(String, Class)

executeNamedQuery

public Object executeNamedQuery(Class entityClass,
                                String queryName,
                                Object[] args)
                         throws DataAccessException
Description copied from interface: TopLinkOperations
Execute a given named query with the given arguments.

Retrieves read-write objects from the TopLink UnitOfWork in case of a non-read-only transaction, and read-only objects else.

Specified by:
executeNamedQuery in interface TopLinkOperations
Parameters:
entityClass - the entity class that has the named query descriptor
queryName - the name of the query
args - the arguments for the query (can be null)
Returns:
the result object or list of result objects for the query (can be cast to the entity class or Collection/List, respectively)
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.executeQuery(String, Class, java.util.Vector)

executeNamedQuery

public Object executeNamedQuery(Class entityClass,
                                String queryName,
                                Object[] args,
                                boolean enforceReadOnly)
                         throws DataAccessException
Description copied from interface: TopLinkOperations
Execute a given named query with the given arguments.

Specified by:
executeNamedQuery in interface TopLinkOperations
Parameters:
entityClass - the entity class that has the named query descriptor
queryName - the name of the query
args - the arguments for the query (can be null)
enforceReadOnly - whether to always retrieve read-only objects from the plain TopLink Session (else, read-write objects will be retrieved from the TopLink UnitOfWork in case of a non-read-only transaction)
Returns:
the result object or list of result objects for the query (can be cast to the entity class or Collection/List, respectively)
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.executeQuery(String, Class, java.util.Vector)

executeQuery

public Object executeQuery(oracle.toplink.queryframework.DatabaseQuery query)
                    throws DataAccessException
Description copied from interface: TopLinkOperations
Execute the given query object with the given arguments.

Retrieves read-write objects from the TopLink UnitOfWork in case of a non-read-only transaction, and read-only objects else.

Specified by:
executeQuery in interface TopLinkOperations
Parameters:
query - the query object to execute (for example, a ReadObjectQuery or ReadAllQuery instance)
Returns:
the result object or list of result objects for the query (can be cast to the entity class or Collection/List, respectively)
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.executeQuery(oracle.toplink.queryframework.DatabaseQuery)

executeQuery

public Object executeQuery(oracle.toplink.queryframework.DatabaseQuery query,
                           boolean enforceReadOnly)
                    throws DataAccessException
Description copied from interface: TopLinkOperations
Execute the given query object with the given arguments.

Specified by:
executeQuery in interface TopLinkOperations
Parameters:
query - the query object to execute (for example, a ReadObjectQuery or ReadAllQuery instance)
enforceReadOnly - whether to always retrieve read-only objects from the plain TopLink Session (else, read-write objects will be retrieved from the TopLink UnitOfWork in case of a non-read-only transaction)
Returns:
the result object or list of result objects for the query (can be cast to the entity class or Collection/List, respectively)
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.executeQuery(oracle.toplink.queryframework.DatabaseQuery)

executeQuery

public Object executeQuery(oracle.toplink.queryframework.DatabaseQuery query,
                           Object[] args)
                    throws DataAccessException
Description copied from interface: TopLinkOperations
Execute the given query object with the given arguments.

Retrieves read-write objects from the TopLink UnitOfWork in case of a non-read-only transaction, and read-only objects else.

Specified by:
executeQuery in interface TopLinkOperations
Parameters:
query - the query object to execute (for example, a ReadObjectQuery or ReadAllQuery instance)
args - the arguments for the query (can be null)
Returns:
the result object or list of result objects for the query (can be cast to the entity class or Collection/List, respectively)
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.executeQuery(oracle.toplink.queryframework.DatabaseQuery, java.util.Vector)

executeQuery

public Object executeQuery(oracle.toplink.queryframework.DatabaseQuery query,
                           Object[] args,
                           boolean enforceReadOnly)
                    throws DataAccessException
Description copied from interface: TopLinkOperations
Execute the given query object with the given arguments.

Specified by:
executeQuery in interface TopLinkOperations
Parameters:
query - the query object to execute (for example, a ReadObjectQuery or ReadAllQuery instance)
args - the arguments for the query (can be null)
enforceReadOnly - whether to always retrieve read-only objects from the plain TopLink Session (else, read-write objects will be retrieved from the TopLink UnitOfWork in case of a non-read-only transaction)
Returns:
the result object or list of result objects for the query (can be cast to the entity class or Collection/List, respectively)
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.executeQuery(oracle.toplink.queryframework.DatabaseQuery, java.util.Vector)

readAll

public List readAll(Class entityClass)
             throws DataAccessException
Description copied from interface: TopLinkOperations
Read all entity instances of the given class.

Retrieves read-write objects from the TopLink UnitOfWork in case of a non-read-only transaction, and read-only objects else.

Specified by:
readAll in interface TopLinkOperations
Parameters:
entityClass - the entity class
Returns:
the list of entity instances
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.readAllObjects(Class)

readAll

public List readAll(Class entityClass,
                    boolean enforceReadOnly)
             throws DataAccessException
Description copied from interface: TopLinkOperations
Read all entity instances of the given class.

Specified by:
readAll in interface TopLinkOperations
Parameters:
entityClass - the entity class
enforceReadOnly - whether to always retrieve read-only objects from the plain TopLink Session (else, read-write objects will be retrieved from the TopLink UnitOfWork in case of a non-read-only transaction)
Returns:
the list of entity instances
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.readAllObjects(Class)

readAll

public List readAll(Class entityClass,
                    oracle.toplink.expressions.Expression expression)
             throws DataAccessException
Description copied from interface: TopLinkOperations
Read all entity instances of the given class that match the given expression.

Retrieves read-write objects from the TopLink UnitOfWork in case of a non-read-only transaction, and read-only objects else.

Specified by:
readAll in interface TopLinkOperations
Parameters:
entityClass - the entity class
expression - the TopLink expression to match, usually built through the TopLink ExpressionBuilder
Returns:
the list of matching entity instances
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.readAllObjects(Class, oracle.toplink.expressions.Expression), ExpressionBuilder

readAll

public List readAll(Class entityClass,
                    oracle.toplink.expressions.Expression expression,
                    boolean enforceReadOnly)
             throws DataAccessException
Description copied from interface: TopLinkOperations
Read all entity instances of the given class that match the given expression.

Specified by:
readAll in interface TopLinkOperations
Parameters:
entityClass - the entity class
expression - the TopLink expression to match, usually built through the TopLink ExpressionBuilder
enforceReadOnly - whether to always retrieve read-only objects from the plain TopLink Session (else, read-write objects will be retrieved from the TopLink UnitOfWork in case of a non-read-only transaction)
Returns:
the list of matching entity instances
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.readAllObjects(Class, oracle.toplink.expressions.Expression), ExpressionBuilder

readAll

public List readAll(Class entityClass,
                    oracle.toplink.queryframework.Call call)
             throws DataAccessException
Description copied from interface: TopLinkOperations
Read all entity instances of the given class, as returned by the given call.

Retrieves read-write objects from the TopLink UnitOfWork in case of a non-read-only transaction, and read-only objects else.

Specified by:
readAll in interface TopLinkOperations
Parameters:
entityClass - the entity class
call - the TopLink Call object to apply (either a SQLCall or an EJBQLCall)
Returns:
the list of matching entity instances
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.readAllObjects(Class, oracle.toplink.queryframework.Call), oracle.toplink.queryframework.SQLCall, oracle.toplink.queryframework.EJBQLCall

readAll

public List readAll(Class entityClass,
                    oracle.toplink.queryframework.Call call,
                    boolean enforceReadOnly)
             throws DataAccessException
Description copied from interface: TopLinkOperations
Read all entity instances of the given class, as returned by the given call.

Specified by:
readAll in interface TopLinkOperations
Parameters:
entityClass - the entity class
call - the TopLink Call object to apply (either a SQLCall or an EJBQLCall)
enforceReadOnly - whether to always retrieve read-only objects from the plain TopLink Session (else, read-write objects will be retrieved from the TopLink UnitOfWork in case of a non-read-only transaction)
Returns:
the list of matching entity instances
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.readAllObjects(Class, oracle.toplink.expressions.Expression), oracle.toplink.queryframework.SQLCall, oracle.toplink.queryframework.EJBQLCall

read

public Object read(Class entityClass,
                   oracle.toplink.expressions.Expression expression)
            throws DataAccessException
Description copied from interface: TopLinkOperations
Read an entity instance of the given class that matches the given expression.

Retrieves read-write objects from the TopLink UnitOfWork in case of a non-read-only transaction, and read-only objects else.

Specified by:
read in interface TopLinkOperations
Parameters:
entityClass - the entity class
expression - the TopLink expression to match, usually built through the TopLink ExpressionBuilder
Returns:
the matching entity instance, or null if none found
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.readAllObjects(Class, oracle.toplink.expressions.Expression), ExpressionBuilder

read

public Object read(Class entityClass,
                   oracle.toplink.expressions.Expression expression,
                   boolean enforceReadOnly)
            throws DataAccessException
Description copied from interface: TopLinkOperations
Read an entity instance of the given class that matches the given expression.

Specified by:
read in interface TopLinkOperations
Parameters:
entityClass - the entity class
expression - the TopLink expression to match, usually built through the TopLink ExpressionBuilder
enforceReadOnly - whether to always retrieve read-only objects from the plain TopLink Session (else, read-write objects will be retrieved from the TopLink UnitOfWork in case of a non-read-only transaction)
Returns:
a matching entity instance, or null if none found
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.readAllObjects(Class, oracle.toplink.expressions.Expression), ExpressionBuilder

read

public Object read(Class entityClass,
                   oracle.toplink.queryframework.Call call)
            throws DataAccessException
Description copied from interface: TopLinkOperations
Read an entity instance of the given class, as returned by the given call.

Retrieves read-write objects from the TopLink UnitOfWork in case of a non-read-only transaction, and read-only objects else.

Specified by:
read in interface TopLinkOperations
Parameters:
entityClass - the entity class
call - the TopLink Call object to apply (either a SQLCall or an EJBQLCall)
Returns:
a matching entity instance, or null if none found
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.readAllObjects(Class, oracle.toplink.queryframework.Call), oracle.toplink.queryframework.SQLCall, oracle.toplink.queryframework.EJBQLCall

read

public Object read(Class entityClass,
                   oracle.toplink.queryframework.Call call,
                   boolean enforceReadOnly)
            throws DataAccessException
Description copied from interface: TopLinkOperations
Read an entity instance of the given class, as returned by the given call.

Specified by:
read in interface TopLinkOperations
Parameters:
entityClass - the entity class
call - the TopLink Call object to apply (either a SQLCall or an EJBQLCall)
enforceReadOnly - whether to always retrieve read-only objects from the plain TopLink Session (else, read-write objects will be retrieved from the TopLink UnitOfWork in case of a non-read-only transaction)
Returns:
a matching entity instance, or null if none found
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.readAllObjects(Class, oracle.toplink.expressions.Expression), oracle.toplink.queryframework.SQLCall, oracle.toplink.queryframework.EJBQLCall

readById

public Object readById(Class entityClass,
                       Object id)
                throws DataAccessException
Description copied from interface: TopLinkOperations
Read the entity instance of the given class with the given id, throwing an exception if not found.

Retrieves read-write objects from the TopLink UnitOfWork in case of a non-read-only transaction, and read-only objects else.

Specified by:
readById in interface TopLinkOperations
Parameters:
entityClass - the entity class
id - the id of the desired object
Returns:
the entity instance
Throws:
ObjectRetrievalFailureException - if not found
DataAccessException - in case of TopLink errors
See Also:
ReadObjectQuery.setSelectionKey(java.util.Vector)

readById

public Object readById(Class entityClass,
                       Object id,
                       boolean enforceReadOnly)
                throws DataAccessException
Description copied from interface: TopLinkOperations
Read the entity instance of the given class with the given id, throwing an exception if not found.

Specified by:
readById in interface TopLinkOperations
Parameters:
entityClass - the entity class
id - the id of the desired object
enforceReadOnly - whether to always retrieve read-only objects from the plain TopLink Session (else, read-write objects will be retrieved from the TopLink UnitOfWork in case of a non-read-only transaction)
Returns:
the entity instance
Throws:
ObjectRetrievalFailureException - if not found
DataAccessException - in case of TopLink errors
See Also:
ReadObjectQuery.setSelectionKey(java.util.Vector)

readById

public Object readById(Class entityClass,
                       Object[] keys)
                throws DataAccessException
Description copied from interface: TopLinkOperations
Read the entity instance of the given class with the given composite id, throwing an exception if not found.

Retrieves read-write objects from the TopLink UnitOfWork in case of a non-read-only transaction, and read-only objects else.

Specified by:
readById in interface TopLinkOperations
Parameters:
entityClass - the entity class
keys - the composite id elements of the desired object
Returns:
the entity instance
Throws:
ObjectRetrievalFailureException - if not found
DataAccessException - in case of TopLink errors
See Also:
ReadObjectQuery.setSelectionKey(java.util.Vector)

readById

public Object readById(Class entityClass,
                       Object[] keys,
                       boolean enforceReadOnly)
                throws DataAccessException
Description copied from interface: TopLinkOperations
Read the entity instance of the given class with the given composite id, throwing an exception if not found.

Specified by:
readById in interface TopLinkOperations
Parameters:
entityClass - the entity class
keys - the composite id elements of the desired object
enforceReadOnly - whether to always retrieve read-only objects from the plain TopLink Session (else, read-write objects will be retrieved from the TopLink UnitOfWork in case of a non-read-only transaction)
Returns:
the entity instance
Throws:
ObjectRetrievalFailureException - if not found
DataAccessException - in case of TopLink errors
See Also:
ReadObjectQuery.setSelectionKey(java.util.Vector)

readAndCopy

public Object readAndCopy(Class entityClass,
                          Object id)
                   throws DataAccessException
Description copied from interface: TopLinkOperations
Read the entity instance of the given class with the given id, throwing an exception if not found. A detached copy of the entity object will be returned, allowing for modifications outside the current transaction, with the changes to be merged into a later transaction.

Retrieves read-write objects from the TopLink UnitOfWork in case of a non-read-only transaction, and read-only objects else.

Specified by:
readAndCopy in interface TopLinkOperations
Parameters:
entityClass - the entity class
id - the id of the desired object
Returns:
a copy of the entity instance
Throws:
ObjectRetrievalFailureException - if not found
DataAccessException - in case of TopLink errors
See Also:
ReadObjectQuery.setSelectionKey(java.util.Vector), Session.copyObject(Object)

readAndCopy

public Object readAndCopy(Class entityClass,
                          Object id,
                          boolean enforceReadOnly)
                   throws DataAccessException
Description copied from interface: TopLinkOperations
Read the entity instance of the given class with the given id, throwing an exception if not found. A detached copy of the entity object will be returned, allowing for modifications outside the current transaction, with the changes to be merged into a later transaction.

Specified by:
readAndCopy in interface TopLinkOperations
Parameters:
entityClass - the entity class
id - the id of the desired object
enforceReadOnly - whether to always retrieve read-only objects from the plain TopLink Session (else, read-write objects will be retrieved from the TopLink UnitOfWork in case of a non-read-only transaction)
Returns:
a copy of the entity instance
Throws:
ObjectRetrievalFailureException - if not found
DataAccessException - in case of TopLink errors
See Also:
ReadObjectQuery.setSelectionKey(java.util.Vector), Session.copyObject(Object)

readAndCopy

public Object readAndCopy(Class entityClass,
                          Object[] keys)
                   throws DataAccessException
Description copied from interface: TopLinkOperations
Read the entity instance of the given class with the given composite id, throwing an exception if not found. A detached copy of the entity object will be returned, allowing for modifications outside the current transaction, with the changes to be merged into a later transaction.

Retrieves read-write objects from the TopLink UnitOfWork in case of a non-read-only transaction, and read-only objects else.

Specified by:
readAndCopy in interface TopLinkOperations
Parameters:
entityClass - the entity class
keys - the composite id elements of the desired object
Returns:
a copy of the entity instance
Throws:
ObjectRetrievalFailureException - if not found
DataAccessException - in case of TopLink errors
See Also:
ReadObjectQuery.setSelectionKey(java.util.Vector), Session.copyObject(Object)

readAndCopy

public Object readAndCopy(Class entityClass,
                          Object[] keys,
                          boolean enforceReadOnly)
                   throws DataAccessException
Description copied from interface: TopLinkOperations
Read the entity instance of the given class with the given composite id, throwing an exception if not found. A detached copy of the entity object will be returned, allowing for modifications outside the current transaction, with the changes to be merged into a later transaction.

Specified by:
readAndCopy in interface TopLinkOperations
Parameters:
entityClass - the entity class
keys - the composite id elements of the desired object
enforceReadOnly - whether to always retrieve read-only objects from the plain TopLink Session (else, read-write objects will be retrieved from the TopLink UnitOfWork in case of a non-read-only transaction)
Returns:
a copy of the entity instance
Throws:
ObjectRetrievalFailureException - if not found
DataAccessException - in case of TopLink errors
See Also:
ReadObjectQuery.setSelectionKey(java.util.Vector), Session.copyObject(Object)

copy

public Object copy(Object entity)
            throws DataAccessException
Description copied from interface: TopLinkOperations
Create a detached copy of the given entity object, using TopLink's default ObjectCopyingPolicy.

Specified by:
copy in interface TopLinkOperations
Parameters:
entity - the entity object to copy
Returns:
the copy of the entity object
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.copyObject(Object)

copy

public Object copy(Object entity,
                   oracle.toplink.sessions.ObjectCopyingPolicy copyingPolicy)
            throws DataAccessException
Description copied from interface: TopLinkOperations
Create a detached copy of the given entity object.

Specified by:
copy in interface TopLinkOperations
Parameters:
entity - the entity object to copy
copyingPolicy - the TopLink ObjectCopyingPolicy to apply
Returns:
the copy of the entity object
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.copyObject(Object, oracle.toplink.sessions.ObjectCopyingPolicy)

copyAll

public List copyAll(Collection entities)
             throws DataAccessException
Description copied from interface: TopLinkOperations
Create detached copies of all given entity objects, using TopLink's default ObjectCopyingPolicy.

Specified by:
copyAll in interface TopLinkOperations
Parameters:
entities - the entity objects to copy
Returns:
the copies of the entity objects
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.copyObject(Object)

copyAll

public List copyAll(Collection entities,
                    oracle.toplink.sessions.ObjectCopyingPolicy copyingPolicy)
             throws DataAccessException
Description copied from interface: TopLinkOperations
Create detached copies of all given entity objects.

Specified by:
copyAll in interface TopLinkOperations
Parameters:
entities - the entity objects to copy
copyingPolicy - the TopLink ObjectCopyingPolicy to apply
Returns:
the copies of the entity objects
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.copyObject(Object)

refresh

public Object refresh(Object entity)
               throws DataAccessException
Description copied from interface: TopLinkOperations
Refresh the given entity object, returning the refreshed object.

The returned object will only be different from the passed-in object if the passed-in object is not the currently registered version of the corresponding entity.

Retrieves read-write objects from the TopLink UnitOfWork in case of a non-read-only transaction, and read-only objects else.

Specified by:
refresh in interface TopLinkOperations
Parameters:
entity - the entity object to refresh
Returns:
the refreshed version of the entity object
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.refreshObject(Object)

refresh

public Object refresh(Object entity,
                      boolean enforceReadOnly)
               throws DataAccessException
Description copied from interface: TopLinkOperations
Refresh the given entity object, returning the refreshed object.

The returned object will only be different from the passed-in object if the passed-in object is not the currently registered version of the corresponding entity.

Retrieves read-write objects from the TopLink UnitOfWork in case of a non-read-only transaction, and read-only objects else.

Specified by:
refresh in interface TopLinkOperations
Parameters:
entity - the entity object to refresh
enforceReadOnly - whether to always retrieve read-only objects from the plain TopLink Session (else, read-write objects will be retrieved from the TopLink UnitOfWork in case of a non-read-only transaction)
Returns:
the refreshed version of the entity object
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.refreshObject(Object)

refreshAll

public List refreshAll(Collection entities)
                throws DataAccessException
Description copied from interface: TopLinkOperations
Refresh the given entity objects, returning the corresponding refreshed objects.

A returned object will only be different from the corresponding passed-in object if the passed-in object is not the currently registered version of the corresponding entity.

Retrieves read-write objects from the TopLink UnitOfWork in case of a non-read-only transaction, and read-only objects else.

Specified by:
refreshAll in interface TopLinkOperations
Parameters:
entities - the entity objects to refresh
Returns:
the refreshed versions of the entity objects
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.refreshObject(Object)

refreshAll

public List refreshAll(Collection entities,
                       boolean enforceReadOnly)
                throws DataAccessException
Description copied from interface: TopLinkOperations
Refresh the given entity objects, returning the corresponding refreshed objects.

A returned object will only be different from the corresponding passed-in object if the passed-in object is not the currently registered version of the corresponding entity.

Specified by:
refreshAll in interface TopLinkOperations
Parameters:
entities - the entity objects to refresh
enforceReadOnly - whether to always retrieve read-only objects from the plain TopLink Session (else, read-write objects will be retrieved from the TopLink UnitOfWork in case of a non-read-only transaction)
Returns:
the refreshed versions of the entity objects
Throws:
DataAccessException - in case of TopLink errors
See Also:
Session.refreshObject(Object)

register

public Object register(Object entity)
Description copied from interface: TopLinkOperations
Register the given (new or existing) entity with the current UnitOfWork.

The entity will be checked for existence, according to TopLink's configured existence checking policy. To avoid the (potentially costly) existence check, consider using the specific registerNew or registerExisting method. Do not edit the passed-in object any further afterwards.

Specified by:
register in interface TopLinkOperations
Parameters:
entity - the entity to register
Returns:
the registered clone of the original object, which needs to be used for further editing
See Also:
UnitOfWork.registerObject(Object), TopLinkOperations.registerNew(Object), TopLinkOperations.registerExisting(Object)

registerAll

public List registerAll(Collection entities)
Description copied from interface: TopLinkOperations
Register all given entities with the current UnitOfWork. Do not edit the passed-in objects any further afterwards.

Specified by:
registerAll in interface TopLinkOperations
Parameters:
entities - the entities to register
Returns:
the registered clones of the original objects, which need to be used for further editing
See Also:
UnitOfWork.registerAllObjects(java.util.Collection)

registerNew

public void registerNew(Object entity)
Description copied from interface: TopLinkOperations
Register the given new entity with the current UnitOfWork. The passed-in object can be edited further afterwards.

Specified by:
registerNew in interface TopLinkOperations
Parameters:
entity - the new entity to register
See Also:
UnitOfWork.registerNewObject(Object)

registerExisting

public Object registerExisting(Object entity)
Description copied from interface: TopLinkOperations
Register the given existing entity with the current UnitOfWork. Do not edit the passed-in object any further afterwards.

Specified by:
registerExisting in interface TopLinkOperations
Parameters:
entity - the existing entity to register
Returns:
the registered clone of the original object, which needs to be used for further editing
See Also:
UnitOfWork.registerExistingObject(Object)

merge

public Object merge(Object entity)
             throws DataAccessException
Description copied from interface: TopLinkOperations
Reassociate the given entity copy with the current UnitOfWork, using simple merging.

The given object will not be reassociated itself: instead, the state will be copied onto the persistent object with the same identifier. In case of a new entity, merge will copy to a registered object as well, but will also update the identifier of the passed-in object.

Specified by:
merge in interface TopLinkOperations
Parameters:
entity - the updated copy to merge
Returns:
the updated, registered persistent instance
Throws:
DataAccessException - in case of TopLink errors
See Also:
UnitOfWork.mergeClone(Object)

deepMerge

public Object deepMerge(Object entity)
                 throws DataAccessException
Description copied from interface: TopLinkOperations
Reassociate the given entity copy with the current UnitOfWork, using deep merging of all contained entities.

The given object will not be reassociated itself: instead, the state will be copied onto the persistent object with the same identifier. In case of a new entity, merge will register a copy as well, but will also update the identifier of the passed-in object.

Specified by:
deepMerge in interface TopLinkOperations
Parameters:
entity - the updated copy to merge
Returns:
the updated, registered persistent instance
Throws:
DataAccessException - in case of TopLink errors
See Also:
UnitOfWork.deepMergeClone(Object)

shallowMerge

public Object shallowMerge(Object entity)
                    throws DataAccessException
Description copied from interface: TopLinkOperations
Reassociate the given entity copy with the current UnitOfWork, using shallow merging of the entity instance.

The given object will not be reassociated itself: instead, the state will be copied onto the persistent object with the same identifier. In case of a new entity, merge will register a copy as well, but will also update the identifier of the passed-in object.

Specified by:
shallowMerge in interface TopLinkOperations
Parameters:
entity - the updated copy to merge
Returns:
the updated, registered persistent instance
Throws:
DataAccessException - in case of TopLink errors
See Also:
UnitOfWork.shallowMergeClone(Object)

mergeWithReferences

public Object mergeWithReferences(Object entity)
                           throws DataAccessException
Description copied from interface: TopLinkOperations
Reassociate the given entity copy with the current UnitOfWork, using merging with all references from this clone.

The given object will not be reassociated itself: instead, the state will be copied onto the persistent object with the same identifier. In case of a new entity, merge will register a copy as well, but will also update the identifier of the passed-in object.

Specified by:
mergeWithReferences in interface TopLinkOperations
Parameters:
entity - the updated copy to merge
Returns:
the updated, registered persistent instance
Throws:
DataAccessException - in case of TopLink errors
See Also:
UnitOfWork.mergeCloneWithReferences(Object)

delete

public void delete(Object entity)
            throws DataAccessException
Description copied from interface: TopLinkOperations
Delete the given entity.

Specified by:
delete in interface TopLinkOperations
Parameters:
entity - the entity to delete
Throws:
DataAccessException - in case of TopLink errors
See Also:
UnitOfWork.deleteObject(Object)

deleteAll

public void deleteAll(Collection entities)
               throws DataAccessException
Description copied from interface: TopLinkOperations
Delete all given entities.

Specified by:
deleteAll in interface TopLinkOperations
Parameters:
entities - the entities to delete
Throws:
DataAccessException - in case of TopLink errors
See Also:
UnitOfWork.deleteAllObjects(java.util.Collection)


Copyright (c) 2002-2006 The Spring Framework Project.