db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r472135 - in /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker: core/MtoNBroker.java util/BrokerHelper.java
Date Tue, 07 Nov 2006 15:18:13 GMT
Author: arminw
Date: Tue Nov  7 07:18:13 2006
New Revision: 472135

URL: http://svn.apache.org/viewvc?view=rev&rev=472135
Log:
minor improvements

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/MtoNBroker.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/BrokerHelper.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/MtoNBroker.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/MtoNBroker.java?view=diff&rev=472135&r1=472134&r2=472135
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/MtoNBroker.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/MtoNBroker.java Tue
Nov  7 07:18:13 2006
@@ -29,7 +29,6 @@
 import org.apache.ojb.broker.OJBRuntimeException;
 import org.apache.ojb.broker.PersistenceBrokerException;
 import org.apache.ojb.broker.PersistenceBrokerSQLException;
-import org.apache.ojb.broker.core.proxy.IndirectionHandler;
 import org.apache.ojb.broker.accesslayer.ResultSetAndStatement;
 import org.apache.ojb.broker.metadata.ClassDescriptor;
 import org.apache.ojb.broker.metadata.CollectionDescriptor;
@@ -37,9 +36,9 @@
 import org.apache.ojb.broker.metadata.FieldDescriptor;
 import org.apache.ojb.broker.metadata.JdbcType;
 import org.apache.ojb.broker.query.Query;
+import org.apache.ojb.broker.util.BrokerHelper;
 import org.apache.ojb.broker.util.logging.Logger;
 import org.apache.ojb.broker.util.logging.LoggerFactory;
-import org.apache.ojb.broker.util.BrokerHelper;
 
 /**
  * Manage all stuff related to non-decomposed M:N association.

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/BrokerHelper.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/BrokerHelper.java?view=diff&rev=472135&r1=472134&r2=472135
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/BrokerHelper.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/BrokerHelper.java
Tue Nov  7 07:18:13 2006
@@ -40,6 +40,7 @@
 import org.apache.ojb.broker.core.PersistenceBrokerImpl;
 import org.apache.ojb.broker.core.ValueContainer;
 import org.apache.ojb.broker.core.proxy.IndirectionHandler;
+import org.apache.ojb.broker.core.proxy.ProxyFactory;
 import org.apache.ojb.broker.metadata.ClassDescriptor;
 import org.apache.ojb.broker.metadata.CollectionDescriptor;
 import org.apache.ojb.broker.metadata.FieldDescriptor;
@@ -73,10 +74,12 @@
 {
     public static final String REPOSITORY_NAME_SEPARATOR = "#";
     private PersistenceBrokerImpl m_broker;
+    private ProxyFactory proxyFactory;
 
     public BrokerHelper(PersistenceBrokerImpl broker)
     {
         this.m_broker = broker;
+        this.proxyFactory = broker.getProxyFactory();
     }
 
     /**
@@ -135,22 +138,22 @@
     }
 
     /**
-     * Answer the real ClassDescriptor for anObj
-     * ie. aCld may be an Interface of anObj, so the cld for anObj is returned
+     * Answer the real ClassDescriptor for realObject
+     * ie. aCld may be an Interface of the realObject, so
+     * the cld for realObject is returned.
      */
-    private ClassDescriptor getRealClassDescriptor(ClassDescriptor aCld, Object anObj)
+    private ClassDescriptor getRealClassDescriptor(ClassDescriptor cld, Object realObject)
     {
         ClassDescriptor result;
-
-        if(aCld.getClassOfObject() == m_broker.getProxyFactory().getRealClass(anObj))
+        Class realClass = proxyFactory.getRealClass(realObject);
+        if(cld.getClassOfObject().equals(realClass))
         {
-            result = aCld;
+            result = cld;
         }
         else
         {
-            result = aCld.getRepository().getDescriptorFor(anObj.getClass());
+            result = cld.getRepository().getDescriptorFor(realClass);
         }
-
         return result;
     }
 
@@ -166,7 +169,7 @@
      */
     public ValueContainer[] getKeyValues(ClassDescriptor cld, Object objectOrProxy, boolean
convertToSql) throws PersistenceBrokerException
     {
-        IndirectionHandler handler = m_broker.getProxyFactory().getIndirectionHandler(objectOrProxy);
+        IndirectionHandler handler = proxyFactory.getIndirectionHandler(objectOrProxy);
 
         if(handler != null)
         {
@@ -181,8 +184,9 @@
 
     /**
      * Get the values of the fk-target-fields for an obj.
-     * @param rds
-     * @param objOrProxy
+     *
+     * @param rds The reference descriptor
+     * @param objOrProxy The object/proxy object.
      * @throws PersistenceBrokerException
      */
     public ValueContainer[] getFkTargetValuesForObject(ObjectReferenceDescriptor rds, Object
objOrProxy, boolean convertToSql) throws PersistenceBrokerException
@@ -191,7 +195,7 @@
 
         Class refClass;
         Object source = null;
-        IndirectionHandler handler = m_broker.getProxyFactory().getIndirectionHandler(objOrProxy);
+        IndirectionHandler handler = proxyFactory.getIndirectionHandler(objOrProxy);
         if(handler != null)
         {
             if(handler.alreadyMaterialized())
@@ -233,19 +237,20 @@
         }
         
         // use the values of the target-fields
-        Object obj = m_broker.getProxyFactory().getRealObject(objOrProxy);
+        Object obj = proxyFactory.getRealObject(objOrProxy);
         return getValuesForObject(targetFd, obj, convertToSql);
     } 
 
     /**
      * Get the values of the fk-fields for an obj.
-     * @param rds
-     * @param objOrProxy
+     *
+     * @param rds The reference descriptor.
+     * @param objOrProxy The object/proxy object.
      * @throws PersistenceBrokerException
      */
     public ValueContainer[] getFkValuesForObject(ObjectReferenceDescriptor rds, Object objOrProxy,
boolean convertToSql) throws PersistenceBrokerException
     {
-        Class refClass = m_broker.getProxyFactory().getRealClass(objOrProxy);
+        Class refClass = proxyFactory.getRealClass(objOrProxy);
         ClassDescriptor refCld = m_broker.getClassDescriptor(refClass);
         FieldDescriptor pkFd[] = refCld.getPkFields();
         FieldDescriptor targetFd[] = rds.getForeignKeyFieldDescriptors(refCld);
@@ -257,7 +262,7 @@
         }
 
         // use the values of the target-fields
-        Object obj = m_broker.getProxyFactory().getRealObject(objOrProxy);
+        Object obj = proxyFactory.getRealObject(objOrProxy);
         return getValuesForObject(targetFd, obj, convertToSql);
     } 
 
