|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.ojb.broker.core.PersistenceBrokerAbstractImpl
org.apache.ojb.broker.core.PersistenceBrokerImpl
The PersistenceBrokerImpl is an implementation of the PersistenceBroker Interface that specifies a persistence mechanism for Java objects. This Concrete implementation provides an object relational mapping and allows to store and retrieve arbitrary objects in/from relational databases accessed by JDBC.
Constructor Summary | |
PersistenceBrokerImpl(PBKey key,
PersistenceBrokerFactoryIF pbf)
Constructor used by PersistenceBrokerFactoryIF implementation. |
Method Summary | |
void |
abortTransaction()
Abort and close the transaction. |
void |
addMtoNImplementor(MtoNImplementor m2n)
Stores the given m:n implementor int the underlying persistence system. |
void |
beginTransaction()
begin a transaction against the underlying RDBMS. |
void |
checkRefreshRelationships(java.lang.Object obj,
Identity oid,
ClassDescriptor cld)
Check if the references of the specified object have enabled the refresh attribute and refresh the reference if set true. |
void |
clearCache()
clears the brokers internal cache. |
boolean |
close()
Closes this broker so that no further requests may be made on it. |
void |
commitTransaction()
Commit and close the transaction. |
java.lang.Object |
createProxy(java.lang.Class baseClassForProxy,
Identity realSubjectsIdentity)
Creates a proxy instance. |
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 concrete representation of the specified 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 |
destroy()
Release all resources used by this class - CAUTION: No further operations can be done with this instance after calling this method. |
java.lang.Object |
doGetObjectByIdentity(Identity id)
Internal used method to retrieve object based on Identity. |
ClassDescriptor |
getClassDescriptor(java.lang.Class clazz)
returns a ClassDescriptor for the persistence capable class clazz. |
ManageableCollection |
getCollectionByQuery(java.lang.Class collectionClass,
Query query)
retrieve a collection of type collectionClass matching the Query query |
java.util.Collection |
getCollectionByQuery(Query query)
retrieve a collection of itemClass Objects matching the Query query |
int |
getCount(Query query)
Returns the number of elements that the given query will return. |
DescriptorRepository |
getDescriptorRepository()
Returns the metadata descriptor repository associated with this broker. |
MaterializationCache |
getInternalCache()
|
java.util.Iterator |
getIteratorByQuery(Query query)
returns an Iterator that iterates Objects of class c if calling the .next() method. |
java.lang.Object |
getObjectByIdentity(Identity id)
Retrieve a persistent object from the underlying datastore by its identity. |
java.lang.Object |
getObjectByQuery(Query query)
retrieve an Object by query I.e perform a SELECT ... |
PBKey |
getPBKey()
Get the PBKey for this broker. |
java.util.Enumeration |
getPKEnumerationByQuery(java.lang.Class primaryKeyClass,
Query query)
returns an Enumeration of PrimaryKey Objects for objects of class DataClass. |
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)
Get an Iterator based on the ReportQuery |
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()
returns true if the broker is currently running a transaction. |
boolean |
isManaged()
If true this instance is handled by a managed environment - registered within a JTA transaction. |
void |
link(java.lang.Object targetObject,
ClassDescriptor cld,
ObjectReferenceDescriptor rds,
java.lang.Object referencedObject,
boolean insert)
Assign FK value to target object by reading PK values of referenced object. |
void |
linkMtoN(java.lang.Object obj,
CollectionDescriptor cod,
boolean insert)
Assign FK values and store entries in indirection table for all objects referenced by given object. |
void |
linkOneToMany(java.lang.Object obj,
CollectionDescriptor cod,
boolean insert)
Assign FK value to all n-side objects referenced by given object. |
void |
linkOneToOne(java.lang.Object obj,
ClassDescriptor cld,
ObjectReferenceDescriptor rds,
boolean insert)
Assign FK value of main object with PK values of the reference object. |
Query |
query()
factory method to create a new Query object. |
void |
refresh()
Lookup the current DescriptorRepository for
this class. |
void |
removeFromCache(java.lang.Object objectOrIdentity)
Removes the given object or, if it is an instance of Identity ,
the object identified by it, from the broker's internal cache. |
void |
retrieveAllReferences(java.lang.Object pInstance)
Retrieve all References (also Collection-attributes) of a given instance. |
void |
retrieveReference(java.lang.Object pInstance,
java.lang.String pAttributeName)
retrieve a single reference- or collection attribute of a persistent instance. |
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 |
setInTransaction(boolean inTransaction)
|
void |
setManaged(boolean managed)
Set true if this instance is registered within a JTA transaction. |
void |
setPBKey(PBKey key)
|
void |
store(java.lang.Object obj)
Store an Object. |
void |
store(java.lang.Object obj,
Identity oid,
ClassDescriptor cld,
boolean insert,
boolean ignoreReferences)
Method which start the real store work (insert or update) and is intended for use by top-level api or internal calls. |
void |
store(java.lang.Object obj,
ObjectModification mod)
Makes object obj persistent in the underlying persistence system. |
void |
unlinkFK(java.lang.Object targetObject,
ClassDescriptor cld,
ObjectReferenceDescriptor rds)
Unkink FK fields of target object. |
void |
unlinkXtoN(java.lang.Object obj,
CollectionDescriptor col)
|
Methods inherited from class org.apache.ojb.broker.core.PersistenceBrokerAbstractImpl |
addListener, addListener, configure, fireBrokerEvent, fireBrokerEvent, fireBrokerEvent, isTxCheck, removeAllListeners, removeAllListeners, removeListener, setTxCheck |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public PersistenceBrokerImpl(PBKey key, PersistenceBrokerFactoryIF pbf)
PersistenceBrokerFactoryIF
implementation.
Method Detail |
public MaterializationCache getInternalCache()
public IdentityFactory serviceIdentity()
PersistenceBroker
IdentityFactory
instance associated with this broker.
serviceIdentity
in interface PersistenceBroker
public org.apache.ojb.broker.accesslayer.sql.SqlGenerator serviceSqlGenerator()
PersistenceBroker
SqlGenerator
instance associated with this broker.
serviceSqlGenerator
in interface PersistenceBroker
public StatementManagerIF serviceStatementManager()
PersistenceBroker
StatementManagerIF
instance associated with this broker.
serviceStatementManager
in interface PersistenceBroker
public JdbcAccess serviceJdbcAccess()
PersistenceBroker
JdbcAccess
instance associated with this broker.
serviceJdbcAccess
in interface PersistenceBroker
public ConnectionManagerIF serviceConnectionManager()
PersistenceBroker
ConnectionManagerIF
instance associated with this broker.
serviceConnectionManager
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 QueryReferenceBroker getReferenceBroker()
PersistenceBrokerInternal
getReferenceBroker
in interface PersistenceBrokerInternal
public RelationshipPrefetcherFactory getRelationshipPrefetcherFactory()
PersistenceBrokerInternal
getRelationshipPrefetcherFactory
in interface PersistenceBrokerInternal
public boolean isClosed()
PersistenceBroker
isClosed
in interface PersistenceBroker
public void setClosed(boolean closed)
PBState
setClosed
in interface PBState
closed
- Whether the broker is passivated (closed)public boolean isManaged()
isManaged
in interface PersistenceBrokerInternal
true
if this broker is managedpublic void setManaged(boolean managed)
close()
call this flag was reset
to false automatic.
setManaged
in interface PersistenceBrokerInternal
managed
- true
if this broker is managedpublic void refresh()
DescriptorRepository
for
this class. This method is responsible to keep this
PB instance in sync with MetadataManager
.
public void destroy()
public PBKey getPBKey()
PersistenceBroker
PBKey
for this broker.
getPBKey
in interface PersistenceBroker
public void setPBKey(PBKey key)
public boolean close()
PersistenceBroker
close
in interface PersistenceBroker
true
if the broker was successfully closedPersistenceBroker.close()
public void abortTransaction() throws TransactionNotInProgressException
abortTransaction
in interface PersistenceBroker
TransactionNotInProgressException
- If no transaction is currently in progresspublic void beginTransaction() throws TransactionInProgressException, TransactionAbortedException
beginTransaction
multiple times,
without an intervening call to commitTransaction
or abortTransaction
,
causes the exception TransactionInProgressException
to be thrown
on the second and subsequent calls.
beginTransaction
in interface PersistenceBroker
TransactionInProgressException
- If there is already a transaction in progress
TransactionAbortedException
public void commitTransaction() throws TransactionNotInProgressException, TransactionAbortedException
commit
commits to the database all
UPDATE, INSERT and DELETE statements called within the transaction and
releases any locks held by the transaction.
If beginTransaction() has not been called before a
TransactionNotInProgressException exception is thrown.
If the transaction cannot be commited a TransactionAbortedException exception is thrown.
commitTransaction
in interface PersistenceBroker
TransactionNotInProgressException
- If there is no transaction currently in progress
TransactionAbortedException
- If the transaction cannot be committedpublic void delete(java.lang.Object obj, boolean ignoreReferences) throws PersistenceBrokerException
delete
in interface PersistenceBrokerInternal
obj
- The object to delete.ignoreReferences
- With this flag the automatic deletion/unlinking
of references can be suppressed (independent of the used auto-delete setting in metadata),
except SuperReferenceDescriptor
these kind of reference (descriptor) will always be performed. If true
all "normal" referenced objects will be ignored, only the specified object is handled.
PersistenceBrokerException
public void delete(java.lang.Object obj) throws PersistenceBrokerException
PersistenceBroker
delete
in interface PersistenceBroker
obj
- The object to delete
PersistenceBrokerException
PersistenceBroker.delete(java.lang.Object)
public void deleteByQuery(Query query) throws PersistenceBrokerException
PersistenceBroker
deleteByQuery
in interface PersistenceBroker
query
- The query determining the objects to delete
PersistenceBrokerException
PersistenceBroker.deleteByQuery(Query)
public void store(java.lang.Object obj) throws PersistenceBrokerException
store
in interface PersistenceBroker
obj
- The object to store
PersistenceBrokerException
PersistenceBroker.store(Object)
public void store(java.lang.Object obj, Identity oid, ClassDescriptor cld, boolean insert, boolean ignoreReferences)
store
in interface PersistenceBrokerInternal
obj
- The object to store.oid
- The Identity
of the object to store.cld
- The ClassDescriptor
of the object.insert
- If true an insert operation will be performed, else update operation.ignoreReferences
- With this flag the automatic storing/linking
of references can be suppressed (independent of the used auto-update setting in metadata),
except SuperReferenceDescriptor
these kind of reference (descriptor) will always be performed. If true
all "normal" referenced objects will be ignored, only the specified object is handled.public void link(java.lang.Object targetObject, ClassDescriptor cld, ObjectReferenceDescriptor rds, java.lang.Object referencedObject, boolean insert)
targetObject
- real (non-proxy) target objectcld
- ClassDescriptor
of the real target objectrds
- An ObjectReferenceDescriptor
or CollectionDescriptor
associated with the real object.referencedObject
- referenced object or proxyinsert
- Show if "linking" is done while insert or update.public void unlinkFK(java.lang.Object targetObject, ClassDescriptor cld, ObjectReferenceDescriptor rds)
targetObject
- real (non-proxy) target objectcld
- ClassDescriptor
of the real target objectrds
- An ObjectReferenceDescriptor
or CollectionDescriptor
associated with the real object.public void linkOneToOne(java.lang.Object obj, ClassDescriptor cld, ObjectReferenceDescriptor rds, boolean insert)
obj
- real object with reference (proxy) object (or real object with set FK values on insert)cld
- ClassDescriptor
of the real objectrds
- An ObjectReferenceDescriptor
of real object.insert
- Show if "linking" is done while insert or update.public void linkOneToMany(java.lang.Object obj, CollectionDescriptor cod, boolean insert)
obj
- real object with 1:n referencecod
- CollectionDescriptor
of referenced 1:n objectsinsert
- flag signal insert operation, false signals update operationpublic void linkMtoN(java.lang.Object obj, CollectionDescriptor cod, boolean insert)
obj
- real object with 1:n referencecod
- CollectionDescriptor
of referenced 1:n objectsinsert
- flag signal insert operation, false signals update operationpublic void unlinkXtoN(java.lang.Object obj, CollectionDescriptor col)
public void retrieveAllReferences(java.lang.Object pInstance) throws PersistenceBrokerException
retrieveAllReferences
in interface PersistenceBroker
pInstance
- the persistent instance to work with
PersistenceBrokerException
public void retrieveReference(java.lang.Object pInstance, java.lang.String pAttributeName) throws PersistenceBrokerException
retrieveReference
in interface PersistenceBroker
pInstance
- the persistent instancepAttributeName
- the name of the Attribute to load
PersistenceBrokerException
public void checkRefreshRelationships(java.lang.Object obj, Identity oid, ClassDescriptor cld)
checkRefreshRelationships
in interface PersistenceBrokerInternal
obj
- The object to check.oid
- The Identity
of the object.cld
- The ClassDescriptor
of the object.
PersistenceBrokerException
- if there is a error refreshing collections or referencespublic ManageableCollection getCollectionByQuery(java.lang.Class collectionClass, Query query) throws PersistenceBrokerException
getCollectionByQuery
in interface PersistenceBroker
collectionClass
- The collection type which needs to implement
ManageableCollection
query
- The query
PersistenceBrokerException
PersistenceBroker.getCollectionByQuery(Class, Query)
public java.util.Collection getCollectionByQuery(Query query) throws PersistenceBrokerException
getCollectionByQuery
in interface PersistenceBroker
query
- The query
PersistenceBrokerException
public java.util.Iterator getIteratorByQuery(Query query) throws PersistenceBrokerException
getIteratorByQuery
in interface PersistenceBroker
query
- The query
PersistenceBrokerException
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 id
PersistenceBrokerException
public java.lang.Object doGetObjectByIdentity(Identity id) throws PersistenceBrokerException
id
-
PersistenceBrokerException
public java.lang.Object getObjectByQuery(Query query) throws PersistenceBrokerException
getObjectByQuery
in interface PersistenceBroker
query
- The query
PersistenceBrokerException
public java.util.Enumeration getPKEnumerationByQuery(java.lang.Class primaryKeyClass, Query query) throws PersistenceBrokerException
getPKEnumerationByQuery
in interface PersistenceBroker
primaryKeyClass
- the pk class for the searched objectsquery
- the query
PersistenceBrokerException
public void store(java.lang.Object obj, ObjectModification mod) throws PersistenceBrokerException
store
in interface PersistenceBroker
obj
- The object to storemod
- Specifies what operation to perform (for generating optimized SQL)
PersistenceBrokerException
public boolean isInTransaction()
isInTransaction
in interface PersistenceBroker
public void setInTransaction(boolean inTransaction)
public void removeFromCache(java.lang.Object objectOrIdentity) 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
objectOrIdentity
- The object to be removed from the cache or its identity
PersistenceBrokerException
PersistenceBroker.removeFromCache(java.lang.Object)
public ClassDescriptor getClassDescriptor(java.lang.Class clazz) throws PersistenceBrokerException
getClassDescriptor
in interface PersistenceBroker
clazz
- The target class
PersistenceBrokerException
- 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 boolean hasClassDescriptor(java.lang.Class clazz)
PersistenceBroker
hasClassDescriptor
in interface PersistenceBroker
clazz
- The target class
true
if a class descriptor was foundpublic void clearCache() throws PersistenceBrokerException
clearCache
in interface PersistenceBroker
PersistenceBrokerException
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 for
PersistenceBrokerException
- If the class is not persistence capable,
if no metadata was defined for this classPersistenceBroker.getTopLevelClass(java.lang.Class)
public int getCount(Query query) throws PersistenceBrokerException
PersistenceBroker
getCount
in interface PersistenceBroker
query
- The query
PersistenceBrokerException
PersistenceBroker.getCount(Query)
public java.util.Iterator getReportQueryIteratorByQuery(Query query) throws PersistenceBrokerException
getReportQueryIteratorByQuery
in interface PersistenceBroker
query
-
PersistenceBrokerException
public Query query()
ObjectContainer
Query
object.
query
in interface ObjectContainer
ObjectContainer.query()
public DescriptorRepository getDescriptorRepository()
PersistenceBroker
getDescriptorRepository
in interface PersistenceBroker
public void deleteMtoNImplementor(MtoNImplementor m2nImpl) throws PersistenceBrokerException
PersistenceBroker
deleteMtoNImplementor
in interface PersistenceBroker
m2nImpl
- The m:n implementor to delete
PersistenceBrokerException
PersistenceBroker.deleteMtoNImplementor(org.apache.ojb.broker.MtoNImplementor)
public void addMtoNImplementor(MtoNImplementor m2n) throws PersistenceBrokerException
PersistenceBroker
addMtoNImplementor
in interface PersistenceBroker
m2n
- The m:n implementor to delete
PersistenceBrokerException
PersistenceBroker.addMtoNImplementor(org.apache.ojb.broker.MtoNImplementor)
public ProxyFactory getProxyFactory()
PersistenceBrokerInternal
getProxyFactory
in interface PersistenceBrokerInternal
public java.lang.Object createProxy(java.lang.Class baseClassForProxy, Identity realSubjectsIdentity)
createProxy
in interface PersistenceBrokerInternal
baseClassForProxy
- The base class that the Proxy should extend. For dynamic Proxies, the method of
generation is dependent on the ProxyFactory implementation.realSubjectsIdentity
- The identity of the subject
PersistenceBrokerException
- If there is an error creating the proxy object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |