db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker Identity.java
Date Mon, 10 Oct 2005 00:01:11 GMT
arminw      2005/10/09 17:01:11

  Modified:    src/java/org/apache/ojb/broker/cache Tag: OJB_1_0_RELEASE
                        ObjectCacheDefaultImpl.java
                        ObjectCacheTwoLevelImpl.java
               src/java/org/apache/ojb/broker Tag: OJB_1_0_RELEASE
                        Identity.java
  Log:
  code cleanup
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.24.2.6  +17 -24    db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCacheDefaultImpl.java
  
  Index: ObjectCacheDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCacheDefaultImpl.java,v
  retrieving revision 1.24.2.5
  retrieving revision 1.24.2.6
  diff -u -r1.24.2.5 -r1.24.2.6
  --- ObjectCacheDefaultImpl.java	26 Apr 2005 22:26:26 -0000	1.24.2.5
  +++ ObjectCacheDefaultImpl.java	10 Oct 2005 00:01:11 -0000	1.24.2.6
  @@ -137,8 +137,8 @@
       /**
        * static Map held all cached objects
        */
  -    protected static Map objectTable = new Hashtable();
  -    private static ReferenceQueue queue = new ReferenceQueue();
  +    protected static final Map objectTable = new Hashtable();
  +    private static final ReferenceQueue queue = new ReferenceQueue();
   
       private static long hitCount = 0;
       private static long failCount = 0;
  @@ -166,11 +166,9 @@
       {
           this.broker = broker;
           timeout = prop == null ? timeout : (Long.parseLong(prop.getProperty(TIMEOUT_PROP,
"" + (60 * 15))) * 1000);
  -        useSoftReferences = prop == null ?
  -                false : (Boolean.valueOf((prop.getProperty(SOFT_REFERENCES_PROP, "true")).trim())).booleanValue();
  +        useSoftReferences = prop != null && (Boolean.valueOf((prop.getProperty(SOFT_REFERENCES_PROP,
"true")).trim())).booleanValue();
           cachingKeyType = prop == null ? 0 : (Integer.parseInt(prop.getProperty(CACHING_KEY_TYPE_PROP,
"0")));
  -        useAutoSync = prop == null ?
  -                false : (Boolean.valueOf((prop.getProperty(AUTOSYNC_PROP, "false")).trim())).booleanValue();
  +        useAutoSync = prop != null && (Boolean.valueOf((prop.getProperty(AUTOSYNC_PROP,
"false")).trim())).booleanValue();
           if(useAutoSync)
           {
               if(broker != null)
  @@ -200,20 +198,20 @@
        */
       public void clear()
       {
  -        processQueue();
  +        //processQueue();
           objectTable.clear();
           identitiesInWork.clear();
       }
   
       public void doInternalCache(Identity oid, Object obj, int type)
       {
  -        processQueue();
  +        //processQueue();
           if((obj != null))
           {
  +            traceIdentity(oid);
               synchronized(objectTable)
               {
                   if(log.isDebugEnabled()) log.debug("Cache object " + oid);
  -                traceIdentity(oid);
                   objectTable.put(buildKey(oid), buildEntry(obj, oid));
               }
           }
  @@ -231,7 +229,7 @@
   
       public boolean cacheIfNew(Identity oid, Object obj)
       {
  -        processQueue();
  +        //processQueue();
           boolean result = false;
           Object key = buildKey(oid);
           if((obj != null))
  @@ -240,11 +238,11 @@
               {
                   if(!objectTable.containsKey(key))
                   {
  -                    traceIdentity(oid);
                       objectTable.put(key, buildEntry(obj, oid));
                       result = true;
                   }
               }
  +            if(result) traceIdentity(oid);
           }
           return result;
       }
  @@ -296,7 +294,7 @@
        */
       public void remove(Identity oid)
       {
  -        processQueue();
  +        //processQueue();
           if(oid != null)
           {
               removeTracedIdentity(oid);
  @@ -315,11 +313,6 @@
           return buf.toString();
       }
   
  -    protected void finalize()
  -    {
  -        log.debug("Finalize ObjectCache: " + this.toString());
  -    }
  -
       private void traceIdentity(Identity oid)
       {
           if(useAutoSync && (broker != null) && broker.isInTransaction())
  @@ -394,11 +387,11 @@
       {
           if(useSoftReferences)
           {
  -            return new CacheEntrySoft(obj, oid, queue);
  +            return new CacheEntrySoft(obj, oid, queue, timeout);
           }
           else
           {
  -            return new CacheEntryHard(obj, oid);
  +            return new CacheEntryHard(obj, oid, timeout);
           }
       }
   
  @@ -562,12 +555,12 @@
           long getLifetime();
       }
   
  -    class CacheEntrySoft extends SoftReference implements CacheEntry
  +    final static class CacheEntrySoft extends SoftReference implements CacheEntry
       {
           private final long lifetime;
           private final Identity oid;
   
  -        CacheEntrySoft(Object object, final Identity k, final ReferenceQueue q)
  +        CacheEntrySoft(Object object, final Identity k, final ReferenceQueue q, long timeout)
           {
               super(object, q);
               oid = k;
  @@ -593,13 +586,13 @@
           }
       }
   
  -    class CacheEntryHard implements CacheEntry
  +    final static class CacheEntryHard implements CacheEntry
       {
           private final long lifetime;
           private final Identity oid;
           private Object obj;
   
  -        CacheEntryHard(Object object, final Identity k)
  +        CacheEntryHard(Object object, final Identity k, long timeout)
           {
               obj = object;
               oid = k;
  
  
  
  1.1.2.13  +7 -5      db-ojb/src/java/org/apache/ojb/broker/cache/Attic/ObjectCacheTwoLevelImpl.java
  
  Index: ObjectCacheTwoLevelImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/Attic/ObjectCacheTwoLevelImpl.java,v
  retrieving revision 1.1.2.12
  retrieving revision 1.1.2.13
  diff -u -r1.1.2.12 -r1.1.2.13
  --- ObjectCacheTwoLevelImpl.java	8 Oct 2005 15:28:28 -0000	1.1.2.12
  +++ ObjectCacheTwoLevelImpl.java	10 Oct 2005 00:01:11 -0000	1.1.2.13
  @@ -622,13 +622,14 @@
               // perform main object values
               FieldDescriptor[] flds = cld.getFieldDescriptor(true);
               FieldDescriptor fld;
  -            for(int i = 0; i < flds.length; i++)
  +            int length = flds.length;
  +            for(int i = 0; i < length; i++)
               {
                   fld = flds[i];
                   // read the field value
                   Object value = source.get(fld.getPersistentField().getName());
                   // copy the field value
  -                value = fld.getJdbcType().getFieldType().copy(value);
  +                if(value != null) value = fld.getJdbcType().getFieldType().copy(value);
                   // now make a field-conversion to java-type, because we only
                   // the sql type of the field
                   value = fld.getFieldConversion().sqlToJava(value);
  @@ -646,7 +647,8 @@
               // perform main object values
               FieldDescriptor[] flds = cld.getFieldDescriptor(true);
               FieldDescriptor fld;
  -            for(int i = 0; i < flds.length; i++)
  +            int length = flds.length;
  +            for(int i = 0; i < length; i++)
               {
                   fld = flds[i];
                   // get the value
  @@ -655,7 +657,7 @@
                   value = fld.getFieldConversion().javaToSql(value);
                   // copy the sql type
                   value = fld.getJdbcType().getFieldType().copy(value);
  -                target.put(fld.getPersistentField().getName(), value);
  +                if(value != null) target.put(fld.getPersistentField().getName(), value);
               }
               target.put(CLASS_NAME_STR, obj.getClass().getName());
               return target;
  
  
  
  No                   revision
  No                   revision
  1.36.2.11 +2 -2      db-ojb/src/java/org/apache/ojb/broker/Identity.java
  
  Index: Identity.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/Identity.java,v
  retrieving revision 1.36.2.10
  retrieving revision 1.36.2.11
  diff -u -r1.36.2.10 -r1.36.2.11
  --- Identity.java	5 Sep 2005 23:38:32 -0000	1.36.2.10
  +++ Identity.java	10 Oct 2005 00:01:11 -0000	1.36.2.11
  @@ -377,7 +377,7 @@
                       iTotal = iTotal * iConstant + (obj != null ? obj.hashCode() : 0);
           }
               }
  -            iTotal = iTotal * iConstant + getObjectsTopLevelClass().hashCode();
  +            iTotal = iTotal * iConstant + m_objectsTopLevelClass.hashCode();
               m_hashCode = new Integer(iTotal);
           }
           return m_hashCode.intValue();
  
  
  

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