db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r431353 - /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/IdentityFactoryImpl.java
Date Mon, 14 Aug 2006 14:39:28 GMT
Author: arminw
Date: Mon Aug 14 07:39:27 2006
New Revision: 431353

URL: http://svn.apache.org/viewvc?rev=431353&view=rev
Log:
minor performance improvement, update comments

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/IdentityFactoryImpl.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/IdentityFactoryImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/IdentityFactoryImpl.java?rev=431353&r1=431352&r2=431353&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/IdentityFactoryImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/IdentityFactoryImpl.java
Mon Aug 14 07:39:27 2006
@@ -58,7 +58,9 @@
         constructor call of Identity class we can run into problems when an object is stored/deleted/stored
in
         the same PB-tx, because then the PK of the object can change (e.g. when DB identity
columns are used)
         but the cached Identity object will always be the same when the Identity object is
requested by the
-        IdentityFactory
+        IdentityFactory. The IdentityFactory needs notification about each object declared
for deletion.
+        NOTE: Before we use such a cache we should run some serious performance tests. Maybe
such a cache
+        doesn't improve performance.
         */
         //this.persistentIdentityMap = new ReferenceIdentityMap(ReferenceIdentityMap.WEAK,
ReferenceIdentityMap.HARD, true);
         this.transientSequenceManager = new SequenceManagerTransientImpl(broker);
@@ -74,7 +76,11 @@
     protected Identity createTransientOrRealIdentity(ClassDescriptor cld, final Object objOrProxy)
     {
         if(objOrProxy == null) throw new NullPointerException("Can't create Identity for
'null'-object");
+
         Identity result = null;
+        //Identity result = (Identity) persistentIdentityMap.get(objOrProxy);
+        //if(result != null) return result;
+
         Class topLevelClass = null;
         Class realClass = null;
         Object[] pks = null;
@@ -87,51 +93,46 @@
             }
             else
             {
-                //result = (Identity) persistentIdentityMap.get(objOrProxy);
-                if(result == null)
+                // now we are sure that the specified object is not a proxy
+                realClass = objOrProxy.getClass();
+                topLevelClass = broker.getTopLevelClass(realClass);
+                if(cld == null)
                 {
-                    // now we are sure that the specified object is not a proxy
-                    realClass = objOrProxy.getClass();
-                    topLevelClass = broker.getTopLevelClass(objOrProxy.getClass());
-                    if(cld == null)
-                    {
-                        cld = broker.getClassDescriptor(objOrProxy.getClass());
-                    }
-                    BrokerHelper helper = broker.serviceBrokerHelper();
+                    cld = broker.getClassDescriptor(realClass);
+                }
+                BrokerHelper helper = broker.serviceBrokerHelper();
 
-                    FieldDescriptor[] fields = cld.getPkFields();
-                    pks = new Object[fields.length];
-                    FieldDescriptor fld;
-                    for(int i = 0; i < fields.length; i++)
+                FieldDescriptor[] fields = cld.getPkFields();
+                pks = new Object[fields.length];
+                FieldDescriptor fld;
+                for(int i = 0; i < fields.length; i++)
+                {
+                    fld = fields[i];
+                    /*
+                    we check all PK fields for 'null'-values
+                    */
+                    Object value = fld.getPersistentField().get(objOrProxy);
+                    if(helper.representsNull(fld, value))
                     {
-                        fld = fields[i];
-                        /*
-                        we check all PK fields for 'null'-values
-                        */
-                        Object value = fld.getPersistentField().get(objOrProxy);
-                        if(helper.representsNull(fld, value))
-                        {
-                            result = (Identity) transientIdentityMap.get(objOrProxy);
-                            if(result == null)
-                            {
-                                pks[i] = transientSequenceManager.getUniqueValue(fld);
-                                result = new Identity(realClass, topLevelClass, pks, true);
-                                //if(activeTx) objectToIdentityMap.put(objOrProxy, result);
-                                transientIdentityMap.put(objOrProxy, result);
-                            }
-                            break;
-                        }
-                        else
+                        result = (Identity) transientIdentityMap.get(objOrProxy);
+                        if(result == null)
                         {
-                            pks[i] = value;
+                            pks[i] = transientSequenceManager.getUniqueValue(fld);
+                            result = new Identity(realClass, topLevelClass, pks, true);
+                            transientIdentityMap.put(objOrProxy, result);
                         }
+                        break;
                     }
-                    if(result == null)
+                    else
                     {
-                        result = new Identity(realClass, topLevelClass, pks, false);
-                        //persistentIdentityMap.put(objOrProxy, result);
+                        pks[i] = value;
                     }
                 }
+                if(result == null)
+                {
+                    result = new Identity(realClass, topLevelClass, pks, false);
+                    //persistentIdentityMap.put(objOrProxy, result);
+                }
             }
         }
         catch(ClassNotPersistenceCapableException e)
@@ -148,7 +149,7 @@
     /** @see org.apache.ojb.broker.IdentityFactory#buildIdentity(Object) */
     public Identity buildIdentity(final Object obj)
     {
-        return createTransientOrRealIdentity(broker.getClassDescriptor(ProxyHelper.getRealClass(obj)),
obj);
+        return createTransientOrRealIdentity(null, obj);
     }
 
     /** @see org.apache.ojb.broker.IdentityFactory#buildIdentity(Object) */



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