db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r422233 [1/4] - in /db/ojb/trunk/src/java/org/apache/ojb/broker: ./ metadata/ metadata/torque/ platforms/ query/ util/ util/dbhandling/
Date Sat, 15 Jul 2006 14:22:36 GMT
Author: arminw
Date: Sat Jul 15 07:22:34 2006
New Revision: 422233

URL: http://svn.apache.org/viewvc?rev=422233&view=rev
Log:
merge trunk with 1.0.x

Modified:
    db/ojb/trunk/src/java/org/apache/ojb/broker/OJB.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/PersistenceBroker.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/PersistenceBrokerInternal.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/FieldType.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/JdbcType.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/JdbcTypesHelper.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/MetadataManager.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/ObjectReferenceDescriptor.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/RepositoryElements.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/RepositoryPersistor.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/RepositoryTags.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/RepositoryXmlHandler.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/SuperReferenceDescriptor.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/torque/TorqueForeignKeyGenerator.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/platforms/Platform.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/platforms/PlatformDefaultImpl.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/platforms/PlatformDerbyImpl.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/platforms/PlatformMySQLImpl.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/platforms/PlatformOracle9iImpl.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/platforms/PlatformPostgreSQLImpl.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/platforms/PlatformSapdbImpl.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/platforms/PlatformWLOracle9iImpl.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/query/QueryByCriteriaImpl.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/query/ReportQuery.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/util/BrokerHelper.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/util/ClassHelper.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/util/ExceptionHelper.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/util/GUID.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/util/IdentityArrayList.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/util/dbhandling/DatabaseHandlingTask.java

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/OJB.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/OJB.java?rev=422233&r1=422232&r2=422233&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/OJB.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/OJB.java Sat Jul 15 07:22:34 2006
@@ -57,15 +57,16 @@
      * Force INSERT on {@link PersistenceBroker#store(Object, org.apache.ojb.broker.util.ObjectModification)}
      * method.
      */
-    public static final ObjectModification INSERT = ObjectModificationImpl.INSERT;
+    public static final ObjectModification INSERT = ObjectModification.INSERT;
     /**
      * Force UPDATE on {@link PersistenceBroker#store(Object, org.apache.ojb.broker.util.ObjectModification)}
      * method.
      */
-    public static final ObjectModification UPDATE = ObjectModificationImpl.UPDATE;
+    public static final ObjectModification UPDATE = ObjectModification.UPDATE;
 
     private Logger log = LoggerFactory.getLogger(OJB.class);
 
+    private String ojbPropertiesPath;
     /** The container */
     private ComponentContainer container;
     /** Whether this runtime is fully initialized */
@@ -114,7 +115,8 @@
         helper.initWithDefaults(container);
         if (loadConf)
         {
-            helper.loadProperties(container, System.getProperty(DEFAULT_PROPERTIES_FILE,
DEFAULT_PROPERTIES_FILE), false);
+            this.ojbPropertiesPath = System.getProperty(DEFAULT_PROPERTIES_FILE, DEFAULT_PROPERTIES_FILE);
+            helper.loadProperties(container, ojbPropertiesPath, false);
         }
         // setting singleton instances
         container.setSingletonInstance(getClass(), this);
@@ -148,6 +150,16 @@
         lockManager = (LockManager) container.getSingletonInstance(LockManager.class);
 
         isInitialized = true;
+    }
+
+    /**
+     * Returns the path of OJB's property file.
+     *
+     * @return The property file path.
+     */
+    public String getOjbPropertiesPath()
+    {
+        return ojbPropertiesPath;
     }
 
     /**

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/PersistenceBroker.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/PersistenceBroker.java?rev=422233&r1=422232&r2=422233&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/PersistenceBroker.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/PersistenceBroker.java Sat Jul 15 07:22:34
2006
@@ -31,6 +31,7 @@
 import org.apache.ojb.broker.util.BrokerHelper;
 import org.apache.ojb.broker.util.ObjectModification;
 import org.apache.ojb.broker.util.sequence.SequenceManager;
+import org.apache.ojb.broker.lob.LobHelper;
 import org.odbms.ObjectContainer;
 
 /**
@@ -50,22 +51,38 @@
     // *************************************************************************
 
     /**
+     * Returns the {@link org.apache.ojb.broker.lob.LobHelper} instance
+     * associated with this broker.
+     *
+     * @return The LOB helper
+     */
+    public LobHelper serviceLobHelper();
+
+    /**
      * Returns the {@link org.apache.ojb.broker.accesslayer.StatementManager} instance associated
with this broker.
+     *
+     * @return The statement manager
      */
     public StatementManager serviceStatementManager();
 
     /**
      * Returns the {@link org.apache.ojb.broker.accesslayer.ConnectionManagerIF} instance
associated with this broker.
+     *
+     * @return The connection manager
      */
     public ConnectionManagerIF serviceConnectionManager();
 
     /**
      * Returns the {@link org.apache.ojb.broker.accesslayer.sql.SqlGenerator} instance associated
with this broker.
+     *
+     * @return The SQL generator
      */
     public SqlGenerator serviceSqlGenerator();
 
     /**
      * Returns the {@link org.apache.ojb.broker.accesslayer.JdbcAccess} instance associated
with this broker.
+     *
+     * @return The JDBC access object
      */
     public JdbcAccess serviceJdbcAccess();
 
