ojb.broker.singlevm
Class PersistenceBrokerImpl

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

public class PersistenceBrokerImpl
extends java.lang.Object
implements PersistenceBroker

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. * * @see test.ojb.tutorial1.Application for a sample application * @author Thomas Mahler


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 clearCache()
          clears the brokers internal cache
 boolean close()
          close connection to last opened repository.
 void commitTransaction()
          Commit and close the transaction
 void delete(java.lang.Object obj)
          deletes Object obj's representation in the underlying RDBMS
 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 *
 ManageableCollection getCollectionByQuery(java.lang.Class collectionClass, Query query, boolean lazy)
           
 java.util.Collection getCollectionByQuery(Query query)
          * retrieve a collection of itemClass Objects matching the Query query *
 java.util.Collection getCollectionByQuery(Query query, boolean lazy)
          * retrieve a collection of itemClass Objects matching the Query query *
 ConnectionManager getConnectionManager()
           
 int getCount(Query query)
          returns the count of elements a given query will return.
 java.lang.Class getExtentClass(java.lang.Class clazz)
          returns the Extent to which the class clazz belongs
 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 * * @param id * @return * @throws PersistenceBrokerException
 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
 java.util.Iterator getReportQueryIteratorByQuery(Query query)
          returns an Iterator that iterates Object[] calling the .next() method.
 StatementManager getStatementManager()
           
 int getUniqueId(java.lang.Class extent, java.lang.String attribute)
          returns a unique int for class extent and field attribute.
 long getUniqueLong(java.lang.Class extent, java.lang.String attribute)
          returns a unique long for class extent and field attribute
 java.lang.Object getUniqueObject(java.lang.Class extent, java.lang.String attribute)
          returns a unique Object for class extent and field attribute
 java.lang.String getUniqueString(java.lang.Class extent, java.lang.String attribute)
          returns a unique String for class extent and field attribute
 void invalidate(Identity oid)
          * removes the objects obj from the brokers internal cache and * inform other caches in OJB cluster about invalidation.
 boolean isInTransaction()
          returns true if the broker is currently running a transaction
 boolean open(java.lang.String repository, java.lang.String user, java.lang.String passwd)
          open a repository. returns true if successfull, else false.
 void refreshRelationships(java.lang.Object obj, ClassDescriptor cld)
          Refresh Relationships * * @param newObj * @param mif
 void removeFromCache(java.lang.Object obj)
          removes the objects obj from the brokers internal cache.
 void retrieveCollections(java.lang.Object newObj, ClassDescriptor mif)
          Retrieve all Collections * * @param newObj * @param mif *
 void retrieveReferences(java.lang.Object newObj, ClassDescriptor mif)
          Retrieve all References * * * @param newObj * @param mif *
 void setClassDescriptor(ClassDescriptor modifiedOrNewDescriptor)
          adds a new or replaces an existing ClassDescriptor to the DescriptorRepository.
 void store(java.lang.Object obj)
          Method declaration * * * @param obj * * @throws PersistenceBrokerException * *
 void store(java.lang.Object obj, ObjectModification mod)
          makes object obj persistent in the underlying persistence system
 
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

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
PersistenceBrokerException

store

public void store(java.lang.Object obj)
           throws PersistenceBrokerException
Method declaration * * * @param obj * * @throws PersistenceBrokerException * *

Specified by:
store in interface PersistenceBroker
PersistenceBrokerException

retrieveReferences

public void retrieveReferences(java.lang.Object newObj,
                               ClassDescriptor mif)
                        throws PersistenceBrokerException
Retrieve all References * * * @param newObj * @param mif *

PersistenceBrokerException

retrieveCollections

public void retrieveCollections(java.lang.Object newObj,
                                ClassDescriptor mif)
                         throws PersistenceBrokerException
Retrieve all Collections * * @param newObj * @param mif *

PersistenceBrokerException

refreshRelationships

public void refreshRelationships(java.lang.Object obj,
                                 ClassDescriptor cld)
                          throws PersistenceBrokerException
Refresh Relationships * * @param newObj * @param mif

PersistenceBrokerException

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
TransactionNotInProgressException

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
TransactionInProgressException
TransactionAbortedException

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
TransactionNotInProgressException
TransactionAbortedException

checkPoint

public void checkPoint()
                throws TransactionNotInProgressException,
                       TransactionAbortedException
TransactionNotInProgressException
TransactionAbortedException

getCollectionByQuery

public ManageableCollection getCollectionByQuery(java.lang.Class collectionClass,
                                                 Query query)
                                          throws PersistenceBrokerException
* retrieve a collection of type collectionClass matching the Query query *

Specified by:
getCollectionByQuery in interface PersistenceBroker
PersistenceBrokerException

getCollectionByQuery

public ManageableCollection getCollectionByQuery(java.lang.Class collectionClass,
                                                 Query query,
                                                 boolean lazy)
                                          throws PersistenceBrokerException
PersistenceBrokerException

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
PersistenceBrokerException

getCollectionByQuery

public java.util.Collection getCollectionByQuery(Query query,
                                                 boolean lazy)
                                          throws PersistenceBrokerException
* retrieve a collection of itemClass Objects matching the Query query *

PersistenceBrokerException

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
PersistenceBrokerException

