openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r813605 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/conf/ openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-persistence/src/main/java/org/apache/openjpa/persistence/
Date Thu, 10 Sep 2009 21:50:08 GMT
Author: faywang
Date: Thu Sep 10 21:50:08 2009
New Revision: 813605

URL: http://svn.apache.org/viewvc?rev=813605&view=rev
Log:
OPENJPA-1286: use Compatibility to check if the relationship defined in the MappedSuperclass
must be uni-directional.

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java?rev=813605&r1=813604&r2=813605&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java
Thu Sep 10 21:50:08 2009
@@ -62,6 +62,7 @@
     private boolean _privatePersistentProperties = false;
     private boolean _autoOff = true;
     private boolean _superclassDiscriminatorStrategyByDefault = true;
+    private boolean _isAbstractMappingUniDirectional = true;
     
     /**
      * Whether to require exact identity value types when creating object
@@ -418,6 +419,36 @@
      */
     public void setPrivatePersistentProperties(boolean privateProps) {
         _privatePersistentProperties = privateProps;
-    }    
+    }
+    
+    /**
+     * Whether OpenJPA allows bi-directional relationship in the MappedSuperclass.
+     * Prior to OpenJPA 2.0, the bi-directional relationship in the MappedSuperclass,
+     * is not blocked. This is contrary to the JPA specification, which states that 
+     * Persistent relationships defined by a mapped superclass must be
+     * unidirectional.
+     * 
+     * @param isAbstractMappingUniDirectional true if relationship defined in the 
+     *        MappedSuperclass must be uni-directional
+     * @since 2.0.0
+     */
+    public void setAbstractMappingUniDirectional(boolean isAbstractMappingUniDirectional)
{
+        _isAbstractMappingUniDirectional = isAbstractMappingUniDirectional;
+    }
+
+    
+    /**
+     * Whether OpenJPA allows bi-directional relationship in the MappedSuperclass.
+     * Prior to OpenJPA 2.0, the bi-directional relationship in the MappedSuperclass,
+     * is not blocked. This is contrary to the JPA specification, which states that 
+     * Persistent relationships defined by a mapped superclass must be
+     * unidirectional. The default value is true.
+     * 
+     * @since 2.0.0
+     */
+    public boolean isAbstractMappingUniDirectional() {
+        return _isAbstractMappingUniDirectional;
+    }
+
 }
 

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java?rev=813605&r1=813604&r2=813605&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
Thu Sep 10 21:50:08 2009
@@ -48,7 +48,6 @@
 import org.apache.commons.collections.comparators.ComparatorChain;
 import org.apache.commons.lang.StringUtils;
 import org.apache.openjpa.conf.OpenJPAConfiguration;
-import org.apache.openjpa.conf.Specification;
 import org.apache.openjpa.kernel.OpenJPAStateManager;
 import org.apache.openjpa.kernel.StoreContext;
 import org.apache.openjpa.lib.conf.Configurations;
@@ -859,18 +858,17 @@
             if (field.getMappedBy() != null)
                 throw new MetaDataException(_loc.get("circ-mapped-by", this,
                     _mappedBy));
-            Specification spec = getRepository().getConfiguration().getSpecificationInstance();
-            if (spec != null) {
-                int specVersion = spec.getVersion();
-                if (specVersion >= 2) {
-                    if (field.getDeclaringMetaData().isAbstract())
-                        throw new MetaDataException(_loc.get("no-mapped-by-in-mapped-super",
field,
-                                field.getDeclaringMetaData()));
-
-                    if (this.getDeclaringMetaData().isAbstract())
-                        throw new MetaDataException(_loc.get("no-mapped-by-in-mapped-super",
this,
-                                this.getDeclaringMetaData()));
-                }            
+            OpenJPAConfiguration conf = getRepository().getConfiguration();
+            boolean isAbstractMappingUniDirectional = getRepository().getMetaDataFactory().
+                    getDefaults().isAbstractMappingUniDirectional(conf);
+            if (isAbstractMappingUniDirectional) {
+                if (field.getDeclaringMetaData().isAbstract())
+                    throw new MetaDataException(_loc.get("no-mapped-by-in-mapped-super",
field,
+                            field.getDeclaringMetaData()));
+
+                if (this.getDeclaringMetaData().isAbstract())
+                    throw new MetaDataException(_loc.get("no-mapped-by-in-mapped-super",
this,
+                            this.getDeclaringMetaData()));
             }
             _mappedByMeta = field;
         }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java?rev=813605&r1=813604&r2=813605&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java
