openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r752557 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/conf/ openjpa-kernel/src/main/resources/org/apache/openjpa/conf/ openjpa-kernel/src/test/java/org/apache/openjpa/conf/ openjpa-persistence-jdbc/src/test/java/org/a...
Date Wed, 11 Mar 2009 18:38:36 GMT
Author: ppoddar
Date: Wed Mar 11 18:38:35 2009
New Revision: 752557

URL: http://svn.apache.org/viewvc?rev=752557&view=rev
Log:
OPENJPA-857: PersistenceProductDerivation sets Compatibility according to current specification.
Allow multiple specifications to coexist.

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Specification.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/SpecificationPlugin.java
    openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/conf/localizer.properties
    openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/conf/TestSpecification.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestSpecificationConfiguration.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
    openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_conf.xml
    openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQueryMultiThreaded.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java?rev=752557&r1=752556&r2=752557&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java
Wed Mar 11 18:38:35 2009
@@ -228,33 +228,36 @@
     public Specification getSpecificationInstance();
     
     /**
-     * Set the Specification that this configuration should use for the
-     * various properties that need to have different defaults for different
-     * specification environments..
-     * 
+     * Set the Specification for this configuration.
+     * Specification determines various default properties and behavior.
+     * For example, {@link Compatibility compatibility} options during runtime.
+     *   
+     * This change will trigger all registered Product Derivations to mutate 
+     * other configuration properties.
+     *
      * @param fullname of the specification that possibly encodes major and
      * minor version information. For encoding format
-     * @see Specification#create(String)
+     * @see Specification
+     * 
+     * @since 1.1.0
      */
-    public boolean setSpecification(String spec);
+    public void setSpecification(String spec);
     
     /**
-     * Set the specification that this configuration should use for the
-     * various properties that need to have different defaults for different
-     * specification environments. The given specification also carry version
-     * information which can help for setting, for example, various
-     * {@link Compatibility compatibility} options during runtime.
+     * Set the Specification for this configuration.
+     * Specification determines various default properties and behavior.
+     * For example, {@link Compatibility compatibility} options during runtime.
      *   
-     * This should be invoked before any configuration options are set, as it 
-     * will mutate various values.
-     * You can only assign the specification once, though it is not fatal
-     * to attempt to do so multiple times. Attempts to set to null will
-     * be ignored.
+     * This change will trigger all registered Product Derivations to mutate 
+     * other configuration properties.
+     *
+     * @param fullname of the specification that possibly encodes major and
+     * minor version information. For encoding format
+     * @see Specification
      * 
      * @since 2.0.0
-     * 
      */
-    public boolean setSpecification(Specification spec);
+    public void setSpecification(Specification spec);
 
     /**
      * The plugin string for the {@link ClassResolver} to use for custom

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java?rev=752557&r1=752556&r2=752557&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
Wed Mar 11 18:38:35 2009
@@ -544,8 +544,7 @@
         
         eagerInitialization = addBoolean("InitializeEagerly");
         
-        specification = new SpecificationPlugin("Specification", 
-            getConfigurationLog());
+        specification = new SpecificationPlugin(this, "Specification"); 
         addValue(specification);
         specification.setInstantiatingGetter("getSpecificationInstance");
         
@@ -598,22 +597,14 @@
      * Sets Specification from the given String.
      * 
      * @param spec should be encoded in the format specified in {@link 
-     * Specification#create(String)}.
+     * Specification}.
      */
