openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r918245 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/
Date Tue, 02 Mar 2010 23:09:14 GMT
Author: curtisr7
Date: Tue Mar  2 23:09:13 2010
New Revision: 918245

URL: http://svn.apache.org/viewvc?rev=918245&view=rev
Log:
OPENJPA-1549: Optimize StateManagerImpl.proxyFields(..).

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestClassMetaData.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java?rev=918245&r1=918244&r2=918245&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
Tue Mar  2 23:09:13 2010
@@ -2890,13 +2890,15 @@
 
         lock();
         try {
-            for (int i = 0, len = _loaded.length(); i < len; i++) {
-                if (_loaded.get(i)) {
-                    provideField(_pc, _single, i);
-                    if (_single.proxy(reset, replaceNull))
-                        replaceField(_pc, _single, i);
-                    else
+            for (FieldMetaData fmd : _meta.getProxyFields()) {
+                int index = fmd.getIndex();
+                if (_loaded.get(index)) {
+                    provideField(_pc, _single, index);
+                    if (_single.proxy(reset, replaceNull)) {
+                        replaceField(_pc, _single, index);
+                    } else {
                         _single.clear();
+                    }
                 }
             }
         } finally {

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=918245&r1=918244&r2=918245&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 23:09:13 2010
@@ -23,11 +23,14 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.security.AccessController;
+import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Calendar;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -64,6 +67,7 @@
 import org.apache.openjpa.util.MetaDataException;
 import org.apache.openjpa.util.ObjectId;
 import org.apache.openjpa.util.OpenJPAId;
+import org.apache.openjpa.util.Proxy;
 import org.apache.openjpa.util.ShortId;
 import org.apache.openjpa.util.StringId;
 import org.apache.openjpa.util.UnsupportedException;
@@ -207,6 +211,7 @@
     private FieldMetaData[] _definedFields = null;
     private FieldMetaData[] _listingFields = null;
     private FieldMetaData[] _allListingFields = null;
+    private FieldMetaData[] _allProxyFields = null;
     private FetchGroup[] _fgs = null;
     private FetchGroup[] _customFGs = null;
     private boolean _intercepting = false;
@@ -977,6 +982,39 @@
     }
 
     /**
+     * Return all fields that are types that need to be wrappered by a proxy.
+     * The types that need to be proxied are:
+     * <p>
+     *  <li>org.apache.openjpa.meta.JavaTypes.CALENDAR
+     *  <li>org.apache.openjpa.meta.JavaTypes.COLLECTION
+     *  <li>org.apache.openjpa.meta.JavaTypes.DATE
+     *  <li>org.apache.openjpa.meta.JavaTypes.MAP
+     *  <li>org.apache.openjpa.meta.JavaTypes.OBJECT
+     */
+    public FieldMetaData[] getProxyFields() {
+        if (_allProxyFields == null) {
+            // Make sure _allFields has been initialized
+            if (_allFields == null) {
+                getFields();
+            }
+            List<FieldMetaData> res = new ArrayList<FieldMetaData>();
+            for (FieldMetaData fmd : _allFields) {
+                switch (fmd.getDeclaredTypeCode()) {
+                    case JavaTypes.CALENDAR:
+                    case JavaTypes.COLLECTION:
+                    case JavaTypes.DATE:
+                    case JavaTypes.MAP:
+                    case JavaTypes.OBJECT:
+                        res.add(fmd);
+                        break;
+                }
+            }
+            _allProxyFields = res.toArray(new FieldMetaData[res.size()]);
+        }
+        return _allProxyFields;
+    }
+    
+    /**
      * Return all field metadata, including superclass fields.
      */
     public FieldMetaData[] getFields() {
@@ -1603,6 +1641,7 @@
         _allFields = null;
         _allDFGFields = null;
         _allPKFields = null;
+        _allProxyFields = null;
         _definedFields = null;
         _listingFields = null;
         _allListingFields = null;

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestClassMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestClassMetaData.java?rev=918245&r1=918244&r2=918245&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestClassMetaData.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestClassMetaData.java
Tue Mar  2 23:09:13 2010
@@ -88,6 +88,17 @@
         assertTrue(_metaTest1.getRequiresExtent());
     }
 
+    public void testGetProxyFields(){
+        FieldMetaData[] proxies = _metaTest3.getProxyFields();
+        assertEquals(2, proxies.length);
+        
+        proxies = _metaTest1.getProxyFields();
+        assertEquals(2, proxies.length);
+        
+        proxies = _metaTest5.getProxyFields();
+        assertEquals(0, proxies.length);
+
+    }
     /**
      * Test non-persistent fields.
      */



Mime
View raw message