|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.jdbc.support.JdbcAccessor org.springframework.orm.ojb.OjbAccessor org.springframework.orm.ojb.PersistenceBrokerTemplate
Helper class that simplifies OJB PersistenceBroker data access code, and converts PersistenceBrokerExceptions into exceptions compatible to the org.springframework.dao exception hierarchy.
The central method is "execute", supporting OJB code implementing the PersistenceBrokerCallback interface. It provides PersistenceBroker handling such that neither the PersistenceBrokerCallback implementation nor the calling code needs to explicitly care about retrieving/closing PersistenceBrokers, or handling OJB lifecycle exceptions.
Typically used to implement data access or business logic services that use OJB within their implementation but are OJB-agnostic in their interface. The latter resp. code calling the latter only have to deal with business objects, query objects, and org.springframework.dao exceptions.
PersistenceBrokerCallback
Constructor Summary | |
PersistenceBrokerTemplate()
Create a new PersistenceBrokerTemplate, using the default connection configured for OJB. |
|
PersistenceBrokerTemplate(boolean allowCreate)
Create a new PersistenceBrokerTemplate, using the default connection configured for OJB. |
|
PersistenceBrokerTemplate(org.apache.ojb.broker.PBKey pbKey)
Create a new PersistenceBrokerTemplate. |
|
PersistenceBrokerTemplate(org.apache.ojb.broker.PBKey pbKey,
boolean allowCreate)
Create a new PersistenceBrokerTemplate. |
Method Summary | |
void |
clearCache()
|
protected void |
closePersistenceBrokerIfNecessary(org.apache.ojb.broker.PersistenceBroker pb)
Close the given PersistenceBroker, created for the PBKey of this template, if it isn't bound to the thread. |
void |
delete(java.lang.Object entity)
|
void |
deleteByQuery(org.apache.ojb.broker.query.Query query)
|
java.lang.Object |
execute(PersistenceBrokerCallback action)
Execute the action specified by the given action object within a PersistenceBroker. |
java.util.Collection |
executeFind(PersistenceBrokerCallback action)
Execute the specified action assuming that the result object is a Collection. |
java.util.Collection |
getCollectionByQuery(org.apache.ojb.broker.query.Query query)
|
int |
getCount(org.apache.ojb.broker.query.Query query)
|
java.util.Iterator |
getIteratorByQuery(org.apache.ojb.broker.query.Query query)
|
java.lang.Object |
getObjectByQuery(org.apache.ojb.broker.query.Query query)
|
protected org.apache.ojb.broker.PersistenceBroker |
getPersistenceBroker()
Get an OJB PersistenceBroker for the PBKey of this template. |
java.util.Iterator |
getReportQueryIteratorByQuery(org.apache.ojb.broker.query.Query query)
|
boolean |
isAllowCreate()
Return if a new PersistenceBroker should be created if no thread-bound found. |
void |
removeFromCache(java.lang.Object entityOrId)
|
void |
setAllowCreate(boolean allowCreate)
Set if a new PersistenceBroker should be created if no thread-bound found. |
void |
store(java.lang.Object entity)
|
Methods inherited from class org.springframework.orm.ojb.OjbAccessor |
convertJdbcAccessException, convertOjbAccessException, getJcdAlias, getPbKey, setJcdAlias, setPbKey |
Methods inherited from class org.springframework.jdbc.support.JdbcAccessor |
afterPropertiesSet, getDataSource, getExceptionTranslator, setDataSource, setExceptionTranslator |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public PersistenceBrokerTemplate()
public PersistenceBrokerTemplate(boolean allowCreate)
allowCreate
- if a new PersistenceBroker should be created
if no thread-bound foundpublic PersistenceBrokerTemplate(org.apache.ojb.broker.PBKey pbKey)
pbKey
- the PBKey of the PersistenceBroker configuration to usepublic PersistenceBrokerTemplate(org.apache.ojb.broker.PBKey pbKey, boolean allowCreate)
pbKey
- the PBKey of the PersistenceBroker configuration to useallowCreate
- if a new PersistenceBroker should be created
if no thread-bound foundMethod Detail |
public void setAllowCreate(boolean allowCreate)
PersistenceBrokerTemplate is aware of a respective PersistenceBroker bound to the current thread, for example when using PersistenceBrokerTransactionManager. If allowCreate is true, a new PersistenceBroker will be created if none found. If false, an IllegalStateException will get thrown in this case.
PersistenceManagerFactoryUtils.getPersistenceManager(javax.jdo.PersistenceManagerFactory, boolean)
public boolean isAllowCreate()
protected org.apache.ojb.broker.PersistenceBroker getPersistenceBroker() throws DataAccessResourceFailureException, java.lang.IllegalStateException
Default implementation delegates to OjbFactoryUtils. Can be overridden in subclasses, e.g. for testing purposes.
DataAccessResourceFailureException
- if the PersistenceBroker couldn't be created
java.lang.IllegalStateException
- if no thread-bound PersistenceBroker found and allowCreate falseOjbAccessor.setJcdAlias(java.lang.String)
,
OjbAccessor.setPbKey(org.apache.ojb.broker.PBKey)
,
setAllowCreate(boolean)
,
OjbFactoryUtils.getPersistenceBroker(PBKey, boolean)
protected void closePersistenceBrokerIfNecessary(org.apache.ojb.broker.PersistenceBroker pb)
Default implementation delegates to OjbFactoryUtils. Can be overridden in subclasses, e.g. for testing purposes.
pb
- PersistenceBroker to closeOjbAccessor.setJcdAlias(java.lang.String)
,
OjbAccessor.setPbKey(org.apache.ojb.broker.PBKey)
,
OjbFactoryUtils.closePersistenceBrokerIfNecessary(org.apache.ojb.broker.PersistenceBroker, org.apache.ojb.broker.PBKey)
public java.lang.Object execute(PersistenceBrokerCallback action) throws DataAccessException
PersistenceBrokerOperations
Note: Callback code is not supposed to handle transactions itself! Use an appropriate transaction manager like PersistenceBrokerTransactionManager.
execute
in interface PersistenceBrokerOperations
action
- action object that specifies the OJB action
DataAccessException
- in case of OJB errorsPersistenceBrokerTransactionManager
,
org.springframework.dao
,
org.springframework.transaction
public java.util.Collection executeFind(PersistenceBrokerCallback action) throws DataAccessException
PersistenceBrokerOperations
executeFind
in interface PersistenceBrokerOperations
action
- action object that specifies the OJB action
DataAccessException
- in case of OJB errorspublic java.lang.Object getObjectByQuery(org.apache.ojb.broker.query.Query query) throws DataAccessException
getObjectByQuery
in interface PersistenceBrokerOperations
DataAccessException
public java.util.Collection getCollectionByQuery(org.apache.ojb.broker.query.Query query) throws DataAccessException
getCollectionByQuery
in interface PersistenceBrokerOperations
DataAccessException
public java.util.Iterator getIteratorByQuery(org.apache.ojb.broker.query.Query query) throws DataAccessException
getIteratorByQuery
in interface PersistenceBrokerOperations
DataAccessException
public java.util.Iterator getReportQueryIteratorByQuery(org.apache.ojb.broker.query.Query query)
getReportQueryIteratorByQuery
in interface PersistenceBrokerOperations
public int getCount(org.apache.ojb.broker.query.Query query) throws DataAccessException
getCount
in interface PersistenceBrokerOperations
DataAccessException
public void removeFromCache(java.lang.Object entityOrId) throws DataAccessException
removeFromCache
in interface PersistenceBrokerOperations
DataAccessException
public void clearCache() throws DataAccessException
clearCache
in interface PersistenceBrokerOperations
DataAccessException
public void store(java.lang.Object entity) throws DataAccessException
store
in interface PersistenceBrokerOperations
DataAccessException
public void delete(java.lang.Object entity) throws DataAccessException
delete
in interface PersistenceBrokerOperations
DataAccessException
public void deleteByQuery(org.apache.ojb.broker.query.Query query) throws DataAccessException
deleteByQuery
in interface PersistenceBrokerOperations
DataAccessException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |