openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r1342767 - in /openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa: kernel/ meta/
Date Fri, 25 May 2012 18:48:21 GMT
Author: curtisr7
Date: Fri May 25 18:48:21 2012
New Revision: 1342767

URL: http://svn.apache.org/viewvc?rev=1342767&view=rev
Log:
OPENJPA-2151: Improve the performance of StateManagerImpl.initialize. Merged from trunk.

Modified:
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ECleanState.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ECopyState.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/EDirtyState.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ENonTransState.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/HollowState.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCState.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCleanState.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PDeletedState.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PDirtyState.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewFlushedDeletedFlushedState.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewProvisionalState.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewState.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNonTransDirtyState.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNonTransNewState.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNonTransState.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/TCleanState.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/TDirtyState.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/TLoadedState.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/TransientState.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ECleanState.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ECleanState.java?rev=1342767&r1=1342766&r2=1342767&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ECleanState.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ECleanState.java
Fri May 25 18:48:21 2012
@@ -30,7 +30,8 @@ package org.apache.openjpa.kernel;
 class ECleanState
     extends PCState {
 
-    void initialize(StateManagerImpl context) {
+    @Override
+    void initialize(StateManagerImpl context, PCState previous) {
         context.setDirty(false);
     }
 

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ECopyState.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ECopyState.java?rev=1342767&r1=1342766&r2=1342767&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ECopyState.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ECopyState.java
Fri May 25 18:48:21 2012
@@ -29,7 +29,8 @@ package org.apache.openjpa.kernel;
 class ECopyState
     extends PCState {
 
-    void initialize(StateManagerImpl context) {
+    @Override
+    void initialize(StateManagerImpl context, PCState previous) {
         // no need to save fields, because this transition doesn't happen
         // until the flush process begins
         context.setLoaded(true);

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/EDirtyState.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/EDirtyState.java?rev=1342767&r1=1342766&r2=1342767&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/EDirtyState.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/EDirtyState.java
Fri May 25 18:48:21 2012
@@ -29,7 +29,8 @@ package org.apache.openjpa.kernel;
 class EDirtyState
     extends PCState {
 
-    void initialize(StateManagerImpl context) {
+    @Override
+    void initialize(StateManagerImpl context, PCState previous) {
         context.saveFields(false);
     }
 

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ENonTransState.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ENonTransState.java?rev=1342767&r1=1342766&r2=1342767&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ENonTransState.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ENonTransState.java
Fri May 25 18:48:21 2012
@@ -30,10 +30,14 @@ package org.apache.openjpa.kernel;
 class ENonTransState
     extends PCState {
 
-    void initialize(StateManagerImpl context) {
+    @Override
+    void initialize(StateManagerImpl context, PCState previous) {
+        if (previous == null)
+            return;
+        
         // spec says all proxies to second class objects should be reset
         context.proxyFields(true, true);
-
+        
         context.setDirty(false);
         context.clearSavedFields();
     }

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/HollowState.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/HollowState.java?rev=1342767&r1=1342766&r2=1342767&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/HollowState.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/HollowState.java
Fri May 25 18:48:21 2012
@@ -32,7 +32,8 @@ package org.apache.openjpa.kernel;
 class HollowState
     extends PCState {
 
-    void initialize(StateManagerImpl context) {
+    @Override
+    void initialize(StateManagerImpl context, PCState previous) {
         context.clearFields();
         context.clearSavedFields();
         context.setDirty(false);

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCState.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCState.java?rev=1342767&r1=1342766&r2=1342767&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCState.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCState.java
Fri May 25 18:48:21 2012
@@ -161,7 +161,7 @@ public class PCState
     /**
      * Called when this state is first assigned to the given state manager.
      */
-    void initialize(StateManagerImpl context) {
+    void initialize(StateManagerImpl context, PCState previousState) {
     }
 
     /**

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCleanState.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCleanState.java?rev=1342767&r1=1342766&r2=1342767&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCleanState.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCleanState.java
Fri May 25 18:48:21 2012
@@ -29,7 +29,11 @@ package org.apache.openjpa.kernel;
 class PCleanState
     extends PCState {
 
-    void initialize(StateManagerImpl context) {
+    @Override
+    void initialize(StateManagerImpl context, PCState previous) {
+        if (previous == null)
+            return;
+
         context.setDirty(false);
     }
 

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PDeletedState.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PDeletedState.java?rev=1342767&r1=1342766&r2=1342767&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PDeletedState.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PDeletedState.java
Fri May 25 18:48:21 2012
@@ -29,7 +29,8 @@ package org.apache.openjpa.kernel;
 class PDeletedState
     extends PCState {
 
-    void initialize(StateManagerImpl context) {
+    @Override
+    void initialize(StateManagerImpl context, PCState previous) {
         context.saveFields(false);
     }
 

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PDirtyState.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PDirtyState.java?rev=1342767&r1=1342766&r2=1342767&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PDirtyState.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PDirtyState.java
Fri May 25 18:48:21 2012
@@ -29,7 +29,8 @@ package org.apache.openjpa.kernel;
 class PDirtyState
     extends PCState {
 
-    void initialize(StateManagerImpl context) {
+    @Override
+    void initialize(StateManagerImpl context, PCState previous) {
         context.saveFields(false);
     }
 

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewFlushedDeletedFlushedState.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewFlushedDeletedFlushedState.java?rev=1342767&r1=1342766&r2=1342767&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewFlushedDeletedFlushedState.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewFlushedDeletedFlushedState.java
Fri May 25 18:48:21 2012
@@ -29,7 +29,8 @@ package org.apache.openjpa.kernel;
 class PNewFlushedDeletedFlushedState
     extends PNewFlushedDeletedState {
 
-    void initialize(StateManagerImpl context) {
+    @Override
+    void initialize(StateManagerImpl context, PCState previous) {
     }
 
     PCState persist(StateManagerImpl context) {

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewProvisionalState.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewProvisionalState.java?rev=1342767&r1=1342766&r2=1342767&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewProvisionalState.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewProvisionalState.java
Fri May 25 18:48:21 2012
@@ -30,7 +30,8 @@ package org.apache.openjpa.kernel;
 class PNewProvisionalState
     extends PCState {
 
-    void initialize(StateManagerImpl context) {
+    @Override
+    void initialize(StateManagerImpl context, PCState previous) {
         context.setLoaded(true);
         context.setDirty(true);
         context.saveFields(false);

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewState.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewState.java?rev=1342767&r1=1342766&r2=1342767&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewState.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewState.java
Fri May 25 18:48:21 2012
@@ -29,7 +29,11 @@ package org.apache.openjpa.kernel;
 class PNewState
     extends PCState {
 
-    void initialize(StateManagerImpl context) {
+    @Override
+    void initialize(StateManagerImpl context, PCState previous) {
+        if (previous == null)
+            return;
+
         context.setLoaded(true);
         context.setDirty(true);
         context.saveFields(false);

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNonTransDirtyState.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNonTransDirtyState.java?rev=1342767&r1=1342766&r2=1342767&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNonTransDirtyState.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNonTransDirtyState.java
Fri May 25 18:48:21 2012
@@ -30,7 +30,8 @@ package org.apache.openjpa.kernel;
 class PNonTransDirtyState
     extends PCState {
 
-    void initialize(StateManagerImpl context) {
+    @Override
+    void initialize(StateManagerImpl context, PCState previous) {
         context.saveFields(false);
     }
 

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNonTransNewState.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNonTransNewState.java?rev=1342767&r1=1342766&r2=1342767&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNonTransNewState.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNonTransNewState.java
Fri May 25 18:48:21 2012
@@ -28,7 +28,8 @@ package org.apache.openjpa.kernel;
 class PNonTransNewState
     extends PCState {
 
-    void initialize(StateManagerImpl context) {
+    @Override
+    void initialize(StateManagerImpl context, PCState previous) {
         context.setLoaded(true);
         context.setDirty(true);
     }

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNonTransState.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNonTransState.java?rev=1342767&r1=1342766&r2=1342767&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNonTransState.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNonTransState.java
Fri May 25 18:48:21 2012
@@ -37,11 +37,16 @@ class PNonTransState
     private static final Localizer _loc = Localizer.forPackage
         (PNonTransState.class);
 
-    void initialize(StateManagerImpl context) {
-        // spec says all proxies to second class objects should be reset
-        context.proxyFields(true, false);
-
-        context.setDirty(false);
+    @Override
+    void initialize(StateManagerImpl context, PCState previous) {
+        if (previous == null)
+         return;
+        // If our previous state is clean, we don't need to do any sort of cleanup
+        if (previous != PCLEAN) {
+            // spec says all proxies to second class objects should be reset
+            context.proxyFields(true, false);
+            context.setDirty(false);
+        }
         context.clearSavedFields();
     }
 

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java?rev=1342767&r1=1342766&r2=1342767&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
Fri May 25 18:48:21 2012
@@ -34,7 +34,6 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Set;
 import java.util.TimeZone;
 import java.util.concurrent.locks.ReentrantLock;
 
@@ -114,7 +113,7 @@ public class StateManagerImpl
 
     // information about the instance
     private transient PersistenceCapable _pc = null;
-    protected transient ClassMetaData _meta = null;
+    private transient ClassMetaData _meta = null;
     protected BitSet _loaded = null;
     private BitSet _dirty = null;
     private BitSet _flush = null;
@@ -170,7 +169,7 @@ public class StateManagerImpl
      */
     protected StateManagerImpl(Object id, ClassMetaData meta, BrokerImpl broker) {
         _id = id;
-        _meta = meta;
+        setMeta(meta);
         _broker = broker;
         _single = new SingleFieldManager(this, broker);
         if (broker.getMultithreaded())
@@ -265,6 +264,7 @@ public class StateManagerImpl
         if (_state == state)
             return;
 
+        PCState prev = _state;
         lock();
         try {
             // notify the store manager that we're changing states; can veto
@@ -274,6 +274,7 @@ public class StateManagerImpl
             boolean wasDeleted = _state.isDeleted();
             boolean wasDirty = _state.isDirty();
             boolean wasPending = _state.isPendingTransactional();
+
             _state = state;
 
             // enlist/delist from transaction
@@ -290,8 +291,7 @@ public class StateManagerImpl
             else
                 _broker.removeFromTransaction(this);
 
-            // initialize
-            _state.initialize(this);
+            _state.initialize(this, prev);
             if (_state.isDeleted() && !wasDeleted)
                 fireLifecycleEvent(LifecycleEvent.AFTER_DELETE);
         } finally {
@@ -323,7 +323,7 @@ public class StateManagerImpl
                     _oid = ApplicationIds.fromPKValues(pkFields, sub);
                 }
             }
-            _meta = sub;
+            setMeta(sub);
         }
 
         PersistenceCapable inst = PCRegistry.newInstance(cls, this, _oid, true);
@@ -356,27 +356,16 @@ public class StateManagerImpl
         _flush = new BitSet(fmds.length);
         _dirty = new BitSet(fmds.length);
 
-        for (int i = 0; i < fmds.length; i++) {
-            // mark primary key and non-persistent fields as loaded
-            if (fmds[i].isPrimaryKey()
-                || fmds[i].getManagement() != fmds[i].MANAGE_PERSISTENT)
-                _loaded.set(i);
-            
-            if (_meta.getIdentityType() == ClassMetaData.ID_APPLICATION) {
-                String mappedByIdValue = fmds[i].getMappedByIdValue(); 
-                if (mappedByIdValue != null) { 
-                    if (!ApplicationIds.isIdSet(_id, _meta, mappedByIdValue)) {
-                        if (_mappedByIdFields == null)
-                            _mappedByIdFields = new ArrayList<FieldMetaData>();
-                        _mappedByIdFields.add(fmds[i]);
-                    }
-                }
-            }
-            // record whether there are any managed inverse fields
-            if (_broker.getInverseManager() != null
-                && fmds[i].getInverseMetaDatas().length > 0)
-                _flags |= FLAG_INVERSES;
+        // mark primary key and non-persistent fields as loaded
+        for(int i : _meta.getPkAndNonPersistentManagedFmdIndexes()){
+            _loaded.set(i);
         }
+            
+        _mappedByIdFields = _meta.getMappyedByIdFields();
+        
+        // record whether there are any managed inverse fields
+        if (_broker.getInverseManager() != null && _meta.hasInverseManagedFields())
+            _flags |= FLAG_INVERSES;
 
         pc.pcSetDetachedState(null);
         _pc = pc;
@@ -413,9 +402,8 @@ public class StateManagerImpl
     public boolean isIntercepting() {
         if (getMetaData().isIntercepting())
             return true;
-        // TODO:JRB Intercepting 
-        if (AccessCode.isProperty(getMetaData().getAccessType())
-            && _pc instanceof DynamicPersistenceCapable)
+        // TODO:JRB Intercepting
+        if (AccessCode.isProperty(getMetaData().getAccessType()) && _pc instanceof
DynamicPersistenceCapable)
             return true;
         return false;
     }
@@ -1598,7 +1586,7 @@ public class StateManagerImpl
             // TODO -- what about version fields? Could probably UT this
             if(_loaded.get(field) && !_meta.getField(field).isPrimaryKey())
                 return;
-            
+                
             beforeRead(field);
             beforeAccessField(field);
         } catch (RuntimeException re) {
@@ -3439,8 +3427,8 @@ public class StateManagerImpl
         // non-null when reconstituting ReflectingPC instances. Sadly, this
         // penalizes the serialization footprint of non-ReflectingPC SMs also.
         Class managedType = (Class) in.readObject();
-        _meta = _broker.getConfiguration().getMetaDataRepositoryInstance()
-            .getMetaData(managedType, null, true);
+        setMeta(_broker.getConfiguration().getMetaDataRepositoryInstance()
+            .getMetaData(managedType, null, true));
 
         _pc = readPC(in);
     }
@@ -3479,8 +3467,13 @@ public class StateManagerImpl
     public void setPc(PersistenceCapable pc) {
         _pc = pc;
     }
+    
+    protected void setMeta(ClassMetaData cmd){
+        _meta = cmd;
+    }
 
     public void setBroker(BrokerImpl ctx) {
         _broker = ctx;
     }
+
 }

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/TCleanState.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/TCleanState.java?rev=1342767&r1=1342766&r2=1342767&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/TCleanState.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/TCleanState.java
Fri May 25 18:48:21 2012
@@ -30,11 +30,15 @@ package org.apache.openjpa.kernel;
 class TCleanState
     extends PCState {
 
-    void initialize(StateManagerImpl context) {
+    @Override
+    void initialize(StateManagerImpl context, PCState previous) {
+        if (previous == null)
+            return;
+        
         // need to replace the second class objects with proxies that
         // listen for dirtying so we can track changes to these objects
         context.proxyFields(true, false);
-
+        
         context.clearSavedFields();
         context.setLoaded(true);
         context.setDirty(false);

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/TDirtyState.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/TDirtyState.java?rev=1342767&r1=1342766&r2=1342767&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/TDirtyState.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/TDirtyState.java
Fri May 25 18:48:21 2012
@@ -29,7 +29,8 @@ package org.apache.openjpa.kernel;
 class TDirtyState
     extends PCState {
 
-    void initialize(StateManagerImpl context) {
+    @Override
+    void initialize(StateManagerImpl context, PCState previous) {
         context.saveFields(false);
         context.setLoaded(true);
         context.setDirty(true);

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/TLoadedState.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/TLoadedState.java?rev=1342767&r1=1342766&r2=1342767&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/TLoadedState.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/TLoadedState.java
Fri May 25 18:48:21 2012
@@ -31,7 +31,8 @@ package org.apache.openjpa.kernel;
 class TLoadedState
     extends PCState {
 
-    void initialize(StateManagerImpl context) {
+    @Override
+    void initialize(StateManagerImpl context, PCState previous) {
         context.setLoaded(true);
     }
 

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/TransientState.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/TransientState.java?rev=1342767&r1=1342766&r2=1342767&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/TransientState.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/TransientState.java
Fri May 25 18:48:21 2012
@@ -30,7 +30,8 @@ package org.apache.openjpa.kernel;
 class TransientState
     extends PCState {
 
-    void initialize(StateManagerImpl context) {
+    @Override
+    void initialize(StateManagerImpl context, PCState previous) {
         // mark r/w ok, remove from management
         context.unproxyFields();
         context.getPersistenceCapable().pcReplaceStateManager(null);

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java?rev=1342767&r1=1342766&r2=1342767&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
Fri May 25 18:48:21 2012
@@ -219,7 +219,11 @@ public class ClassMetaData
     private boolean _abstract = false;
     private Boolean _hasAbstractPKField = null;
     private Boolean _hasPKFieldsFromAbstractClass = null;
-    
+    private int[] _pkAndNonPersistentManagedFmdIndexes = null;
+    private Boolean inverseManagedFields = null;
+    private List<FieldMetaData> _mappedByIdFields;
+    private boolean _mappedByIdFieldsSet = false;
+
     /**
      * Constructor. Supply described type and repository.
      */
@@ -2763,5 +2767,55 @@ public class ClassMetaData
     public String getSourceName(){
         return _srcName; 
     }
-}
+    
+    public int[] getPkAndNonPersistentManagedFmdIndexes() {
+        if (_pkAndNonPersistentManagedFmdIndexes == null) {
+            List<Integer> ids = new ArrayList<Integer>();
+            for (FieldMetaData fmd : getFields()) {
+                if (fmd.isPrimaryKey() || fmd.getManagement() != FieldMetaData.MANAGE_PERSISTENT)
{
+                    ids.add(fmd.getIndex());
+                }
+            }
+            int idsSize = ids.size();
+            _pkAndNonPersistentManagedFmdIndexes = new int[idsSize];
+            for(int i = 0; i<idsSize; i++){
+                _pkAndNonPersistentManagedFmdIndexes[i] = ids.get(i).intValue();
+            }
+        }
+        return _pkAndNonPersistentManagedFmdIndexes;
+    }
 
+    public boolean hasInverseManagedFields() {
+        if (inverseManagedFields == null) {
+            Boolean res = Boolean.FALSE;
+            for (FieldMetaData fmd : getFields()) {
+                if (fmd.getInverseMetaDatas().length > 0) {
+                    res = Boolean.TRUE;
+                    break;
+                }
+            }
+            inverseManagedFields = res;
+        }
+        return inverseManagedFields.booleanValue();
+    }
+    
+    public List<FieldMetaData> getMappyedByIdFields() {
+        if (!_mappedByIdFieldsSet) {
+            List<FieldMetaData> fmdArray = null;
+            for (FieldMetaData fmd : getFields()) {
+                if (getIdentityType() == ClassMetaData.ID_APPLICATION) {
+                    String mappedByIdValue = fmd.getMappedByIdValue();
+                    if (mappedByIdValue != null) {
+                        if (fmdArray == null) {
+                            fmdArray = new ArrayList<FieldMetaData>();
+                        }
+                        fmdArray.add(fmd);
+                    }
+                }
+            }
+            _mappedByIdFields = fmdArray;
+            _mappedByIdFieldsSet = true;
+        }
+        return _mappedByIdFields;
+    }
+}



Mime
View raw message