db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: jakarta-ojb/src/java/org/apache/ojb/broker Identity.java PBKey.java PersistenceBroker.java PersistenceBrokerFactory.java
Date Tue, 24 Dec 2002 13:31:58 GMT
arminw      2002/12/24 05:31:58

  Modified:    src/java/org/apache/ojb/broker Identity.java PBKey.java
                        PersistenceBroker.java
                        PersistenceBrokerFactory.java
  Log:
  improve metadata handling:
  separate the object stuff (class descriptor, field descriptor, ...)
  from the connection stuff (jdbc descriptor).
  DescriptorRepository now handles only object
  specific properties.
  
  Do some performance improvements
  
  Revision  Changes    Path
  1.8       +55 -75    jakarta-ojb/src/java/org/apache/ojb/broker/Identity.java
  
  Index: Identity.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/Identity.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Identity.java	21 Sep 2002 15:34:16 -0000	1.7
  +++ Identity.java	24 Dec 2002 13:31:58 -0000	1.8
  @@ -58,6 +58,7 @@
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  +import org.apache.ojb.broker.util.BrokerHelper;
   
   import java.io.ByteArrayInputStream;
   import java.io.ByteArrayOutputStream;
  @@ -65,7 +66,7 @@
   import java.io.ObjectOutputStream;
   import java.util.zip.GZIPInputStream;
   import java.util.zip.GZIPOutputStream;
  - 
  +
   //#ifdef JDK13
   import java.lang.reflect.InvocationHandler;
   import java.lang.reflect.Proxy;
  @@ -85,7 +86,6 @@
    */
   public class Identity implements java.io.Serializable
   {
  -
       /**
        * the Class of the identified object<br>
        * ie: an Interface
  @@ -112,56 +112,63 @@
           super();
       }
   
  -    public Identity(Object objectToIdentitify, PersistenceBroker targetBroker)
  +    /**
  +     * creates an Identity from a class and the objects primary key values.
  +     * used for the definition of proxies.
  +     * Important note:
  +     * The caller is responsible to assure
  +     * that aClass is not a member of an extent, or that it is the base class of
  +     * an extent!
  +     *
  +     * @param aClass java.lang.Class
  +     * @param pkValues List
  +     *
  +     */
  +    public Identity(Class aClass, Object[] pkValues)
       {
  -        try
  -        {
  -            if (objectToIdentitify instanceof VirtualProxy)
  -            {
  -                VirtualProxy p = (VirtualProxy) objectToIdentitify;
  -                Identity sourceOID = p.getIdentity();
  -                this.objectsClass = sourceOID.objectsClass;
  -                this.objectsRealClass = sourceOID.objectsRealClass;
  -                this.pkValues = sourceOID.pkValues;
  -            }
  -            else if (objectToIdentitify instanceof Proxy)
  -            {
  -                Proxy p = (Proxy) objectToIdentitify;
  -                InvocationHandler h = Proxy.getInvocationHandler(p);
  -                IndirectionHandler ih = (IndirectionHandler) h;
  -                Identity sourceOID = ih.getIdentity();
  -                this.objectsClass = sourceOID.objectsClass;
  -                this.objectsRealClass = sourceOID.objectsRealClass;
  -                this.pkValues = sourceOID.pkValues;
  -            }
  -            else
  -            {
  -                ClassDescriptor cld = targetBroker.getClassDescriptor(objectToIdentitify.getClass());
  -
  -                // identities must be unique accross extents !
  -                this.objectsClass = targetBroker.getExtentClass(objectToIdentitify.getClass());
  -                this.objectsRealClass = objectToIdentitify.getClass();
  -                this.pkValues = cld.getKeyValues(objectToIdentitify);
  -            }
  +        this.objectsClass = aClass;
  +        this.pkValues = pkValues;
  +        checkForPrimaryKeys();
  +    }
   
  -            checkForPrimaryKeys();
  -        }
  -        catch (Throwable t)
  -        {
  -            LoggerFactory.getDefaultLogger().error(t);
  -            throw new ClassNotPersistenceCapableException(t.getMessage(), t);
  -        }
  +    public Identity(Object objectToIdentitify, PersistenceBroker targetBroker)
  +    {
  +        init(objectToIdentitify, targetBroker, null);
       }
   
       /**
        * creates an Identity from an object. Reads the objects primary key values.
        * @param objectToIdentitify java.lang.Object
  +     * @deprecated Identity does indirect access the sequence manager, thus
  +     * you should overgive a PB too.
        */
       public Identity(Object objectToIdentitify)
       {
           PersistenceBroker broker = null;
           try
           {
  +            broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +            init(objectToIdentitify, broker, null);
  +        }
  +        finally
  +        {
  +        	if (broker != null)
  +        	{
  +            	broker.close();
  +        	}
  +        }
  +    }
  +
  +    public Identity(Object objectToIdentitify, PersistenceBroker targetBroker, ClassDescriptor
cld)
  +    {
  +        init(objectToIdentitify, targetBroker, cld);
  +    }
  +
  +    private void init(Object objectToIdentitify, PersistenceBroker targetBroker, ClassDescriptor
cld)
  +    {
  +        boolean closeBroker = false;
  +        try
  +        {
               if (objectToIdentitify instanceof VirtualProxy)
               {
                   VirtualProxy p = (VirtualProxy) objectToIdentitify;
  @@ -182,28 +189,19 @@
               }
               else
               {
  -                broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -                ClassDescriptor cld = broker.getClassDescriptor(objectToIdentitify.getClass());
  -
  +                if(cld == null) cld = targetBroker.getClassDescriptor(objectToIdentitify.getClass());
                   // identities must be unique accross extents !
  -                this.objectsClass = broker.getExtentClass(objectToIdentitify.getClass());
  +                this.objectsClass = targetBroker.getExtentClass(objectToIdentitify.getClass());
                   this.objectsRealClass = objectToIdentitify.getClass();
  -                this.pkValues = cld.getKeyValues(objectToIdentitify);
  +                this.pkValues = targetBroker.serviceBrokerHelper().getKeyValues(cld, objectToIdentitify);
               }
   
               checkForPrimaryKeys();
           }
  -        catch (Throwable t)
  -        {
  -            LoggerFactory.getDefaultLogger().error(t);
  -            throw new ClassNotPersistenceCapableException(t.getMessage(), t);
  -        }
  -        finally
  +        catch (Exception e)
           {
  -        	if (broker != null)
  -        	{
  -            	broker.close();
  -        	}
  +            throw new ClassNotPersistenceCapableException("Could not init Identity for
given object " +
  +                    objectToIdentitify.getClass(), e);
           }
       }
   
  @@ -236,7 +234,7 @@
        * return the Class of the real subject
        * @return java.lang.Class
        */
  -    public java.lang.Class getObjectsClass()
  +    public Class getObjectsClass()
       {
           return objectsClass;
       }
  @@ -245,7 +243,7 @@
        * return the "real" Class of the real subject
        * @return java.lang.Class
        */
  -    public java.lang.Class getObjectsRealClass()
  +    public Class getObjectsRealClass()
       {
           return objectsRealClass;
       }
  @@ -306,25 +304,7 @@
           return stringRepresentation;
       }
   
  -    /**
  -     * creates an Identity from a class and the objects primary key values.
  -     * used for the definition of proxies.
  -     * Important note:
  -     * The caller is responsible to assure
  -     * that aClass is not a member of an extent, or that it is the base class of
  -     * an extent!
  -     *
  -     * @param aClass java.lang.Class
  -     * @param pkValues List
  -     *
  -     */
  -    public Identity(Class aClass, Object[] pkValues)
  -    {
  -        this.objectsClass = aClass;
  -        this.pkValues = pkValues;
   
  -        checkForPrimaryKeys();
  -    }
   
   
       /**
  
  
  
  1.5       +33 -10    jakarta-ojb/src/java/org/apache/ojb/broker/PBKey.java
  
  Index: PBKey.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/PBKey.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PBKey.java	26 Oct 2002 19:53:42 -0000	1.4
  +++ PBKey.java	24 Dec 2002 13:31:58 -0000	1.5
  @@ -4,27 +4,39 @@
   
   /**
    * A immutable key to identify PB instances in pools, ...
  + * <br>
  + * The used <i>jcdAlias</i> name represents an alias for a connection
  + * defined in the repository file.
    *
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
    * @version $Id$
    */
   public class PBKey implements Cloneable, Serializable
   {
  -    private final String repositoryFile;
  +    private final String jcdAlias;
       private final String user;
       private final String password;
       private int hashCode;
   
  -    public PBKey(final String repositoryFile, final String user, final String password)
  +    /**
  +     * Constructor for new PBKey.
  +     * @param jcdAlias alias name, defined in the repository file.
  +     * @param user
  +     * @param password
  +     */
  +    public PBKey(final String jcdAlias, final String user, final String password)
       {
  -        this.repositoryFile = repositoryFile;
  +        this.jcdAlias = jcdAlias;
           this.user = user;
           this.password = password;
       }
   
  -    public PBKey(final String repositoryFile)
  +    /**
  +     * Convenience constructor for PBKey(jcdAlias, null, null)
  +     */
  +    public PBKey(final String jcdAlias)
       {
  -        this(repositoryFile, null, null);
  +        this(jcdAlias, null, null);
       }
   
       public boolean equals(Object obj)
  @@ -41,7 +53,7 @@
        */
       protected Object clone() throws CloneNotSupportedException
       {
  -        return new PBKey(this.repositoryFile, this.user, this.password);
  +        return new PBKey(this.jcdAlias, this.user, this.password);
       }
   
       /**
  @@ -52,20 +64,31 @@
       {
           if(hashCode == 0)
           {
  -            hashCode = new String("" + this.repositoryFile + this.user + this.password).hashCode();
  +            hashCode = new String("" + this.jcdAlias + this.user + this.password).hashCode();
           }
           return hashCode;
       }
   
       public String toString()
       {
  -        return this.getClass().getName() + ": repository="+repositoryFile+", user="+user+
  +        return this.getClass().getName() + ": repository="+jcdAlias+", user="+user+
                   (user != null ? ", password=*****" : ", password="+password);
       }
   
  +    /**
  +     * Returns the jcd-alias name, defined in the repository file.
  +     */
  +    public String getAlias()
  +    {
  +        return jcdAlias;
  +    }
  +
  +    /**
  +     * @deprecated use {@link #getAlias} instead.
  +     */
       public String getRepositoryFile()
       {
  -        return repositoryFile;
  +        return jcdAlias;
       }
   
       public String getUser()
  
  
  
  1.14      +235 -183  jakarta-ojb/src/java/org/apache/ojb/broker/PersistenceBroker.java
  
  Index: PersistenceBroker.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/PersistenceBroker.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- PersistenceBroker.java	21 Nov 2002 22:25:49 -0000	1.13
  +++ PersistenceBroker.java	24 Dec 2002 13:31:58 -0000	1.14
  @@ -56,12 +56,15 @@
   
   import org.apache.ojb.broker.accesslayer.ConnectionManagerIF;
   import org.apache.ojb.broker.accesslayer.StatementManagerIF;
  +import org.apache.ojb.broker.accesslayer.sql.SqlGenerator;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.DescriptorRepository;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
   import org.apache.ojb.broker.query.Query;
  +import org.apache.ojb.broker.util.BrokerHelper;
   import org.apache.ojb.broker.util.ObjectModification;
   import org.apache.ojb.broker.util.configuration.Configurable;
  +import org.apache.ojb.broker.util.sequence.SequenceManager;
   import org.odbms.ObjectContainer;
   
   import java.util.Collection;
  @@ -79,83 +82,94 @@
    */
   public interface PersistenceBroker extends Configurable, ObjectContainer
   {
  +    public static final int EVENT_BEFORE_STORE = 1;
  +    public static final int EVENT_AFTER_STORE = 2;
  +    public static final int EVENT_BEFORE_DELETE = 3;
  +    public static final int EVENT_AFTER_DELETE = 4;
  +    public static final int EVENT_AFTER_LOOKUP = 5;
  +
  +    // *************************************************************************
  +    // Services handled by the PersistenceBroker
  +    // *************************************************************************
  +
       /**
  -     * Returns the {@link org.apache.ojb.broker.metadata.DescriptorRepository} of this
broker.
  +     * Returns the {@link org.apache.ojb.broker.accesslayer.StatementManagerIF} associated
with this broker.
        */
  -    public DescriptorRepository getDescriptorRepository();
  +    public StatementManagerIF serviceStatementManager();
   
       /**
  -     * Get the broker key.
  +     * Returns the {@link org.apache.ojb.broker.accesslayer.ConnectionManagerIF} associated
with this broker.
        */
  -    public PBKey getPBKey();
  +    public ConnectionManagerIF serviceConnectionManager();
   
       /**
  -     * Intern used! Set the broker key.
  +     * Returns the {@link org.apache.ojb.broker.accesslayer.sql.SqlGenerator} associated
with this broker.
        */
  -    public void setPBKey(PBKey key);
  +    public SqlGenerator serviceSqlGenerator();
   
       /**
  -     *
  -     * deletes the objects obj concrete representation in the underlying persistence system.
  -     * E.G. by DELETE FROM ... WHERE ... in an RDBMS
  -     *
  +     * Returns the {@link org.apache.ojb.broker.util.sequence.SequenceManager} associated
with this broker.
        */
  -    public void delete(Object obj) throws PersistenceBrokerException;
  +    public SequenceManager serviceSequenceManager();
   
       /**
  -     *
  -     * deletes all objects matching the query from the underlying persistence system.
  -     * E.G. by DELETE FROM ... WHERE ... in an RDBMS
  -     *
  +     * Returns the {@link org.apache.ojb.broker.util.BrokerHelper} associated with this
broker.
  +     * Makes some helper methods available.
        */
  -    public void deleteByQuery(Query query) throws PersistenceBrokerException;
  +    public BrokerHelper serviceBrokerHelper();
  +
  +
   
   
  +    // *************************************************************************
  +    // PersistenceBroker listener methods
  +    // *************************************************************************
       /**
  +     * Performs appropriate callback on the instance object, if it implements
  +     * PersistenceBrokerAware, and then notifys all listeners of the
  +     * event.
        *
  -     * removes the objects obj from the brokers internal cache.
  -     * removing is not recursive.
  -     *
  +     * @param instance the object being manipulated by the PersistenceBroker
  +     * @param eventId the id of the event. Should be one of
  +     *  EVENT_BEFORE_STORE, EVENT_AFTER_STORE, EVENT_BEFORE_DELETE,
  +     *  EVENT_AFTER_DELETE, EVENT_AFTER_LOOKUP;
        */
  -    public void removeFromCache(Object obj) throws PersistenceBrokerException;
  +    public void fireBrokerEvent(Object instance, int eventId);
   
       /**
  -     *
  -     * removes the objects obj from the brokers internal cache and
  -     * inform other caches in OJB cluster about invalidation.
  +     * Adds a listener to this PersistenceBroker instance
  +     * @param listener
        */
  -    public void invalidate(Identity oid) throws PersistenceBrokerException;
  -
  +    public void addListener(PersistenceBrokerListener listener) 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.
  -     *
  +     * Removes a listener from this PersistenceBroker instance
  +     * @param listener
        */
  -    public void clearCache() throws PersistenceBrokerException;
  -
  +    public void removeListener(PersistenceBrokerListener listener) throws PersistenceBrokerException;;
   
       /**
  -     * make object obj persistent in the underlying persistence system.
  -     * E.G. by INSERT INTO ... or UPDATE ...  in an RDBMS
  +     * Removes all listeners from this PersistenceBroker instance
        */
  -    public void store(Object obj) throws PersistenceBrokerException;
  +    public void removeAllListeners() throws PersistenceBrokerException;
   
   
  +
  +
  +    // *************************************************************************
  +    // Transaction and instance handling stuff
  +    // *************************************************************************
       /**
        * Abort and close the transaction.
        * Calling abort abandons all persistent object modifications and releases the
        * associated locks.
  -     *
  +     * <br>
        * If transaction is not in progress a TransactionNotInProgressException is thrown
  -     *
        */
       public void abortTransaction() throws TransactionNotInProgressException;
   
       /**
  -     * begin a transaction against the underlying RDBMS.
  +     * Begin a transaction against the underlying RDBMS.
        * Calling <code>beginTransaction</code> multiple times,
        * without an intervening call to <code>commitTransaction</code> or <code>abortTransaction</code>,
        * causes the exception <code>TransactionInProgressException</code> to
be thrown
  @@ -178,8 +192,7 @@
   
   
       /**
  -     * returns true if the broker performs a transaction.
  -     * returns false if broker is not in a transaction.
  +     * Returns true if the broker performs a transaction, false in the other case
        */
       public boolean isInTransaction() throws PersistenceBrokerException;
   
  @@ -193,76 +206,75 @@
        */
       public boolean close();
   
  +
  +
  +
  +    // *************************************************************************
  +    // Metadata service methods
  +    // *************************************************************************
  +
       /**
  -     *
  -     * retrieve a collection of itemClass Objects matching the Query query.
  -     *
  -     * if the Query has no criteria no WHERE-clause is generated, i.e. ALL table rows are
selected.
  -     *
  +     * Returns the {@link org.apache.ojb.broker.metadata.DescriptorRepository}
  +     * associated with this broker.
        */
  -    public Collection getCollectionByQuery(Query query) throws PersistenceBrokerException;
  +    public DescriptorRepository getDescriptorRepository();
   
       /**
  -     * returns the count of elements a given query will return.
  +     * Get the {@link PBKey} for this broker.
        */
  -    public int getCount(Query query) throws PersistenceBrokerException;
  -
  +    public PBKey getPBKey();
   
       /**
  -     *
  -     * retrieve a userdefined Collection that implements the interface Manageable collection
  -     * that contains all Objects matching the Query query.
  -     *
  -     * If query has no criteria no WHERE-clause is generated, i.e. ALL table rows are selected.
  -     *
  +     * 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.
        */
  -
  -    public ManageableCollection getCollectionByQuery(Class collectionClass, Query query)
  -            throws PersistenceBrokerException;
  -
  +    public ClassDescriptor getClassDescriptor(Class clazz) 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.
  +     * same as getClassDescriptor, but does not throw. Useful for checking if an object
is
  +     * persistence Capable.
  +     * @param clazz
  +     * @return true if descriptor was found
        */
  -    public Iterator getIteratorByQuery(Query query) throws PersistenceBrokerException;
  -
  +    public boolean hasClassDescriptor(Class clazz);
   
       /**
  -     * 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
  +     * returnsthe 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.
        */
  -    public Iterator getReportQueryIteratorByQuery(Query query) throws PersistenceBrokerException;
  +    public Class getExtentClass(Class clazz) throws PersistenceBrokerException;
  +
  +
   
   
  +    // *************************************************************************
  +    // Object lifecycle
  +    // *************************************************************************
  +
       /**
  -     * retrieve an Object by its Identity. Application Developers are encouraged to use
getObjectByQuery().
  -     * This method is mainly used for internal performant handling of
  -     * materialization by OID (e.g. in Proxies)
  +     * 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.
  +     *
        */
  -    public Object getObjectByIdentity(Identity id) throws PersistenceBrokerException;
  +    public void clearCache() throws PersistenceBrokerException;
   
       /**
  -     * retrieve an Object by query.
  -     * I.e perform a SELECT ... FROM ... WHERE ...  in an RDBMS
  +     * Removes the objects obj from the brokers internal cache.
  +     * removing is not recursive.
        */
  -    public Object getObjectByQuery(Query query) throws PersistenceBrokerException;
  +    public void removeFromCache(Object obj) 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...
  -     * NOT YET AWARE OF EXTENTS !
  -     * @param PrimaryKeyClass the pk class for the searched objects
  -     * @param query the query
  +     * Removes the objects obj from the brokers internal cache and
  +     * inform other caches in OJB cluster about invalidation.
        */
  -    public Enumeration getPKEnumerationByQuery(Class PrimaryKeyClass,
  -                                               Query query) throws PersistenceBrokerException;
  +    public void invalidate(Identity oid) throws PersistenceBrokerException;
   
       /**
        * makes object obj persistent in the underlying persistence system.
  @@ -276,143 +288,183 @@
                         ObjectModification modification) throws PersistenceBrokerException;
   
       /**
  -     * Returns a unique int value for the given field attribute.
  -     * The returned int value is unique accross all tables in the extent
  -     * of class the field belongs to.
  -     *
  -     * @deprecated use {@link #getUniqueId(FieldDescriptor field)} instead
  +     * make object obj persistent in the underlying persistence system.
  +     * E.G. by INSERT INTO ... or UPDATE ...  in an RDBMS
        */
  -    public int getUniqueId(Class extent, String attribute) throws PersistenceBrokerException;
  +    public void store(Object obj) throws PersistenceBrokerException;
   
       /**
  -     * Returns a unique long value for the given field attribute.
  -     * The returned long value is unique accross all tables in the extent
  -     * of class the field belongs to.
        *
  -     * @deprecated use {@link #getUniqueLong(FieldDescriptor field)} instead
  -     */
  -    public long getUniqueLong(Class extent, String attribute) throws PersistenceBrokerException;
  -
  -
  -    /**
  -     * Returns a unique String for the given field attribute.
  -     * The returned String is unique accross all tables in the extent
  -     * of class the field belongs to.
  +     * deletes the objects obj concrete representation in the underlying persistence system.
  +     * E.G. by DELETE FROM ... WHERE ... in an RDBMS
        *
  -     * @deprecated use {@link #getUniqueString(FieldDescriptor field)} instead
        */
  -    public String getUniqueString(Class extent, String attribute) throws PersistenceBrokerException;
  +    public void delete(Object obj) throws PersistenceBrokerException;
   
       /**
  -     * Returns a unique object for the given field attribute.
  -     * The returned object is unique accross all tables in the extent
  -     * of class the field belongs to.
  -     *
  -     * @deprecated use {@link #getUniqueObject(FieldDescriptor field)} instead
  +     * Deletes all objects matching the query from the underlying persistence system.
  +     * E.G. by DELETE FROM ... WHERE ... in an RDBMS
        */
  -    public Object getUniqueObject(Class extent, String attribute) throws PersistenceBrokerException;
  +    public void deleteByQuery(Query query) throws PersistenceBrokerException;
  +
   
   
  -    /**
  -     * Returns a unique int value for the given field attribute.
  -     * The returned int value is unique accross all tables in the extent
  -     * of class the field belongs to.
  -     */
  -    public int getUniqueId(FieldDescriptor field) throws PersistenceBrokerException;
   
  -    /**
  -     * Returns a unique long value for the given field attribute.
  -     * The returned long value is unique accross all tables in the extent
  -     * of class the field belongs to.
  -     */
  -    public long getUniqueLong(FieldDescriptor field) throws PersistenceBrokerException;
   
  +    // *************************************************************************
  +    // Query methods
  +    // *************************************************************************
   
       /**
  -     * Returns a unique String for the given field attribute.
  -     * The returned String is unique accross all tables in the extent
  -     * of class the field belongs to.
  +     * Retrieve all Reference- and  Collection-attributes of a given instance
  +     * @param pInstance the persistent instance
        */
  -    public String getUniqueString(FieldDescriptor field) throws PersistenceBrokerException;
  +    public void retrieveAllReferences(Object pInstance) throws PersistenceBrokerException;
   
       /**
  -     * Returns a unique object for the given field attribute.
  -     * The returned object is unique accross all tables in the extent
  -     * of class the field belongs to.
  +     * retrieve a single reference- or collection attribute
  +     * of a persistent instance.
  +     * @param pInstance the persistent instance
  +     * @param pAttributeName the name of the Attribute to load
        */
  -    public Object getUniqueObject(FieldDescriptor field) throws PersistenceBrokerException;
  -
  -
  -
  -
  +    public void retrieveReference(Object pInstance, String pAttributeName) 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.
  -
  +     * Returns the count of elements a given query will return.
        */
  -    public ClassDescriptor getClassDescriptor(Class clazz) throws PersistenceBrokerException;
  +    public int getCount(Query query) throws PersistenceBrokerException;
   
       /**
  -     * same as getClassDescriptor, but does not throw. Useful for checking if an object
is
  -     * persistence Capable.
  -     * @param clazz
  -     * @return true if descriptor was found
  +     *
  +     * Retrieve a collection of itemClass Objects matching the Query query.
  +     * If the Query has no criteria no WHERE-clause is generated, i.e. ALL table rows are
selected.
        */
  -    public boolean hasClassDescriptor(Class clazz);
  +    public Collection getCollectionByQuery(Query query) throws PersistenceBrokerException;
   
       /**
  -     * adds a new or replaces an existing ClassDescriptor to the DescriptorRepository.
  +     * Retrieve a userdefined Collection that implements the interface Manageable collection
  +     * that contains all Objects matching the Query query.
  +     * <br>
  +     * If query has no criteria no WHERE-clause is generated, i.e. ALL table rows are selected.
        */
  -    public void setClassDescriptor(ClassDescriptor modifiedOrNewDescriptor) throws PersistenceBrokerException;
  +    public ManageableCollection getCollectionByQuery(Class collectionClass, Query query)
  +            throws PersistenceBrokerException;
   
       /**
  -     * returnsthe 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.
  +     * 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.
        */
  -    public Class getExtentClass(Class clazz) throws PersistenceBrokerException;
  +    public Iterator getIteratorByQuery(Query query) throws PersistenceBrokerException;
   
       /**
  -     *
  -     * @return the statement manager associated with this persistence broker type.
  +     * 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
        */
  -    public StatementManagerIF getStatementManager();
  -
  -    public ConnectionManagerIF getConnectionManager();
  -
  -
  -	/**
  -	 * retrieve all Reference- and  Collection-attributes of a given instance
  -	 * @param pInstance the persistent instance
  -	 */
  -	public void retrieveAllReferences(Object pInstance) throws PersistenceBrokerException;
  -
  -	/**
  -	 * retrieve a single reference- or collection attribute
  -	 * of a persistent instance.
  -	 * @param pInstance the persistent instance
  -	 * @param pAttributeName the name of the Attribute to load
  -	 */
  -	public void retrieveReference(Object pInstance, String pAttributeName) throws PersistenceBrokerException;
  +    public Iterator getReportQueryIteratorByQuery(Query query) throws PersistenceBrokerException;
   
       /**
  -     * Adds a listener to the PersistenceBroker
  -     * @param listener
  +     * Retrieve an Object by its Identity. Application Developers are encouraged to use
getObjectByQuery().
  +     * This method is mainly used for internal performant handling of
  +     * materialization by OID (e.g. in Proxies)
        */
  -	public void addListener(PersistenceBrokerListener listener) throws PersistenceBrokerException;;
  +    public Object getObjectByIdentity(Identity id) throws PersistenceBrokerException;
   
       /**
  -     * Removes a listener from the PersistenceBroker
  -     * @param listener
  +     * Retrieve an Object by query.
  +     * I.e perform a SELECT ... FROM ... WHERE ...  in an RDBMS
        */
  -    public void removeListener(PersistenceBrokerListener listener) throws PersistenceBrokerException;;
  +    public Object getObjectByQuery(Query query) throws PersistenceBrokerException;
   
       /**
  -     * Removes all listeners from the PersistenceBroker
  +     * 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...
  +     * NOT YET AWARE OF EXTENTS !
  +     * @param PrimaryKeyClass the pk class for the searched objects
  +     * @param query the query
        */
  -    public void removeAllListeners() throws PersistenceBrokerException;
  +    public Enumeration getPKEnumerationByQuery(Class PrimaryKeyClass, Query query)
  +            throws PersistenceBrokerException;
  +
  +
  +
  +
  +//    /**
  +//     * adds a new or replaces an existing ClassDescriptor to the DescriptorRepository.
  +//     */
  +//    public void setClassDescriptor(ClassDescriptor modifiedOrNewDescriptor) throws PersistenceBrokerException;
  +
  +
  +//    /**
  +//     * Returns a unique int value for the given field attribute.
  +//     * The returned int value is unique accross all tables in the extent
  +//     * of class the field belongs to.
  +//     *
  +//     * @deprecated use {@link #getUniqueId(FieldDescriptor field)} instead
  +//     */
  +//    public int getUniqueId(Class extent, String attribute) throws PersistenceBrokerException;
  +//
  +//    /**
  +//     * Returns a unique long value for the given field attribute.
  +//     * The returned long value is unique accross all tables in the extent
  +//     * of class the field belongs to.
  +//     *
  +//     * @deprecated use {@link #getUniqueLong(FieldDescriptor field)} instead
  +//     */
  +//    public long getUniqueLong(Class extent, String attribute) throws PersistenceBrokerException;
  +//
  +//
  +//    /**
  +//     * Returns a unique String for the given field attribute.
  +//     * The returned String is unique accross all tables in the extent
  +//     * of class the field belongs to.
  +//     *
  +//     * @deprecated use {@link #getUniqueString(FieldDescriptor field)} instead
  +//     */
  +//    public String getUniqueString(Class extent, String attribute) throws PersistenceBrokerException;
  +//
  +//    /**
  +//     * Returns a unique object for the given field attribute.
  +//     * The returned object is unique accross all tables in the extent
  +//     * of class the field belongs to.
  +//     *
  +//     * @deprecated use {@link #getUniqueObject(FieldDescriptor field)} instead
  +//     */
  +//    public Object getUniqueObject(Class extent, String attribute) throws PersistenceBrokerException;
  +//
  +//
  +//    /**
  +//     * Returns a unique int value for the given field attribute.
  +//     * The returned int value is unique accross all tables in the extent
  +//     * of class the field belongs to.
  +//     */
  +//    public int getUniqueId(FieldDescriptor field) throws PersistenceBrokerException;
  +//
  +//    /**
  +//     * Returns a unique long value for the given field attribute.
  +//     * The returned long value is unique accross all tables in the extent
  +//     * of class the field belongs to.
  +//     */
  +//    public long getUniqueLong(FieldDescriptor field) throws PersistenceBrokerException;
  +//
  +//
  +//    /**
  +//     * Returns a unique String for the given field attribute.
  +//     * The returned String is unique accross all tables in the extent
  +//     * of class the field belongs to.
  +//     */
  +//    public String getUniqueString(FieldDescriptor field) throws PersistenceBrokerException;
  +//
  +//    /**
  +//     * Returns a unique object for the given field attribute.
  +//     * The returned object is unique accross all tables in the extent
  +//     * of class the field belongs to.
  +//     */
  +//    public Object getUniqueObject(FieldDescriptor field) throws PersistenceBrokerException;
  +
   }
  
  
  
  1.15      +14 -5     jakarta-ojb/src/java/org/apache/ojb/broker/PersistenceBrokerFactory.java
  
  Index: PersistenceBrokerFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/PersistenceBrokerFactory.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- PersistenceBrokerFactory.java	28 Nov 2002 22:14:36 -0000	1.14
  +++ PersistenceBrokerFactory.java	24 Dec 2002 13:31:58 -0000	1.15
  @@ -77,12 +77,21 @@
       }
   
       /**
  -     * Set the default PersistenceBroker used within OJB
  -     * to find OJB internal tables.
  +     * Set the default PersistenceBroker (e.g. used within OJB
  +     * to find OJB internal tables)
        */
  -    public void setDefaultPersistenceBroker(PBKey key)
  +    public void setDefaultKey(PBKey key)
       {
  -        PersistenceBrokerFactoryFactory.instance().setDefaultPersistenceBroker(key);
  +        PersistenceBrokerFactoryFactory.instance().setDefaultKey(key);
  +    }
  +
  +    /**
  +     * Get the default PersistenceBroker (e.g. used within OJB
  +     * to find OJB internal tables)
  +     */
  +    public PBKey getDefaultKey()
  +    {
  +        return PersistenceBrokerFactoryFactory.instance().getDefaultKey();
       }
   
       /**
  
  
  

Mime
View raw message