db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r367076 - /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/cache/ObjectCacheTwoLevelImpl.java
Date Sun, 08 Jan 2006 19:56:52 GMT
Author: arminw
Date: Sun Jan  8 11:56:48 2006
New Revision: 367076

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

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/cache/ObjectCacheTwoLevelImpl.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/cache/ObjectCacheTwoLevelImpl.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/cache/ObjectCacheTwoLevelImpl.java?rev=367076&r1=367075&r2=367076&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/cache/ObjectCacheTwoLevelImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/cache/ObjectCacheTwoLevelImpl.java
Sun Jan  8 11:56:48 2006
@@ -22,6 +22,7 @@
 import java.util.Iterator;
 import java.util.Properties;
 
+import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.ojb.broker.Identity;
 import org.apache.ojb.broker.PBStateEvent;
 import org.apache.ojb.broker.PBStateListener;
@@ -35,7 +36,6 @@
 import org.apache.ojb.broker.util.ClassHelper;
 import org.apache.ojb.broker.util.logging.Logger;
 import org.apache.ojb.broker.util.logging.LoggerFactory;
-import org.apache.commons.lang.builder.ToStringBuilder;
 
 /**
  * A two-level {@link ObjectCache} implementation with a session- and an application cache.
The application
@@ -114,14 +114,14 @@
     private static final String DEF_COPY_STRATEGY = ObjectCacheTwoLevelImpl.CopyStrategyImpl.class.getName();
     private static final String DEF_APP_CACHE = ObjectCacheDefaultImpl.class.getName();
 
-    private HashMap sessionCache;
+    private final HashMap sessionCache;
     // private boolean enabledReadCache;
     private int invokeCounter;
-    private ReferenceQueue queue = new ReferenceQueue();
+    private final ReferenceQueue queue = new ReferenceQueue();
     private short counter;
     private ObjectCacheInternal applicationCache;
     private CopyStrategy copyStrategy;
-    private PersistenceBrokerImpl broker;
+    private final PersistenceBrokerImpl broker;
     private boolean forceProxies = false;
 
     public ObjectCacheTwoLevelImpl(final PersistenceBroker broker, Properties prop)
@@ -230,7 +230,7 @@
         return applicationCache;
     }
 
-    private Object lookupFromApplicationCache(Identity oid)
+    private Object lookupFromApplicationCache(final Identity oid)
     {
         Object result = null;
         Object obj = getApplicationCache().lookup(oid);
@@ -241,7 +241,7 @@
         return result;
     }
 
-    private boolean putToApplicationCache(Identity oid, Object obj, boolean cacheIfNew)
+    private boolean putToApplicationCache(final Identity oid, final Object obj, boolean cacheIfNew)
     {
         /*
         we allow to reuse cached objects, so lookup the old cache object
@@ -320,7 +320,7 @@
      * to session cache. If the specified object to cache is of type {@link #TYPE_NEW_MATERIALIZED}
      * it will be immediately pushed to the application cache.
      */
-    public void doInternalCache(Identity oid, Object obj, int type)
+    public void doInternalCache(final Identity oid, final Object obj, final int type)
     {
         processQueue();
         // pass new materialized objects immediately to application cache
@@ -360,7 +360,7 @@
      * the underlying real {@link ObjectCache} - Return <em>null</em> if no
      * object was found.
      */
-    public Object lookup(Identity oid)
+    public Object lookup(final Identity oid)
     {
         Object result = null;
         // 1. lookup an instance in session cache
@@ -400,7 +400,7 @@
      *
      * @param target The "flat" object for full materialization
      */
-    public void materializeFullObject(Object target)
+    public void materializeFullObject(final Object target)
     {
         ClassDescriptor cld = broker.getClassDescriptor(target.getClass());
         // don't force, let OJB use the user settings
@@ -417,7 +417,7 @@
     /**
      * Remove the corresponding object from session AND application cache.
      */
-    public void remove(Identity oid)
+    public void remove(final Identity oid)
     {
         if(log.isDebugEnabled()) log.debug("Remove object " + oid);
         sessionCache.remove(oid);
@@ -436,12 +436,12 @@
     /**
      * Put the specified object to session cache.
      */
-    public void cache(Identity oid, Object obj)
+    public void cache(final Identity oid, final Object obj)
     {
         doInternalCache(oid, obj, TYPE_UNKNOWN);
     }
 
-    public boolean cacheIfNew(Identity oid, Object obj)
+    public boolean cacheIfNew(final Identity oid, final Object obj)
     {
         boolean result = putToApplicationCache(oid, obj, true);
         if(result)
@@ -459,7 +459,7 @@
      * @param entry The {@link org.apache.ojb.broker.cache.ObjectCacheTwoLevelImpl.CacheEntry}
of the object
      * @param onlyIfNew Flag, if set <em>true</em> only new objects (not already
in session cache) be cached.
      */
-    private void putToSessionCache(Identity oid, CacheEntry entry, boolean onlyIfNew)
+    private void putToSessionCache(final Identity oid, final CacheEntry entry, final boolean
onlyIfNew)
     {
         if(onlyIfNew)
         {
@@ -615,7 +615,7 @@
         public Object write(PersistenceBroker broker, Object obj, Object oldObject);
     }
 
-    public static class CopyStrategyImpl implements CopyStrategy
+    public static final class CopyStrategyImpl implements CopyStrategy
     {
         static final String CLASS_NAME_STR = "ojbClassName11";
 
@@ -623,7 +623,7 @@
         {
         }
 
-        public Object read(PersistenceBroker broker, Object obj)
+        public Object read(final PersistenceBroker broker, final Object obj)
         {
             HashMap source = (HashMap) obj;
             String className = (String) source.get(CLASS_NAME_STR);
@@ -649,11 +649,12 @@
             return target;
         }
 
-        public Object write(PersistenceBroker broker, Object obj, Object oldObject)
+        public Object write(final PersistenceBroker broker, final Object obj, Object oldObject)
         {
             ClassDescriptor cld = broker.getClassDescriptor(obj.getClass());
             // we store field values by name in a Map
-            HashMap target = oldObject != null ? (HashMap) oldObject : new HashMap();
+            final boolean old = oldObject != null;
+            HashMap target = old ? (HashMap) oldObject : new HashMap();
             // perform main object values
             FieldDescriptor[] flds = cld.getFieldDescriptor(true);
             FieldDescriptor fld;
@@ -666,14 +667,18 @@
             for(int i = 0; i < length; i++)
             {
                 fld = flds[i];
-                // get the value
-                Object value = fld.getPersistentField().get(obj);
-                // convert value to a supported sql type, because we only
-                // can copy this type
-                value = fld.getFieldConversion().javaToSql(value);
-                // copy the sql type
-                value = fld.getJdbcType().getFieldType().copy(value);
-                target.put(fld.getPersistentField().getName(), value);
+                // if first time put in cache write all fields, else only non-PK
+                if(!old || !fld.isPrimaryKey())
+                {
+                    // get the value
+                    Object value = fld.getPersistentField().get(obj);
+                    // convert value to a supported sql type, because we only
+                    // can copy this type
+                    value = fld.getFieldConversion().javaToSql(value);
+                    // copy the sql type
+                    value = fld.getJdbcType().getFieldType().copy(value);
+                    target.put(fld.getPersistentField().getName(), value);
+                }
             }
             target.put(CLASS_NAME_STR, obj.getClass().getName());
             return target;



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