@@ -78,24 +95,32 @@
 
     /**
      * Returns the {@link org.apache.ojb.broker.util.sequence.SequenceManager} instance associated
with this broker.
+     *
+     * @return The sequence manager
      */
     public SequenceManager serviceSequenceManager();
 
     /**
-     * Returns the {@link org.apache.ojb.broker.util.BrokerHelper} instance associated with
this broker.
-     * Makes some helper methods available.
+     * Returns the {@link org.apache.ojb.broker.util.BrokerHelper} instance associated with
this broker, which
+     * makes some additional helper methods available.
+     *
+     * @return The broker helper object
      */
     public BrokerHelper serviceBrokerHelper();
 
     /**
      * Returns the {@link org.apache.ojb.broker.cache.ObjectCache} instance associated
      * with this broker.
+     *
+     * @return The object cache
      * @deprecated use {@link #serviceSessionCache()} instead.
      */
     public ObjectCache serviceObjectCache();
 
     /**
      * Returns the used {@link org.apache.ojb.broker.cache.SessionCache} instance.
+     *
+     * @return The session cache object.
      */
     public SessionCache serviceSessionCache();
 
@@ -111,26 +136,31 @@
     // *************************************************************************
 
     /**
-     * Performs a broker event to inform all managed
-     * {@link PBListener} implementations.
+     * Fires a broker event to inform all registered {@link PBListener} instances.
+     *
+     * @param event The event to fire
      */
     public void fireBrokerEvent(PersistenceBrokerEvent event);
 
     /**
-     * Performs a broker event to inform all managed
-     * {@link PBListener} implementations.
+     * Fires a life cycle event to inform all registered {@link PBListener} instances.
+     *
+     * @param event The event to fire
      */
     public void fireBrokerEvent(PBLifeCycleEvent event);
 
     /**
-     * Performs a broker event to inform all managed
-     * {@link PBListener} implementations.
+     * Fires a state event to inform all registered {@link PBListener} instances.
+     *
+     * @param event The event to fire
      */
     public void fireBrokerEvent(PBStateEvent event);
 
     /**
      * Removes all temporary listeners from this PersistenceBroker instance
-     * - Handle with care!
+     * <b>NOTE:</b> Use with care, because some internals rely on this mechanism.
+     *
+     * @see #removeListener(PBListener)
      */
     public void removeAllListeners() throws PersistenceBrokerException;
 
@@ -138,8 +168,11 @@
      * If parameter <code>permanet</code> was <code>true</code> all
permanent and temporary listeners
      * will be removed from this PersistenceBroker instance.
      * <br/>
-     * <b>NOTE:</b> Handle with care!
+     * <b>NOTE:</b> Use with care, because some internals rely on this mechanism.
      *
+     * @param permanent If <em>false</em> all temporary listener will be removed.
If
+     * <em>true</em> temporaray and permanent listern will be removed from this
instance.
+     * @see #removeListener(PBListener)
      * @see #removeListener(PBListener listener)
      */
     public void removeAllListeners(boolean permanent) throws PersistenceBrokerException;
@@ -169,12 +202,17 @@
      * implementation {@link org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl}
      * and add the listener at creation of the {@link org.apache.ojb.broker.PersistenceBroker}
      * instances.
+     *
+     * @param listener  The listener to add
+     * @param permanent Whether the listener will stay registered after closing
+     *                  the broker
      */
     public void addListener(PBListener listener, boolean permanent) throws PersistenceBrokerException;
 
     /**
-     * Removes a listener from this PersistenceBroker instance
-     * @param listener
+     * Removes the specified listener from this broker.
+     *
+     * @param listener The listener to remove
      */
     public void removeListener(PBListener listener) throws PersistenceBrokerException;
 
@@ -184,55 +222,51 @@
     // *************************************************************************
 
     /**
-     * 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
+     * Aborts and closes the current transaction. This abandons all persistent object modifications
+     * and releases the associated locks.
+     *
+     * @throws TransactionNotInProgressException If no transaction is currently in progress
      */
     public void abortTransaction() throws TransactionNotInProgressException;
 
     /**
-     * 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
-     * on the second and subsequent calls.
+     * Begins a transaction against the underlying RDBMS.
+     *
+     * @throws TransactionInProgressException If there is already a transaction in progress
      */
     public void beginTransaction()
             throws TransactionInProgressException, TransactionAbortedException;
 
     /**
-     * Commit and close the transaction.
-     * Calling <code>commit</code> 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.
+     * Commits and closes the current transaction. This commits all database-changing statements
(e.g.
+     * UPDATE, INSERT and DELETE) issued within the transaction since the last commit to
the database,
+     * and releases any locks held by the transaction.
+     *
+     * @throws TransactionNotInProgressException If there is no transaction currently in
progress
+     * @throws TransactionAbortedException       If the transaction cannot be committed
      */
     public void commitTransaction()
             throws TransactionNotInProgressException, TransactionAbortedException;
 