Thu Sep 10 21:50:08 2009
@@ -20,6 +20,7 @@
 
 import java.lang.reflect.Member;
 
+import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.event.CallbackModes;
 
 /**
@@ -105,4 +106,12 @@
      * managed interface methods.
      */
     public Class getUnimplementedExceptionType();
+    
+    /**
+     * Whether the relationship in MappedSuper class must be
+     * uni-directional.  
+     * @return 2.0.0
+     */
+    public boolean isAbstractMappingUniDirectional(OpenJPAConfiguration conf);
+
 }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java?rev=813605&r1=813604&r2=813605&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
Thu Sep 10 21:50:08 2009
@@ -24,6 +24,7 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.lib.meta.ClassArgParser;
 
 /**
@@ -157,4 +158,8 @@
     public Class<?> getManagedClass(Class<?> c) {
         return null;
     }
+
+    public boolean isAbstractMappingUniDirectional(OpenJPAConfiguration conf) {
+        return true;
+    }
 }

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java?rev=813605&r1=813604&r2=813605&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
Thu Sep 10 21:50:08 2009
@@ -131,7 +131,8 @@
     protected AnnotatedFilter annotatedFilter = new AnnotatedFilter();
     protected GetterFilter getterFilter = new GetterFilter();
     protected SetterFilter setterFilter = new SetterFilter();
-
+    private Boolean _isAbstractMappingUniDirectional = null;
+    
     public PersistenceMetaDataDefaults() {
         setCallbackMode(CALLBACK_RETHROW | CALLBACK_ROLLBACK |
             CALLBACK_FAIL_FAST);
@@ -861,4 +862,14 @@
     String toMethodNames(List<Method> methods) {
     	return methods.toString();
     }
+    
+    public boolean isAbstractMappingUniDirectional(OpenJPAConfiguration conf) {
+        if (_isAbstractMappingUniDirectional == null)
+            setAbstractMappingUniDirectional(conf);
+        return _isAbstractMappingUniDirectional;
+    }
+    
+    public void setAbstractMappingUniDirectional(OpenJPAConfiguration conf) {
+        _isAbstractMappingUniDirectional = conf.getCompatibilityInstance().isAbstractMappingUniDirectional();
+    }
 }

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java?rev=813605&r1=813604&r2=813605&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
Thu Sep 10 21:50:08 2009
@@ -35,9 +35,9 @@
 import java.util.MissingResourceException;
 import java.util.Set;
 
-import javax.persistence.spi.ValidationMode;
 import javax.persistence.spi.PersistenceUnitInfo;
 import javax.persistence.spi.PersistenceUnitTransactionType;
+import javax.persistence.spi.ValidationMode;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.openjpa.conf.Compatibility;
@@ -45,7 +45,6 @@
 import org.apache.openjpa.conf.OpenJPAConfigurationImpl;
 import org.apache.openjpa.conf.OpenJPAProductDerivation;
 import org.apache.openjpa.conf.Specification;
-import org.apache.openjpa.event.LifecycleEventManager;
 import org.apache.openjpa.kernel.MixedLockLevels;
 import org.apache.openjpa.lib.conf.AbstractProductDerivation;
 import org.apache.openjpa.lib.conf.Configuration;
@@ -58,10 +57,6 @@
 import org.apache.openjpa.lib.meta.XMLVersionParser;
 import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
-import org.apache.openjpa.persistence.validation.ValidatorImpl;
-import org.apache.openjpa.validation.Validator;
-import org.apache.openjpa.validation.ValidationException;
-import org.apache.openjpa.validation.ValidatingLifecycleEventManager;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 
@@ -187,6 +182,7 @@
             compatibility.setFlushBeforeDetach(true);
             compatibility.setCopyOnDetach(true);
             compatibility.setPrivatePersistentProperties(true);
+            compatibility.setAbstractMappingUniDirectional(false);
             // Disable bean validation for spec level < 2 configurations
             conf.validationMode.set(String.valueOf(ValidationMode.NONE));
         } 



Mime
View raw message