public class TransactionAwarePersistenceManagerFactoryProxy extends Object implements org.springframework.beans.factory.FactoryBean<javax.jdo.PersistenceManagerFactory>
PersistenceManagerFactory
,
returning the current thread-bound PersistenceManager (the Spring-managed
transactional PersistenceManager or the single OpenPersistenceManagerInView
PersistenceManager) on getPersistenceManager()
, if any.
Essentially, getPersistenceManager()
calls get seamlessly
forwarded to PersistenceManagerFactoryUtils.getPersistenceManager(javax.jdo.PersistenceManagerFactory, boolean)
.
Furthermore, PersistenceManager.close
calls get forwarded to
PersistenceManagerFactoryUtils.releasePersistenceManager(javax.jdo.PersistenceManager, javax.jdo.PersistenceManagerFactory)
.
The main advantage of this proxy is that it allows DAOs to work with a plain JDO PersistenceManagerFactory reference, while still participating in Spring's (or a J2EE server's) resource and transaction management. DAOs will only rely on the JDO API in such a scenario, without any Spring dependencies.
Note that the behavior of this proxy matches the behavior that the JDO spec defines for a PersistenceManagerFactory as exposed by a JCA connector, when deployed in a J2EE server. Hence, DAOs could seamlessly switch between a JNDI PersistenceManagerFactory and this proxy for a local PersistenceManagerFactory, receiving the reference through Dependency Injection. This will work without any Spring API dependencies in the DAO code!
Of course, you can still access the target PersistenceManagerFactory even when your DAOs go through this proxy, by defining a bean reference that points directly at your target PersistenceManagerFactory bean.
PersistenceManagerFactory.getPersistenceManager()
,
PersistenceManager.close()
,
PersistenceManagerFactoryUtils.getPersistenceManager(javax.jdo.PersistenceManagerFactory, boolean)
,
PersistenceManagerFactoryUtils.releasePersistenceManager(javax.jdo.PersistenceManager, javax.jdo.PersistenceManagerFactory)
Constructor and Description |
---|
TransactionAwarePersistenceManagerFactoryProxy() |
Modifier and Type | Method and Description |
---|---|
javax.jdo.PersistenceManagerFactory |
getObject() |
Class<? extends javax.jdo.PersistenceManagerFactory> |
getObjectType() |
javax.jdo.PersistenceManagerFactory |
getTargetPersistenceManagerFactory()
Return the target JDO PersistenceManagerFactory that this proxy delegates to.
|
protected boolean |
isAllowCreate()
Return whether the PersistenceManagerFactory proxy is allowed to create
a non-transactional PersistenceManager when no transactional
PersistenceManager can be found for the current thread.
|
boolean |
isSingleton() |
void |
setAllowCreate(boolean allowCreate)
Set whether the PersistenceManagerFactory proxy is allowed to create
a non-transactional PersistenceManager when no transactional
PersistenceManager can be found for the current thread.
|
void |
setTargetPersistenceManagerFactory(javax.jdo.PersistenceManagerFactory target)
Set the target JDO PersistenceManagerFactory that this proxy should
delegate to.
|
public TransactionAwarePersistenceManagerFactoryProxy()
public void setTargetPersistenceManagerFactory(javax.jdo.PersistenceManagerFactory target)
JdoTransactionManager
public javax.jdo.PersistenceManagerFactory getTargetPersistenceManagerFactory()
public void setAllowCreate(boolean allowCreate)
Default is "true". Can be turned off to enforce access to
transactional PersistenceManagers, which safely allows for DAOs
written to get a PersistenceManager without explicit closing
(i.e. a PersistenceManagerFactory.getPersistenceManager()
call without corresponding PersistenceManager.close()
call).
protected boolean isAllowCreate()
public javax.jdo.PersistenceManagerFactory getObject()
getObject
in interface org.springframework.beans.factory.FactoryBean<javax.jdo.PersistenceManagerFactory>
public Class<? extends javax.jdo.PersistenceManagerFactory> getObjectType()
getObjectType
in interface org.springframework.beans.factory.FactoryBean<javax.jdo.PersistenceManagerFactory>
public boolean isSingleton()
isSingleton
in interface org.springframework.beans.factory.FactoryBean<javax.jdo.PersistenceManagerFactory>