-
     /**
-     * Returns <tt>true</tt> if the broker performs a transaction, <tt>false</tt>
-     * in the other case.
+     * Determines whether there is currently a transaction in progress.
+     *
+     * @return <code>true</code> if there is a transaction in progress
      */
     public boolean isInTransaction() throws PersistenceBrokerException;
 
     /**
-     * Close this PersistenceBroker so that no further requests may be made on it.
-     * A PersistenceBroker instance can be used only until it is closed.
-     * Closing a PersistenceBroker might release it to the pool of
-     * available PersistenceBrokers, or might be garbage collected, at the option of the
implementation.
+     * Closes this broker so that no further requests may be made on it. Closing a broker
might release
+     * it to the pool of available brokers, or might be garbage collected, at the option
of the implementation.
      *
-     * @return true if successful
+     * @return <code>true</code> if the broker was successfully closed
      */
     public boolean close();
 
     /**
-     * Returns <tt>true</tt> if this instance is closed.
+     * Determines whether this broker is closed.
+     *
+     * @return <tt>true</tt> if this instance is closed
      */
     public boolean isClosed();
 
@@ -245,36 +279,47 @@
     /**
      * Returns the {@link org.apache.ojb.broker.metadata.DescriptorRepository}
      * associated with this broker.
+     *
+     * @return The descriptor repository
      */
     public DescriptorRepository getDescriptorRepository();
 
     /**
      * Get the {@link PBKey} for this broker.
+     *
+     * @return The broker key
      */
     public PBKey getPBKey();
 
     /**
-     * Returns a ClassDescriptor for the persistence capable class.
-     * Throws a PersistenceBrokerException if clazz is not persistence capable,
-     * i.e. if no metadata was defined for this class or class was not found.
+     * Returns the class descriptor for the given persistence capable class.
+     *
+     * @param clazz The target class
+     * @return The class descriptor
+     * @throws 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 found
      */
     public ClassDescriptor getClassDescriptor(Class clazz) throws PersistenceBrokerException;
 
     /**
-     * Same as {@link #getClassDescriptor}, but does not throw an exception when class was
not found.
-     * Useful for checking if an object is persistence Capable.
-     * @param clazz target class
-     * @return true if descriptor was found
+     * Determines whether the given class is persistence capable and thus has an associated
+     * class descriptor in the metadata.
+     *
+     * @param clazz The target class
+     * @return <code>true</code> if a class descriptor was found
      */
     public boolean hasClassDescriptor(Class clazz);
 
-
     /**
-     * Returns the top level (extent) class to which the given class belongs.
-     * This may be a (abstract) base-class, an interface or the given class itself, if
-     * no extent is defined.
-     * @throws PersistenceBrokerException if clazz is not persistence capable,
-     * i.e. if clazz is not defined in the DescriptorRepository.
+     * Returns the top level class (most abstract class in terms of extents) from which the
+     * given class extends. This may be a (abstract) base-class, an interface or the given
+     * class itself, if no extent is defined.
+     *
+     * @param clazz The class to get the top level class for
+     * @return The top level class for it
+     * @throws PersistenceBrokerException If the class is not persistence capable,
+     *         if no metadata was defined for this class
      */
     public Class getTopLevelClass(Class clazz) throws PersistenceBrokerException;
 
@@ -291,36 +336,36 @@
     // *************************************************************************
 
     /**
-     * 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.
-     *
+     * Clears the broker's internal cache.
      */
     public void clearCache() throws PersistenceBrokerException;
 
     /**
-     * Removes the object from the brokers internal cache.
-     * If object is instance of {@link org.apache.ojb.broker.Identity},
-     * the associated object was removed from cache.
-     * <br/>
-     * Note: Removing is not recursive.
+     * Removes the given object or, if it is an instance of {@link org.apache.ojb.broker.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.
+     *
+     * @param objectOrIdentity The object to be removed from the cache or its identity
      */
     public void removeFromCache(Object objectOrIdentity) throws PersistenceBrokerException;
 
     /**
-     * makes object obj persistent in the underlying persistence system.
-     * E.G. by INSERT INTO ... or UPDATE ...  in an RDBMS.
+     * Makes the given object persistent in the underlying persistence system.
+     * This is usually done by issuing an INSERT ... or UPDATE ...  in an RDBMS.
      * The ObjectModification parameter can be used to generate optimized SQL code
      *
-     * (decide whether insert or update is needed. And for updates only generate code for
modified columns)
+     * @param obj The object to store
+     * @param modification Specifies what operation to perform (for generating optimized
SQL)
      */
     public void store(Object obj,
                       ObjectModification modification) throws PersistenceBrokerException;
 
     /**
-     * make object obj persistent in the underlying persistence system.
-     * E.G. by INSERT INTO ... or UPDATE ...  in an RDBMS
+     * Make the given object persistent in the underlying persistence system.
+     * This is usually done by issuing an INSERT ... or UPDATE ...  in an RDBMS.
+     *
+     * @param obj The object to store
      */
     public void store(Object obj) throws PersistenceBrokerException;
 
