public class DelegatingPersistenceBroker extends java.lang.Object implements PersistenceBrokerInternal, PBState
Constructor and Description |
---|
DelegatingPersistenceBroker(PersistenceBrokerInternal broker) |
Modifier and Type | Method and Description |
---|---|
void |
abortTransaction()
Aborts and closes the current transaction.
|
void |
addListener(PBListener listener)
Adds a temporary
PBListener to this broker. |
void |
addListener(PBListener listener,
boolean permanent)
Adds a temporary or permanent
PBListener to this broker,
depending on the parameter value. |
void |
addMtoNImplementor(MtoNImplementor m2nImpl)
Stores the given m:n implementor int the underlying persistence system.
|
void |
beginTransaction()
Begins a transaction against the underlying RDBMS.
|
void |
checkRefreshRelationships(java.lang.Object obj,
Identity oid,
ClassDescriptor cld)
Refreshes the references of the given object whose
refresh
is set to true . |
void |
clearCache()
Clears the broker's internal cache.
|
boolean |
close()
Closes this broker so that no further requests may be made on it.
|
void |
commitTransaction()
Commits and closes the current transaction.
|
void |
configure(org.apache.ojb.broker.util.configuration.Configuration pConfig)
configure an object using the Configuration pConfig
|
java.lang.Object |
createProxy(java.lang.Class proxyClass,
Identity realSubjectsIdentity)
Shortcut method for creating a proxy of the given type.
|
void |
delete(java.lang.Object obj)
Deletes the given object's persistent representation in the underlying persistence system.
|
void |
delete(java.lang.Object obj,
boolean ignoreReferences)
Deletes the persistence representation of the given object in the underlying
persistence system.
|
void |
deleteByQuery(Query query)
Deletes all objects matching the given query, from the underlying persistence system.
|
void |
deleteMtoNImplementor(MtoNImplementor m2nImpl)
Deletes an m:n implementor which defines the relationship between two persistent objects.
|
void |
fireBrokerEvent(PBLifeCycleEvent event)
Fires a life cycle event to inform all registered
PBListener instances. |
void |
fireBrokerEvent(PBStateEvent event)
Fires a state event to inform all registered
PBListener instances. |
void |
fireBrokerEvent(PersistenceBrokerEvent event)
Fires a broker event to inform all registered
PBListener instances. |
ClassDescriptor |
getClassDescriptor(java.lang.Class clazz)
Returns the class descriptor for the given persistence capable class.
|
ManageableCollection |
getCollectionByQuery(java.lang.Class collectionClass,
Query query)
Retrieves the persistent objects matching the given query.
|
java.util.Collection |
getCollectionByQuery(Query query)
Retrieves the persistent objects matching the given query.
|
int |
getCount(Query query)
Returns the number of elements that the given query will return.
|
PersistenceBrokerInternal |
getDelegate()
Returns only the wrapped
PersistenceBroker instance |
DescriptorRepository |
getDescriptorRepository()
Returns the metadata descriptor repository associated with this broker.
|
PersistenceBroker |
getInnermostDelegate()
If my underlying
PersistenceBroker
is not a DelegatingPersistenceBroker , returns it,
otherwise recursively invokes this method on my delegate. |
java.util.Iterator |
getIteratorByQuery(Query query)
Retrieves the persistent objects matching the given query and returns them as an iterator
which may, depending on the configured collection type, be reloading the objects from
the database upon calling
Iterator.next() . |
java.lang.Object |
getObjectByIdentity(Identity id)
Retrieve a persistent object from the underlying datastore by its identity.
|
java.lang.Object |
getObjectByQuery(Query query)
Retrieve the (first) persistent object from the underlying datastore that matches the given
query.
|
PBKey |
getPBKey()
Get the
PBKey for this broker. |
java.util.Enumeration |
getPKEnumerationByQuery(java.lang.Class primaryKeyClass,
Query query)
Returns an enumeration of objects representing the primary keys for the objects that match
the given query.
|
ProxyFactory |
getProxyFactory()
Return the factory for creating proxies.
|
QueryReferenceBroker |
getReferenceBroker()
Returns the broker specifically for retrieving references via query.
|
RelationshipPrefetcherFactory |
getRelationshipPrefetcherFactory()
Return the factory for creating relationship prefetcher objects.
|
java.util.Iterator |
getReportQueryIteratorByQuery(Query query)
Retrieves the rows (as
Object[] instances) matching the given query and
returns them as an iterator which may, depending on the configured collection type, be reloading
the objects from the database upon calling Iterator.next() . |
java.lang.Class |
getTopLevelClass(java.lang.Class clazz)
Returns the top level class (most abstract class in terms of extents) from which the
given class extends.
|
boolean |
hasClassDescriptor(java.lang.Class clazz)
Determines whether the given class is persistence capable and thus has an associated
class descriptor in the metadata.
|
boolean |
isClosed()
Determines whether this broker is closed.
|
boolean |
isInTransaction()
Determines whether there is currently a transaction in progress.
|
boolean |
isManaged()
Determines whether this instance is handled by a managed
environment, i.e.
|
Query |
query()
factory method to create a new
Query object. |
void |
removeAllListeners()
Removes all temporary listeners from this broker.
|
void |
removeAllListeners(boolean permanent)
Removes all temporary and, if desired, permanent listeners from this broker.
|
void |
removeFromCache(java.lang.Object obj)
Removes the given object or, if it is an instance of
Identity ,
the object identified by it, from the broker's internal cache. |
void |
removeListener(PBListener listener)
Removes the specified listener from this broker.
|
void |
retrieveAllReferences(java.lang.Object pInstance)
Retrieve all references and collections of the given object irrespective of the
metadata settings defined for them.
|
void |
retrieveReference(java.lang.Object pInstance,
java.lang.String pAttributeName)
Retrieve the specified reference or collection attribute for the given persistent object.
|
BrokerHelper |
serviceBrokerHelper()
Returns the
BrokerHelper instance associated with this broker, which
makes some additional helper methods available. |
ConnectionManagerIF |
serviceConnectionManager()
Returns the
ConnectionManagerIF instance associated with this broker. |
IdentityFactory |
serviceIdentity()
Return the
IdentityFactory instance associated with this broker. |
JdbcAccess |
serviceJdbcAccess()
Returns the
JdbcAccess instance associated with this broker. |
ObjectCache |
serviceObjectCache()
Returns the
ObjectCache instance associated
with this broker. |
SequenceManager |
serviceSequenceManager()
Returns the
SequenceManager instance associated with this broker. |
org.apache.ojb.broker.accesslayer.sql.SqlGenerator |
serviceSqlGenerator()
Returns the
SqlGenerator instance associated with this broker. |
StatementManagerIF |
serviceStatementManager()
Returns the
StatementManagerIF instance associated with this broker. |
void |
setClosed(boolean closed)
Is called when the persistence broker is activated or passivated (or closed).
|
void |
setDelegate(PersistenceBrokerInternal broker) |
void |
setManaged(boolean managed)
Specifies whether this instance is handled by a managed
environment, i.e.
|
void |
store(java.lang.Object obj)
Make the given object persistent in the underlying persistence system.
|
void |
store(java.lang.Object obj,
Identity oid,
ClassDescriptor cld,
boolean insert,
boolean ignoreReferences)
Performs the real store work (insert or update) and is intended for use by
top-level apis internally.
|
void |
store(java.lang.Object obj,
ObjectModification modification)
Makes the given object persistent in the underlying persistence system.
|
public DelegatingPersistenceBroker(PersistenceBrokerInternal broker)
public PersistenceBrokerInternal getDelegate()
PersistenceBroker
instancepublic void setDelegate(PersistenceBrokerInternal broker)
public PersistenceBroker getInnermostDelegate()
PersistenceBroker
is not a DelegatingPersistenceBroker
, returns it,
otherwise recursively invokes this method on my delegate.
Hence this method will return the first
delegate that is not a DelegatingPersistenceBroker
,
or null when no non-DelegatingPersistenceBroker
delegate can be found by transversing this chain.
This method is useful when you may have nested
DelegatingPersistenceBroker
s, and you want to make
sure to obtain a "genuine" PersistenceBroker
implementaion instance.
public boolean isManaged()
PersistenceBrokerInternal
isManaged
in interface PersistenceBrokerInternal
true
if this broker is managedpublic void setManaged(boolean managed)
PersistenceBrokerInternal
PersistenceBroker.close()
this will automatically be reset
to false.setManaged
in interface PersistenceBrokerInternal
managed
- true
if this broker is managedpublic QueryReferenceBroker getReferenceBroker()
PersistenceBrokerInternal
getReferenceBroker
in interface PersistenceBrokerInternal
public void checkRefreshRelationships(java.lang.Object obj, Identity oid, ClassDescriptor cld)
PersistenceBrokerInternal
refresh
is set to true
.checkRefreshRelationships
in interface PersistenceBrokerInternal
obj
- The object to checkoid
- The identity of the objectcld
- The class descriptor for the objectpublic RelationshipPrefetcherFactory getRelationshipPrefetcherFactory()
PersistenceBrokerInternal
getRelationshipPrefetcherFactory
in interface PersistenceBrokerInternal
public void store(java.lang.Object obj, Identity oid, ClassDescriptor cld, boolean insert, boolean ignoreReferences)
PersistenceBrokerInternal
store
in interface PersistenceBrokerInternal
obj
- The object to storeoid
- The identity of the object to storecld
- The class descriptor of the objectinsert
- If true an insert operation will be performed, else update
operationignoreReferences
- Whether automatic storing of contained references/collections (except
super-references) shall be suppressed (independent of the auto-update
setting in the metadata)public void delete(java.lang.Object obj, boolean ignoreReferences) throws PersistenceBrokerException
PersistenceBrokerInternal
delete
in interface PersistenceBrokerInternal
obj
- The object to deleteignoreReferences
- Whether automatic deletion of contained references/collections (except
super-references) shall be suppressed (independent of the auto-delete
setting in the metadata)PersistenceBrokerException
public boolean isInTransaction() throws PersistenceBrokerException
PersistenceBroker
isInTransaction
in interface PersistenceBroker
true
if there is a transaction in progressPersistenceBrokerException
public boolean isClosed()
PersistenceBroker
isClosed
in interface PersistenceBroker
public void setClosed(boolean closed)
PBState
public void beginTransaction() throws TransactionInProgressException, TransactionAbortedException
PersistenceBroker
beginTransaction
in interface PersistenceBroker
TransactionInProgressException
- If there is already a transaction in progressTransactionAbortedException
public void commitTransaction() throws TransactionNotInProgressException, TransactionAbortedException
PersistenceBroker
commitTransaction
in interface PersistenceBroker
TransactionNotInProgressException
- If there is no transaction currently in progressTransactionAbortedException
- If the transaction cannot be committedpublic void abortTransaction() throws TransactionNotInProgressException
PersistenceBroker
abortTransaction
in interface PersistenceBroker
TransactionNotInProgressException
- If no transaction is currently in progresspublic boolean close()
PersistenceBroker
close
in interface PersistenceBroker
true
if the broker was successfully closedpublic org.apache.ojb.broker.accesslayer.sql.SqlGenerator serviceSqlGenerator()
PersistenceBroker
SqlGenerator
instance associated with this broker.serviceSqlGenerator
in interface PersistenceBroker
public JdbcAccess serviceJdbcAccess()
PersistenceBroker
JdbcAccess
instance associated with this broker.serviceJdbcAccess
in interface PersistenceBroker
public void delete(java.lang.Object obj) throws PersistenceBrokerException
PersistenceBroker
delete
in interface PersistenceBroker
obj
- The object to deletePersistenceBrokerException
public void store(java.lang.Object obj) throws PersistenceBrokerException
PersistenceBroker
store
in interface PersistenceBroker
obj
- The object to storePersistenceBrokerException
public void store(java.lang.Object obj, ObjectModification modification) throws PersistenceBrokerException
PersistenceBroker
store
in interface PersistenceBroker
obj
- The object to storemodification
- Specifies what operation to perform (for generating optimized SQL)PersistenceBrokerException
public PBKey getPBKey()
PersistenceBroker
PBKey
for this broker.getPBKey
in interface PersistenceBroker
public void removeFromCache(java.lang.Object obj) throws PersistenceBrokerException
PersistenceBroker
Identity
,
the object identified by it, from the broker's internal cache. Note that the removal is
not recursive. This means, objects referenced by the removed object will not be
automatically removed from the cache by this operation.removeFromCache
in interface PersistenceBroker
obj
- The object to be removed from the cache or its identityPersistenceBrokerException
public void clearCache() throws PersistenceBrokerException
PersistenceBroker
clearCache
in interface PersistenceBroker
PersistenceBrokerException
public DescriptorRepository getDescriptorRepository()
PersistenceBroker
getDescriptorRepository
in interface PersistenceBroker
public void removeAllListeners() throws PersistenceBrokerException
PersistenceBroker
removeAllListeners
in interface PersistenceBroker
PersistenceBrokerException
PersistenceBroker.removeListener(PBListener)
public void removeAllListeners(boolean permanent) throws PersistenceBrokerException
PersistenceBroker
removeAllListeners
in interface PersistenceBroker
permanent
- Whether the listener will stay registered after closing
the brokerPersistenceBrokerException
PersistenceBroker.removeListener(PBListener)
public void retrieveReference(java.lang.Object pInstance, java.lang.String pAttributeName) throws PersistenceBrokerException
PersistenceBroker
retrieveReference
in interface PersistenceBroker
pInstance
- The persistent objectpAttributeName
- The name of the attribute to retrievePersistenceBrokerException
public void retrieveAllReferences(java.lang.Object pInstance) throws PersistenceBrokerException
PersistenceBroker
retrieveAllReferences
in interface PersistenceBroker
pInstance
- The persistent objectPersistenceBrokerException
public ConnectionManagerIF serviceConnectionManager()
PersistenceBroker
ConnectionManagerIF
instance associated with this broker.serviceConnectionManager
in interface PersistenceBroker
public StatementManagerIF serviceStatementManager()
PersistenceBroker
StatementManagerIF
instance associated with this broker.serviceStatementManager
in interface PersistenceBroker
public SequenceManager serviceSequenceManager()
PersistenceBroker
SequenceManager
instance associated with this broker.serviceSequenceManager
in interface PersistenceBroker
public BrokerHelper serviceBrokerHelper()
PersistenceBroker
BrokerHelper
instance associated with this broker, which
makes some additional helper methods available.serviceBrokerHelper
in interface PersistenceBroker
public ObjectCache serviceObjectCache()
PersistenceBroker
ObjectCache
instance associated
with this broker.serviceObjectCache
in interface PersistenceBroker
public IdentityFactory serviceIdentity()
PersistenceBroker
IdentityFactory
instance associated with this broker.serviceIdentity
in interface PersistenceBroker
public void fireBrokerEvent(PersistenceBrokerEvent event)
PersistenceBroker
PBListener
instances.fireBrokerEvent
in interface PersistenceBroker
event
- The event to firepublic void fireBrokerEvent(PBLifeCycleEvent event)
PersistenceBroker
PBListener
instances.fireBrokerEvent
in interface PersistenceBroker
event
- The event to firepublic void fireBrokerEvent(PBStateEvent event)
PersistenceBroker
PBListener
instances.fireBrokerEvent
in interface PersistenceBroker
event
- The event to firepublic void addListener(PBListener listener) throws PersistenceBrokerException
PersistenceBroker
PBListener
to this broker.
Note that temporary listeners will be removed upon closing a broker (returning
it to the pool).addListener
in interface PersistenceBroker
listener
- The listener to addPersistenceBrokerException
PersistenceBroker.addListener(PBListener, boolean)
public void addListener(PBListener listener, boolean permanent) throws PersistenceBrokerException
PersistenceBroker
PBListener
to this broker,
depending on the parameter value. Note that temporary listeners will be removed upon
closing a broker (returning it to the pool).
PersistenceBrokerFactoryIF
or extend the default
one, PersistenceBrokerFactoryDefaultImpl
. There you
can add the listener at creation of the PersistenceBroker
instances.addListener
in interface PersistenceBroker
listener
- The listener to addpermanent
- Whether the listener will stay registered after closing
the brokerPersistenceBrokerException
public void removeListener(PBListener listener) throws PersistenceBrokerException
PersistenceBroker
removeListener
in interface PersistenceBroker
listener
- The listener to removePersistenceBrokerException
public java.lang.Class getTopLevelClass(java.lang.Class clazz) throws PersistenceBrokerException
PersistenceBroker
getTopLevelClass
in interface PersistenceBroker
clazz
- The class to get the top level class forPersistenceBrokerException
- If the class is not persistence capable,
if no metadata was defined for this classpublic boolean hasClassDescriptor(java.lang.Class clazz)
PersistenceBroker
hasClassDescriptor
in interface PersistenceBroker
clazz
- The target classtrue
if a class descriptor was foundpublic ClassDescriptor getClassDescriptor(java.lang.Class clazz) throws PersistenceBrokerException
PersistenceBroker
getClassDescriptor
in interface PersistenceBroker
clazz
- The target classPersistenceBrokerException
- If the class is not persistence capable, i.e.
if no metadata was defined for this class and hence its class descriptor
was not foundpublic java.util.Enumeration getPKEnumerationByQuery(java.lang.Class primaryKeyClass, Query query) throws PersistenceBrokerException
PersistenceBroker
getPKEnumerationByQuery
in interface PersistenceBroker
primaryKeyClass
- The class to use for the primary keysquery
- The queryPersistenceBrokerException
public java.lang.Object getObjectByQuery(Query query) throws PersistenceBrokerException
PersistenceBroker
getObjectByQuery
in interface PersistenceBroker
query
- The queryPersistenceBrokerException
public java.lang.Object getObjectByIdentity(Identity id) throws PersistenceBrokerException
PersistenceBroker
PersistenceBroker.getObjectByQuery(Query)
instead, as this method is mainly
intended to be used for internal handling of materialization by OID (e.g. in Proxies).getObjectByIdentity
in interface PersistenceBroker
id
- The persistent object's idPersistenceBrokerException
public java.util.Iterator getReportQueryIteratorByQuery(Query query) throws PersistenceBrokerException
PersistenceBroker
Object[]
instances) matching the given query and
returns them as an iterator which may, depending on the configured collection type, be reloading
the objects from the database upon calling Iterator.next()
.getReportQueryIteratorByQuery
in interface PersistenceBroker
query
- The report queryPersistenceBrokerException
public java.util.Iterator getIteratorByQuery(Query query) throws PersistenceBrokerException
PersistenceBroker
Iterator.next()
. Note that if the Query has no criteria
ALL persistent objects of the class targeted by the query will be returned.getIteratorByQuery
in interface PersistenceBroker
query
- The queryPersistenceBrokerException
public ManageableCollection getCollectionByQuery(java.lang.Class collectionClass, Query query) throws PersistenceBrokerException
PersistenceBroker
getCollectionByQuery
in interface PersistenceBroker
collectionClass
- The collection type which needs to implement
ManageableCollection
query
- The queryPersistenceBrokerException
public int getCount(Query query) throws PersistenceBrokerException
PersistenceBroker
getCount
in interface PersistenceBroker
query
- The queryPersistenceBrokerException
public java.util.Collection getCollectionByQuery(Query query) throws PersistenceBrokerException
PersistenceBroker
getCollectionByQuery
in interface PersistenceBroker
query
- The queryPersistenceBrokerException
public void configure(org.apache.ojb.broker.util.configuration.Configuration pConfig) throws org.apache.ojb.broker.util.configuration.ConfigurationException
org.apache.ojb.broker.util.configuration.Configurable
configure
in interface org.apache.ojb.broker.util.configuration.Configurable
pConfig
- the Configuration object used to configure current instanceorg.apache.ojb.broker.util.configuration.ConfigurationException
public Query query()
ObjectContainer
Query
object.query
in interface ObjectContainer
public void deleteByQuery(Query query) throws PersistenceBrokerException
PersistenceBroker
deleteByQuery
in interface PersistenceBroker
query
- The query determining the objects to deletePersistenceBrokerException
public void deleteMtoNImplementor(MtoNImplementor m2nImpl) throws PersistenceBrokerException
PersistenceBroker
deleteMtoNImplementor
in interface PersistenceBroker
m2nImpl
- The m:n implementor to deletePersistenceBrokerException
PersistenceBroker.deleteMtoNImplementor(org.apache.ojb.broker.MtoNImplementor)
public void addMtoNImplementor(MtoNImplementor m2nImpl) throws PersistenceBrokerException
PersistenceBroker
addMtoNImplementor
in interface PersistenceBroker
m2nImpl
- The m:n implementor to deletePersistenceBrokerException
PersistenceBroker.addMtoNImplementor(org.apache.ojb.broker.MtoNImplementor)
public ProxyFactory getProxyFactory()
PersistenceBrokerInternal
getProxyFactory
in interface PersistenceBrokerInternal
public java.lang.Object createProxy(java.lang.Class proxyClass, Identity realSubjectsIdentity)
PersistenceBrokerInternal
createProxy
in interface PersistenceBrokerInternal
proxyClass
- The proxy typerealSubjectsIdentity
- The identity of the real subject(C) 2002 - 2005 Apache Software Foundation
All rights reserved. Published under the Apache License 2.0.
http://db.apache.org/ojb
Version: 1.0.4, 2005-12-30