| java.lang.Object org.springframework.orm.toplink.TopLinkAccessor org.springframework.orm.toplink.TopLinkTemplate
TopLinkTemplate | public class TopLinkTemplate extends TopLinkAccessor implements TopLinkOperations(Code) | | Helper class that simplifies TopLink data access code, and converts
TopLinkExceptions into unchecked DataAccessExceptions, following the
org.springframework.dao exception hierarchy.
The central method is execute , supporting TopLink access 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.
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. The Spring application context will manage its lifecycle,
initializing and shutting down the factory as part of the application.
Thanks to Slavik Markovich for implementing the initial TopLink support prototype!
author: Juergen Hoeller author: James Clark since: 1.2 See Also: TopLinkTemplate.setSessionFactory See Also: TopLinkCallback See Also: oracle.toplink.sessions.Session See Also: TopLinkInterceptor See Also: LocalSessionFactoryBean See Also: TopLinkTransactionManager See Also: org.springframework.transaction.jta.JtaTransactionManager |
Method Summary | |
public Object | copy(Object entity) | public Object | copy(Object entity, ObjectCopyingPolicy copyingPolicy) | public List | copyAll(Collection entities) | public List | copyAll(Collection entities, ObjectCopyingPolicy copyingPolicy) | public Object | deepMerge(Object entity) | public void | delete(Object entity) | public void | deleteAll(Collection entities) | public Object | execute(TopLinkCallback action) | public List | executeFind(TopLinkCallback action) | public Object | executeNamedQuery(Class entityClass, String queryName) | public Object | executeNamedQuery(Class entityClass, String queryName, boolean enforceReadOnly) | public Object | executeNamedQuery(Class entityClass, String queryName, Object[] args) | public Object | executeNamedQuery(Class entityClass, String queryName, Object[] args, boolean enforceReadOnly) | public Object | executeQuery(DatabaseQuery query) | public Object | executeQuery(DatabaseQuery query, boolean enforceReadOnly) | public Object | executeQuery(DatabaseQuery query, Object[] args) | public Object | executeQuery(DatabaseQuery query, Object[] args, boolean enforceReadOnly) | public boolean | isAllowCreate() Return if a new Session should be created if no thread-bound found. | public Object | merge(Object entity) | public Object | mergeWithReferences(Object entity) | public Object | read(Class entityClass, Expression expression) | public Object | read(Class entityClass, Expression expression, boolean enforceReadOnly) | public Object | read(Class entityClass, Call call) | public Object | read(Class entityClass, Call call, boolean enforceReadOnly) | public List | readAll(Class entityClass) | public List | readAll(Class entityClass, boolean enforceReadOnly) | public List | readAll(Class entityClass, Expression expression) | public List | readAll(Class entityClass, Expression expression, boolean enforceReadOnly) | public List | readAll(Class entityClass, Call call) | public List | readAll(Class entityClass, Call call, boolean enforceReadOnly) | public Object | readAndCopy(Class entityClass, Object id) | public Object | readAndCopy(Class entityClass, Object id, boolean enforceReadOnly) | public Object | readAndCopy(Class entityClass, Object[] keys) | public Object | readAndCopy(Class entityClass, Object[] keys, boolean enforceReadOnly) | public Object | readById(Class entityClass, Object id) | public Object | readById(Class entityClass, Object id, boolean enforceReadOnly) | public Object | readById(Class entityClass, Object[] keys) | public Object | readById(Class entityClass, Object[] keys, boolean enforceReadOnly) | public Object | refresh(Object entity) | public Object | refresh(Object entity, boolean enforceReadOnly) | public List | refreshAll(Collection entities) | public List | refreshAll(Collection entities, boolean enforceReadOnly) | public Object | register(Object entity) | public List | registerAll(Collection entities) | public Object | registerExisting(Object entity) | public void | registerNew(Object entity) | public void | setAllowCreate(boolean allowCreate) Set if a new Session should be created when no transactional Session
can be found for the current thread. | public Object | shallowMerge(Object entity) |
TopLinkTemplate | public TopLinkTemplate()(Code) | | Create a new TopLinkTemplate instance.
|
TopLinkTemplate | public TopLinkTemplate(SessionFactory sessionFactory)(Code) | | Create a new TopLinkTemplate instance.
|
TopLinkTemplate | public TopLinkTemplate(SessionFactory sessionFactory, boolean allowCreate)(Code) | | Create a new TopLinkTemplate instance.
Parameters: allowCreate - if a new Session should be created if no thread-bound found |
isAllowCreate | public boolean isAllowCreate()(Code) | | Return if a new Session should be created if no thread-bound found.
|
setAllowCreate | public void setAllowCreate(boolean allowCreate)(Code) | | 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(SessionFactoryboolean) |
Fields inherited from org.springframework.orm.toplink.TopLinkAccessor | final protected Log logger(Code)(Java Doc)
|
|
|