openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgras...@apache.org
Subject svn commit: r1579042 - in /openjpa/branches/2.2.1.x: openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-persistence/src/main/java/org/apache/openjpa/persistence/
Date Tue, 18 Mar 2014 21:20:23 GMT
Author: jgrassel
Date: Tue Mar 18 21:20:22 2014
New Revision: 1579042

URL: http://svn.apache.org/r1579042
Log:
OPENJPA-1988: OpenJPA does not process persistence unit default <cascade-persist>

Modified:
    openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
    openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java
    openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
    openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaData.java
    openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java
    openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
    openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
    openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java

Modified: openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java?rev=1579042&r1=1579041&r2=1579042&view=diff
==============================================================================
--- openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
(original)
+++ openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
Tue Mar 18 21:20:22 2014
@@ -2188,6 +2188,10 @@ public class FieldMetaData
     public void setCascadePersist(int persist) {
         _val.setCascadePersist(persist);
     }
+    
+    public void setCascadePersist(int cascade, boolean checkPUDefault) {
+        _val.setCascadePersist(cascade, checkPUDefault);
+    }
 
     public int getCascadeAttach() {
         return _val.getCascadeAttach();

Modified: openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java?rev=1579042&r1=1579041&r2=1579042&view=diff
==============================================================================
--- openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java
(original)
+++ openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java
Tue Mar 18 21:20:22 2014
@@ -127,4 +127,11 @@ public interface MetaDataDefaults
      */
     public boolean isNonDefaultMappingAllowed(OpenJPAConfiguration conf);
     
+    /**
+     * Whether cascade-persist was declared in the persistence unit defaults.
+     * @return
+     */
+    public Boolean isDefaultCascadePersistEnabled();
+    
+    public void setDefaultCascadePersistEnabled(Boolean bool);
 }

Modified: openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java?rev=1579042&r1=1579041&r2=1579042&view=diff
==============================================================================
--- openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
(original)
+++ openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
Tue Mar 18 21:20:22 2014
@@ -169,4 +169,12 @@ public class NoneMetaDataFactory
     public boolean isNonDefaultMappingAllowed(OpenJPAConfiguration conf) {
         return false;
     }
+    
+    public Boolean isDefaultCascadePersistEnabled() {
+        return false;
+    }
+    
+    public void setDefaultCascadePersistEnabled(Boolean bool) {
+        
+    }
 }

Modified: openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaData.java?rev=1579042&r1=1579041&r2=1579042&view=diff
==============================================================================
--- openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaData.java
(original)
+++ openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaData.java
Tue Mar 18 21:20:22 2014
@@ -202,6 +202,13 @@ public interface ValueMetaData
      * @see #getCascadePersist
      */
     public void setCascadePersist(int cascade);