@@ -335,120 +380,135 @@
     public void update(Object obj, String[] fields);
 
     /**
-     * deletes the objects obj concrete representation in the underlying persistence system.
-     * E.G. by DELETE FROM ... WHERE ... in an RDBMS
+     * Deletes the given object's persistent representation in the underlying persistence
system.
+     * This is usually done by issuing a DELETE ... in an RDBMS
+     *
+     * @param obj The object to delete
      */
     public void delete(Object obj) throws PersistenceBrokerException;
 
     /**
-     * Deletes and MtoN implementor (a row on a indirection table)
-     * As it is today, ojb doesn't handle collection inherence, so collections descriptors
+     * Deletes an m:n implementor which defines the relationship between two persistent objects.
+     * This is usually a row in an indirection table.<br/>
+     * Note that OJB currently doesn't handle collection inheritance, so collections descriptors
      * are written per class. We try to match one of these collection descriptors, iterating
from the left side
-     * and looking for possible for classes on the right side using : collection descriptor
element . isAssinableFrom(rightClass)
+     * and looking for possible for classes on the right side using isAssignableFrom(rightClass).
      *
      * TODO: handle cache problems
      * TODO: delete more than one row if possible
      *
-     *
-     * <b>Pre-coditions :</b>
-     * <li></li>
-     *
-     * <b>Pos-coditions :</b>
-     * <li></li>
-     *
-     * <b>Assertions :</b>
-     * <li></li>
-     *
-     * @param m2nImpl
-     * @throws PersistenceBrokerException if an error occours
+     * @param m2nImpl The m:n implementor to delete
      */
     public void deleteMtoNImplementor(MtoNImplementor m2nImpl) throws PersistenceBrokerException;
 
     /**
+     * Stores the given m:n implementor int the underlying persistence system.
+     * This is usually done by inserting a row in an indirection table.<br/>
+     * Note that OJB currently doesn't handle collection inheritance, so collections descriptors
+     * are written per class. We try to match one of these collection descriptors, iterating
from the left side
+     * and looking for possible for classes on the right side using isAssignableFrom(rightClass).
      *
+     * @param m2nImpl The m:n implementor to delete
      */
     public void addMtoNImplementor(MtoNImplementor m2nImpl) throws PersistenceBrokerException;
 
     /**
-     * Deletes all objects matching the query from the underlying persistence system.
-     * E.G. by DELETE FROM ... WHERE ... in an RDBMS
-     * <p/>
-     * <b>Note:</b> This method directly perform the delete statement ignoring
object
-     * references and do not synchronize the cache - take care!
+     * Deletes all objects matching the given query, from the underlying persistence system.
+     * This is usually done via DELETE ... in an RDBMS.<br/>
+     * <b>Note:</b> This method directly perform the delete statement ignoring
any object
+     * references and does not synchronize the cache - take care!
+     *
+     * @param query The query determining the objects to delete
      */
     public void deleteByQuery(Query query) throws PersistenceBrokerException;
 
-
-
-
-
     // *************************************************************************
     // Query methods
     // *************************************************************************
 
     /**
-     * Retrieve all Reference- and  Collection-attributes of a given
-     * instance, independent from the used metadata-settings of the
-     * references.
+     * Retrieve all references and collections of the given object irrespective of the
+     * metadata settings defined for them.
      *
-     * @param pInstance the persistent instance
+     * @param obj The persistent object
      */
-    public void retrieveAllReferences(Object pInstance) throws PersistenceBrokerException;
+    public void retrieveAllReferences(Object obj) 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
+     * Retrieve the specified reference or collection attribute for the given persistent
object.
+     *
+     * @param obj      The persistent object
+     * @param attrName The name of the attribute to retrieve
      */