@@ -339,7 +344,7 @@
         FieldDescriptor[] fields = cld.getPkFields();
         boolean hasNull = false;
         // an unmaterialized proxy object can never have nullified PK's
-        IndirectionHandler handler = m_broker.getProxyFactory().getIndirectionHandler(obj);
+        IndirectionHandler handler = proxyFactory.getIndirectionHandler(obj);
         if(handler == null || handler.alreadyMaterialized())
         {
             if(handler != null) obj = handler.getRealSubject();
@@ -391,10 +396,16 @@
     }
 
     /**
-     * Get the values of the fields for an obj
-     * Autoincrement values are automatically set.
-     * @param fields
-     * @param obj
+     * Get the values of the fields for an obj.
+     * Autoincrement values can be automatically assigned.
+     *
+     * @param fields The fields to extract values.
+     * @param obj The real (non-proxy) object.
+     * @param convertToSql If <em>true</em> all values are converted to sql-type.
+     * @param assignAutoincrement This argument is for backward compatibility with OJB versions
+     * before OJB 1.0.5. If <em>true</em> all nullified auto-increment fields
will be automatically
+     * populated with the next sequence value.
+     * @return An array of extracted values.
      * @throws PersistenceBrokerException
      */
     public ValueContainer[] getValuesForObject(FieldDescriptor[] fields, Object obj, boolean
convertToSql, boolean assignAutoincrement) throws PersistenceBrokerException
@@ -434,6 +445,15 @@
         return result;
     }
 
+    /**
+     * Extracts the values of the specified fields.
+     *
+     * @param fields The fields to extract values.
+     * @param obj The real (non-proxy) object.
+     * @param convertToSql If <em>true</em> all values are converted to sql-type.
+     * @return An array of extracted values.
+     * @throws PersistenceBrokerException
+     */
     public ValueContainer[] getValuesForObject(FieldDescriptor[] fields, Object obj, boolean
convertToSql) throws PersistenceBrokerException
     {
         return getValuesForObject(fields, obj, convertToSql, false);
@@ -447,7 +467,7 @@
      * the caller is reponsible to pass a valid descriptor.
      *
      * @param cld The {@link org.apache.ojb.broker.metadata.ClassDescriptor} to extract the
RW-fields
-     * @param obj The object with target fields to extract.
+     * @param obj The non-proxy object with target fields to extract.
      * @throws MetadataException if there is an erros accessing obj field values
      */
     public ValueContainer[] getNonKeyRwValues(ClassDescriptor cld, Object obj) throws PersistenceBrokerException
@@ -525,7 +545,7 @@
      */
     public boolean assertValidPkForDelete(ClassDescriptor cld, Object obj)
     {
-        if(!m_broker.getProxyFactory().isProxy(obj))
+        if(!proxyFactory.isProxy(obj))
         {
             FieldDescriptor fieldDescriptors[] = cld.getPkFields();
             int fieldDescriptorSize = fieldDescriptors.length;
@@ -594,9 +614,9 @@
     private Query getQueryByCriteriaCount(QueryByCriteria aQuery)
     {
         Class                 searchClass = aQuery.getSearchClass();
-        ReportQueryByCriteria countQuery  = null;
+        ReportQueryByCriteria countQuery;
         Criteria              countCrit   = null;
-        String[]              columns     = new String[1];
+        String[]              columns;
 
         // BRJ: copied Criteria without groupby, orderby, and prefetched relationships
         if (aQuery.getCriteria() != null)
@@ -856,7 +876,7 @@
     public boolean link(Object obj, String attributeName, Object reference, boolean insert)
     {
         ClassDescriptor cld = m_broker.getDescriptorRepository().getDescriptorFor(
-                m_broker.getProxyFactory().getRealClass(obj));
+                proxyFactory.getRealClass(obj));
         ObjectReferenceDescriptor ord;
         boolean match = false;
         // first look for reference then for collection
@@ -918,7 +938,7 @@
     {
         boolean match = false;
         ClassDescriptor cld = m_broker.getDescriptorRepository().getDescriptorFor(
-                m_broker.getProxyFactory().getRealClass(obj));
+                proxyFactory.getRealClass(obj));
         ObjectReferenceDescriptor ord;
 
         // first look for reference then for collection
@@ -983,7 +1003,7 @@
         ClassDescriptor cld = ord.getClassDescriptor();
         if(cld.isInterface())
         {
-            cld = m_broker.getDescriptorRepository().getDescriptorFor(m_broker.getProxyFactory().getRealClass(obj));
+            cld = m_broker.getDescriptorRepository().getDescriptorFor(proxyFactory.getRealClass(obj));
         }
 
         if (doLink)



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