db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r538364 - in /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker: accesslayer/RsIterator.java cache/ObjectCacheDefaultImpl.java
Date Tue, 15 May 2007 23:01:57 GMT
Author: arminw
Date: Tue May 15 16:01:56 2007
New Revision: 538364

URL: http://svn.apache.org/viewvc?view=rev&rev=538364
Log:
optimize source

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/cache/ObjectCacheDefaultImpl.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java?view=diff&rev=538364&r1=538363&r2=538364
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
Tue May 15 16:01:56 2007
@@ -158,21 +158,21 @@
      */
     public RsIterator(RsQueryObject queryObject, final PersistenceBrokerImpl broker)
     {
-        setCache(broker.getInternalCache());
-        setRow(new HashMap());
-        setBroker(broker);
-        setQueryObject(queryObject);
+        m_cache = broker.getInternalCache();
+        m_row = new HashMap();
+        m_broker = broker;
+        m_queryObject = queryObject;
 
         if(queryObject.getClassDescriptor() != null)
         {
             Class classToPrefetch = broker.getReferenceBroker().getClassToPrefetch();
             if ((classToPrefetch != null) && classToPrefetch.isAssignableFrom(queryObject.getClassDescriptor().getClassOfObject()))
             {
-                setItemProxyClass(null);
+                m_itemProxyClass = null;
             }
             else
             {
-                setItemProxyClass(queryObject.getClassDescriptor().getProxyClass());
+                m_itemProxyClass = queryObject.getClassDescriptor().getProxyClass();
             }
         }
 
@@ -181,7 +181,7 @@
 		 * events and set the target object on every use TODO: Find a better
 		 * solution
 		 */
-        setAfterLookupEvent(new PBLifeCycleEvent(getBroker(), PBLifeCycleEvent.Type.AFTER_LOOKUP));
+        afterLookupEvent = new PBLifeCycleEvent(getBroker(), PBLifeCycleEvent.Type.AFTER_LOOKUP);
 
         try
         {
@@ -215,7 +215,7 @@
     {
         if (m_itemTopLevelClass == null)
         {
-            m_itemTopLevelClass = getQueryObject().getClassDescriptor().getTopLevelClass();
+            m_itemTopLevelClass = m_queryObject.getClassDescriptor().getTopLevelClass();
         }
         return m_itemTopLevelClass;
     }
@@ -228,12 +228,12 @@
     {
         try
         {
-            if (!isHasCalledCheck())
+            if (!m_hasCalledCheck)
             {
-                setHasCalledCheck(true);
-                setHasNext(getRsAndStmt().m_rs.next());
+                m_hasCalledCheck = true;
+                hasNext = getRsAndStmt().m_rs.next();
                 m_current_row++;
-                if (!getHasNext())
+                if (!hasNext)
                 {
                     autoReleaseDbResources();
                 }
@@ -241,7 +241,7 @@
         }
         catch (Exception ex)
         {
-            setHasNext(false);
+            hasNext = false;
             autoReleaseDbResources();
             if(ex instanceof ResourceClosedException)
             {
@@ -257,9 +257,9 @@
             }
         }
         if (logger.isDebugEnabled())
-            logger.debug("hasNext() -> " + getHasNext());
+            logger.debug("hasNext() -> " + hasNext);
 
-        return getHasNext();
+        return hasNext;
     }
 
     /**
@@ -270,12 +270,12 @@
     {
         try
         {
-            if (!isHasCalledCheck())
+            if (!m_hasCalledCheck)
             {
                 hasNext();
             }
-            setHasCalledCheck(false);
-            if (getHasNext())
+            m_hasCalledCheck = false;
+            if (hasNext)
             {
                 Object obj = getObjectFromResultSet();
                 //m_current_row++;
@@ -284,9 +284,9 @@
                 // set target object
                 if (!disableLifeCycleEvents)
                 {
-                    getAfterLookupEvent().setTarget(obj);
-                    getBroker().fireBrokerEvent(getAfterLookupEvent());
-                    getAfterLookupEvent().setTarget(null);
+                    afterLookupEvent.setTarget(obj);
+                    getBroker().fireBrokerEvent(afterLookupEvent);
+                    afterLookupEvent.setTarget(null);
                 }    
                 return obj;
             }
@@ -352,7 +352,7 @@
         }
 
         // prevent releasing of DBResources
-        setInBatchedMode(true);
+        m_inBatchedMode = true;
 
         prefetchedRel = query.getPrefetchedRelationships();
         prefetchers = new RelationshipPrefetcher[prefetchedRel.size()];
@@ -362,7 +362,7 @@
         {
             relName = (String) prefetchedRel.get(i);
             prefetchers[i] = getBroker().getRelationshipPrefetcherFactory()
-                    .createRelationshipPrefetcher(getQueryObject().getClassDescriptor(),
relName);
+                    .createRelationshipPrefetcher(m_queryObject.getClassDescriptor(), relName);
             prefetchers[i].prepareRelationshipSettings();
         }
 
@@ -390,8 +390,8 @@
             logger.error("beforeFirst failed !", e);
         }
 
-        setInBatchedMode(false);
-        setHasCalledCheck(false);
+        m_inBatchedMode = false;
+        m_hasCalledCheck = false;
     }
 
     /**
@@ -401,18 +401,18 @@
     {
         // fill primary key values from Resultset
         FieldDescriptor fld;
-        FieldDescriptor[] pkFields = getQueryObject().getClassDescriptor().getPkFields();
+        FieldDescriptor[] pkFields = m_queryObject.getClassDescriptor().getPkFields();
         Object[] pkValues = new Object[pkFields.length];
 
         for (int i = 0; i < pkFields.length; i++)
         {
             fld = pkFields[i];
-            pkValues[i] = getRow().get(fld.getColumnName());
+            pkValues[i] = m_row.get(fld.getColumnName());
         }
 
         // return identity object build up from primary keys
         return getBroker().serviceIdentity().buildIdentity(
-                getQueryObject().getClassDescriptor().getClassOfObject(), getTopLevelClass(),
pkValues);
+                m_queryObject.getClassDescriptor().getClassOfObject(), getTopLevelClass(),
pkValues);
     }
 
     /**
@@ -423,7 +423,7 @@
      */
     protected Object getObjectFromResultSet() throws PersistenceBrokerException
     {
-        Map row = getRow();
+        Map row = m_row;
         PersistenceBrokerInternal pb = getBroker();
         row.clear();
         /**
@@ -436,12 +436,12 @@
          * itemProxyClass should NOT be a member variable.
          */
 
-        RowReader rowReader = getQueryObject().getClassDescriptor().getRowReader();
+        RowReader rowReader = m_queryObject.getClassDescriptor().getRowReader();
         // in any case we need the PK values of result set row
         // provide m_row with primary key data of current row
         rowReader.readPkValuesFrom(getRsAndStmt(), row);
 
-        if (getItemProxyClass() != null)
+        if (m_itemProxyClass != null)
         {
             // assert: m_row is filled with primary key values from db
             return getProxyFromResultSet();
@@ -453,7 +453,7 @@
             Object result;
 
             // 2. check if Object is in cache. if so return cached version.
-            result = getCache().lookup(oid);
+            result = m_cache.lookup(oid);
             if (result == null)
             {
 
@@ -472,10 +472,10 @@
 					 */
                     synchronized (result)
                     {
-                        getCache().enableMaterializationCache();
+                        m_cache.enableMaterializationCache();
                         try
                         {
-                            getCache().doInternalCache(oid, result, ObjectCacheInternal.TYPE_NEW_MATERIALIZED);
+                            m_cache.doInternalCache(oid, result, ObjectCacheInternal.TYPE_NEW_MATERIALIZED);
                             /**
                              * MBAIRD if you have multiple classes mapped to a
                              * table, and you query on the base class you could get
@@ -490,12 +490,12 @@
                             pb.getReferenceBroker().retrieveReferences(result, cld, false);
                             pb.getReferenceBroker().retrieveCollections(result, cld, false);
 
-                            getCache().disableMaterializationCache();
+                            m_cache.disableMaterializationCache();
                         }
                         catch(RuntimeException e)
                         {
                             // catch runtime exc. to guarantee clearing of internal buffer
on failure
-                            getCache().doLocalClear();
+                            m_cache.doLocalClear();
                             throw e;
                         }
                     }
@@ -554,7 +554,7 @@
         Identity oid = getIdentityFromResultSet();
 
         // 2. return a Proxy instance:
-        return getBroker().createProxy(getItemProxyClass(), oid);
+        return getBroker().createProxy(m_itemProxyClass, oid);
     }
 
     /**
@@ -579,9 +579,9 @@
      */
     protected int countedSize() throws PersistenceBrokerException
     {
-        Query countQuery = getBroker().serviceBrokerHelper().getCountQuery(getQueryObject().getQuery());
+        Query countQuery = getBroker().serviceBrokerHelper().getCountQuery(m_queryObject.getQuery());
         ResultSetAndStatement rsStmt;
-        ClassDescriptor cld = getQueryObject().getClassDescriptor();
+        ClassDescriptor cld = m_queryObject.getClassDescriptor();
         int count = 0;
 
         // BRJ: do not use broker.getCount() because it's extent-aware
@@ -728,9 +728,9 @@
         if(row == -1)
         {
             int size = size();
-            if(getQueryObject().usePaging())
+            if(m_queryObject.usePaging())
             {
-                int span = getQueryObject().getEndIndex() + 1 - getQueryObject().getStartIndex();
+                int span = m_queryObject.getEndIndex() + 1 - m_queryObject.getStartIndex();
                 if(span < size)
                 {
                     size = span;
@@ -749,15 +749,15 @@
                     if(retval) m_current_row++;
                     else break;
                 }
-                setHasCalledCheck(true);
-                setHasNext(retval);
+                m_hasCalledCheck = true;
+                hasNext = retval;
                 if(!retval) autoReleaseDbResources();
                 System.out.println("result: " + getRsAndStmt().m_rs.getString(1) +", "+ getRsAndStmt().m_rs.getString("Lagerbestand"));
             }
             catch (Exception ex)
             {
-                setHasCalledCheck(true);
-                setHasNext(false);
+                m_hasCalledCheck = true;
+                hasNext = false;
                 retval = false;
                 autoReleaseDbResources();
             }
@@ -795,8 +795,8 @@
                     retval = getRsAndStmt().m_rs.absolute(row);
                 }
                 if(retval) m_current_row = row;
-                setHasCalledCheck(retval);
-                setHasNext(retval);
+                m_hasCalledCheck = retval;
+                hasNext = retval;
             }
         }
         catch (SQLException e)
@@ -860,7 +860,7 @@
 
     void release(boolean removeResourceListener)
     {
-        if (!isInBatchedMode()) // resources are reused in batched mode
+        if (!m_inBatchedMode) // resources are reused in batched mode
         {
             // If we haven't released resources yet, then do so.
             if (!this.resourcesAreReleased)
@@ -976,7 +976,7 @@
      */
     public ClassDescriptor getClassDescriptor()
     {
-        return getQueryObject().getClassDescriptor();
+        return m_queryObject.getClassDescriptor();
     }
 
     protected void setBroker(PersistenceBrokerImpl broker)

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/cache/ObjectCacheDefaultImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/cache/ObjectCacheDefaultImpl.java?view=diff&rev=538364&r1=538363&r2=538364
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/cache/ObjectCacheDefaultImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/cache/ObjectCacheDefaultImpl.java
Tue May 15 16:01:56 2007
@@ -18,11 +18,11 @@
 import java.lang.ref.ReferenceQueue;
 import java.lang.ref.SoftReference;
 import java.util.ArrayList;
-import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.HashMap;
 
 import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.commons.lang.builder.ToStringStyle;
@@ -137,7 +137,7 @@
     /**
      * static Map held all cached objects
      */
-    protected static final Map objectTable = new Hashtable();
+    protected static final Map objectTable = new HashMap();
     private static final Object lock = new Object();
     private static final ReferenceQueue queue = new ReferenceQueue();
     private volatile static short counter;
@@ -201,7 +201,10 @@
     public void clear()
     {
         //processQueue();
-        objectTable.clear();
+        synchronized(lock)
+        {
+            objectTable.clear();
+        }
         if(identitiesInWork.size() > 0) identitiesInWork.clear();
     }
 
@@ -211,7 +214,7 @@
         if((obj != null))
         {
             traceIdentity(oid);
-            synchronized(objectTable)
+            synchronized(lock)
             {
                 if(log.isDebugEnabled()) log.debug("Cache object " + oid);
                 objectTable.put(buildKey(oid), buildEntry(obj, oid));
@@ -300,7 +303,10 @@
         if(oid != null)
         {
             removeTracedIdentity(oid);
-            objectTable.remove(buildKey(oid));
+            synchronized(lock)
+            {
+                objectTable.remove(buildKey(oid));
+            }
             if(log.isDebugEnabled()) log.debug("Remove object " + oid);
         }
     }
@@ -308,7 +314,7 @@
     public String toString()
     {
         ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE);
-        buf.append("Count of cached objects", objectTable.keySet().size());
+        buf.append("Count of cached objects", objectTable.size());
         buf.append("Lookup hits", hitCount);
         buf.append("Failures", failCount);
         buf.append("Reclaimed", gcCount);
@@ -336,7 +342,10 @@
         for(Iterator iterator = identitiesInWork.iterator(); iterator.hasNext();)
         {
             oid = (Identity) iterator.next();
-            objectTable.remove(buildKey(oid));
+            synchronized(lock)
+            {
+                objectTable.remove(buildKey(oid));
+            }
         }
     }
 



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