-    public void retrieveReference(Object pInstance, String pAttributeName) throws PersistenceBrokerException;
+    public void retrieveReference(Object obj, String attrName) throws PersistenceBrokerException;
 
     /**
-     * Returns the count of elements a given query will return.
+     * Returns the number of elements that the given query will return.
+     *
+     * @param query The query
+     * @return The number of elements returned by the query
      */
     public int getCount(Query query) throws PersistenceBrokerException;
 
     /**
+     * Retrieves the persistent objects matching the given query. Note that if the Query
has
+     * no criteria ALL persistent objects of the class targeted by the query will be returned.
      *
-     * 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.
+     * @param query The query
+     * @return The persistent objects matching the query
      */
     public Collection getCollectionByQuery(Query query) throws PersistenceBrokerException;
 
     /**
-     * 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.
+     * Retrieves the persistent objects matching the given query. The resulting collection
will
+     * be of the supplied collection type. Note that if the Query has no criteria ALL persistent
+     * objects of the class targeted by the query will be returned.
+     *
+     * @param collectionClass The collection type which needs to implement
+     *                        {@link ManageableCollection}
+     * @param query           The query
+     * @return The persistent objects matching the query
      */
     public ManageableCollection getCollectionByQuery(Class collectionClass, 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.
+     * 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 {@link java.util.Iterator#next()}. Note that if the Query
has no criteria
+     * ALL persistent objects of the class targeted by the query will be returned.
+     *
+     * @param query The query
+     * @return The persistent objects matching the query
      */
     public OJBIterator getIteratorByQuery(Query query) throws PersistenceBrokerException;
 
     /**
-     * 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
+     * Retrieves the rows (as <code>Object[]</code> 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 {@link java.util.Iterator#next()}.
+     *
+     * @param query The report query
+     * @return The rows matching the query
      */
     public OJBIterator getReportQueryIteratorByQuery(Query query) throws PersistenceBrokerException;
 
     /**
-     * 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)
+     * Retrieve a persistent object from the underlying datastore by its identity. However,
users
+     * are encouraged to use {@link #getObjectByQuery(Query)} instead, as this method is
mainly
+     * intended to be used for internal handling of materialization by OID (e.g. in Proxies).
+     *
+     * @param id The persistent object's id
+     * @return The persistent object
      */
     public Object getObjectByIdentity(Identity id) throws PersistenceBrokerException;
 
     /**
-     * Retrieve an Object by query.
-     * I.e perform a SELECT ... FROM ... WHERE ...  in an RDBMS
+     * Retrieve the (first) persistent object from the underlying datastore that matches
the given
+     * query.
+     *
+     * @param query The query
+     * @return The persistent object
      */
     public Object getObjectByQuery(Query query) throws PersistenceBrokerException;
 }

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/PersistenceBrokerInternal.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/PersistenceBrokerInternal.java?rev=422233&r1=422232&r2=422233&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/PersistenceBrokerInternal.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/PersistenceBrokerInternal.java Sat Jul 15
07:22:34 2006
@@ -96,7 +96,7 @@
      * @return the QueryFactory
      */
     public QueryFactoryNew getQueryFactory();
-    
+
     /**
      * Answer the ReferenceBroker.
      * @return QueryReferenceBroker
@@ -193,4 +193,34 @@
      * Return the relationship prefetcher factory.
      */
     public RelationshipPrefetcherFactory getRelationshipPrefetcherFactory();
+
+//    /**
+//     * Returns <em>true</em> if the development checks are enabled.
+//     *
+//     * @see #setTxCheck(boolean)
+//     */
+//    public boolean isTxCheck();
+//
+//    /**
+//     * This setting can be helpful during development if the PersistenceBroker transaction
+//     * demarcation was used (this is true in most cases). If set 'true' on PB#store(...)
+//     * and PB#delete(...) methods calls OJB check for active PB-tx and if no active tx
is
+//     * found a error is logged. This can help to avoid store/delete calls without a running
+//     * PB-tx while development. Default setting is 'false'.
+//     * <p/>
+//     * <strong>Note:</strong> When using OJB in a managed
+//     * environment <em>without</em> OJB-caching, it's valid to use store/delete
+//     * calls without a running PB-tx.
+//     *
+//     * @param txCheck Set <em>true</em> to enable the checks
+//     */
+//    public void setTxCheck(boolean txCheck);
+//
+//    /**
+//     * If
+//     * @return
+//     */
+//    public boolean isBrokerLeakDetection();
+//
+//    public void setBrokerLeakDetection(boolean brokerLeakDetection);
 }

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java?rev=422233&r1=422232&r2=422233&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java Sat Jul 15 07:22:34
2006
@@ -16,6 +16,9 @@
  */
 
 import java.io.Serializable;
+import java.sql.Types;
+import java.sql.SQLException;
+import java.sql.CallableStatement;
 import java.util.Comparator;
 
 import org.apache.commons.lang.SerializationUtils;
@@ -23,10 +26,13 @@
 import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.commons.lang.builder.ToStringStyle;
 import org.apache.ojb.broker.OJBRuntimeException;
-import org.apache.ojb.broker.metadata.fieldaccess.AnonymousPersistentField;
+import org.apache.ojb.broker.PersistenceBroker;
 import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
-import org.apache.ojb.broker.accesslayer.conversions.FieldConversionDefaultImpl;
 import org.apache.ojb.broker.accesslayer.conversions.FieldConversionExt;
