openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r768428 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/ openjpa-persistence/s...
Date Fri, 24 Apr 2009 22:24:45 GMT
Author: ppoddar
Date: Fri Apr 24 22:24:45 2009
New Revision: 768428

URL: http://svn.apache.org/viewvc?rev=768428&view=rev
Log:
OPENJPA-926: entity without any property can have unknown access type.

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ApplicationIdTool.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCSubclassValidator.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ReflectingPersistenceCapable.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AccessCode.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/TestSubclassedBehavior.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
    openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ApplicationIdTool.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ApplicationIdTool.java?rev=768428&r1=768427&r2=768428&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ApplicationIdTool.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ApplicationIdTool.java
Fri Apr 24 22:24:45 2009
@@ -49,6 +49,7 @@
 import org.apache.openjpa.lib.util.JavaVersions;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.lib.util.Options;
+import org.apache.openjpa.meta.AccessCode;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.DelegatingMetaDataFactory;
 import org.apache.openjpa.meta.FieldMetaData;
@@ -549,7 +550,8 @@
      * Return the getters and setters for all primary key fields.
      */
     private String getProperties() {
-        if (_meta.getAccessType() == ClassMetaData.ACCESS_FIELD)
+        if (AccessCode.isExplicit(_meta.getAccessType()) 
+         && AccessCode.isField(_meta.getAccessType()))
             return "";
 
         CodeFormat code = newCodeFormat();

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java?rev=768428&r1=768427&r2=768428&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java
Fri Apr 24 22:24:45 2009
@@ -233,7 +233,7 @@
             // only warn about declared fields; superclass fields will be
             // warned about when the superclass is handled
             for (FieldMetaData fmd : meta.getDeclaredFields()) {
-                if (fmd.getAccessType() == ClassMetaData.ACCESS_PROPERTY)
+                if (AccessCode.isProperty(fmd.getAccessType()))
                     continue;
                 switch (fmd.getTypeCode()) {
                     case JavaTypes.COLLECTION:

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java?rev=768428&r1=768427&r2=768428&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
Fri Apr 24 22:24:45 2009
@@ -488,9 +488,6 @@
      * @return <code>ENHANCE_*</code> constant
      */
     public int run() {
-        if (_log.isTraceEnabled())
-            _log.trace(_loc.get("enhance-start", _managedType.getType()));
-
         try {
             // if managed interface, skip
             if (_pc.isInterface())
@@ -500,11 +497,14 @@
             Class[] interfaces = _managedType.getDeclaredInterfaceTypes();
             for (int i = 0; i < interfaces.length; i++) {
                 if (interfaces[i].getName().equals(PCTYPE.getName())) {
-                    if (_log.isTraceEnabled())
-                        _log.trace(_loc.get("pc-type", _managedType.getType()));
+                    if (_log.isInfoEnabled())
+                        _log.info(_loc.get("pc-type", _managedType.getType()));
                     return ENHANCE_NONE;
                 }
             }
+            if (_log.isInfoEnabled())
+                _log.info(_loc.get("enhance-start", _managedType.getType()));
+
 
             configureBCs();
 

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCSubclassValidator.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCSubclassValidator.java?rev=768428&r1=768427&r2=768428&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCSubclassValidator.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCSubclassValidator.java
Fri Apr 24 22:24:45 2009
@@ -27,6 +27,7 @@
 import java.util.Collection;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.openjpa.meta.AccessCode;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.FieldMetaData;
 import org.apache.openjpa.util.UserException;
@@ -126,7 +127,7 @@
             throw new InternalException(
                 loc.get("subclasser-class-already-pc", name));
 
-        if (meta.getAccessType() == ClassMetaData.ACCESS_PROPERTY)
+        if (AccessCode.isProperty(meta.getAccessType()))
             checkPropertiesAreInterceptable();
 
         if (errors != null && !errors.isEmpty())

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ReflectingPersistenceCapable.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ReflectingPersistenceCapable.java?rev=768428&r1=768427&r2=768428&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ReflectingPersistenceCapable.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ReflectingPersistenceCapable.java
Fri Apr 24 22:24:45 2009
@@ -28,6 +28,7 @@
 import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.kernel.OpenJPAStateManager;
 import org.apache.openjpa.kernel.StateManagerImpl;
+import org.apache.openjpa.meta.AccessCode;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.FieldMetaData;
 import org.apache.openjpa.meta.JavaTypes;
@@ -338,7 +339,7 @@
 
     private Object getValue(int i, Object o) {
         FieldMetaData fmd = meta.getField(i);
-        if (fmd.getAccessType() == ClassMetaData.ACCESS_PROPERTY) {
+        if (AccessCode.isProperty(fmd.getAccessType())) {
             Field field = Reflection.findField(meta.getDescribedType(),
                 toFieldName(i), true);
             return Reflection.get(o, field);
@@ -358,7 +359,7 @@
 
     private void setValue(int i, Object o, Object val) {
         FieldMetaData fmd = meta.getField(i);
-        if (fmd.getAccessType() == ClassMetaData.ACCESS_PROPERTY) {
+        if (AccessCode.isProperty(fmd.getAccessType())) {
             if (!meta.isIntercepting()) {
                 Method meth = Reflection.findSetter(meta.getDescribedType(),
                     meta.getField(i).getName(), true);

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AccessCode.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AccessCode.java?rev=768428&r1=768427&r2=768428&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AccessCode.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AccessCode.java Fri
Apr 24 22:24:45 2009
@@ -120,6 +120,8 @@
 	 * access style.
 	 */
 	public static boolean isCompatibleSuper(int subCode, int superCode) {
+		if (!isSet(superCode))
+			return true;
 		if (isValidClassCode(subCode) && isValidClassCode(superCode)) {
 			if (isExplicit(subCode))
 				return true;

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/TestSubclassedBehavior.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/TestSubclassedBehavior.java?rev=768428&r1=768427&r2=768428&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/TestSubclassedBehavior.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/TestSubclassedBehavior.java
Fri Apr 24 22:24:45 2009
@@ -38,6 +38,7 @@
 import junit.framework.AssertionFailedError;
 import org.apache.openjpa.kernel.Broker;
 import org.apache.openjpa.kernel.OpenJPAStateManager;
+import org.apache.openjpa.meta.AccessCode;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.FieldMetaData;
 import org.apache.openjpa.persistence.JPAFacadeHelper;
@@ -539,7 +540,7 @@
             .getMetaDataRepositoryInstance().
             getMetaData(DerivedEntity.class, null, false);
         assertTrue("meta's access should be ACCESS_PROPERTY",
-            meta.getAccessType() == ClassMetaData.ACCESS_PROPERTY);
+        		AccessCode.isProperty(meta.getAccessType()));
         FieldMetaData[] fmds = meta.getFields();
         for (int i = 0; i < fmds.length; i++) {
             assertEquals(Method.class, fmds[i].getBackingMember().getClass());

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java?rev=768428&r1=768427&r2=768428&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
Fri Apr 24 22:24:45 2009
@@ -456,6 +456,8 @@
     @SuppressWarnings("unchecked")
     public <T> T find(Class<T> cls, Object oid) {
         assertNotCloseInvoked();
+        if (oid == null)
+        	return null;
         oid = _broker.newObjectId(cls, oid);
         return (T) _broker.find(oid, true, this);
     }
@@ -476,6 +478,8 @@
         if (mode != null && mode != LockModeType.NONE)
             _broker.assertActiveTransaction();
 
+        if (oid == null)
+        	return null;
         processLockProperties(pushFetchPlan(), mode, properties);
         try {
             oid = _broker.newObjectId(cls, oid);

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java?rev=768428&r1=768427&r2=768428&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
Fri Apr 24 22:24:45 2009
@@ -225,7 +225,7 @@
      */
     public void setDefaultAccessType(String type) {
         if ("PROPERTY".equals(type.toUpperCase()))
-            setDefaultAccessType(ClassMetaData.ACCESS_PROPERTY);
+            setDefaultAccessType(AccessCode.PROPERTY);
         else if ("FIELD".equals(type.toUpperCase()))
             setDefaultAccessType(ClassMetaData.ACCESS_FIELD);
         else
@@ -236,9 +236,7 @@
     @Override
     public void populate(ClassMetaData meta, int access) {
     	if (!AccessCode.isSet(access)) {
-    		meta.setAccessType(determineAccessType(meta));
-    	} else {
-    		meta.setAccessType(access);
+    		access = determineAccessType(meta);
     	}
         super.populate(meta, access);
         meta.setDetachable(true);
@@ -276,20 +274,36 @@
      * on members for the given class without an explicit access annotation.
      */
     private int determineAccessType(ClassMetaData meta) {
+    	if (meta == null)
+    		return AccessCode.UNKNOWN;
+        if (meta.getDescribedType().isInterface()) // managed interfaces 
+        	return AccessCode.PROPERTY;
+    	if (AccessCode.isSet(meta.getAccessType()))
+    		return meta.getAccessType();
+    	int access = determineImplicitAccessType(meta.getDescribedType());
+    	if (AccessCode.isSet(access))
+    		return access;
+    	
     	ClassMetaData sup = getCachedSuperclassMetaData(meta);
     	while (sup != null && sup.isExplicitAccess())
-    		sup = sup.getPCSuperclassMetaData();
+    		sup = getCachedSuperclassMetaData(sup);
     	if (sup != null && AccessCode.isSet(sup.getAccessType()))
     		return sup.getAccessType();
     	
-        // traversed entire hierarchy without finding access type
-        if (meta.getDescribedType().isInterface()) // managed interfaces 
-        	return ClassMetaData.ACCESS_PROPERTY;
+        return AccessCode.UNKNOWN;
+    }
+    
+    /**
+     * Determines the access type for the given class by placement of 
+     * annotations on field or getter method.
+     */
+    private int determineImplicitAccessType(Class cls) {
         Field[] allFields = AccessController.doPrivileged(J2DoPrivHelper.
-                getDeclaredFieldsAction(meta.getDescribedType()));
+                getDeclaredFieldsAction(cls));
         List<Field> fields = filter(allFields, nonTransientFilter, 
         		annotatedFilter);
-		Method[] publicMethods = meta.getDescribedType().getMethods();
+		Method[] publicMethods = AccessController.doPrivileged(
+				J2DoPrivHelper.getDeclaredMethodsAction(cls));
         
 		List<Method> getters = filter(publicMethods, getterFilter, 
     		nonTransientFilter, annotatedFilter);
@@ -300,9 +314,9 @@
         		throw new UserException(getters.toString());
         	return ClassMetaData.ACCESS_FIELD;
         } else if (!getters.isEmpty()) {
-        	return ClassMetaData.ACCESS_PROPERTY;
+        	return AccessCode.PROPERTY;
         } 
-        return getDefaultAccessType();
+        return AccessCode.UNKNOWN;
     }
     
     /**
@@ -328,8 +342,6 @@
                     break;
             }
             if (!matched) {
-                System.err.println(_loc.get("getter-unmatched", getter) 
-                    .toString());
                 unmatched.add(getter);
             }
 
@@ -368,7 +380,8 @@
     	boolean isProperty  = AccessCode.isProperty(meta.getAccessType());
     	
     	if (explicit || unknown || isProperty) {
-    		Method[] publicMethods = meta.getDescribedType().getMethods();
+    		Method[] publicMethods = AccessController.doPrivileged(
+              J2DoPrivHelper.getDeclaredMethodsAction(meta.getDescribedType()));
         
     		List<Method> getters = filter(publicMethods, methodFilter, 
                 getterFilter, nonTransientFilter, 
@@ -403,8 +416,7 @@
     	boolean unknown     = !AccessCode.isSet(meta.getAccessType());
     	
     	if (isEmpty) {
-    		if (unknown)
-    			warn(_loc.get("access-unknown", meta));
+    		warn(meta, _loc.get("access-empty", meta));
     		return Collections.EMPTY_LIST;
     	}
     	if (explicit) {
@@ -418,9 +430,9 @@
     		}
     	} else {
     		if (isMixed)
-    			error(_loc.get("access-mixed", meta, fields, getters));
+                error(meta, _loc.get("access-mixed", meta, fields, getters));
     		if (fields.isEmpty()) {
-    			meta.setAccessType(ClassMetaData.ACCESS_PROPERTY);
+    			meta.setAccessType(AccessCode.PROPERTY);
     			members.addAll(getters);
     		} else {
     			meta.setAccessType(ClassMetaData.ACCESS_FIELD);
@@ -434,11 +446,16 @@
     	
     }
     
-    void error(Localizer.Message message) {
-    	System.err.println(message.toString());
+    void error(ClassMetaData meta, Localizer.Message message) {
+    	Log log = meta.getRepository().getConfiguration()
+    		.getLog(OpenJPAConfiguration.LOG_RUNTIME);
+    	log.error(message.toString());
     }
-    void warn(Localizer.Message message) {
-    	System.err.println(message.toString());
+    
+    void warn(ClassMetaData meta, Localizer.Message message) {
+    	Log log = meta.getRepository().getConfiguration()
+		.getLog(OpenJPAConfiguration.LOG_RUNTIME);
+    	log.warn(message.toString());
     }
     
     @Override
@@ -475,11 +492,9 @@
             }            
             try {
                 // check for setters for methods
-                Method setter = AccessController.doPrivileged(
-                    J2DoPrivHelper.getDeclaredMethodAction(
-                        meta.getDescribedType(), "set" +
-                        StringUtils.capitalize(name), new Class[] { 
-                            ((Method) member).getReturnType() }));
+                Method setter = meta.getDescribedType().getMethod(
+                		"set" + StringUtils.capitalize(name), 
+                        new Class[] {((Method) member).getReturnType()});
                 if (setter == null && !isAnnotatedTransient(member)) {
                     logNoSetter(meta, name, null);
                     return false;

Modified: openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties?rev=768428&r1=768427&r2=768428&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
Fri Apr 24 22:24:45 2009
@@ -15,6 +15,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
+access-empty: Found no persistent property in "{0}" 
 close-invoked: You have closed the EntityManager, though the persistence \
     context will remain active until the current transaction commits.
 no-managed-trans: There is no managed transaction in progress to sync this \



Mime
View raw message