ojb.broker
Class PersistenceBrokerImpl

java.lang.Object
  |
  +--ojb.broker.PersistenceBrokerImpl
All Implemented Interfaces:
PersistenceBroker

public class PersistenceBrokerImpl
extends java.lang.Object
implements PersistenceBroker

The PersistenceBrokerClient is an implementation of the PersistenceBroker Interface that specifies a persistence mechanism for generic objects. This Concrete implementation provides an object relational mapping and allows to store and retrieve arbitrary objects in/from relational databases accessed by JDBC.

Author:
Thomas Mahler
See Also:
for a sample application

Constructor Summary
PersistenceBrokerImpl(DescriptorRepository repository)
           
 
Method Summary
 void abortTransaction()
          Abort and close the transaction.
 void beginTransaction()
          begin a transaction against the underlying RDBMS.
 void checkPoint()
           
 void commitTransaction()
          Commit and close the transaction.
 void delete(java.lang.Object obj)
          deletes Object obj's representation in the underlying RDBMS
 ManageableCollection getCollectionByQuery(java.lang.Class collectionClass, Query query)
          retrieve a collection of itemClass Objects matching the Query query
 java.util.Collection getCollectionByQuery(Query query)
          retrieve a collection of itemClass Objects matching the Query query
 ConnectionManager getConnectionManager()
           
 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)
          Method declaration
 java.lang.Object getObjectByQuery(Query query)
          retrieve an Object by query I.e perform a SELECT ...
 java.util.Enumeration getPKEnumerationByQuery(java.lang.Class primaryKeyClass, Query query)
          returns an Enumeration of PrimaryKey Objects for objects of class DataClass.
 StatementManager getStatementManager()
           
 int getUniqueId(java.lang.Class extent, java.lang.String attribute)
          returns a unique int for class extent and field attribute. the returned uid is unique accross all tables in the extent of class extent.
 boolean isInTransaction()
          returns true if the broker is currently running a transaction.
 void removeFromCache(java.lang.Object obj)
          removes the objects obj from the brokers internal cache. removing is recursive.
 void retrieveCollections(java.lang.Object newObj, ClassDescriptor mif)
          Method declaration
 void retrieveReferences(java.lang.Object newObj, ClassDescriptor mif)
          Method declaration
static void setDebug(boolean b)
          set the debugging flag to true to enable debugging
 void store(java.lang.Object obj)
          Method declaration
 void store(java.lang.Object obj, ObjectModification mod)
          makes object obj persistent in the underlying persistence system.
 void storeImmediate(java.lang.Object obj)
          make object obj persistent in the underlying persistence system. this method does not care about transactions.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PersistenceBrokerImpl

public PersistenceBrokerImpl(DescriptorRepository repository)
Method Detail

setDebug

public static void setDebug(boolean b)
set the debugging flag to true to enable debugging

getStatementManager

public StatementManager getStatementManager()

getConnectionManager

public ConnectionManager getConnectionManager()

delete

public void delete(java.lang.Object obj)
            throws PersistenceBrokerException
deletes Object obj's representation in the underlying RDBMS
Specified by:
delete in interface PersistenceBroker

store

public void store(java.lang.Object obj)
           throws PersistenceBrokerException
Method declaration
Specified by:
store in interface PersistenceBroker
Parameters:
obj -  
Throws:
PersistenceBrokerException -  
See Also:

retrieveReferences

public void retrieveReferences(java.lang.Object newObj,
                               ClassDescriptor mif)
Method declaration
Parameters:
newObj -  
mif -  
See Also:

retrieveCollections

public void retrieveCollections(java.lang.Object newObj,
                                ClassDescriptor mif)
Method declaration
Parameters:
newObj -  
mif -  
See Also:

abortTransaction

public void abortTransaction()
                      throws TransactionNotInProgressException
Abort and close the transaction. Calling abort abandons all persistent object modifications and releases the associated locks. If transaction is not in progress a TransactionNotInProgressException is thrown
Specified by:
abortTransaction in interface PersistenceBroker

beginTransaction

public void beginTransaction()
                      throws TransactionInProgressException,
                             TransactionAbortedException
begin a transaction against the underlying RDBMS. Calling beginTransaction multiple times, without an intervening call to commitTransaction or abortTransaction, causes the exception TransactionInProgressException to be thrown on the second and subsequent calls.
Specified by:
beginTransaction in interface PersistenceBroker