+import org.apache.ojb.broker.accesslayer.NullCheck;
+import org.apache.ojb.broker.accesslayer.NullCheckDefaultImpl;
+import org.apache.ojb.broker.accesslayer.ResultSetAndStatement;
+import org.apache.ojb.broker.metadata.fieldaccess.AnonymousPersistentField;
 import org.apache.ojb.broker.util.ClassHelper;
 
 /**
@@ -47,6 +53,8 @@
     public static final String ACCESS_READONLY = RepositoryElements.TAG_ACCESS_READONLY;
     public static final String ACCESS_READWRITE = RepositoryElements.TAG_ACCESS_READWRITE;
 
+    protected static final String JDBC_TYPE_CLASS_PROPERTY = "jdbcTypeClass";
+
     private int m_ColNo;
     private String m_ColumnName;
     private String m_ColumnType;
@@ -64,6 +72,7 @@
     private boolean precisionSpecified = false;
     private boolean lengthSpecified = false;
     private FieldConversion fieldConversion = null;
+    private NullCheck nullCheck = null;
     // true if field is used for optimistic locking BRJ
     private boolean m_locking = false;
     // if locking is true and updateLock is true then
@@ -114,7 +123,9 @@
     }
 
     /**
+     * Return the name of the mapped database column.
      *
+     * @see #getFullColumnName()
      */
     public String getColumnName()
     {
@@ -122,10 +133,14 @@
     }
 
     /**
-     * Answer the qualified ColumnName<br>
+     * Answer the qualified ColumnName
+     * <br>
      * ie: myTab.name
+     *
+     * @return The full column name
+     * @see #getColumnName()
      */
-    public String getFullColumnName()			// BRJ
+    public String getFullColumnName()
     {
         return getClassDescriptor().getFullTableName() + "." + getColumnName();
     }
