|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.springframework.extensions.jcr.TransactionAwareRepository
public class TransactionAwareRepository
This FactoryBean exposes a proxy for a target JCR Repository, returning the current thread-bound Repository
(the Spring-managed transactional Repository or the single OpenPersistenceManagerInView Repository) on
login(), if any.
login() calls get seamlessly forwarded to
SessionFactoryUtils.getSession. Furthermore, Session.logout calls get forwarded
to SessionFactoryUtils.releaseSession.
As the Session returned depends on the workspace and credentials given, this implementation accepts a
JcrSessionFactory as parameter (basically a wrapper for Repository, Credentials and Workspace properties).
The proxy will check the parameters and proxy the Repository for sessions that are retrieved with the
credentials and workspace name defined on the session factory. Sessions retrieved with different workspace,
credentials are not proxied.
The main advantage of this proxy is that it allows DAOs to work with a plain JCR Repository reference,
while still participating in Spring's (or a J2EE server's) resource and transaction management. DAOs will
only rely on the JCR API in such a scenario, without any Spring dependencies. DAOs could seamlessly switch
between a JNDI Repository and this proxy for a local Repository receiving the reference through Dependency
Injection. This will work without any Spring API dependencies in the DAO code!
It is usually preferable to write your JCR-based DAOs with Spring Extensions's JcrTemplate, offering
benefits such as consistent data access exceptions instead of RepositoryExceptions at the DAO layer.
However, Spring's resource and transaction management (and Dependency Injection) will work for DAOs written
against the plain JCR API too.
Of course, you can still access the target Repository even when your DAOs go through this proxy, by
defining a bean reference that points directly at your target Repository bean.
| Constructor Summary | |
|---|---|
TransactionAwareRepository()
|
|
| Method Summary | |
|---|---|
void |
afterPropertiesSet()
|
java.lang.Object |
getObject()
|
java.lang.Class |
getObjectType()
|
javax.jcr.Repository |
getTargetRepository()
Return the target JCR Repository that this proxy delegates to. |
boolean |
isAllowCreate()
|
boolean |
isAllowNonTxRepository()
|
boolean |
isSingleton()
|
void |
setAllowCreate(boolean allowCreate)
Set whether the Repository proxy is allowed to create a non-transactional Session when no transactional Session can be found for the current thread. |
void |
setAllowNonTxRepository(boolean allowNonTxRepository)
Set whether the Repository proxy is accepted even if it does not support transactions which allows the functionality of thread-bound session but without the tx support. |
void |
setTargetFactory(JcrSessionFactory target)
Set the target JCR Repository that this proxy should delegate to wrapped in a JcrSessionFactory object along with the credentials and workspace. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public TransactionAwareRepository()
| Method Detail |
|---|
public java.lang.Object getObject()
throws java.lang.Exception
getObject in interface org.springframework.beans.factory.FactoryBeanjava.lang.ExceptionFactoryBean.getObject()public java.lang.Class getObjectType()
getObjectType in interface org.springframework.beans.factory.FactoryBeanFactoryBean.getObjectType()public boolean isSingleton()
isSingleton in interface org.springframework.beans.factory.FactoryBeanFactoryBean.isSingleton()public boolean isAllowCreate()
public void afterPropertiesSet()
throws java.lang.Exception
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanjava.lang.ExceptionInitializingBean.afterPropertiesSet()public void setAllowCreate(boolean allowCreate)
Default is "true". Can be turned off to enforce access to transactional Sessionss, which safely allows
for DAOs written to get a Session without explicit closing (i.e. a Session.login() call
without corresponding Session.logout() call).
allowCreate - The allowCreate to set.SessionFactoryUtils.getSession(SessionFactory, boolean)public boolean isAllowNonTxRepository()
public void setAllowNonTxRepository(boolean allowNonTxRepository)
Default is "true". Can be turned off to enforce only transactional Sessionss, which safely allows for
DAOs written to get a Session without explicit closing (i.e. a Session.login() call
without corresponding Session.logout() call).
allowNonTxRepository - The allowNonTxRepository to set.public void setTargetFactory(JcrSessionFactory target)
public javax.jcr.Repository getTargetRepository()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||