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 Fri, 07 Oct 2005 14:54:49 GMT
arminw      2005/10/07 07:54:49

  Modified:    src/java/org/apache/ojb/broker/cache
                        CachingStrategyTwoLevelImpl.java
                        ObjectCacheDefaultImpl.java
               src/java/org/apache/ojb/broker/metadata ClassDescriptor.java
               src/java/org/apache/ojb/broker/util/logging
                        LoggerFactoryImpl.java
               src/java/org/apache/ojb/broker/util BrokerHelper.java
               src/java/org/apache/ojb/broker Identity.java
  Log:
  code optimization
  
  Revision  Changes    Path
  1.5       +11 -7     db-ojb/src/java/org/apache/ojb/broker/cache/CachingStrategyTwoLevelImpl.java
  
  Index: CachingStrategyTwoLevelImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/CachingStrategyTwoLevelImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CachingStrategyTwoLevelImpl.java	30 Sep 2005 21:45:15 -0000	1.4
  +++ CachingStrategyTwoLevelImpl.java	7 Oct 2005 14:54:48 -0000	1.5
  @@ -127,16 +127,19 @@
           // perform main object values
           FieldDescriptor[] flds = cld.getFieldDescriptor(true);
           FieldDescriptor fld;
  -        for(int i = 0; i < flds.length; i++)
  +        Object source = entry.getObject();
  +        int length = flds.length;
  +        for(int i = 0; i < length; i++)
           {
               fld = flds[i];
               // get the value
  -            Object value = fld.getPersistentField().get(entry.getObject());
  +            Object value = fld.getPersistentField().get(source);
               // convert value to a supported sql type
               value = fld.getFieldConversion().javaToSql(value);
               // copy the sql type
               value = fld.getJdbcType().getFieldType().copy(value);
  -            target.put(fld.getPersistentField().getName(), value);
  +            // only need to cache non-null values
  +            if(value != null) target.put(fld.getPersistentField().getName(), value);
           }
           target.put(CLASS_NAME_STR, entry.getObject().getClass().getName());
           return new ObjectEntryImpl(target);
  @@ -181,14 +184,15 @@
       {
           Object[] result = new Object[fields.length];
   
  -        for (int idx = 0; idx < fields.length; idx++)
  +        int length = fields.length;
  +        for (int idx = 0; idx < length; idx++)
           {
               FieldDescriptor field = fields[idx];
   
               // read the field value
               Object value = source.get(field.getPersistentField().getName());
               // copy the field value
  -            value = field.getJdbcType().getFieldType().copy(value);
  +            if(value != null) value = field.getJdbcType().getFieldType().copy(value);
               // now make a field-conversion to java-type, because we only
               // the sql type of the field
               result[idx] = field.getFieldConversion().sqlToJava(value);
  @@ -224,7 +228,7 @@
   
       static final class ObjectEntryImpl implements ObjectEntry
       {
  -        Object obj;
  +        final Object obj;
   
           public ObjectEntryImpl(Object obj)
           {
  
  
  
  1.32      +10 -10    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.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- ObjectCacheDefaultImpl.java	25 Sep 2005 01:45:06 -0000	1.31
  +++ ObjectCacheDefaultImpl.java	7 Oct 2005 14:54:48 -0000	1.32
  @@ -149,13 +149,13 @@
        */
       public void clear()
       {
  -        processQueue();
           objectTable.clear();
       }
   
       public boolean cacheIfNew(Identity oid, Object obj)
       {
           boolean result = false;
  +        // perform queue before check for key in objectTable
           processQueue();
           synchronized(dummy)
           {
  @@ -176,7 +176,7 @@
        */
       public void cache(Identity oid, Object obj)
       {
  -        processQueue();
  +        //processQueue();
           if ((obj != null))
           {
               CacheEntry entry = buildEntry(obj, oid);
  @@ -218,7 +218,7 @@
        */
       public void remove(Identity oid)
       {
  -        processQueue();
  +        //processQueue();
           if (oid != null)
           {
               synchronized (dummy)
  @@ -247,11 +247,11 @@
       {
           if(useSoftReferences)
           {
  -            return new CacheEntrySoft(obj, oid, queue);
  +            return new CacheEntrySoft(obj, oid, timeout, queue);
           }
           else
           {
  -            return new CacheEntryHard(obj, oid);
  +            return new CacheEntryHard(obj, oid, timeout);
           }
       }
   
  @@ -277,12 +277,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;
   
  -        public CacheEntrySoft(Object object, final Identity k, final ReferenceQueue q)
  +        public CacheEntrySoft(Object object, final Identity k, long timeout, final ReferenceQueue
q)
           {
               super(object, q);
               oid = k;
  @@ -318,13 +318,13 @@
           }
       }
   
  -    class CacheEntryHard implements CacheEntry
  +    final static class CacheEntryHard implements CacheEntry
       {
           private final long lifetime;
           private final Identity oid;
           private Object obj;
   
  -        public CacheEntryHard(Object object, final Identity k)
  +        public CacheEntryHard(Object object, final Identity k, long timeout)
           {
               obj = object;
               oid = k;
  
  
  
  1.115     +36 -23    db-ojb/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java
  
  Index: ClassDescriptor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java,v
  retrieving revision 1.114
  retrieving revision 1.115
  diff -u -r1.114 -r1.115
  --- ClassDescriptor.java	3 Oct 2005 19:23:25 -0000	1.114
  +++ ClassDescriptor.java	7 Oct 2005 14:54:48 -0000	1.115
  @@ -61,13 +61,16 @@
   public final class ClassDescriptor extends DescriptorBase
       implements Serializable, XmlCapable
   {
  -    private String persistentFieldClassName;
  -
  -    private static final long serialVersionUID = -5212253607374173965L;
  +	private static final long serialVersionUID = -5212253607374173965L;
   
       public static final String DYNAMIC_STR = "dynamic";
       public static final String OJB_CONCRETE_CLASS = "ojbConcreteClass";
       private static final Class[] NO_PARAMS = {};
  +    private static final FieldDescriptor[] EMPTY_FIELDDESCRIPTOR = {};
  +
  +    private boolean useObjectFactory;
  +
  +    private String persistentFieldClassName;
   
       //---------------------------------------------------------------
       /**
  @@ -139,7 +142,7 @@
        */
       private String m_TableName = null;
   //    private Vector superPersistentFieldDescriptors = null;
  -    /** The class name of the row reader specifically configured for this class */ 
  +    /** The class name of the row reader specifically configured for this class */
       private String rowReaderClassName = null;
       /**
        * the class that this class extends
  @@ -447,8 +450,8 @@
       {
           ObjectReferenceDescriptor ord = (ObjectReferenceDescriptor)
               getObjectReferenceDescriptorsNameMap().get(name);
  -        
  -        // 
  +
  +        //
           // BRJ: if the ReferenceDescriptor is not found
           // look in the ClassDescriptor referenced by 'super' for it
           //
  @@ -483,7 +486,7 @@
   
       /**
        * Returns the reference to the enclosing persistent class if any.
  -     * 
  +     *
        * @return The reference or <code>null</code> if there is no such reference
        */
       public EnclosingClassReferenceDescriptor getEnclosingClassReferenceDescriptor()
  @@ -496,7 +499,7 @@
               }
           });
       }
  -    
  +
       /**
        * Get an CollectionDescriptor by name  BRJ
        * @param name
  @@ -511,7 +514,7 @@
   
           CollectionDescriptor cod  = (CollectionDescriptor) getCollectionDescriptorNameMap().get(name);
   
  -        // 
  +        //
           // BRJ: if the CollectionDescriptor is not found
           // look in the ClassDescriptor referenced by 'super' for it
           //
  @@ -541,7 +544,7 @@
               }
               m_collectionDescriptorNameMap = nameMap;
           }
  -        
  +
           return m_collectionDescriptorNameMap;
       }
   
  @@ -690,7 +693,7 @@
           }
           return proxyClass;
       }
  -    
  +
       public boolean isDynamicProxy()
       {
           return DYNAMIC_STR.equalsIgnoreCase(proxyClassName);
  @@ -968,7 +971,7 @@
       /**
        * Returns the fields used as arguments for creating instances for this
        * class descriptor.
  -     * 
  +     *
        * @return The fields
        */
       public FieldDescriptor[] getCreationArgumentFields()
  @@ -976,11 +979,11 @@
           if (getCreationDescriptor().hasFieldParameters())
           {
               ArrayList result = new ArrayList();
  -    
  +
               for (Iterator it = getCreationDescriptor().getParameters().iterator(); it.hasNext();)
               {
                   CreationParameter param = (CreationParameter)it.next();
  -    
  +
                   if (!param.isConstantValue())
                   {
                       result.add(getFieldDescriptorByName(param.getFieldName()));
  @@ -990,7 +993,7 @@
           }
           else
           {
  -            return new FieldDescriptor[0];
  +            return EMPTY_FIELDDESCRIPTOR;
           }
       }
   
  @@ -1012,7 +1015,7 @@
               for (Iterator it = getCreationDescriptor().getParameters().iterator(); it.hasNext();)
               {
                   CreationParameter param = (CreationParameter)it.next();
  -    
  +
                   if (!param.isConstantValue())
                   {
                       result.remove(getFieldDescriptorByName(param.getFieldName()));
  @@ -1182,9 +1185,9 @@
               if (processedSegment.length() > 0)
               {
                   processedSegment.append(".");
  -            }           
  -            processedSegment.append(segment); 
  -            
  +            }
  +            processedSegment.append(segment);
  +
               // look for 1:1 or n:1 Relationship
               ord = cld.getObjectReferenceDescriptorByName(segment);
               if (ord == null)
  @@ -1196,7 +1199,7 @@
               if (ord != null)
               {
                   // BRJ : look for hints for the processed segment
  -                // ie: ref pointng to ClassA and ref.ref pointing to ClassC 
  +                // ie: ref pointng to ClassA and ref.ref pointing to ClassC
                   List hintClasses = (List) pathHints.get(processedSegment.toString());
                   if (hintClasses != null && hintClasses.get(0) != null)
                   {
  @@ -1519,7 +1522,7 @@
   
       /**
        * Returns the creation descriptor for this class.
  -     * 
  +     *
        * @return The creation descriptor
        */
       public synchronized CreationDescriptor getCreationDescriptor()
  @@ -1533,7 +1536,7 @@
   
       /**
        * Sets the creation descriptor for this class.
  -     * 
  +     *
        * @param creationDescriptor The creation descriptor
        */
       public synchronized void setCreationDescriptor(CreationDescriptor creationDescriptor)
  @@ -1541,6 +1544,16 @@
           this.creationDescriptor = creationDescriptor;
       }
   
  +	public boolean useObjectFactory()
  +	{
  +		return useObjectFactory;
  +	}
  +
  +	public void setUseObjectFactory(boolean value)
  +	{
  +		this.useObjectFactory = value;
  +	}
  +
       //---------------------------------------------------------------
       /**
        * Change the descriptor for the insert procedure/function.
  @@ -2117,4 +2130,4 @@
           return getIsolationLevel().getName();
       }
   
  -}
  +}
  \ No newline at end of file
  
  
  
  1.22      +25 -28    db-ojb/src/java/org/apache/ojb/broker/util/logging/LoggerFactoryImpl.java
  
  Index: LoggerFactoryImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/logging/LoggerFactoryImpl.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- LoggerFactoryImpl.java	18 Dec 2004 13:42:52 -0000	1.21
  +++ LoggerFactoryImpl.java	7 Oct 2005 14:54:48 -0000	1.22
  @@ -122,36 +122,33 @@
        */
       public Logger getLogger(String loggerName)
       {
  +        Logger logger;
           //lookup in the cache first
  -        if (cache.containsKey(loggerName))
  -        {
  -            //getBootLogger().debug("Returning cached version of Logger[" + loggerName
+ "]");
  -            return (Logger) cache.get(loggerName);
  -        }
  -        //getBootLogger().debug("Logger[" + loggerName + "] not cached");
  -
  -        Logger logger      = null;
  -        Class  loggerClass = null;
  +        logger = (Logger) cache.get(loggerName);
   
  -        try
  +        if(logger == null)
           {
  -            // get the configuration (not from the configurator because this is independent)
  -            LoggingConfiguration conf = getConfiguration();
  +            Class  loggerClass = null;
  +            try
  +            {
  +                // get the configuration (not from the configurator because this is independent)
  +                LoggingConfiguration conf = getConfiguration();
   
  -            loggerClass = conf.getLoggerClass();
  -            getBootLogger().debug("Using logger class " + loggerClass + " for " + loggerName);
  -            logger = (Logger) ClassHelper.newInstance(loggerClass,
  -                                                      new Class[] { String.class, LoggingConfiguration.class
},
  -                                                      new Object[] { loggerName, conf });
  +                loggerClass = conf.getLoggerClass();
  +                getBootLogger().debug("Using logger class " + loggerClass + " for " + loggerName);
  +                logger = (Logger) ClassHelper.newInstance(loggerClass,
  +                                                          new Class[] { String.class, LoggingConfiguration.class
},
  +                                                          new Object[] { loggerName, conf
});
   
  -            //cache it so we can get it faster the next time
  -            cache.put(loggerName, logger);
  -        }
  -        catch (Throwable t)
  -        {
  -            logger = getBootLogger();
  -            logger.error("[" + this.getClass().getName()
  -                    + "] Could not set logger for class " + (loggerClass != null ? loggerClass.getName()
: "'null'"), t);
  +                //cache it so we can get it faster the next time
  +                cache.put(loggerName, logger);
  +            }
  +            catch (Throwable t)
  +            {
  +                logger = getBootLogger();
  +                logger.error("[" + this.getClass().getName()
  +                        + "] Could not set logger for class " + (loggerClass != null ?
loggerClass.getName() : "'null'"), t);
  +            }
           }
           return logger;
       }
  
  
  
  1.85      +4 -3      db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java
  
  Index: BrokerHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java,v
  retrieving revision 1.84
  retrieving revision 1.85
  diff -u -r1.84 -r1.85
  --- BrokerHelper.java	1 Oct 2005 13:48:50 -0000	1.84
  +++ BrokerHelper.java	7 Oct 2005 14:54:49 -0000	1.85
  @@ -474,8 +474,9 @@
        */
       public Object[] extractValueArray(ValueContainer[] containers)
       {
  -        Object[] result = new Object[containers.length];
  -        for(int i = 0; i < containers.length; i++)
  +        int length = containers.length;
  +        Object[] result = new Object[length];
  +        for(int i = 0; i < length; i++)
           {
               result[i] = containers[i].getValue();
           }
  
  
  
  1.46      +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.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- Identity.java	30 Sep 2005 21:45:14 -0000	1.45
  +++ Identity.java	7 Oct 2005 14:54:49 -0000	1.46
  @@ -399,7 +399,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