+    
+    /**
+     * Cascade behavior for persist operation.
+     *
+     * @see #getCascadePersist
+     */
+    public void setCascadePersist(int cascade, boolean checkPUDefault);
 
     /**
      * Cascade behavior for attach operation. Only applies to

Modified: openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java?rev=1579042&r1=1579041&r2=1579042&view=diff
==============================================================================
--- openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java
(original)
+++ openjpa/branches/2.2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java
Tue Mar 18 21:20:22 2014
@@ -58,6 +58,8 @@ public class ValueMetaDataImpl
     private int _resMode = MODE_NONE;
     private String _mappedBy = null;
     private FieldMetaData _mappedByMeta = null;
+    
+    private boolean _checkPUDefaultCascadePersist = true;
 
     protected ValueMetaDataImpl(FieldMetaData owner) {
         _owner = owner;
@@ -233,6 +235,14 @@ public class ValueMetaDataImpl
     }
 
     public int getCascadePersist() {
+        if (_checkPUDefaultCascadePersist) {
+            Boolean dcpe = getRepository().getMetaDataFactory().getDefaults().isDefaultCascadePersistEnabled();
+            if (dcpe != null && dcpe.equals(Boolean.TRUE)) {
+                _persist = CASCADE_IMMEDIATE;
+            }
+            _checkPUDefaultCascadePersist = false;
+        }
+        
         if (_owner.getManagement() != FieldMetaData.MANAGE_PERSISTENT)
             return CASCADE_NONE;
         if (isDeclaredTypePC())
@@ -244,7 +254,12 @@ public class ValueMetaDataImpl
     }
 
     public void setCascadePersist(int persist) {
+        setCascadePersist(persist, true);
+    }
+    
+    public void setCascadePersist(int persist, boolean checkPUDefault) {
         _persist = persist;
+        _checkPUDefaultCascadePersist = checkPUDefault;
     }
 
     public int getCascadeAttach() {

Modified: openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java?rev=1579042&r1=1579041&r2=1579042&view=diff
==============================================================================
--- openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
(original)
+++ openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
Tue Mar 18 21:20:22 2014
@@ -1765,7 +1765,7 @@ public class AnnotationPersistenceMetaDa
             if (cascade == CascadeType.ALL || cascade == CascadeType.REMOVE)
                 vmd.setCascadeDelete(ValueMetaData.CASCADE_IMMEDIATE);
             if (cascade == CascadeType.ALL || cascade == CascadeType.PERSIST)
-                vmd.setCascadePersist(ValueMetaData.CASCADE_IMMEDIATE);
+                vmd.setCascadePersist(ValueMetaData.CASCADE_IMMEDIATE, false);
             if (cascade == CascadeType.ALL || cascade == CascadeType.MERGE)
                 vmd.setCascadeAttach(ValueMetaData.CASCADE_IMMEDIATE);
             if (cascade == CascadeType.ALL || cascade == CascadeType.DETACH)

Modified: openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java?rev=1579042&r1=1579041&r2=1579042&view=diff
==============================================================================
--- openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
(original)
+++ openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
Tue Mar 18 21:20:22 2014
@@ -134,6 +134,8 @@ public class PersistenceMetaDataDefaults
     private Boolean _isAbstractMappingUniDirectional = null;
     private Boolean _isNonDefaultMappingAllowed = null;
     
+    private Boolean _isCascadePersistPersistenceUnitDefaultEnabled = null;
+    
     public PersistenceMetaDataDefaults() {
         setCallbackMode(CALLBACK_RETHROW | CALLBACK_ROLLBACK |
             CALLBACK_FAIL_FAST);
@@ -945,4 +947,12 @@ public class PersistenceMetaDataDefaults
         _isNonDefaultMappingAllowed = conf.getCompatibilityInstance().
             isNonDefaultMappingAllowed();
     }
+    
+    public Boolean isDefaultCascadePersistEnabled() {
+        return _isCascadePersistPersistenceUnitDefaultEnabled;
+    }
+    
+    public void setDefaultCascadePersistEnabled(Boolean bool) {
+        _isCascadePersistPersistenceUnitDefaultEnabled = bool;
+    }
 }

Modified: openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java?rev=1579042&r1=1579041&r2=1579042&view=diff
==============================================================================
--- openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
(original)
+++ openjpa/branches/2.2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
Tue Mar 18 21:20:22 2014
@@ -62,6 +62,7 @@ import org.apache.openjpa.meta.FieldMeta
 import org.apache.openjpa.meta.JavaTypes;
 import org.apache.openjpa.meta.LifecycleMetaData;
 import org.apache.openjpa.meta.MetaDataContext;
+import org.apache.openjpa.meta.MetaDataDefaults;
 import org.apache.openjpa.meta.MetaDataFactory;
 import org.apache.openjpa.meta.UpdateStrategies;
 
@@ -1325,6 +1326,8 @@ public class XMLPersistenceMetaDataParse
         throws SAXException {
         if (!isMetaDataMode())
             return false;
+        
+        boolean puDefault = false;
 
         Set<CascadeType> cascades = null;
         if (currentElement() instanceof FieldMetaData) {
@@ -1335,10 +1338,17 @@ public class XMLPersistenceMetaDataParse
             if (_pkgCascades == null)
                 _pkgCascades = EnumSet.noneOf(CascadeType.class);
             cascades = _pkgCascades;
+            puDefault = true;
         }
         boolean all = ELEM_CASCADE_ALL == tag;
-        if (all || ELEM_CASCADE_PER == tag)
+        if (all || ELEM_CASCADE_PER == tag) {
             cascades.add(PERSIST);
+            if (puDefault) {
+                MetaDataDefaults mdd = _repos.getMetaDataFactory().getDefaults();
+                mdd.setDefaultCascadePersistEnabled(true);
+            }
+        }
+            
         if (all || ELEM_CASCADE_REM == tag)
             cascades.add(REMOVE);
         if (all || ELEM_CASCADE_MER == tag)
@@ -1367,7 +1377,7 @@ public class XMLPersistenceMetaDataParse
         for (CascadeType cascade : cascades) {
             switch (cascade) {
                 case PERSIST:
-                    vmd.setCascadePersist(ValueMetaData.CASCADE_IMMEDIATE);
+                    vmd.setCascadePersist(ValueMetaData.CASCADE_IMMEDIATE, false);
                     break;
                 case MERGE:
                     vmd.setCascadeAttach(ValueMetaData.CASCADE_IMMEDIATE);



Mime
View raw message