You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pc...@apache.org on 2007/07/27 00:08:41 UTC

svn commit: r560016 [4/4] - in /openjpa/trunk: openjpa-all/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ openjpa...

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java?view=diff&rev=560016&r1=560015&r2=560016
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java Thu Jul 26 15:08:37 2007
@@ -56,12 +56,12 @@
 import org.apache.openjpa.lib.util.Options;
 import org.apache.openjpa.lib.util.concurrent.ConcurrentHashMap;
 import serp.bytecode.BCClass;
-import serp.bytecode.BCClassLoader;
 import serp.bytecode.BCField;
 import serp.bytecode.BCMethod;
 import serp.bytecode.Code;
 import serp.bytecode.JumpInstruction;
 import serp.bytecode.Project;
+import serp.bytecode.BCClassLoader;
 import serp.util.Strings;
 
 /**
@@ -364,10 +364,12 @@
         // we don't lock here; ok if two proxies get generated for same type
         ProxyCollection proxy = (ProxyCollection) _proxies.get(type);
         if (proxy == null) {
-            ClassLoader l = getMostDerivedLoader(type, ProxyCollection.class);
+            ClassLoader l = GeneratedClasses.getMostDerivedLoader(type,
+                ProxyCollection.class);
             Class pcls = loadBuildTimeProxy(type, l);
             if (pcls == null)
-                pcls = loadProxy(generateProxyCollectionBytecode(type, true),l);
+                pcls = GeneratedClasses.loadBCClass(
+                    generateProxyCollectionBytecode(type, true), l);
             proxy = (ProxyCollection) instantiateProxy(pcls, null, null);
             _proxies.put(type, proxy);
         }
@@ -381,10 +383,12 @@
         // we don't lock here; ok if two proxies get generated for same type
         ProxyMap proxy = (ProxyMap) _proxies.get(type);
         if (proxy == null) {
-            ClassLoader l = getMostDerivedLoader(type, ProxyMap.class);
+            ClassLoader l = GeneratedClasses.getMostDerivedLoader(type,
+                ProxyMap.class);
             Class pcls = loadBuildTimeProxy(type, l);
             if (pcls == null)
-                pcls = loadProxy(generateProxyMapBytecode(type, true), l);
+                pcls = GeneratedClasses.loadBCClass(
+                    generateProxyMapBytecode(type, true), l);
             proxy = (ProxyMap) instantiateProxy(pcls, null, null);
             _proxies.put(type, proxy);
         }
@@ -398,10 +402,12 @@
         // we don't lock here; ok if two proxies get generated for same type
         ProxyDate proxy = (ProxyDate) _proxies.get(type);
         if (proxy == null) {
-            ClassLoader l = getMostDerivedLoader(type, ProxyDate.class);
+            ClassLoader l = GeneratedClasses.getMostDerivedLoader(type,
+                ProxyDate.class);
             Class pcls = loadBuildTimeProxy(type, l);
             if (pcls == null)
-                pcls = loadProxy(generateProxyDateBytecode(type, true), l);
+                pcls = GeneratedClasses.loadBCClass(
+                    generateProxyDateBytecode(type, true), l);
             proxy = (ProxyDate) instantiateProxy(pcls, null, null);
             _proxies.put(type, proxy);
         }
@@ -415,10 +421,12 @@
         // we don't lock here; ok if two proxies get generated for same type
         ProxyCalendar proxy = (ProxyCalendar) _proxies.get(type);
         if (proxy == null) {
-            ClassLoader l = getMostDerivedLoader(type, ProxyCalendar.class);
+            ClassLoader l = GeneratedClasses.getMostDerivedLoader(type,
+                ProxyCalendar.class);
             Class pcls = loadBuildTimeProxy(type, l);
             if (pcls == null)
-                pcls = loadProxy(generateProxyCalendarBytecode(type, true), l);
+                pcls = GeneratedClasses.loadBCClass(
+                    generateProxyCalendarBytecode(type, true), l);
             proxy = (ProxyCalendar) instantiateProxy(pcls, null, null);
             _proxies.put(type, proxy);
         }
@@ -436,15 +444,16 @@
         // we don't lock here; ok if two proxies get generated for same type
         ProxyBean proxy = (ProxyBean) _proxies.get(type);
         if (proxy == null && !_proxies.containsKey(type)) {
-            ClassLoader l = getMostDerivedLoader(type, ProxyBean.class);
+            ClassLoader l = GeneratedClasses.getMostDerivedLoader(type,
+                ProxyBean.class);
             Class pcls = loadBuildTimeProxy(type, l);
             if (pcls == null) {
                 BCClass bc = generateProxyBeanBytecode(type, true);
                 if (bc != null)
-                    pcls = loadProxy(bc, l);
+                    pcls = GeneratedClasses.loadBCClass(bc, l);
             }
             if (pcls != null)
-                proxy = (ProxyBean) instantiateProxy(pcls, 
+                proxy = (ProxyBean) instantiateProxy(pcls,
                     findCopyConstructor(type), new Object[] {orig});
             _proxies.put(type, proxy);
         }
@@ -476,20 +485,6 @@
     }
 
     /**
-     * Load the proxy class represented by the given bytecode.
-     */
-    private Class loadProxy(BCClass bc, ClassLoader loader) {
-        BCClassLoader bcloader = new BCClassLoader(bc.getProject(), loader);
-        try {
-            Class c = Class.forName(bc.getName(), true, bcloader);
-            bc.getProject().clear();
-            return c;
-        } catch (Throwable t) {
-            throw new GeneralException(bc.getName()).setCause(t);
-        }
-    }
-
-    /**
      * Instantiate the given proxy class.
      */
     private Proxy instantiateProxy(Class cls, Constructor cons, Object[] args) {
@@ -500,12 +495,12 @@
             return (Proxy) AccessController.doPrivileged(
                 J2DoPrivHelper.newInstanceAction(cls));
         } catch (InstantiationException ie) {
-            throw new UnsupportedException(_loc.get("cant-newinstance", 
+            throw new UnsupportedException(_loc.get("cant-newinstance",
                 cls.getSuperclass().getName()));
         } catch (PrivilegedActionException pae) {
             Exception e = pae.getException();
             if (e instanceof InstantiationException)
-                throw new UnsupportedException(_loc.get("cant-newinstance", 
+                throw new UnsupportedException(_loc.get("cant-newinstance",
                     cls.getSuperclass().getName()));
             else
                 throw new GeneralException(cls.getName()).setCause(e);
@@ -515,31 +510,6 @@
     }
 
     /**
-     * Return the more derived loader of the class laoders for the given 
-     * classes.
-     */
-    private static ClassLoader getMostDerivedLoader(Class c1, Class c2) {
-        ClassLoader l1 = (ClassLoader) AccessController.doPrivileged(
-            J2DoPrivHelper.getClassLoaderAction(c1)); 
-        ClassLoader l2 = (ClassLoader) AccessController.doPrivileged(
-            J2DoPrivHelper.getClassLoaderAction(c2)); 
-        if (l1 == l2)
-            return l1;
-        if (l1 == null)
-            return l2;
-        if (l2 == null)
-            return l1;
-        
-        for (ClassLoader p = (ClassLoader) AccessController.doPrivileged(
-                J2DoPrivHelper.getParentAction(l1)); p != null;
-                p = (ClassLoader) AccessController.doPrivileged(
-                    J2DoPrivHelper.getParentAction(p)))
-            if (p == l2)
-                return l1;
-        return l2;
-    }
-
-    /**
      * Generate the bytecode for a collection proxy for the given type.
      */
     protected BCClass generateProxyCollectionBytecode(Class type, 
@@ -551,7 +521,7 @@
         bc.declareInterface(ProxyCollection.class);
  
         delegateConstructors(bc, type);
-        addProxyMethods(bc, type, false);
+        addProxyMethods(bc, false);
         addProxyCollectionMethods(bc, type);
         proxyRecognizedMethods(bc, type, ProxyCollections.class, 
             ProxyCollection.class);
@@ -588,7 +558,7 @@
         bc.declareInterface(ProxyMap.class);
  
         delegateConstructors(bc, type);
-        addProxyMethods(bc, type, false);
+        addProxyMethods(bc, false);
         addProxyMapMethods(bc, type);
         proxyRecognizedMethods(bc, type, ProxyMaps.class, ProxyMap.class);
         proxySetters(bc, type);
@@ -607,7 +577,7 @@
         bc.declareInterface(ProxyDate.class);
  
         delegateConstructors(bc, type);
-        addProxyMethods(bc, type, true);
+        addProxyMethods(bc, true);
         addProxyDateMethods(bc, type);
         proxySetters(bc, type);
         addWriteReplaceMethod(bc, runtime);
@@ -626,7 +596,7 @@
         bc.declareInterface(ProxyCalendar.class);
  
         delegateConstructors(bc, type);
-        addProxyMethods(bc, type, true);
+        addProxyMethods(bc, true);
         addProxyCalendarMethods(bc, type);
         proxySetters(bc, type);
         addWriteReplaceMethod(bc, runtime);
@@ -660,7 +630,7 @@
         bc.declareInterface(ProxyBean.class);
  
         delegateConstructors(bc, type);
-        addProxyMethods(bc, type, true);
+        addProxyMethods(bc, true);
         addProxyBeanMethods(bc, type, cons);
         if (!proxySetters(bc, type))
             return null;
@@ -699,8 +669,7 @@
      * @param changeTracker whether to implement a null change tracker; if false
      * the change tracker method is left unimplemented
      */
-    private void addProxyMethods(BCClass bc, Class type, 
-        boolean changeTracker) {
+    private void addProxyMethods(BCClass bc, boolean changeTracker) {
         BCField sm = bc.declareField("sm", OpenJPAStateManager.class);
         sm.setTransient(true);
         BCField field = bc.declareField("field", int.class);
@@ -1631,9 +1600,14 @@
         BCClass bc;
         for (int i = 0; i < types.size(); i++) {
             cls = Class.forName((String) types.get(i));
-            if (mgr.loadBuildTimeProxy(cls, getMostDerivedLoader(cls, 
-                Proxy.class)) != null)
-                continue;
+            try {
+                if (Class.forName(getProxyClassName(cls, false), true,
+                    GeneratedClasses.getMostDerivedLoader(cls, Proxy.class))
+                    != null)
+                    continue;
+            } catch (Throwable t) {
+                // expected if the class hasn't been generated
+            }
 
             if (Collection.class.isAssignableFrom(cls))
                 bc = mgr.generateProxyCollectionBytecode(cls, false);         

Modified: openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties?view=diff&rev=560016&r1=560015&r2=560016
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties (original)
+++ openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties Thu Jul 26 15:08:37 2007
@@ -38,6 +38,17 @@
 	a custom readExternal and/or writeExternal method.  You cannot use custom \
 	serialization with detachment. 
 enhance-start: Enhancing type "{0}".
+enhance-and-subclass-and-redef-start: Creating subclass and redefining methods \
+    for "{0}". This means that your application will be less efficient \
+    than it would if you ran the OpenJPA enhancer.
+enhance-and-subclass-no-redef-start: Creating subclass for "{0}". \
+    This means that your application will be less efficient and will consume \
+    more memory than it would if you ran the OpenJPA enhancer. Additionally, \
+    lazy loading will not be available for one-to-one and many-to-one \
+    persistent attributes in types using field access; they will be loaded \
+    eagerly instead.
+redefine-types: Redefining {0} using Java 5 type redefinition.
+retransform-types: Redefining {0} using Java 6 type retransformation.
 pc-type: Type "{0}" is already persistence capable; skipping.
 pers-aware: Type "{0}" has no metadata; enhancing as persistence aware. \
 	If you intended for "{0}" to be persistence-capable, then this means that \
@@ -121,3 +132,58 @@
 	field "{1}", while the getter method returns field "{2}".
 cft-exception-thrown: An exception was thrown while attempting to perform \
 	class file transformation on "{0}":
+subclasser-error-field: Error while processing persistent field {1}, declared \
+	in {2}. Error details: {0}
+subclasser-error-meta: Error while processing persistent type {1}, declared \
+	in {2}. Error details: {0}
+subclasser-contract-violation-field: Possible violation of subclassing contract\
+	detected while processing persistent field {1}, declared in {2}. Are you \
+	sure you are obeying the OpenJPA requirements? Details: {0}
+subclasser-setter-getter-field-mismatch: Mismatch between getter and setter.
+subclasser-no-ifaces: OpenJPA does not currently support automatic handling of \
+    interface types. Failed type: {0}
+subclasser-no-final-classes: OpenJPA cannot dynamically subclass final types. \
+    To use final types, you must run the OpenJPA enhancer after compilation, \
+    or deploy to an environment that supports deploy-time enhancement, such as \
+    a Java EE 5 application server. Failed type: {0}
+subclasser-no-private-classes: OpenJPA cannot dynamically subclass final types.\
+    To use final types, you must run the OpenJPA enhancer after compilation, \
+    or deploy to an environment that supports deploy-time enhancement, such as \
+    a Java EE 5 application server. Failed type: {0}
+subclasser-super-already-pc: The superclass for type {0} implements \
+    org.apache.openjpa.enhance.PersistenceCapable, which means that it was \
+    processed by the OpenJPA enhancer. If you are enhancing some of your \
+    persistent types, you must enhance all of them.
+subclasser-private-ctor: Unenhanced classes must have a public or protected \
+    no-args constructor. Type {0}'s no-args constructor is private or \
+    package-visible. If you do not want to add such a constructor, you must\
+    run the OpenJPA enhancer after compilation, \
+    or deploy to an environment that supports deploy-time enhancement, such as \
+    a Java EE 5 application server.
+subclasser-no-void-ctor: Unenhanced classes must have a public or protected \
+    no-args constructor. Type {0} does not have any no-args constructors. \
+    If you do not want to add such a constructor, you must \
+    run the OpenJPA enhancer after compilation, \
+    or deploy to an environment that supports deploy-time enhancement, such as \
+    a Java EE 5 application server.
+subclasser-class-already-pc: Type {0} is already persistence-capable. Please \
+    report this problem to the OpenJPA team at dev@openjpa.apache.org.
+subclasser-no-getter: No getter exists for field {0}.
+subclasser-no-setter: No setter exists for field {0}.
+subclasser-invalid-getter: The getter for field {0} does not obey OpenJPA's \
+    subclassing restrictions. Getters must return a single non-computed field.
+subclasser-invalid-setter: The setter for field {0} does not obey OpenJPA's \
+    subclassing restrictions. Setters must assign the passed-in parameter to a \
+    single field in the object.
+subclasser-private-accessors-unsupported: The accessor for field {1} in type \
+    {0} is private or package-visible. OpenJPA requires accessors in \
+    unenhanced instances to be public or protected. \
+    If you do not want to add such an accessor, you must run the OpenJPA \
+    enhancer after compilation, or deploy to an environment that supports \
+    deploy-time enhancement, such as a Java EE 5 application server.
+subclasser-final-methods-not-allowed: The method {1} in type {0} is final. \
+    OpenJPA requires methods in unenhanced instances to be non-final.
+subclasser-native-methods-not-allowed: The method {1} in type {0} is native. \
+    OpenJPA requires methods in unenhanced instances to be non-native.
+subclasser-static-methods-not-supported: The method {1} in type {0} is static. \
+    OpenJPA requires methods in unenhanced instances to be non-static.

Modified: openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/jpql/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/jpql/localizer.properties?view=diff&rev=560016&r1=560015&r2=560016
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/jpql/localizer.properties (original)
+++ openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/jpql/localizer.properties Thu Jul 26 15:08:37 2007
@@ -55,3 +55,5 @@
 update-constant-value: Update expression "{0}" may only use literals \
 	or parameters as update values.
 bad-parse: Encountered "{0}" at character {1}, but expected: {2}.
+no-saved-fields: No state snapshot is available for "{0}", but this instance \
+    uses state-comparison for dirty detection.

Modified: openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties?view=diff&rev=560016&r1=560015&r2=560016
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties (original)
+++ openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties Thu Jul 26 15:08:37 2007
@@ -169,7 +169,8 @@
 	primary key fields.
 invalid-id: The id class specified by type "{0}" does not match the \
 	primary key fields of the class.  Make sure your identity class has the \
-	same primary keys as your persistent type.  Mismatched property: "{1}"
+	same primary keys as your persistent type, including pk field types. \
+    Mismatched property: "{1}"
 null-cons: The id class specified by type "{0}" does not have public a \
 	no-args constructor.
 hc-method: The identity class specified by type "{0}" is not valid, as the \

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java?view=diff&rev=560016&r1=560015&r2=560016
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java Thu Jul 26 15:08:37 2007
@@ -601,22 +601,4 @@
             }
         };
     }
-
-    /**
-     * Return a PrivilegeAction object for bcClass.isInstanceOf().
-     * 
-     * Requires security policy:
-     *   'permission java.lang.RuntimePermission "getClassLoader";'
-     *   
-     * @return Boolean
-     */
-    public static final PrivilegedAction isInstanceOfAction(
-        final BCClass bcClass, final Class clazz) {
-        return new PrivilegedAction() {
-            public Object run() {
-                return bcClass.isInstanceOf(clazz) ? Boolean.TRUE
-                    : Boolean.FALSE;
-            }
-        };
-    }
 }

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/ConcurrentReferenceHashMap.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/ConcurrentReferenceHashMap.java?view=diff&rev=560016&r1=560015&r2=560016
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/ConcurrentReferenceHashMap.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/ConcurrentReferenceHashMap.java Thu Jul 26 15:08:37 2007
@@ -105,11 +105,28 @@
      */
     private int maxSize = Integer.MAX_VALUE;
 
-    private static boolean eq(Object x, Object y) {
+    /**
+     * Compare two objects. These might be keys, values, or Entry instances.
+     * This implementation uses a normal null-safe object equality algorithm.
+     *
+     * @since 1.0.0
+     */
+    protected boolean eq(Object x, Object y) {
         return x == y || (x != null && x.equals(y));
     }
 
     /**
+     * Obtain the hashcode of an object. The object might be a key, a value,
+     * or an Entry. This implementation just delegates to
+     * {@link Object#hashCode}
+     *
+     * @since 1.0.0
+     */
+    protected int hc(Object o) {
+        return o == null ? 0 : o.hashCode();
+    }
+
+    /**
      * Constructs a new, empty HashMap with the specified initial
      * capacity and the specified load factor.
      *
@@ -251,7 +268,7 @@
             return false;
 
         Entry[] tab = table;
-        int hash = (key == null) ? 0 : key.hashCode();
+        int hash = hc(key);
         int index = (hash & 0x7FFFFFFF) % tab.length;
         for (Entry e = tab[index]; e != null; e = e.getNext())
             if (e.getHash() == hash && eq(key, e.getKey()))
@@ -270,7 +287,7 @@
             return null;
 
         Entry[] tab = table;
-        int hash = (key == null) ? 0 : key.hashCode();
+        int hash = hc(key);
         int index = (hash & 0x7FFFFFFF) % tab.length;
         for (Entry e = tab[index]; e != null; e = e.getNext())
             if ((e.getHash() == hash) && eq(key, e.getKey()))
@@ -331,7 +348,7 @@
             || (value == null && valueType != HARD))
             throw new IllegalArgumentException("Null references not supported");
 
-        int hash = (key == null) ? 0 : key.hashCode();
+        int hash = hc(key);
         synchronized (this) {
             expungeStaleEntries();
 
@@ -413,7 +430,7 @@
         if (key == null && keyType != HARD)
             return null;
 
-        int hash = (key == null) ? 0 : key.hashCode();
+        int hash = hc(key);
         synchronized (this) {
             expungeStaleEntries();
 
@@ -662,7 +679,7 @@
                     Map.Entry entry = (Map.Entry) o;
                     Object key = entry.getKey();
                     Entry[] tab = table;
-                    int hash = (key == null ? 0 : key.hashCode());
+                    int hash = hc(key);
                     int index = (hash & 0x7FFFFFFF) % tab.length;
 
                     for (Entry e = tab[index]; e != null; e = e.getNext())
@@ -678,7 +695,7 @@
                     Object key = entry.getKey();
                     synchronized (ConcurrentReferenceHashMap.this) {
                         Entry[] tab = table;
-                        int hash = (key == null ? 0 : key.hashCode());
+                        int hash = hc(key);
                         int index = (hash & 0x7FFFFFFF) % tab.length;
 
                         for (Entry e = tab[index], prev = null; e != null;
@@ -757,7 +774,7 @@
     /**
      * Hard entry.
      */
-    private static class HardEntry implements Entry {
+    private class HardEntry implements Entry {
 
         private int hash;
         private Object key;
@@ -829,7 +846,7 @@
     /**
      * Weak entry.
      */
-    private static class WeakEntry extends WeakReference implements Entry {
+    private class WeakEntry extends WeakReference implements Entry {
 
         private int hash;
         private Object hard;
@@ -902,7 +919,7 @@
     /**
      * Soft entry.
      */
-    private static class SoftEntry extends SoftReference implements Entry {
+    private class SoftEntry extends SoftReference implements Entry {
 
         private int hash;
         private Object hard;

Modified: openjpa/trunk/openjpa-persistence-jdbc/pom.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/pom.xml?view=diff&rev=560016&r1=560015&r2=560016
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/pom.xml (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/pom.xml Thu Jul 26 15:08:37 2007
@@ -399,6 +399,8 @@
                                     dir="${project.build.testOutputDirectory}">
                                     <include name="**/*.class"/>
                                     <exclude name="**/inheritance/serializable/*.class"/>
+                                    <exclude name="**/xml/*.class"/>
+                                    <exclude name="**/Unenhanced*.class"/>
                                 </fileset>
                                 <openjpac>
                                     <classpath refid="cp"/>

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/AbstractUnenhancedClassTest.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/AbstractUnenhancedClassTest.java?view=auto&rev=560016
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/AbstractUnenhancedClassTest.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/AbstractUnenhancedClassTest.java Thu Jul 26 15:08:37 2007
@@ -0,0 +1,458 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.enhance;
+
+import java.io.IOException;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ByteArrayInputStream;
+import java.util.List;
+import java.util.Collections;
+import java.lang.reflect.Field;
+
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.kernel.OpenJPAStateManager;
+import org.apache.openjpa.meta.ClassMetaData;
+import org.apache.openjpa.util.ImplHelper;
+
+public abstract class AbstractUnenhancedClassTest
+    extends SingleEMFTestCase {
+
+    // ##### To do:
+    // - clearing in pnew property-access without redefinition
+    // - lazy loading override for -to-one field types
+    // - figure out how to auto-test the redefinition code, either in Java 5
+    //   or in Java 6
+    // - run CTS in the following combinations:
+    //   * Java 6
+    //   * Java 5 with javaagent
+    //   * Java 5 without javaagent
+
+    public void setUp() {
+        setUp(getUnenhancedClass(), getUnenhancedSubclass(), CLEAR_TABLES,
+            "openjpa.Log", "Enhance=TRACE");
+        // trigger class redefinition
+        emf.createEntityManager().close();
+    }
+
+    protected abstract Class<? extends UnenhancedType> getUnenhancedClass();
+
+    protected abstract UnenhancedType newUnenhancedInstance();
+
+    protected abstract Class<? extends UnenhancedSubtype> getUnenhancedSubclass();
+
+    protected abstract UnenhancedSubtype newUnenhancedSubclassInstance();
+
+    public void testMetaData() {
+        ClassMetaData meta = OpenJPAPersistence.getMetaData(emf,
+            getUnenhancedClass());
+        assertEquals(ClassRedefiner.canRedefineClasses(),
+            meta.isIntercepting());
+    }
+
+    public void testImplHelperCalls() {
+        assertTrue(ImplHelper.isManagedType(getUnenhancedClass()));
+
+        UnenhancedType un = newUnenhancedInstance();
+        assertFalse(un instanceof PersistenceCapable);
+        PersistenceCapable pc = ImplHelper.toPersistenceCapable(un,
+            emf.getConfiguration());
+        assertNotNull(pc);
+        assertTrue(ImplHelper.isManageable(un));
+    }
+
+    public void testBasicPersistenceCapableBehavior() {
+        UnenhancedType un = newUnenhancedInstance();
+        un.setStringField("bar");
+        PersistenceCapable pc = ImplHelper.toPersistenceCapable(un,
+            emf.getConfiguration());
+        assertFalse(pc.pcIsDeleted());
+        assertFalse(pc.pcIsDirty());
+        assertFalse(pc.pcIsNew());
+        assertFalse(pc.pcIsPersistent());
+        assertFalse(pc.pcIsTransactional());
+    }
+
+    public void testPCRegistry() {
+        assertTrue(PCRegistry.isRegistered(getUnenhancedClass()));
+        PersistenceCapable pc = PCRegistry.newInstance(
+            getUnenhancedClass(), null, false);
+        assertNotNull(pc);
+    }
+
+    public void testClearingOnSubtypeInstance() {
+        // the boolean at the end of newInstance will cause clear to be invoked
+        UnenhancedType un = (UnenhancedType)
+            PCRegistry.newInstance(getUnenhancedClass(), null, true);
+        assertEquals(null, un.getStringField());
+    }
+
+    public void testGetObjectIdOnOpenJPAType() {
+        getObjectIdHelper(true, false);
+    }
+
+    public void testGetObjectIdOnOpenJPATypeSubclass() {
+        getObjectIdHelper(false, false);
+    }
+
+    public void testGetObjectIdOnUserDefined() {
+        getObjectIdHelper(true, true);
+    }
+
+    public void testGetObjectIdOnUserDefinedSubclass() {
+        getObjectIdHelper(false, true);
+    }
+
+    private void getObjectIdHelper(boolean sub, boolean userDefined) {
+        OpenJPAEntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        UnenhancedType un = newInstance(sub);
+        em.persist(un);
+        em.getTransaction().commit();
+
+        if (!userDefined) {
+            em.close();
+            em = emf.createEntityManager();
+            un = em.find(getUnenhancedClass(), un.getId());
+        }
+
+        assertNotNull(em.getObjectId(un));
+    }
+
+    public void testOperations() {
+        opsHelper(false);
+    }
+
+    public void testSubclassOperations() {
+        opsHelper(true);
+    }
+
+    private void opsHelper(boolean sub) {
+        OpenJPAEntityManager em = null;
+        try {
+            UnenhancedType un = newInstance(sub);
+            em = emf.createEntityManager();
+
+            em.getTransaction().begin();
+            em.persist(un);
+            un.setStringField("bar");
+            assertEquals("bar", un.getStringField());
+            em.flush();
+            assertTrue(un.getId() != 0);
+            UnenhancedType un2 = em.find(getUnenhancedClass(), un.getId());
+            assertSame(un, un2);
+            em.getTransaction().commit();
+            un2 = em.find(getUnenhancedClass(), un.getId());
+            assertSame(un, un2);
+            em.close();
+
+            em = emf.createEntityManager();
+            un = em.find(getUnenhancedClass(), un.getId());
+            assertNotNull(un);
+            assertTrue(un instanceof PersistenceCapable);
+            assertEquals("bar", un.getStringField());
+            em.getTransaction().begin();
+            un.setStringField("baz");
+            assertEquals("baz", un.getStringField());
+
+            if (sub)
+                ((UnenhancedSubtype) un).setIntField(17);
+
+            assertTrue(em.isDirty(un));
+            
+            em.getTransaction().commit();
+            em.close();
+
+            em = emf.createEntityManager();
+            un = em.find(getUnenhancedClass(), un.getId());
+            assertNotNull(un);
+            assertTrue(un instanceof PersistenceCapable);
+            assertEquals("baz", un.getStringField());
+            if (sub)
+                assertEquals(17, ((UnenhancedSubtype) un).getIntField());
+            em.close();
+        } finally {
+            if (em != null && em.getTransaction().isActive())
+                em.getTransaction().rollback();
+            if (em != null && em.isOpen())
+                em.close();
+        }
+    }
+
+    public void testRelations() {
+        OpenJPAEntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        UnenhancedSubtype un = newUnenhancedSubclassInstance();
+        em.persist(un);
+        un.setStringField("aoeu");
+        UnenhancedSubtype related = newUnenhancedSubclassInstance();
+        un.setRelated(related);
+        related.setStringField("snth");
+        em.getTransaction().commit();
+        em.close();
+
+        em = emf.createEntityManager();
+        un = (UnenhancedSubtype) em.find(getUnenhancedClass(), un.getId());
+        assertEquals("aoeu", un.getStringField());
+        assertNotNull(un.getRelated());
+        assertEquals("snth", un.getRelated().getStringField());
+        em.close();
+    }
+
+    public void testEnhancer() throws IOException {
+        List<Class> subs =  ManagedClassSubclasser.prepareUnenhancedClasses(
+            emf.getConfiguration(),
+            Collections.singleton(getUnenhancedClass()), null);
+        Class sub = subs.get(0);
+        assertNotNull(sub);
+        assertEquals("org.apache.openjpa.enhance."
+            + getUnenhancedClass().getName().replace('.', '$') + "$pcsubclass",
+            sub.getName());
+        assertTrue(PersistenceCapable.class.isAssignableFrom(sub));
+        assertTrue(getUnenhancedClass().isAssignableFrom(sub));
+    }
+
+    public void testPCSubclassName() {
+        assertEquals("org.apache.openjpa.enhance."
+            + getUnenhancedClass().getName().replace('.', '$') + "$pcsubclass",
+            PCEnhancer.toPCSubclassName(getUnenhancedClass()));
+    }
+
+    public void testLazyLoadingInUserCreatedInstance()
+        throws NoSuchFieldException, IllegalAccessException {
+        lazyLoading(true);
+    }
+
+    public void testLazyLoadingInOpenJPACreatedInstance()
+        throws NoSuchFieldException, IllegalAccessException {
+        lazyLoading(false);
+    }
+
+    private void lazyLoading(boolean userDefined)
+        throws NoSuchFieldException, IllegalAccessException {
+        OpenJPAEntityManager em = emf.createEntityManager();
+        UnenhancedType un = newUnenhancedInstance();
+        em.getTransaction().begin();
+        em.persist(un);
+        em.getTransaction().commit();
+
+        if (!userDefined) {
+            em.close();
+            em = emf.createEntityManager();
+            un = em.find(getUnenhancedClass(), un.getId());
+            assertTrue(getUnenhancedClass() != un.getClass());
+        }
+
+        em.evict(un);
+        OpenJPAStateManager sm = (OpenJPAStateManager)
+            ImplHelper.toPersistenceCapable(un, null).pcGetStateManager();
+
+        // we only expect lazy loading to work when we can redefine classes
+        // or when accessing a property-access record that OpenJPA created.
+        if (ClassRedefiner.canRedefineClasses()
+            || (!userDefined && sm.getMetaData().getAccessType()
+                != ClassMetaData.ACCESS_FIELD)) {
+
+            assertFalse(sm.getLoaded()
+                .get(sm.getMetaData().getField("stringField").getIndex()));
+
+            // make sure that the value was cleared...
+            Field field = getUnenhancedClass().getDeclaredField(
+                this instanceof TestUnenhancedFieldAccess
+                    ? "stringField" : "sf");
+            field.setAccessible(true);
+            assertEquals(null, field.get(un));
+
+            // ... and that it gets reloaded properly
+            assertEquals("foo", un.getStringField());
+            assertTrue(sm.getLoaded()
+                .get(sm.getMetaData().getField("stringField").getIndex()));
+        } else {
+            // unredefined properties with user-defined instance, or any
+            // unredefined field access
+            assertTrue(sm.getLoaded()
+                .get(sm.getMetaData().getField("stringField").getIndex()));
+
+            // make sure that the value was not cleared
+            Field field = getUnenhancedClass().getDeclaredField(
+                this instanceof TestUnenhancedFieldAccess
+                    ? "stringField" : "sf");
+            field.setAccessible(true);
+            assertEquals("foo", field.get(un));
+        }
+
+        em.close();
+    }
+
+    public void testSerializationOfUserDefinedInstance()
+        throws IOException, ClassNotFoundException {
+        serializationHelper(true, false);
+    }
+
+    public void testSerializationOfUserDefinedSubclassInstance()
+        throws IOException, ClassNotFoundException {
+        serializationHelper(true, true);
+    }
+
+    public void testSerializationOfOpenJPADefinedInstance()
+        throws IOException, ClassNotFoundException {
+        serializationHelper(false, false);
+    }
+
+    public void testSerializationOfOpenJPADefinedSubclassInstance()
+        throws IOException, ClassNotFoundException {
+        serializationHelper(false, true);
+    }
+
+    private void serializationHelper(boolean userDefined, boolean sub)
+        throws IOException, ClassNotFoundException {
+        OpenJPAEntityManager em = emf.createEntityManager();
+        UnenhancedType un = newInstance(sub);
+        em.getTransaction().begin();
+        em.persist(un);
+
+        if (sub) {
+            UnenhancedType related = newInstance(false);
+            related.setStringField("related");
+            ((UnenhancedSubtype) un).setRelated(related);
+        }
+
+        em.getTransaction().commit();
+
+        if (!userDefined) {
+            em.close();
+            em = emf.createEntityManager();
+        }
+
+        un = em.find(getUnenhancedClass(), un.getId());
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        ObjectOutputStream oout = new ObjectOutputStream(out);
+        oout.writeObject(un);
+        oout.flush();
+        byte[] bytes = out.toByteArray();
+
+        ObjectInputStream oin = new ObjectInputStream(
+            new ByteArrayInputStream(bytes));
+        UnenhancedType deserialized = (UnenhancedType) oin.readObject();
+
+        copiedInstanceHelper(sub, em, un, deserialized, false);
+        em.close();
+    }
+
+    public void testCloningOfUserDefinedInstance()
+        throws IOException, ClassNotFoundException, CloneNotSupportedException {
+        cloneHelper(true, false);
+    }
+
+    public void testCloningOfUserDefinedSubclassInstance()
+        throws IOException, ClassNotFoundException, CloneNotSupportedException {
+        cloneHelper(true, true);
+    }
+
+    public void testCloningOfOpenJPADefinedInstance()
+        throws IOException, ClassNotFoundException, CloneNotSupportedException {
+        cloneHelper(false, false);
+    }
+
+    public void testCloningOfOpenJPADefinedSubclassInstance()
+        throws IOException, ClassNotFoundException, CloneNotSupportedException {
+        cloneHelper(false, true);
+    }
+
+    private void cloneHelper(boolean userDefined, boolean sub)
+        throws IOException, ClassNotFoundException, CloneNotSupportedException {
+        OpenJPAEntityManager em = emf.createEntityManager();
+        UnenhancedType un = newInstance(sub);
+        em.getTransaction().begin();
+        em.persist(un);
+
+        if (sub) {
+            UnenhancedType related = newInstance(false);
+            related.setStringField("related");
+            ((UnenhancedSubtype) un).setRelated(related);
+        }
+
+        em.getTransaction().commit();
+
+        if (!userDefined) {
+            em.close();
+            em = emf.createEntityManager();
+        }
+
+        un = em.find(getUnenhancedClass(), un.getId());
+        UnenhancedType cloned = (UnenhancedType) un.clone();
+
+        copiedInstanceHelper(sub, em, un, cloned, true);
+        em.close();
+    }
+
+    private void copiedInstanceHelper(boolean sub, OpenJPAEntityManager em,
+        UnenhancedType un, UnenhancedType copy, boolean viaClone) {
+        assertNotSame(un, copy);
+        if (!viaClone)
+            assertEquals(sub ? getUnenhancedSubclass() : getUnenhancedClass(),
+                copy.getClass());
+        assertEquals(un.getId(), copy.getId());
+        assertEquals(un.getStringField(), copy.getStringField());
+        if (sub) {
+            assertEquals(
+                ((UnenhancedSubtype) un).getIntField(),
+                ((UnenhancedSubtype) copy).getIntField());
+            assertNotSame(
+                ((UnenhancedSubtype) un).getRelated(),
+                ((UnenhancedSubtype) copy).getRelated());
+            assertEquals(
+                ((UnenhancedSubtype) un).getRelated().getId(),
+                ((UnenhancedSubtype) copy).getRelated().getId());
+        }
+
+        assertFalse(em.isDetached(un));
+        assertTrue(em.isDetached(copy));
+        copy.setStringField("offline update");
+
+        em.getTransaction().begin();
+        assertSame(un, em.merge(copy));
+        assertTrue(em.isDirty(un));
+        assertEquals("offline update", un.getStringField());
+        em.getTransaction().commit();
+    }
+
+    private UnenhancedType newInstance(boolean sub) {
+        return sub ? newUnenhancedSubclassInstance()
+            : newUnenhancedInstance();
+    }
+
+    public void testGetMetaDataOfSubtype() {
+        ClassMetaData meta = OpenJPAPersistence.getMetaData(emf,
+            getUnenhancedClass());
+        List<Class> subs =  ManagedClassSubclasser.prepareUnenhancedClasses(
+            emf.getConfiguration(),
+            Collections.singleton(getUnenhancedClass()), null);
+        assertSame(meta, OpenJPAPersistence.getMetaData(emf, subs.get(0)));
+
+        meta = OpenJPAPersistence.getMetaData(emf, getUnenhancedSubclass());
+        subs =  ManagedClassSubclasser.prepareUnenhancedClasses(
+            emf.getConfiguration(),
+            Collections.singleton(getUnenhancedSubclass()), null);
+        assertSame(meta, OpenJPAPersistence.getMetaData(emf, subs.get(0)));
+    }
+}
\ No newline at end of file

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestUnenhancedCompoundPK.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestUnenhancedCompoundPK.java?view=auto&rev=560016
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestUnenhancedCompoundPK.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestUnenhancedCompoundPK.java Thu Jul 26 15:08:37 2007
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.enhance;
+
+import org.apache.openjpa.persistence.test.SingleEMTestCase;
+
+public class TestUnenhancedCompoundPK
+    extends SingleEMTestCase {
+
+    public void setUp() {
+        setUp(UnenhancedCompoundPKFieldAccess.class,
+            UnenhancedCompoundPKPropertyAccess.class, CLEAR_TABLES);
+    }
+
+    public void testCompoundPKFieldAccessUserDefined() {
+        UnenhancedCompoundPKFieldAccess un
+            = new UnenhancedCompoundPKFieldAccess(17, 31);
+        UnenhancedCompoundPKFieldAccess.PK oid
+            = new UnenhancedCompoundPKFieldAccess.PK(17, 31);
+        compoundPKHelper(un, oid, true);
+    }
+
+    public void testCompoundPKFieldAccessOpenJPADefined() {
+        UnenhancedCompoundPKFieldAccess un
+            = new UnenhancedCompoundPKFieldAccess(17, 31);
+        UnenhancedCompoundPKFieldAccess.PK oid
+            = new UnenhancedCompoundPKFieldAccess.PK(17, 31);
+        compoundPKHelper(un, oid, false);
+    }
+
+    public void testCompoundPKPropertyAccessUserDefined() {
+        UnenhancedCompoundPKPropertyAccess un
+            = new UnenhancedCompoundPKPropertyAccess(17, 31);
+        UnenhancedCompoundPKPropertyAccess.PK oid
+            = new UnenhancedCompoundPKPropertyAccess.PK(17, 31);
+        compoundPKHelper(un, oid, true);
+    }
+
+    public void testCompoundPKPropertyAccessOpenJPADefined() {
+        UnenhancedCompoundPKPropertyAccess un
+            = new UnenhancedCompoundPKPropertyAccess(17, 31);
+        UnenhancedCompoundPKPropertyAccess.PK oid
+            = new UnenhancedCompoundPKPropertyAccess.PK(17, 31);
+        compoundPKHelper(un, oid, false);
+    }
+
+    private void compoundPKHelper(Object o, Object oid, boolean userDefined) {
+        em.getTransaction().begin();
+        em.persist(o);
+        em.getTransaction().commit();
+
+        if (!userDefined) {
+            em.close();
+            em = emf.createEntityManager();
+        }
+
+        em.find(o.getClass(), oid);
+    }
+}
\ No newline at end of file

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestUnenhancedFieldAccess.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestUnenhancedFieldAccess.java?view=auto&rev=560016
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestUnenhancedFieldAccess.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestUnenhancedFieldAccess.java Thu Jul 26 15:08:37 2007
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.enhance;
+
+public class TestUnenhancedFieldAccess
+    extends AbstractUnenhancedClassTest {
+
+    protected Class<? extends UnenhancedType> getUnenhancedClass() {
+        return UnenhancedFieldAccess.class;
+    }
+
+    protected UnenhancedType newUnenhancedInstance() {
+        return new UnenhancedFieldAccess();
+    }
+
+    protected Class<? extends UnenhancedSubtype> getUnenhancedSubclass() {
+        return UnenhancedFieldAccessSubclass.class;
+    }
+
+    protected UnenhancedSubtype newUnenhancedSubclassInstance() {
+        return new UnenhancedFieldAccessSubclass();
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestUnenhancedPropertyAccess.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestUnenhancedPropertyAccess.java?view=auto&rev=560016
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestUnenhancedPropertyAccess.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestUnenhancedPropertyAccess.java Thu Jul 26 15:08:37 2007
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.enhance;
+
+public class TestUnenhancedPropertyAccess
+    extends AbstractUnenhancedClassTest {
+
+    protected Class<? extends UnenhancedType> getUnenhancedClass() {
+        return UnenhancedPropertyAccess.class;
+    }
+
+    protected UnenhancedType newUnenhancedInstance() {
+        return new UnenhancedPropertyAccess();
+    }
+
+    protected Class<? extends UnenhancedSubtype> getUnenhancedSubclass() {
+        return UnenhancedPropertyAccessSubclass.class;
+    }
+
+    protected UnenhancedSubtype newUnenhancedSubclassInstance() {
+        return new UnenhancedPropertyAccessSubclass();
+    }
+}
\ No newline at end of file

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedCompoundPKFieldAccess.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedCompoundPKFieldAccess.java?view=auto&rev=560016
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedCompoundPKFieldAccess.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedCompoundPKFieldAccess.java Thu Jul 26 15:08:37 2007
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.enhance;
+
+import javax.persistence.Entity;
+import javax.persistence.IdClass;
+import javax.persistence.Id;
+
+import org.apache.openjpa.enhance.UnenhancedCompoundPKFieldAccess.PK;
+
+@Entity
+@IdClass(PK.class)
+public class UnenhancedCompoundPKFieldAccess {
+
+    @Id private int id0;
+    @Id private int id1;
+
+    protected UnenhancedCompoundPKFieldAccess() {
+    }
+
+    public UnenhancedCompoundPKFieldAccess(
+        int i0, int i1) {
+        id0 = i0;
+        id1 = i1;
+    }
+
+    public static class PK {
+        static {
+            // register persistent class in JVM
+            try {
+                Class.forName(UnenhancedCompoundPKFieldAccess.class.getName());
+            } catch (Exception e) {
+                // ignore
+            }
+        }
+
+        public int id0;
+        public int id1;
+
+        public PK() {
+        }
+
+        public PK(int i0, int i1) {
+            id0 = i0;
+            id1 = i1;
+        }
+
+        public String toString() {
+            return String.valueOf(id0)
+                + "::" + String.valueOf(id1);
+        }
+
+        public int hashCode() {
+            int rs = 17;
+            rs = rs * 37 + (int) (id0 ^ (id1 >>> 32));
+            rs = rs * 37 + (int) (id0 ^ (id1 >>> 32));
+            return rs;
+        }
+
+        public boolean equals(Object obj) {
+            if(this == obj)
+                return true;
+            if(obj == null || obj.getClass() != getClass())
+                return false;
+
+            PK other = (PK) obj;
+            return (id0 == other.id0)
+                && (id1 == other.id1);
+        }
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedCompoundPKPropertyAccess.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedCompoundPKPropertyAccess.java?view=auto&rev=560016
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedCompoundPKPropertyAccess.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedCompoundPKPropertyAccess.java Thu Jul 26 15:08:37 2007
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.enhance;
+
+import javax.persistence.Entity;
+import javax.persistence.IdClass;
+import javax.persistence.Id;
+
+import org.apache.openjpa.enhance.UnenhancedCompoundPKPropertyAccess.PK;
+
+@Entity
+@IdClass(PK.class)
+public class UnenhancedCompoundPKPropertyAccess {
+
+    private int id0;
+    private int id1;
+
+    protected UnenhancedCompoundPKPropertyAccess() {
+    }
+
+    public UnenhancedCompoundPKPropertyAccess(
+        int i0, int i1) {
+        id0 = i0;
+        id1 = i1;
+    }
+
+    @Id
+    public int getId0() {
+        return id0;
+    }
+
+    public void setId0(int id0) {
+        this.id0 = id0;
+    }
+
+    @Id
+    public int getId1() {
+        return id1;
+    }
+
+    public void setId1(int id1) {
+        this.id1 = id1;
+    }
+
+    public static class PK {
+        static {
+            // register persistent class in JVM
+            try {
+                Class.forName(
+                    UnenhancedCompoundPKPropertyAccess.class.getName());
+            } catch (Exception e) {
+                // ignore
+            }
+        }
+
+        public int id0;
+        public int id1;
+
+        public PK() {
+        }
+
+        public PK(int i0, int i1) {
+            id0 = i0;
+            id1 = i1;
+        }
+
+        public int getId0() {
+            return id0;
+        }
+
+        public void setId0(int id0) {
+            this.id0 = id0;
+        }
+
+        public int getId1() {
+            return id1;
+        }
+
+        public void setId1(int id1) {
+            this.id1 = id1;
+        }
+
+        public String toString() {
+            return String.valueOf(id0)
+                + "::" + String.valueOf(id1);
+        }
+
+        public int hashCode() {
+            int rs = 17;
+            rs = rs * 37 + (int) (id0 ^ (id1 >>> 32));
+            rs = rs * 37 + (int) (id0 ^ (id1 >>> 32));
+            return rs;
+        }
+
+        public boolean equals(Object obj) {
+            if(this == obj)
+                return true;
+            if(obj == null || obj.getClass() != getClass())
+                return false;
+
+            PK other = (PK) obj;
+            return (id0 == other.id0)
+                && (id1 == other.id1);
+        }
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedFieldAccess.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedFieldAccess.java?view=auto&rev=560016
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedFieldAccess.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedFieldAccess.java Thu Jul 26 15:08:37 2007
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.enhance;
+
+import java.io.Serializable;
+import javax.persistence.Entity;
+import javax.persistence.Version;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+
+import org.apache.openjpa.persistence.DetachedState;
+
+@Entity
+@Table(name="UN_FIELD")
+@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
+public class UnenhancedFieldAccess
+    implements UnenhancedType, Serializable, Cloneable {
+    
+    @Id @GeneratedValue private int id;
+    @Version public int version;
+    protected String stringField = "foo";
+
+    public int getId() {
+        return id;
+    }
+
+    public void setStringField(String s) {
+        stringField = s;
+    }
+
+    public String getStringField() {
+        return stringField;
+    }
+
+    public boolean equals(Object o) {
+        if (o == this)
+            return true;
+        if (o == null)
+            return false;
+        if (!getClass().isAssignableFrom(o.getClass()))
+            return false;
+
+        return id == ((UnenhancedFieldAccess) o).id;
+    }
+
+    public int hashCode() {
+        return id;
+    }
+
+    public Object clone() throws CloneNotSupportedException {
+        return super.clone();
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedFieldAccessSubclass.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedFieldAccessSubclass.java?view=auto&rev=560016
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedFieldAccessSubclass.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedFieldAccessSubclass.java Thu Jul 26 15:08:37 2007
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.enhance;
+
+import javax.persistence.OneToOne;
+import javax.persistence.Entity;
+import javax.persistence.CascadeType;
+
+@Entity
+public class UnenhancedFieldAccessSubclass
+    extends UnenhancedFieldAccess 
+    implements UnenhancedSubtype {
+
+    @OneToOne(cascade = CascadeType.ALL)
+    private UnenhancedFieldAccess related;
+    private int intField;
+
+    public UnenhancedType getRelated() {
+        return related;
+    }
+
+    public void setRelated(UnenhancedType related) {
+        this.related = (UnenhancedFieldAccess) related;
+    }
+
+    public void setIntField(int i) {
+        intField = i;
+    }
+
+    public int getIntField() {
+        return intField;
+    }
+
+    public Object clone() throws CloneNotSupportedException {
+        UnenhancedFieldAccessSubclass un =
+            (UnenhancedFieldAccessSubclass) super.clone();
+        un.setRelated((UnenhancedType) getRelated().clone());
+        return un;
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedPropertyAccess.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedPropertyAccess.java?view=auto&rev=560016
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedPropertyAccess.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedPropertyAccess.java Thu Jul 26 15:08:37 2007
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.enhance;
+
+import java.io.Serializable;
+import javax.persistence.Entity;
+import javax.persistence.Version;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Basic;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+
+import org.apache.openjpa.persistence.DetachedState;
+
+@Entity
+@Table(name="UN_PROP")
+@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
+public class UnenhancedPropertyAccess
+    implements UnenhancedType, Serializable, Cloneable {
+
+    private int id;
+    private int version;
+    private String sf = "foo";
+
+    @Id @GeneratedValue
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    @Version
+    protected int getVersion() {
+        return version;
+    }
+
+    protected void setVersion(int v) {
+        version = v;
+    }
+
+    public void setStringField(String s) {
+        sf = s;
+    }
+
+    @Basic
+    public String getStringField() {
+        return sf;
+    }
+
+    public boolean equals(Object o) {
+        if (o == this)
+            return true;
+        if (o == null)
+            return false;
+        if (!getClass().isAssignableFrom(o.getClass()))
+            return false;
+
+        return getId() == ((UnenhancedPropertyAccess) o).getId();
+    }
+
+    public int hashCode() {
+        return getId();
+    }
+
+    public Object clone() throws CloneNotSupportedException {
+        return super.clone();
+    }
+}
\ No newline at end of file

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedPropertyAccessSubclass.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedPropertyAccessSubclass.java?view=auto&rev=560016
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedPropertyAccessSubclass.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedPropertyAccessSubclass.java Thu Jul 26 15:08:37 2007
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.enhance;
+
+import javax.persistence.OneToOne;
+import javax.persistence.Transient;
+import javax.persistence.Entity;
+import javax.persistence.CascadeType;
+
+import org.apache.openjpa.persistence.Type;
+
+@Entity
+public class UnenhancedPropertyAccessSubclass
+    extends UnenhancedPropertyAccess
+    implements UnenhancedSubtype {
+
+    private UnenhancedPropertyAccess related;
+    private int intField;
+
+    @OneToOne(cascade = CascadeType.ALL)
+    @Type(UnenhancedPropertyAccess.class)
+    public UnenhancedType getRelated() {
+        return related;
+    }
+
+    public void setRelated(UnenhancedType related) {
+        this.related = (UnenhancedPropertyAccess) related;
+    }
+
+    public void setIntField(int i) {
+        intField = i;
+    }
+
+    public int getIntField() {
+        return intField;
+    }
+
+    public Object clone() throws CloneNotSupportedException {
+        UnenhancedPropertyAccessSubclass un =
+            (UnenhancedPropertyAccessSubclass) super.clone();
+        un.setRelated((UnenhancedType) getRelated().clone());
+        return un;
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedSubtype.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedSubtype.java?view=auto&rev=560016
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedSubtype.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedSubtype.java Thu Jul 26 15:08:37 2007
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.enhance;
+
+public interface UnenhancedSubtype
+    extends UnenhancedType {
+
+    UnenhancedType getRelated();
+
+    void setRelated(UnenhancedType related);
+
+    void setIntField(int i);
+
+    int getIntField();
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedType.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedType.java?view=auto&rev=560016
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedType.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/UnenhancedType.java Thu Jul 26 15:08:37 2007
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.enhance;
+
+/**
+ * Used in {@link AbstractUnenhancedClassTest}
+ */
+public interface UnenhancedType {
+
+    void setStringField(String s);
+    String getStringField();
+    int getId();
+
+    Object clone() throws CloneNotSupportedException;
+}

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java?view=diff&rev=560016&r1=560015&r2=560016
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java Thu Jul 26 15:08:37 2007
@@ -751,7 +751,7 @@
         if (detached != null) {
             if (!detached.enabled())
                 meta.setDetachedState(null);
-            else if (!StringUtils.isEmpty(detached.fieldName()))
+            else if (StringUtils.isEmpty(detached.fieldName()))
                 meta.setDetachedState(ClassMetaData.SYNTHETIC);
             else
                 meta.setDetachedState(detached.fieldName());

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAEntityManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAEntityManager.java?view=diff&rev=560016&r1=560015&r2=560016
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAEntityManager.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAEntityManager.java Thu Jul 26 15:08:37 2007
@@ -887,12 +887,10 @@
      * JavaBeans convention, this method will create a concrete implementation
      * according to the metadata that defines the class. If <code>cls</code>
      * is a non-final concrete type that has metadata but does not implement
-     * {@link org.apache.openjpa.enhance.PersistenceCapable}, this method will create a
-     * subclass of the type that does implement
-     * {@link org.apache.openjpa.enhance.PersistenceCapable},
-     * following the property-based persistent attribute access rules, or
-     * will raise an exception if the class does not meet the requirements
-     * for subclassing. Otherwise, this will return an instance of the
+     * {@link PersistenceCapable}, this method will create a subclass of the
+     * type that does implement {@link PersistenceCapable}, and will attempt
+     * to redefine the methods in <code>cls</code> to enable persistent
+     * attribute tracking. Otherwise, this will return an instance of the
      * specified class.
      */
     public <T> T createInstance(Class<T> cls);

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java?view=diff&rev=560016&r1=560015&r2=560016
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java Thu Jul 26 15:08:37 2007
@@ -273,9 +273,11 @@
      */
     public static OpenJPAEntityManager getEntityManager(Object o) {
         try {
-            if (o instanceof PersistenceCapable)
-                return toEntityManager((Broker) ((PersistenceCapable) o).
-                    pcGetGenericContext());
+            if (ImplHelper.isManageable(o)) {
+                PersistenceCapable pc = ImplHelper.toPersistenceCapable(o, null);
+                if (pc != null)
+                    return toEntityManager((Broker) pc.pcGetGenericContext());
+            }
             return null;
         } catch (Exception e) {
             throw PersistenceExceptions.toPersistenceException(e);
@@ -290,7 +292,8 @@
         if (o == null)
             return null;
         EntityManager em = getEntityManager(o);
-        return (em == null) ? null : getMetaData(em, o.getClass());
+        return (em == null) ? null : getMetaData(em,
+            ImplHelper.getManagedInstance(o).getClass());
     }
 
     /**



OpenJPA for Service Data Objects

Posted by Pinaki Poddar <pp...@bea.com>.
 Hi,
   Under the aegis of Apache Lab, a prototype is built to explore how
OpenJPA can provide persistence service for 
Service Data Objects. 

   Current state of this prototype is available at:

   http://people.apache.org/~ppoddar/fluid/site/welcome.html

 
  Your comments/suggestions are most welcome.

  Regards --


Pinaki Poddar
972.834.2865

Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.