commitTransaction

public void commitTransaction()
                       throws TransactionNotInProgressException,
                              TransactionAbortedException
Commit and close the transaction. Calling 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.
Specified by:
commitTransaction in interface PersistenceBroker

checkPoint

public void checkPoint()
                throws TransactionNotInProgressException,
                       TransactionAbortedException

getCollectionByQuery

public ManageableCollection getCollectionByQuery(java.lang.Class collectionClass,
                                                 Query query)
                                          throws PersistenceBrokerException
retrieve a collection of itemClass Objects matching the Query query
Specified by:
getCollectionByQuery in interface PersistenceBroker

getCollectionByQuery

public java.util.Collection getCollectionByQuery(Query query)
                                          throws PersistenceBrokerException
retrieve a collection of itemClass Objects matching the Query query
Specified by:
getCollectionByQuery in interface PersistenceBroker

getIteratorByQuery

public java.util.Iterator getIteratorByQuery(Query query)
                                      throws PersistenceBrokerException
returns an Iterator that iterates Objects of class c if calling the .next() method. The Elements returned come from a SELECT ... WHERE Statement that is defined by the Query query. If itemProxy is null, no proxies are used.
Specified by:
getIteratorByQuery in interface PersistenceBroker

getObjectByIdentity

public java.lang.Object getObjectByIdentity(Identity id)
                                     throws PersistenceBrokerException
Method declaration
Specified by:
getObjectByIdentity in interface PersistenceBroker
Parameters:
id -  
Returns:
 
Throws:
PersistenceBrokerException -  
See Also:

getObjectByQuery

public java.lang.Object getObjectByQuery(Query query)
                                  throws PersistenceBrokerException
retrieve an Object by query I.e perform a SELECT ... FROM ... WHERE ... in an RDBMS
Specified by:
getObjectByQuery in interface PersistenceBroker

getPKEnumerationByQuery

public java.util.Enumeration getPKEnumerationByQuery(java.lang.Class primaryKeyClass,
                                                     Query query)
                                              throws PersistenceBrokerException
returns an Enumeration of PrimaryKey Objects for objects of class DataClass. The Elements returned come from a SELECT ... WHERE Statement that is defined by the fields and their coresponding values of vecFields and vecValues. Useful for EJB Finder Methods...
Specified by:
getPKEnumerationByQuery in interface PersistenceBroker
Parameters:
PrimaryKeyClass - the pk class for the searched objects
query - the query

store

public void store(java.lang.Object obj,
                  ObjectModification mod)
           throws PersistenceBrokerException
makes object obj persistent in the underlying persistence system. E.G. by INSERT INTO ... or UPDATE ... in an RDBMS. The ModificationState parameter can be used to generate optimized SQL code. This functionality is typically called from transaction managers, that track which objects have to be stored. Thus this store method does not use update cascading to referenced objects.
Specified by:
store in interface PersistenceBroker

isInTransaction

public boolean isInTransaction()
returns true if the broker is currently running a transaction.
Returns:
boolean

getUniqueId

public int getUniqueId(java.lang.Class extent,
                       java.lang.String attribute)
Description copied from interface: PersistenceBroker
returns a unique int for class extent and field attribute. the returned uid is unique accross all tables in the extent of class extent.
Specified by:
getUniqueId in interface PersistenceBroker

removeFromCache

public void removeFromCache(java.lang.Object obj)
                     throws PersistenceBrokerException
removes the objects obj from the brokers internal cache. removing is recursive. That is referenced Objects are also removed from the cache, if the auto-retrieve flag is set for obj.getClass() in the metadata repository.
Specified by:
removeFromCache in interface PersistenceBroker

storeImmediate

public void storeImmediate(java.lang.Object obj)
                    throws PersistenceBrokerException
make object obj persistent in the underlying persistence system. this method does not care about transactions. It just performs an immediate update or insert.
Specified by:
storeImmediate in interface PersistenceBroker


Authors: Thomas Mahler, David Dixon-Peugh. (C) 2000, 2001.
All rights reserved. Published under the Gnu Public License.
http://objectbridge.sourceforge.net
Version: 0.5.180, 2001-09-29