-    public boolean setSpecification(String spec) {
-        if (spec == null)
-            return false;
+    public void setSpecification(String spec) {
         specification.setString(spec);
-        ProductDerivations.afterSpecificationSet(this);
-        return true;
     }
     
-    public boolean setSpecification(Specification newSpec) {
-        if (newSpec == null)
-            return false;
+    public void setSpecification(Specification newSpec) {
         specification.set(newSpec);
-        ProductDerivations.afterSpecificationSet(this);
-        return true;
     }
 
     public void setClassResolver(String classResolver) {

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Specification.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Specification.java?rev=752557&r1=752556&r2=752557&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Specification.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Specification.java
Wed Mar 11 18:38:35 2009
@@ -20,6 +20,9 @@
 
 import java.text.MessageFormat;
 
+import org.apache.commons.lang.StringUtils;
+import org.apache.openjpa.lib.conf.Configurable;
+import org.apache.openjpa.lib.conf.Configuration;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.util.UserException;
 
@@ -33,23 +36,13 @@
  *
  */
 public class Specification {
-    private String _name;
-    private int    _major;
-    private String _minor;
-    private String _description;
-    
-    static final MessageFormat _format = new MessageFormat("{0} {1}.{2}");
-    static final String _printableFormat = "<name> [<major>[.<minor>]]";
-    static final MessageFormat _vformat = new MessageFormat("{0}.{1}");
-    static final String _printableVersionFormat = "<major>[.<minor>]";
+    private String _name = "";
+    private int    _major = 1;
+    private String _minor = "0";
+    private String _description = "";
+
     private static Localizer _loc = Localizer.forPackage(Specification.class);
     
-    private Specification(String name, int major, String minor) {
-        this._name = name == null ? "" : name.trim();
-        this._major = major;
-        this._minor = minor == null ? "" : minor.trim();
-    }
-    
     /**
      * Construct from a String that encodes name and version fields.
      * 
@@ -59,134 +52,67 @@
      * 'major' version defaults to 1 and must be an integer. 
      * 'minor' version defaults to 0 and can be a String. 
      */
-    public static Specification create(String fullName) {
-        try {
-            Object[] tokens = _format.parse(fullName);
-            return new Specification(tokens[0].toString(),
-                tokens.length > 1 ? Integer.parseInt(tokens[1].toString()) : 1,
-                tokens.length > 2 ? tokens[2].toString() : "0");
-        } catch (Exception e) {
-            throw new UserException(_loc.get("spec-wrong-format", 
-                fullName, _printableFormat));
-        }
-    }
-    
-    /**
-     * Construct from a String and version.
-     * 
-     * @param name is the name of the Specification.
-     * @param version a encoded string in the following prescribed format.
-     * <code>major.minor</code> e.g. <code>2.0-draft</code>
-     * 'major' version defaults to 1 and must be an integer. 
-     * 'minor' version defaults to 0 and can be a String. 
-     */
-    public static Specification create(String name, String version) {
+    public Specification(String fullName) {
         try {
-            Object[] tokens = _vformat.parse(version);
-            return new Specification(name,
-                tokens.length > 0 ? Integer.parseInt(tokens[0].toString()) : 1,
-                tokens.length > 1 ? tokens[1].toString() : "0");
+            Object[] tokens = parse(fullName);
+            _name = tokens[0].toString();
+            _major = tokens.length > 1 ? 
+                Integer.parseInt(tokens[1].toString()) : 1;
+            _minor = tokens.length > 2 ? tokens[2].toString() : "0";
         } catch (Exception e) {
-            throw new UserException(_loc.get("spec-wrong-version-format", 
-                version, _printableVersionFormat));
+            throw new UserException(_loc.get("spec-wrong-format", fullName));
         }
     }
     
-    /**
-     * Construct from a String and major and minor version.
-     * 
-     * @param name is the name of the Specification.
-     * @param version a encoded string in the following prescribed format.
-     * <code>major.minor</code> e.g. <code>2.0-draft</code>
-     * 'major' version defaults to 1 and must be an integer. 
-     * 'minor' version defaults to 0 and can be a String. 
-     */
-    public static Specification create(String name, int major, String minor) {
-        return new Specification(name, major, minor);
-    }
-    
-    /**
-     * Construct from a String and major and minor version.
-     * 
-     * @param name is the name of the Specification.
-     * @param version a encoded string in the following prescribed format.
-     * <code>major.minor</code> e.g. <code>2.0-draft</code>
-     * 'major' version defaults to 1 and must be an integer. 
-     * 'minor' version defaults to 0 and can be a String. 
-     */
-    public static Specification create(String name, int major) {
-        return new Specification(name, major, "0");
-    }
-
-    /**
-     * Construct from a String and major and minor version.
-     * 
-     * @param name is the name of the Specification.
-     * @param version a encoded string in the following prescribed format.
-     * <code>major.minor</code> e.g. <code>2.0-draft</code>
-     * 'major' version defaults to 1 and must be an integer. 
-     * 'minor' version defaults to 0 and can be a String. 
-     */
-    public static Specification create(String name, int major, int minor) {
-        return new Specification(name, major, ""+minor);
-    }
-    
-    public Specification setDescription(String desc) {
-        _description = desc;
-        return this;
-    }
-    
     public String getName() {
         return _name;
     }
-
-    public int getMajorVersion() {
+    
+    public int getVersion() {
         return _major;
     }
-
+    
     public String getMinorVersion() {
         return _minor;
     }
-
+    
     public String getDescription() {
         return _description;
     }
-
-    /**
-     * Get the Specification encoding format in {@link MessageFormat} syntax.   
-     */
-    public static String getFormat() {
-        return _printableFormat;
-    }
     
-    /**
-     * Get the Specification version encoding format in {@link MessageFormat} 
-     * syntax.   
-     */
-    public static String getVersionFormat() {
-        return _printableVersionFormat;
+    public Specification setDescription(String description) {
+        this._description = description;
+        return this;
     }
     
     /**
      * Affirms if the given argument is equal to this receiver.
-     * They are equal if
-     *    other is a String that equals this receiver's name ignoring case and
-     *    any leading or trailing blank spaces.
-     *    other is a Specification whose name equals this receiver's name 
-     *    ignoring case and any leading or trailing blank spaces.
-     *    or if they are same reference (of course)
      */
     public boolean equals(Object other) {
         if (this == other)
             return true;
-        if (other == null)
+        if (other == null || !this.getClass().isInstance(other))
             return false;
-        if (other instanceof String)
-            return _name.equalsIgnoreCase(((String)other).trim());
-        if (other instanceof Specification)
-            return _name.equalsIgnoreCase((((Specification)other)._name)
-                .trim());
-        return false;
+        Specification that = (Specification)other;
+        return StringUtils.equals(_name, this._name) && _major == that._major 
+            && StringUtils.equals(_minor, this._minor);
+    }    
+    
+    /**
+     * Affirms if the given specification has the same name of this receiver,
+     * ignoring the case.
+     */
+    public boolean isSame(Specification other) {
+        return this == other 
+            || (other != null && _name.equalsIgnoreCase(other._name));
+    }
+    
+    /**
+     * Affirms if the given string equals name of this receiver, ignoring the 
+     * case.
+     */
+    public boolean isSame(String other) {
+        return _name.equalsIgnoreCase(other);
     }
     
     /**
@@ -199,10 +125,23 @@
      */
     public int compareVersion(Specification other) {
         return _major > other._major ? 1 : _major == other._major ? 0 : -1;
-        
     }
     
     public String toString() {
-        return MessageFormat.format(_format.toPattern(), _name, _major, _minor);
+        return _name.toUpperCase() + " " + _major + "." + _minor;
+    }
+    
+    private Object[] parse(String str) {
+        int space = str.indexOf(' ');
+        
+        if (space == -1)
+            return new Object[]{str};
+        String name = str.substring(0,space);
+        String version = str.substring(space+1);
+        int dot = version.indexOf('.');
+        if (dot == -1)
+            return new Object[] {name, version};
+        return new Object[] {name, 
+            version.substring(0,dot), version.substring(dot+1)};
     }
 }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/SpecificationPlugin.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/SpecificationPlugin.java?rev=752557&r1=752556&r2=752557&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/SpecificationPlugin.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/SpecificationPlugin.java
Wed Mar 11 18:38:35 2009
@@ -18,7 +18,11 @@
  */
 package org.apache.openjpa.conf;
 
+import org.apache.openjpa.lib.conf.Configuration;
 import org.apache.openjpa.lib.conf.ObjectValue;
+import org.apache.openjpa.lib.conf.ProductDerivations;
+import org.apache.openjpa.lib.conf.Value;
+import org.apache.openjpa.lib.conf.ValueListener;
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.util.UserException;
@@ -29,15 +33,15 @@
  * @author Pinaki Poddar
  *
  */
-public class SpecificationPlugin extends ObjectValue {
-    private Log _log;
-    
+public class SpecificationPlugin extends ObjectValue implements ValueListener {
+    private Configuration _conf;
     protected static final Localizer _loc = Localizer.forPackage
         (SpecificationPlugin.class);
     
-    public SpecificationPlugin(String prop, Log log) {
+    public SpecificationPlugin(Configuration conf, String prop) {
         super(prop);
-        _log = log; 
+        _conf = conf;
+        addListener(this);
     }
     
     @Override
@@ -54,11 +58,7 @@
      */
     @Override
     public void setString(String str) {
-        if (str == null)
-            set(null);
-        else {
-            this.set(Specification.create(str));
-        }
+        this.set(str == null ? null : new Specification(str));
     }
     
     /**
@@ -81,29 +81,37 @@
     }
     
     /**
-     * Validates if the currently Specification is set.
-     * Given newSpec must be equal to the current Specification and must have
-     * a major version number equal or less than the current one.
+     * Validates if the given Specification can overwrite the current 
+     * Specification. If the given Specification is not same as the
+     * current one, then it is valid to overwrite.
+     * If the given Specification is same as the current Specification then
+     * it must have a major version number equal or less than the current one.
      * 
-     * @exception fatal UserException if newSpec is not equal to the current
-     * Specification or has a higher major version.
+     * @exception fatal UserException if the given Specification is same as
+     * the current Specification but has a higher major version.
      * 
      * @see Specification#equals(Object)
      */
     protected void validateOverwrite(Specification newSpec) {
         Specification current = (Specification)get();
         if (current != null) {
-            if (!current.equals(newSpec)) {
-                throw new UserException(_loc.get("spec-different", newSpec, 
-                    current)).setFatal(true);
+            Log log = _conf.getConfigurationLog(); 
+            if (!current.isSame(newSpec)) {
+                log.warn(_loc.get("spec-different", newSpec, current));
+                return;
             }
             if (current.compareVersion(newSpec) < 0) {
                 throw new UserException(_loc.get("spec-version-higher", 
                     newSpec, current)).setFatal(true);
             }
             if (current.compareVersion(newSpec) > 0) {
-                _log.warn(_loc.get("spec-version-lower", newSpec, current));
+                log.warn(_loc.get("spec-version-lower", newSpec, current));
             }
         }
     }
+    
+    public void valueChanged(Value value) {
+        if (this.getClass().isInstance(value))
+            ProductDerivations.afterSpecificationSet(_conf);
+    }
 }

Modified: openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/conf/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/conf/localizer.properties?rev=752557&r1=752556&r2=752557&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/conf/localizer.properties
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/conf/localizer.properties
Wed Mar 11 18:38:35 2009
@@ -595,16 +595,16 @@
 	find the right marshaller to use to load and store cached data.
 cache-marshaller-not-found: No cache marshaller found for id {0}.
 cache-marshaller-found: Cache marshaller of type {1} found for id {0}.
-spec-different: Attempt to set a different Specification "{0}" failed. The \
-	Specification is already set to "{1}".
+spec-different: A different Specification "{0}" has overwritten the current \
+	Specification "{1}".
 spec-version-higher: Attempt to set a higer Specification "{0}" version failed.\
 	The Specification is already set to "{1}".
-spec-version-lower: Specification "{0}" is set to a lower version than the \
-	current default Specification "{1}".
+spec-version-lower: Specification is set to a lower version "{0}" than the \
+	current Specification "{1}".
 spec-wrong-format: "{0}" is not valid Specification. The correct format is \
-	"{1}" where <name> is the name of the Specification, <major> is the \
-	integer major version number and <minor> is a string.
+	 <name> [<major>[.<minor>]] where <name> is the name of the Specification,
\
+	 <major> is the integer major version number and <minor> is a string.
 spec-wrong-version-format: "{0}" is not a valid version for Specification. The \
-	correct version format is "{1}" where <major> is the integer major version \
-	number and <minor> is a string. 	
+	correct version format is "<major>[.<minor>]" where <major> is the integer
\
+	major version number and <minor> is a string. 	
 spec-wrong-obj: Can not set Specification from "{0}" of "{1}". 
\ No newline at end of file

Modified: openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/conf/TestSpecification.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/conf/TestSpecification.java?rev=752557&r1=752556&r2=752557&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/conf/TestSpecification.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/conf/TestSpecification.java
Wed Mar 11 18:38:35 2009
@@ -28,54 +28,45 @@
  */
 public class TestSpecification extends TestCase {
     public void testStaticConstruction() {
-        Specification spec1 = Specification.create("JPA 2.3");
+        Specification spec1 = new Specification("JPA 2.3");
         assertEquals("JPA", spec1.getName());
-        assertEquals(2, spec1.getMajorVersion());
+        assertEquals(2, spec1.getVersion());
         assertEquals("3", spec1.getMinorVersion());
 
-        Specification spec2 = Specification.create("JPA", "1.1");
+        Specification spec2 = new Specification("JPA 1.1");
         assertEquals("JPA", spec2.getName());
-        assertEquals(1, spec2.getMajorVersion());
+        assertEquals(1, spec2.getVersion());
         assertEquals("1", spec2.getMinorVersion());
         
-        Specification spec3 = Specification.create("JDO", 3, "ED");
+        Specification spec3 = new Specification("JDO 3.ED");
         assertEquals("JDO", spec3.getName());
-        assertEquals(3, spec3.getMajorVersion());
+        assertEquals(3, spec3.getVersion());
         assertEquals("ED", spec3.getMinorVersion());
         
-        Specification spec4 = Specification.create("JDO", 3, 5);
+        Specification spec4 = new Specification("JDO 3.5");
         assertEquals("JDO", spec4.getName());
-        assertEquals(3, spec4.getMajorVersion());
+        assertEquals(3, spec4.getVersion());
         assertEquals("5", spec4.getMinorVersion());
     }
     
-    public void testEquality() {
-        Specification spec1 = Specification.create("JPA 2.3");
-        Specification spec2 = Specification.create("JPA 1.0");
-        Specification spec3 = Specification.create("JDO 3.1");
+    public void testEqualityByName() {
+        Specification spec1 = new Specification("JPA 2.3");
+        Specification spec2 = new Specification("JPA 1.0");
+        Specification spec3 = new Specification("JDO 3.1");
         
-        assertEquals(spec1, spec2);
-        assertTrue(spec1.equals("jpa"));
-        assertTrue(spec1.equals("JPA"));
-        assertTrue(spec1.equals("JPA "));
+        assertTrue(spec1.isSame(spec2));
+        assertTrue(spec1.isSame("jpa"));
+        assertTrue(spec1.isSame("JPA"));
         
-        assertTrue(spec2.equals("jpa"));
-        assertTrue(spec2.equals("JPA"));
-        assertTrue(spec2.equals("JPA "));
-        
-        assertFalse(spec1.equals(spec3));
+     
+        assertFalse(spec1.isSame(spec3));
     }
     
     public void testVersionCompare() {
-        Specification spec1 = Specification.create("JPA 1.1");
-        Specification spec2 = Specification.create("JPA 2.2");
+        Specification spec1 = new Specification("JPA 1.1");
+        Specification spec2 = new Specification("JPA 2.2");
         assertTrue(spec1.compareVersion(spec2) < 0);
         assertTrue(spec2.compareVersion(spec1) > 0);
         assertTrue(spec1.compareVersion(spec1) == 0);
-    }
-    
-    public void testFormat() {
-        assertEquals("<name> [<major>[.<minor>]]", Specification.getFormat());
-        assertEquals("<major>[.<minor>]", Specification.getVersionFormat());
-    }
+    } 
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestSpecificationConfiguration.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestSpecificationConfiguration.java?rev=752557&r1=752556&r2=752557&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestSpecificationConfiguration.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestSpecificationConfiguration.java
Wed Mar 11 18:38:35 2009
@@ -38,24 +38,24 @@
     
     public void testSpecificationIsJPA() {
         Specification spec = getSpecifcation();
-        assertTrue(spec.equals("JPA"));
-        assertTrue(spec.equals("jpa"));
+        assertTrue(spec.isSame("JPA"));
+        assertTrue(spec.isSame("jpa"));
     }
     
     public void testSpecificationVersionIsJPA2() {
         Specification spec = getSpecifcation();
-        int major = spec.getMajorVersion();
+        int major = spec.getVersion();
         assertEquals(2, major);
-        assertTrue(spec.equals("JPA"));
+        assertTrue(spec.isSame("JPA"));
     }
     
     public void testLowerVersionCanBeSet() {
-        super.setUp("openjpa.Specification", "jpa 1.0", 
+        super.setUp("openjpa.Specification", "JPA 1.0", 
             "openjpa.Log", "DefaultLevel=WARN");
         Specification spec = getSpecifcation();
         
         assertNotNull(spec);
-        assertEquals(1, spec.getMajorVersion());
+        assertEquals(1, spec.getVersion());
     }
     
     public void testHigherVersionCanNotBeSet() {
@@ -68,6 +68,25 @@
         }
     }
     
+    public void testDifferentSpecCanBeSet() {
+        super.setUp("openjpa.Specification", "jdo 3.0", 
+            "openjpa.Log", "DefaultLevel=WARN");
+    }
+    
+    public void testSpecCanBeSetToNullString() {
+        Specification spec = getSpecifcation();
+        assertNotNull(spec);
+        emf.getConfiguration().setSpecification((String)null);
+        assertNull(getSpecifcation());
+    }
+    
+    public void testSpecCanBeSetToNullSpecification() {
+        Specification spec = getSpecifcation();
+        assertNotNull(spec);
+        emf.getConfiguration().setSpecification((Specification)null);
+        assertNull(getSpecifcation());
+    }
+    
     public Specification getSpecifcation() {
         return emf.getConfiguration().getSpecificationInstance();
     }

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=752557&r1=752556&r2=752557&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
Wed Mar 11 18:38:35 2009
@@ -35,6 +35,7 @@
 import javax.persistence.spi.PersistenceUnitTransactionType;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.openjpa.conf.Compatibility;
 import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.conf.OpenJPAConfigurationImpl;
 import org.apache.openjpa.conf.OpenJPAProductDerivation;
@@ -72,8 +73,8 @@
     extends AbstractProductDerivation
     implements OpenJPAProductDerivation {
 
-    public static final Specification SPEC_JPA = Specification.create("jpa", 2);
-    public static final Specification ALIAS_EJB = Specification.create("ejb", 3);
+    public static final Specification SPEC_JPA = new Specification("jpa 2");
+    public static final Specification ALIAS_EJB = new Specification("ejb 3");
     public static final String RSRC_GLOBAL = "META-INF/openjpa.xml";
     public static final String RSRC_DEFAULT = "META-INF/persistence.xml";
 
@@ -138,9 +139,9 @@
 
     @Override
     public boolean afterSpecificationSet(Configuration c) {
-      if (!(c instanceof OpenJPAConfigurationImpl)
-         || !SPEC_JPA.equals(((OpenJPAConfiguration) c).getSpecification()))
-          return false;
+        if (!OpenJPAConfigurationImpl.class.isInstance(c)
+         && !SPEC_JPA.isSame(((OpenJPAConfiguration) c).getSpecification()))
+            return false;
  
         OpenJPAConfigurationImpl conf = (OpenJPAConfigurationImpl) c;
         conf.metaFactoryPlugin.setDefault(SPEC_JPA.getName());
@@ -149,6 +150,13 @@
         conf.lockManagerPlugin.setString("mixed");
         conf.nontransactionalWrite.setDefault("true");
         conf.nontransactionalWrite.set(true);
+        int specVersion = ((OpenJPAConfiguration) c).getSpecificationInstance()
+            .getVersion();
+        if (specVersion < 2) {
+            Compatibility compatibility = conf.getCompatibilityInstance();
+            compatibility.setFlushBeforeDetach(true);
+            compatibility.setCopyOnDetach(true);
+        }
         return true;
     }
 

Modified: openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_conf.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_conf.xml?rev=752557&r1=752556&r2=752557&view=diff
==============================================================================
--- openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_conf.xml (original)
+++ openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_conf.xml Wed Mar 11 18:38:35 2009
@@ -3016,7 +3016,44 @@
 system sequence. See <xref linkend="ref_guide_sequence"/> for more
 information.
             </para>
-        </section>
+        </section>
+        <section id="openjpa.Specification">
+            <title>
+                openjpa.Specification
+            </title>
+            <indexterm zone="openjpa.Specification">
+                <primary>
+                    Specification
+                </primary>
+            </indexterm>
+            <para>
+<emphasis role="bold">Property name: </emphasis><literal>openjpa.Specification
+</literal>
+            </para>
+            <para>
+<emphasis role="bold">Configuration API:</emphasis>
+<ulink url="../javadoc/org/apache/openjpa/conf/OpenJPAConfiguration.html#getSpecificationInstance()">
+<methodname>org.apache.openjpa.conf.OpenJPAConfiguration.getSpecificationInstance
+</methodname></ulink>
+            </para>
+            <para>
+<emphasis role="bold">Resource adaptor config-property: </emphasis><literal>
+Specification</literal>
+            </para>
+            <para>
+<emphasis role="bold">Default: </emphasis><literal>table</literal>
+            </para>
+            <para>
+<emphasis role="bold">Description:</emphasis> A formatted string describing the
Specification
+to use for the default configuration options. The format of the Specifcation string is 
+<literal>name [major.[minor]]</literal> where <literal>name</literal>
denotes the name of the
+Specification such as <literal>JPA</literal> or <literal>JDO</literal>,
<literal>major</literal>
+denotes the major integral version number of the Specification and <literal>minor</literal>
+denotes a minor version which can be an arbitrary string.  
+See <xref linkend="ref_guide_spec_compatibility"/> for more information.
+            </para>
+        </section>
+        
         <section id="openjpa.TransactionMode">
             <title>
                 openjpa.TransactionMode
@@ -3971,5 +4008,41 @@
             </para>
         </section>
         
+        <section id="ref_guide_spec_compatibility">
+        <title>Compatibility with Specification</title>
+        <para>
+The default behavior of certain OpenJPA API methods can evolve to align with the behaviors
+defined in JPA specification. To maintain backward compatibility, OpenJPA allows configuration
+options such that while the default behavior changes to align with current JPA Specification,
the
+previous behaviors can always be emulated. 
+		</para>
+		<para>
+For example, JPA 2.0 specification
+introduces a new API <literal>void EntityManager.detach(Object entity)</literal>
that detaches
+the given entity from the current persistence context. OpenJPA has provided similar
+feature via <literal>&lt;T&gt; T OpenJPAEntityManager.detach(T entity)</literal>
prior to JPA 2.0. 
+OpenJPA <literal>detach()</literal>, however, has different default behavior
than what JPA 2.0
+specification mandates. Firstly, OpenJPA creates a copy of the given entity as a detached
instance
+and returns it, whereas JPA 2.0 behavior requires the same given entity instance be detached.
+Secondly, the given instance is removed from the persistence context for JPA 2.0, whereas
+OpenJPA <literal>detach()</literal> method, prior to JPA 2.0, does not remove
the instance
+from the persistence context as a copy is returned. Thirdly, OpenJPA will flush before
+detaching a dirty instance so that the detached instance can later be merged, whereas
+JPA 2.0 <literal>detach()</literal> semantics does not require a dirty instance
be flushed
+before detach.        
+		</para>
+		<para>
+A user application running with OpenJPA that is compliant to a specific version of JPA of
specification,
+the older behavior can be emulated by configuring OpenJPA Compatibility options.
+For example, <literal>openjpa.Compatibility=FlushBeforeDetach=false,CopyOnDetach=true</literal>
+will emulate the older behavior of detach even when running with OpenJPA that are
+compliant to JPA 2.0 Specification.  The configuration can also be set to a different version
of the specification.
+For example, <literal>openjpa.Specification="JPA 1.0"</literal> configuration
setting will emulate
+default OpenJPA behavior as it were for JPA Specification version 1.0. Setting via
+<literal>openjpa.Specification</literal> is a shorthand for more fine-grained
control available via
+<literal>openjpa.Compatibility</literal>.    
+  
+		</para>
+        </section>
     </section>
 </chapter>

Modified: openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQueryMultiThreaded.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQueryMultiThreaded.java?rev=752557&r1=752556&r2=752557&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQueryMultiThreaded.java
(original)
+++ openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQueryMultiThreaded.java
Wed Mar 11 18:38:35 2009
@@ -75,7 +75,6 @@
 	
 	public void tearDown()  throws Exception {
 		group.shutdown();
-		super.tearDown();
 	}
 
 	void create(int N) {



Mime
View raw message