openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r918167 - /openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
Date Tue, 02 Mar 2010 20:04:42 GMT
Author: curtisr7
Date: Tue Mar  2 20:04:42 2010
New Revision: 918167

URL: http://svn.apache.org/viewvc?rev=918167&view=rev
Log:
OPENJPA-1548: Refactored ClassMetaData and cached hashCode() to improve performance.

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java?rev=918167&r1=918166&r2=918167&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
Tue Mar  2 20:04:42 2010
@@ -152,6 +152,7 @@
     private int _resMode = MODE_NONE;
 
     private Class<?> _type = Object.class;
+    private int _hashCode = Object.class.getName().hashCode();
     private final Map<String,FieldMetaData> _fieldMap = new TreeMap<String,FieldMetaData>();
     private Map<String,FieldMetaData> _supFieldMap = null;
     private boolean _defSupFields = false;
@@ -265,6 +266,7 @@
             (type.getSuperclass().getName()))
             throw new MetaDataException(_loc.get("enum", type));
         _type = type;
+        _hashCode = _type.getName().hashCode();
         if (PersistenceCapable.class.isAssignableFrom(type))
             setIntercepting(true);
     }
@@ -1116,14 +1118,15 @@
      * Return the version field for this class, if any.
      */
     public FieldMetaData getVersionField() {
+        if (_allFields == null) {
+            getFields();
+        }
         if (_versionIdx == Integer.MIN_VALUE) {
-            FieldMetaData[] fields = getFields();
             int idx = -1;
-            for (int i = 0; i < fields.length; i++) {
-                if (fields[i].isVersion()) {
+            for (int i = 0; i < _allFields.length; i++) {
+                if (_allFields[i].isVersion()) {
                     if (idx != -1)
-                        throw new MetaDataException(_loc.get
-                            ("mult-vers-fields", this, fields[idx], fields[i]));
+                        throw new MetaDataException(_loc.get("mult-vers-fields", this, _allFields[idx],
_allFields[i]));
                     idx = i;
                 }
             }
@@ -1131,7 +1134,8 @@
         }
         if (_versionIdx == -1)
             return null;
-        return getFields()[_versionIdx];
+
+        return _allFields[_versionIdx];
     }
 
     /**
@@ -1141,10 +1145,12 @@
      * @return the field's metadata, or null if not found
      */
     public FieldMetaData getField(int index) {
-        FieldMetaData[] fields = getFields();
-        if (index < 0 || index >= fields.length)
+        if(_allFields == null){
+            getFields();
+        }
+        if (index < 0 || index >= _allFields.length)
             return null;
-        return fields[index];
+        return _allFields[index];
     }
 
     /**
@@ -1646,7 +1652,7 @@
     }
 
     public int hashCode() {
-        return _type.getName().hashCode();
+        return _hashCode;
     }
 
     public boolean equals(Object other) {



Mime
View raw message