@@ -159,8 +174,7 @@
      */
     public JdbcType getJdbcType()
     {
-        // check for 'null' in any case, because after serialisation
-        // field can be null
+        // check if jdbcType is assigned
         if(m_jdbcType == null)
         {
             m_jdbcType = lookupJdbcType();
@@ -178,33 +192,62 @@
     private JdbcType lookupJdbcType()
     {
         JdbcType result;
-        String columnType = getColumnType();
-        // if sql type was not set in metadata we use reflection
-        // to determine sql type by reflection
-        if (columnType == null)
-        {
-            try
+        /*
+        we allow to define specific {@link JdbcType} implementations
+        via custom attribute
+        */
+        String jdbcTypeClass = getAttribute(JDBC_TYPE_CLASS_PROPERTY);
+        if(jdbcTypeClass == null || jdbcTypeClass.length() == 0)
+        {
+            String columnType = getColumnType();
+            // if sql type was not set in metadata we use reflection
+            // to determine sql type by reflection
+            if (columnType == null || columnType.length() == 0)
             {
-                result = JdbcTypesHelper.getJdbcTypeByReflection(m_PersistentField.getType().getName());
+                try
+                {
+                        result = JdbcTypesHelper.getJdbcTypeByReflection(m_PersistentField);
+                }
+                catch(Exception e)
+                {
+                    String eol = SystemUtils.LINE_SEPARATOR;
+                    throw new OJBRuntimeException("Can't automatically assign a jdbc field-type
for field: "
+                            + eol + this.toXML() + eol + "in class: " + eol + getClassDescriptor(),
e);
+                }
             }
-            catch(Exception e)
+            else
             {
-                String eol = SystemUtils.LINE_SEPARATOR;
-                throw new OJBRuntimeException("Can't automatically assign a jdbc field-type
for field: "
-                        + eol + this.toXML() + eol + "in class: " + eol + getClassDescriptor(),
e);
+                try
+                {
+                    result = JdbcTypesHelper.getJdbcTypeByName(columnType);
+                    // TODO: find better solution, workaround to handle Blob/Clob columns
with byte-array/String fields
+                    if(result.getType() == Types.BLOB && (new byte[]{}).getClass().isAssignableFrom(getPersistentField().getType()))
+                    {
+                        result = new JdbcTypes.T_BlobToByteArray();
+                    }
+                    else if(result.getType() == Types.CLOB && String.class.isAssignableFrom(getPersistentField().getType()))
+                    {
+                        result = new JdbcTypes.T_ClobToString();
+                    }
+                }
+                catch(Exception e)
+                {
+                    String eol = SystemUtils.LINE_SEPARATOR;
+                    throw new OJBRuntimeException("Can't assign the specified jdbc field-type
'"+columnType+"' for field: "
+                            + eol + this.toXML() + eol + "in class: " + eol + getClassDescriptor(),
e);
+                }
             }
         }
         else
         {
             try
             {
-                result = JdbcTypesHelper.getJdbcTypeByName(columnType);
+                result = (JdbcType) ClassHelper.newInstance(jdbcTypeClass);
             }
             catch(Exception e)
             {
-                String eol = SystemUtils.LINE_SEPARATOR;
-                throw new OJBRuntimeException("Can't assign the specified jdbc field-type
'"+columnType+"' for field: "
-                        + eol + this.toXML() + eol + "in class: " + eol + getClassDescriptor(),
e);
+                throw new MetadataException("Can't create specified " + JdbcType.class.getName()
+                        + " implementation: " + jdbcTypeClass, e);
             }
         }
         return result;
@@ -223,6 +266,7 @@
         buf.append("isAutoincrement", m_autoIncrement);
         buf.append("access", m_access);
         buf.append("sequenceName", m_sequenceName);
+        buf.append("nullCheck", nullCheck.toString());
         buf.append("jdbcType", m_jdbcType);
         buf.append("super_class_fields ", "=> " + super.toString());
         buf.append(SystemUtils.LINE_SEPARATOR);
@@ -238,7 +282,7 @@
         // if no conversion is specified use the default conversion
         if (fieldConversion == null)
         {
-            fieldConversion = new FieldConversionDefaultImpl();
+            fieldConversion = FieldConversion.DEFAULT;
         }
         return fieldConversion;
     }
@@ -279,6 +323,37 @@
         }
     }
 
+    /**
+     * Returns the NullCheck instance used for this field.
+     * @return NullCheck instance for this field
+     */
+    public NullCheck getNullCheck()
+    {
+        // if no explicit class is specified use the default implementation
+        if (nullCheck == null)
+        {
+        	nullCheck = new NullCheckDefaultImpl();
+        }
+        return nullCheck;
+    }
+
+    /**
+     * Creates the NullCheck implementation to use for this field.
+     * @param nullCheckClassName FQCN of the NullCheck implementation to instantiate
+     */
+    public void setNullCheckClassName(String nullCheckClassName)
+    {
+        try
+        {
+            this.nullCheck = (NullCheck) ClassHelper.newInstance(nullCheckClassName);
+        }
+        catch (Exception e)
+        {
+            throw new MetadataException(
+                    "Could not instantiate NullCheck class using default constructor", e);
+        }
+    }
+
     public boolean isIndexed()
     {
         return indexed;
@@ -475,6 +550,82 @@
         return AnonymousPersistentField.class.isAssignableFrom(getPersistentField().getClass());
     }
 
+    /**
+     * Returns <em>true</em> if the field is of type {@link java.sql.Blob}
+     * or {@link java.sql.Clob}.
+     */
+    public boolean isLobFieldType()
+    {
+        return getJdbcType().getFieldType().isLobField();
+    }
+
+
+    /**
+     * Reads in the value of the field/column represented by this <code>FieldDescriptor</code>.
+     *
+     * @param rs_stmt The current used {@link org.apache.ojb.broker.accesslayer.ResultSetAndStatement}
instance.
+     * @param convert If set <em>true</em> a
+     * {@link org.apache.ojb.broker.accesslayer.conversions.FieldConversion#sqlToJava(Object)}
conversion call
+     * is done.
+     * @return The read in value of this field.
+     * @throws SQLException
+     */
+    public Object readValue(final ResultSetAndStatement rs_stmt, boolean convert)
+            throws SQLException
+    {
+        int idx = rs_stmt.m_sql.getColumnIndex(this);
+        return readValue(rs_stmt, idx, convert);
+    }
+
+    /**
+     * Reads in the value of the field/column represented by this <code>FieldDescriptor</code>.
+     *
+     * @param rs_stmt The current used {@link org.apache.ojb.broker.accesslayer.ResultSetAndStatement}
instance.
+     * @param index The result set column index.
+     * @param convert If set <em>true</em> a
+     * {@link org.apache.ojb.broker.accesslayer.conversions.FieldConversion#sqlToJava(Object)}
conversion call
+     * is done.
+     * @return The read in value of this field.
+     * @throws SQLException
+     */
+    public Object readValue(final ResultSetAndStatement rs_stmt, int index, boolean convert)
+            throws SQLException
+    {
+        Object val = getJdbcType().getObjectFromColumn(rs_stmt.m_rs, null, getColumnName(),
index);
+        val = rs_stmt.m_platform.postPrepareReadInValue(this, val);
+        if(convert) val = getFieldConversion().sqlToJava(val);
+        if(isLobFieldType())
+        {
+            val = rs_stmt.m_broker.serviceLobHelper().wrapLobField(this, val);
+        }
+        return val;
+    }
+
+    /**
+     * Reads in the value of the field/column represented by this <code>FieldDescriptor</code>.
+     *
+     * @param broker The current used <code>PersistenceBroker</code>.
+     * @param stmt The current used <code>CallableStatement</code>.
+     * @param index The result set column index.
+     * @param convert If set <em>true</em> a
+     * {@link org.apache.ojb.broker.accesslayer.conversions.FieldConversion#sqlToJava(Object)}
conversion call
+     * is done.
+     * @return The read in value of this field.
+     * @throws SQLException
+     */
+    public Object readValue(final PersistenceBroker broker, final CallableStatement stmt,
int index, boolean convert)
+            throws SQLException
+    {
+        Object val = getJdbcType().getObjectFromColumn(stmt, index);
+        val = broker.serviceConnectionManager().getSupportedPlatform().postPrepareReadInValue(this,
val);
+        if(convert) val = getFieldConversion().sqlToJava(val);
+        if(isLobFieldType())
+        {
+            val = broker.serviceLobHelper().wrapLobField(this, val);
+        }
+        return val;
+    }
+
     /*
      * @see XmlCapable#toXML()
      */
@@ -556,7 +707,7 @@
         // default-fetch not yet implemented
 
         // conversion
-        if( this.getFieldConversion().getClass() != FieldConversionDefaultImpl.class )
+        if( this.getFieldConversion().getClass() != FieldConversion.DEFAULT.getClass() )
         {
             result.append( "        " );
             result.append( RepositoryTags.getAttribute( FIELD_CONVERSION, getFieldConversion().getClass().getName()
) );
@@ -600,7 +751,7 @@
         return result.toString();
     }
 
-    public Object clone()
+    public Object clone() throws CloneNotSupportedException
     {
         // TODO: think this can be critical, becuase it will serialize all dependent objects
too
         return SerializationUtils.deserialize(SerializationUtils.serialize(this));

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/FieldType.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/FieldType.java?rev=422233&r1=422232&r2=422233&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/FieldType.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/FieldType.java Sat Jul 15 07:22:34
2006
@@ -1,9 +1,6 @@
 package org.apache.ojb.broker.metadata;
 
-import java.io.Serializable;
-
-
-/* Copyright 2002-2004 The Apache Software Foundation
+/* Copyright 2002-2005 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -18,6 +15,8 @@
  * limitations under the License.
  */
 
+import java.io.Serializable;
+
 /**
  * OJB implements the mapping conventions for JDBC as specified by the JDBC 3.0 specification
and
  * this class representing the jdbc java types of the sql types mappings - e.g.
@@ -50,20 +49,15 @@
     public boolean equals(Object firstValue, Object secondValue);
 
     /**
-     * Returns the sql {@link java.sql.Types} of this field.
+     * Returns <em>true</em> if the field type is mutable, e.g.
+     * <code>Timestamp</code> field. All immutable fields types,
+     * e.g like <code>String</code>, will return <em>false</em>.
      */
-    public int getSqlType();
-
-    /**
-     * Dets the associated sql field type of this field.
-     * @param jdbcType The associated {@link org.apache.ojb.broker.metadata.JdbcType}.
-     */
-    public void setSqlType(JdbcType jdbcType);
+    public boolean isMutable();
 
     /**
-     * Returns <em>true</em> if the field type is mutable, e.g. a jdbc BLOB field
or
-     * jdbc TIMESTAMP field.
-     * @return
+     * Returns <em>true</em> if the field is of type {@link java.sql.Blob}
+     * or {@link java.sql.Clob}.
      */
-    public boolean isMutable();
+    public boolean isLobField();
 }

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/JdbcType.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/JdbcType.java?rev=422233&r1=422232&r2=422233&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/JdbcType.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/JdbcType.java Sat Jul 15 07:22:34
2006
@@ -1,13 +1,6 @@
 package org.apache.ojb.broker.metadata;
 
-import java.sql.ResultSet;
-import java.sql.CallableStatement;
-import java.sql.SQLException;
-import java.io.Serializable;
-
-import org.apache.ojb.broker.util.sequence.SequenceManagerException;
-
-/* Copyright 2003-2004 The Apache Software Foundation
+/* Copyright 2003-2006 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,6 +15,13 @@
  * limitations under the License.
  */
 
+import java.sql.ResultSet;
+import java.sql.CallableStatement;
+import java.sql.SQLException;
+import java.io.Serializable;
+
+import org.apache.ojb.broker.util.sequence.SequenceManagerException;
+
 /**
  * Represents a jdbc sql type object defined by the JDBC 3.0 specification to handle
  * data conversion (see JDBC 3.0 specification <em>Appendix B, Data Type Conversion
Tables</em>).
@@ -60,6 +60,11 @@
     public Object getObjectFromColumn(ResultSet rs, String columnName) throws SQLException;
 
     /**
+     * Convenience method for {@link #getObjectFromColumn(ResultSet, CallableStatement, String,
int)}
+     */
+    public Object getObjectFromColumn(ResultSet rs, int columnId) throws SQLException;
+
+    /**
      * Convert the given {@link java.lang.Long} value to
      * a java object representation of this jdbc type.
      */
@@ -71,11 +76,6 @@
     public int getType();
 
     /**
-     * Returns the string representing of the {@link java.sql.Types sql type}.
-     */
-    public String getTypeAsString();
-
-    /**
      * Indicates whether some other object is "equal to" this one.
      */
     public boolean equals(Object obj);
@@ -90,8 +90,4 @@
 //     * Convenience method for {@link #getObjectFromColumn(ResultSet, CallableStatement,
String, int)}
 //     */
 //    Object getObjectFromColumn(CallableStatement stmt, String columnName) throws SQLException;
-//    /**
-//     * Convenience method for {@link #getObjectFromColumn(ResultSet, CallableStatement,
String, int)}
-//     */
-//    Object getObjectFromColumn(ResultSet rs, int columnId) throws SQLException;
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message