getObjectByIdentity

public java.lang.Object getObjectByIdentity(Identity id)
                                     throws PersistenceBrokerException
Method declaration * * @param id * @return * @throws PersistenceBrokerException

Specified by:
getObjectByIdentity in interface PersistenceBroker
PersistenceBrokerException

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
PersistenceBrokerException

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... * @param PrimaryKeyClass the pk class for the searched objects * @param query the query

Specified by:
getPKEnumerationByQuery in interface PersistenceBroker
Parameters:
primaryKeyClass - the pk class for the searched objects
query - the query
PersistenceBrokerException

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 ObjectModification parameter can be used to determine whether INSERT or update is to be used. * This functionality is typically called from transaction managers, that * track which objects have to be stored.

Specified by:
store in interface PersistenceBroker
PersistenceBrokerException

isInTransaction

public boolean isInTransaction()
returns true if the broker is currently running a transaction. * @return boolean

Specified by:
isInTransaction in interface PersistenceBroker

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.

Specified by:
removeFromCache in interface PersistenceBroker
PersistenceBrokerException

getUniqueString

public java.lang.String getUniqueString(java.lang.Class extent,
                                        java.lang.String attribute)
                                 throws PersistenceBrokerException
returns a unique String for class extent and field attribute. * * the returned String is unique accross all tables in the extent of class extent. *

Specified by:
getUniqueString in interface PersistenceBroker
PersistenceBrokerException

getUniqueObject

public java.lang.Object getUniqueObject(java.lang.Class extent,
                                        java.lang.String attribute)
                                 throws PersistenceBrokerException
returns a unique Object for class extent and field attribute. * the returned Object is unique accross all tables in the extent of class extent.

Specified by:
getUniqueObject in interface PersistenceBroker
PersistenceBrokerException

getClassDescriptor

public ClassDescriptor getClassDescriptor(java.lang.Class clazz)
                                   throws PersistenceBrokerException
returns a ClassDescriptor for the persistence capable class clazz. * throws a PersistenceBrokerException if clazz is not persistence capable, * i.e. if clazz is not defined in the DescriptorRepository.

Specified by:
getClassDescriptor in interface PersistenceBroker
PersistenceBrokerException

clearCache

public void clearCache()
                throws PersistenceBrokerException
clears 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:
clearCache in interface PersistenceBroker
PersistenceBrokerException

setClassDescriptor

public void setClassDescriptor(ClassDescriptor modifiedOrNewDescriptor)
                        throws PersistenceBrokerException
adds a new or replaces an existing ClassDescriptor to the DescriptorRepository.

Specified by:
setClassDescriptor in interface PersistenceBroker
PersistenceBrokerException

getExtentClass

public java.lang.Class getExtentClass(java.lang.Class clazz)
                               throws PersistenceBrokerException
returns the Extent to which the class clazz belongs. * This may be a baseclass,an interface or clazz itself, if no Extent * is defined. * throws a PersistenceBrokerException if clazz is not persistence capable, * i.e. if clazz is not defined in the DescriptorRepository.

Specified by:
getExtentClass in interface PersistenceBroker
PersistenceBrokerException

invalidate

public void invalidate(Identity oid)
                throws PersistenceBrokerException
* removes the objects obj from the brokers internal cache and * inform other caches in OJB cluster about invalidation.

Specified by:
invalidate in interface PersistenceBroker
PersistenceBrokerException

getUniqueLong

public long getUniqueLong(java.lang.Class extent,
                          java.lang.String attribute)
                   throws PersistenceBrokerException
returns a unique long for class extent and field attribute. * the returned number is unique accross all tables in the extent of class extent.

Specified by:
getUniqueLong in interface PersistenceBroker
PersistenceBrokerException

getCount

public int getCount(Query query)
             throws PersistenceBrokerException
Description copied from interface: PersistenceBroker
returns the count of elements a given query will return.

Specified by:
getCount in interface PersistenceBroker
PersistenceBrokerException

getReportQueryIteratorByQuery

public java.util.Iterator getReportQueryIteratorByQuery(Query query)
                                                 throws PersistenceBrokerException
Description copied from interface: PersistenceBroker
returns an Iterator that iterates Object[] calling the .next() method. The Elements returned come from a SELECT ... WHERE sqlStatement The Class c is only used to provide the associated JDBC Connection

Specified by:
getReportQueryIteratorByQuery in interface PersistenceBroker
PersistenceBrokerException

close

public boolean close()
Description copied from interface: PersistenceBroker
close connection to last opened repository.

Specified by:
close in interface PersistenceBroker
Returns:
true if successful

open

public boolean open(java.lang.String repository,
                    java.lang.String user,
                    java.lang.String passwd)
             throws PersistenceBrokerException
Description copied from interface: PersistenceBroker
open a repository. returns true if successfull, else false.

Specified by:
open in interface PersistenceBroker
Parameters:
repository - name of the repository
user - user name, if left null username is taken from repository.
passwd - password, if left null password is taken from repository.
Returns:
true if successful, else false.
PersistenceBrokerException


Authors: Thomas Mahler and others. (C) 2000, 2001.
All rights reserved. Published under the Gnu Public License.
http://objectbridge.sourceforge.net
Version: 0.8.375, 2002-04-04