openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r768498 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-kernel/src/test/java/org/apache/openjpa/meta/ openjpa-persistence-jdbc/src/test/java/org/apac...
Date Sat, 25 Apr 2009 09:11:12 GMT
Author: ppoddar
Date: Sat Apr 25 09:11:11 2009
New Revision: 768498

URL: http://svn.apache.org/viewvc?rev=768498&view=rev
Log:
OPENJPA-926,OPENJPA-1050: handling corner cases of access type. moving uniformaly to access code. adding type parameters.

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ObjectIdStateManager.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AccessCode.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java
    openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/meta/TestAccessCode.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/AbstractUnenhancedClassTest.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex6/FullName.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.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/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataSerializer.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/kernel/ObjectIdStateManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ObjectIdStateManager.java?rev=768498&r1=768497&r2=768498&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ObjectIdStateManager.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ObjectIdStateManager.java Sat Apr 25 09:11:11 2009
@@ -30,6 +30,7 @@
 import org.apache.openjpa.enhance.StateManager;
 import org.apache.openjpa.enhance.Reflection;
 import org.apache.openjpa.lib.util.J2DoPrivHelper;
+import org.apache.openjpa.meta.AccessCode;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.FieldMetaData;
 import org.apache.openjpa.meta.JavaTypes;
@@ -698,8 +699,7 @@
             val = Reflection.get(_oid, (Field) fmd.getBackingMember());
         else if (fmd.getBackingMember() instanceof Method) 
             val = Reflection.get(_oid, (Method) fmd.getBackingMember());
-        else if (fmd.getDefiningMetaData().getAccessType()
-            == ClassMetaData.ACCESS_FIELD)
+        else if (AccessCode.isField(fmd.getDefiningMetaData().getAccessType()))
             val = Reflection.get(_oid, Reflection.findField(_oid.getClass(), 
                 fmd.getName(), true));
         else 
@@ -733,11 +733,10 @@
         FieldMetaData fmd = getMetaData().getField(field);
         if (fmd.getBackingMember() instanceof Field)
             Reflection.set(_oid, (Field) fmd.getBackingMember(), val);
-        else if (fmd.getDefiningMetaData().getAccessType()
-            == ClassMetaData.ACCESS_FIELD) {
+        else if (AccessCode.isField(fmd.getDefiningMetaData().getAccessType()))
             Reflection.set(_oid, Reflection.findField(_oid.getClass(), 
                 fmd.getName(), true), val);
-        } else
+        else
             Reflection.set(_oid, Reflection.findSetter(_oid.getClass(),
                 fmd.getName(), fmd.getDeclaredType(), true), val);
 	}

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java?rev=768498&r1=768497&r2=768498&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java Sat Apr 25 09:11:11 2009
@@ -51,7 +51,7 @@
     private static final Localizer _loc = Localizer.forPackage
         (AbstractMetaDataDefaults.class);
 
-    private int _access = ClassMetaData.ACCESS_FIELD;
+    private int _access = AccessCode.FIELD;
     private int _identity = ClassMetaData.ID_UNKNOWN;
     private boolean _ignore = true;
     private boolean _interface = true;
@@ -180,7 +180,7 @@
             for (int i = 0; i < fieldNames.length; i ++) {
             	String property = fieldNames[i];
                 member = getMemberByProperty(meta, property);
-                if (member == null) // transient
+                if (member == null) // transient or indeterminable access
                 	continue;
                 fmd = meta.addDeclaredField(property, fieldTypes[i]);
                 fmd.backingMember(member);
@@ -331,29 +331,32 @@
     public Member getBackingMember(FieldMetaData fmd) {
         if (fmd == null)
             return null;
-        try {
-            //### note that we might not have access to declaring metadata yet
-            //### (this could be used during parse), so we have to settle for
-            //### defining.  could cause problems if maps a superclass field
-            //### where the superclass uses a different access type
-            if (fmd.getBackingMember() == null) {
-                if ((fmd.getDefiningMetaData().getAccessType() &
-                    ClassMetaData.ACCESS_FIELD) == ClassMetaData.ACCESS_FIELD)
-                    return AccessController.doPrivileged(
-                        J2DoPrivHelper.getDeclaredFieldAction(
-                            fmd.getDeclaringType(), fmd.getName())); 
-                return Reflection.findGetter(fmd.getDeclaringType(), 
-                    fmd.getName(), true);                
-            } else {
-                return fmd.getBackingMember();
-            }
-        } catch (OpenJPAException ke) {
-            throw ke;
-        } catch (Exception e) {
-            if (e instanceof PrivilegedActionException)
-                e = ((PrivilegedActionException) e).getException();
-            throw new InternalException(e);
-        }
+        if (fmd.getBackingMember() != null)
+        	return fmd.getBackingMember();
+        return getMemberByProperty(fmd.getDeclaringMetaData(), fmd.getName());
+//        try {
+//            //### note that we might not have access to declaring metadata yet
+//            //### (this could be used during parse), so we have to settle for
+//            //### defining.  could cause problems if maps a superclass field
+//            //### where the superclass uses a different access type
+//            if (fmd.getBackingMember() == null) {
+//                if ((fmd.getDefiningMetaData().getAccessType() &
+//                    ClassMetaData.ACCESS_FIELD) == ClassMetaData.ACCESS_FIELD)
+//                    return AccessController.doPrivileged(
+//                        J2DoPrivHelper.getDeclaredFieldAction(
+//                            fmd.getDeclaringType(), fmd.getName())); 
+//                return Reflection.findGetter(fmd.getDeclaringType(), 
+//                    fmd.getName(), true);                
+//            } else {
+//                return fmd.getBackingMember();
+//            }
+//        } catch (OpenJPAException ke) {
+//            throw ke;
+//        } catch (Exception e) {
+//            if (e instanceof PrivilegedActionException)
+//                e = ((PrivilegedActionException) e).getException();
+//            throw new InternalException(e);
+//        }
     }
     
 

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=768498&r1=768497&r2=768498&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 Sat Apr 25 09:11:11 2009
@@ -26,8 +26,10 @@
  * The bits designate following aspects of access style being used at class
  * level:<br>
  * 
- * <LI>Bit position 0 (UNKNOWN): always 0. All bits as zero represent    
- *              that no access style has been set. 
+ * <LI>Bit position 0 (UNKNOWN): generally 0. All bits as zero represent    
+ *              that no access style has been set. 1 denotes that the 
+ *              class has no property at all and its access can not be
+ *              determined.
  * <LI>Bit position 1 (FIELD): Field based access is default
  * <LI>Bit position 2 (PROPERTY): Property based access is default 
  * <LI>Bit position 3 (EXPLICIT): whether explicit or implicit 
@@ -66,6 +68,7 @@
  */
 public class AccessCode {
 	public static int UNKNOWN   = 0;
+	public static int EMPTY     = 1;
 	public static int FIELD     = 2 << 0;
 	public static int PROPERTY  = 2 << 1;
 	public static int EXPLICIT  = 2 << 2;
@@ -75,11 +78,13 @@
 	 * Affirms if the given code is valid. 
 	 */
 	public static boolean isValidClassCode(int code) {
-		return code%2 == 0 // code must be even
+		if (code == EMPTY)
+			return true;
+		return (code%2 == 0 || code == EMPTY) 
 		 && code >= UNKNOWN 
 		 && code <= (MIXED|EXPLICIT|PROPERTY)
          && !(isProperty(code) && isField(code)) // both 1 & 2 can not be set 
-		 && (isProperty(code) || isField(code) || !isSet(code))
+		 && (isProperty(code) || isField(code) || isUnknown(code))
 		 && ((isMixed(code) && isExplicit(code)) || !isMixed(code));
 	}
 	
@@ -88,7 +93,7 @@
 		    && code >= UNKNOWN 
 		    && code <= (EXPLICIT|PROPERTY)
             && !(isProperty(code) && isField(code))
-            && (isProperty(code) || isField(code) || !isSet(code));
+            && (isProperty(code) || isField(code) || isUnknown(code));
 	}
 	
 	/**
@@ -111,8 +116,40 @@
 		return (code & FIELD) != 0;
 	}
 	
-	public static boolean isSet(int code) {
-		return code != UNKNOWN;
+	public static boolean isUnknown(int code) {
+		return code == UNKNOWN;
+	}
+	
+	public static boolean isEmpty(int code) {
+		return code == EMPTY;
+	}
+	
+	public static boolean isField(ClassMetaData meta) {
+		return isField(meta.getAccessType());
+	}
+	
+	public static boolean isProperty(ClassMetaData meta) {
+		return isProperty(meta.getAccessType());
+	}
+	
+	public static boolean isUnknown(ClassMetaData meta) {
+		return isUnknown(meta.getAccessType());
+	}
+	
+	public static boolean isEmpty(ClassMetaData meta) {
+		return isEmpty(meta.getAccessType());
+	}
+	
+	public static boolean isField(FieldMetaData meta) {
+		return isField(meta.getAccessType());
+	}
+	
+	public static boolean isProperty(FieldMetaData meta) {
+		return isProperty(meta.getAccessType());
+	}
+	
+	public static boolean isUnknown(FieldMetaData meta) {
+		return isUnknown(meta.getAccessType());
 	}
 	
 	/**
@@ -120,7 +157,7 @@
 	 * access style.
 	 */
 	public static boolean isCompatibleSuper(int subCode, int superCode) {
-		if (!isSet(superCode))
+		if (isEmpty(superCode))
 			return true;
 		if (isValidClassCode(subCode) && isValidClassCode(superCode)) {
 			if (isExplicit(subCode))
@@ -139,8 +176,8 @@
 	 */
 	public static int mergeFieldCode(int cCode, int fCode) {
 		if (isValidClassCode(cCode) && isValidFieldCode(fCode)) {
-			if (!isSet(cCode)) {
-				if (!isSet(fCode))
+			if (isUnknown(cCode)) {
+				if (isUnknown(fCode))
 					return UNKNOWN;
 				return isProperty(fCode) ? PROPERTY : FIELD;
 			}
@@ -181,6 +218,8 @@
 			return "invalid code " + code;
 		if (code == UNKNOWN)
 			return "unknown access";
+		if (code == EMPTY)
+			return "empty access";
 		return (isMixed(code) ? "mixed " : "") 
 		    + (isExplicit(code) ? "explicit " : "implicit ") 
 		    + (isField(code) ? "field" : "property")

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java?rev=768498&r1=768497&r2=768498&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java Sat Apr 25 09:11:11 2009
@@ -175,7 +175,7 @@
     	new HashMap<Class<?>,Map<String,String>>();
     private int _identity = ID_UNKNOWN;
     private int _idStrategy = ValueStrategies.NONE;
-    private int _accessType = ACCESS_UNKNOWN;
+    private int _accessType = AccessCode.UNKNOWN;
     private boolean _replicated = false;
     
     private String _seqName = DEFAULT_STRING;
@@ -677,13 +677,13 @@
      * Sets the access type. 
      */
     public void setAccessType(int type) {
-    	if (type == _accessType || type == ACCESS_UNKNOWN)
+    	if (type == _accessType || type == AccessCode.UNKNOWN)
     		return;
     	if (!AccessCode.isValidClassCode(type)) {
             throw new IllegalArgumentException(_loc.get("access-type-invalid", 
     		    this, AccessCode.toString(type)).getMessage());
     	}
-    	if (_accessType != ACCESS_UNKNOWN) { // changing access type
+    	if (_accessType != AccessCode.UNKNOWN) { // changing access type
     	    _repos.getLog().warn(_loc.get("access-type-change", 
     		    this, AccessCode.toString(type), 
     		    AccessCode.toString(_accessType)).getMessage());
@@ -2087,7 +2087,7 @@
                     c = fmds[i].getObjectIdFieldType();
             }
 
-            if (fmds[i].getAccessType() == ACCESS_FIELD) {
+            if (AccessCode.isField(fmds[i].getAccessType())) {
                 f = Reflection.findField(oid, fmds[i].getName(), false);
                 if (f == null || !f.getType().isAssignableFrom(c))
                     throw new MetaDataException(_loc.get("invalid-id",
@@ -2123,8 +2123,8 @@
      * same as that of this receiver. 
      */
     private void validateAccessType() {
-        if (!AccessCode.isSet(_accessType) 
-          || AccessCode.isExplicit(_accessType))
+        if (AccessCode.isEmpty(_accessType) 
+           || AccessCode.isExplicit(_accessType))
             return;
         ClassMetaData sup = getPCSuperclassMetaData();
         while (sup != null && sup.isExplicitAccess())

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java?rev=768498&r1=768497&r2=768498&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java Sat Apr 25 09:11:11 2009
@@ -72,6 +72,7 @@
  *
  * @author Abe White
  */
+@SuppressWarnings("serial")
 public class FieldMetaData
     extends Extensions
     implements ValueMetaData, MetaDataContext, MetaDataModes, Commentable {
@@ -137,13 +138,13 @@
     private final ValueMetaData _elem;
     private final ClassMetaData _owner;
     private final String _name;
-    private Class _dec = null;
+    private Class<?> _dec = null;
     private ClassMetaData _decMeta = null;
     private String _fullName = null;
     private String _embedFullName = null;
     private int _resMode = MODE_NONE;
     private String _mappedByIdValue = null;
-    private int _access = ClassMetaData.ACCESS_UNKNOWN;
+    private int _access = AccessCode.UNKNOWN;
 
     // load/store info
     private String[] _comments = null;
@@ -154,7 +155,7 @@
     ////////////////////////////////////////////////////////////////////
 
     // misc info
-    private Class _proxyClass = null;
+    private Class<?> _proxyClass = null;
     private Object _initializer = null;
     private boolean _transient = false;
     private boolean _primKey = false;
@@ -166,7 +167,7 @@
     private int _pkIndex = -1;
     private boolean _explicit = false;
     private int _dfg = 0;
-    private Set _fgSet = null;
+    private Set<String> _fgSet = null;
     private String[] _fgs = null;
     private String   _lfg = null;
     private Boolean _lrs = null;
@@ -220,7 +221,7 @@
      * @param type the field type
      * @param owner the owning class metadata
      */
-    protected FieldMetaData(String name, Class type, ClassMetaData owner) {
+    protected FieldMetaData(String name, Class<?> type, ClassMetaData owner) {
         _name = name;
         _owner = owner;
         _dec = null;
@@ -246,18 +247,18 @@
 
         _backingMember = new MemberProvider(member);
 
-        Class type;
-        Class[] types;
+        Class<?> type;
+        Class<?>[] types;
         if (member instanceof Field) {
             Field f = (Field) member;
             type = f.getType();
             types = JavaVersions.getParameterizedTypes(f);
-            setAccessType(ClassMetaData.ACCESS_FIELD);
+            setAccessType(AccessCode.FIELD);
         } else {
             Method meth = (Method) member;
             type = meth.getReturnType();
             types = JavaVersions.getParameterizedTypes(meth);
-            setAccessType(ClassMetaData.ACCESS_PROPERTY);
+            setAccessType(AccessCode.PROPERTY);
         }
 
         setDeclaredType(type);
@@ -305,7 +306,7 @@
     /**
      * The declaring class.
      */
-    public void setDeclaringType(Class cls) {
+    public void setDeclaringType(Class<?> cls) {
         _dec = cls;
         _decMeta = null;
         _fullName = null;
@@ -397,7 +398,7 @@
      * The type this field was initialized with, and therefore the
      * type to use for proxies when loading data into this field.
      */
-    public Class getProxyType() {
+    public Class<?> getProxyType() {
         return (_proxyClass == null) ? getDeclaredType() : _proxyClass;
     }
 
@@ -405,7 +406,7 @@
      * The type this field was initialized with, and therefore the
      * type to use for proxies when loading data into this field.
      */
-    public void setProxyType(Class type) {
+    public void setProxyType(Class<?> type) {
         _proxyClass = type;
     }
 
@@ -568,7 +569,7 @@
      * For a primary key field, return the type of the corresponding object id 
      * class field.
      */
-    public Class getObjectIdFieldType() {
+    public Class<?> getObjectIdFieldType() {
         ClassMetaData relmeta = getDeclaredTypeMetaData();
         if (relmeta == null || getValue().isEmbedded())
             return getDeclaredType();
@@ -640,8 +641,8 @@
 
     private boolean isEnum() {
         if (_enumField == null) {
-            Class dt = getDeclaredType();
-            _enumField = JavaVersions.isEnumeration(dt)
+            Class<?> decl = getDeclaredType();
+            _enumField = JavaVersions.isEnumeration(decl)
                 ? Boolean.TRUE : Boolean.FALSE;
         }
         return _enumField.booleanValue();
@@ -649,8 +650,8 @@
 
     private boolean isSerializable() {
         if (_serializableField == null) {
-            Class dt = getDeclaredType();
-            if (Serializable.class.isAssignableFrom(dt))
+            Class<?> decl = getDeclaredType();
+            if (Serializable.class.isAssignableFrom(decl))
                 _serializableField = Boolean.TRUE;
             else
                 _serializableField = Boolean.FALSE;
@@ -661,9 +662,9 @@
     private boolean isLobArray() {
         // check for byte[], Byte[], char[], Character[]
         if (_lobField == null) {
-            Class dt = getDeclaredType();
-            if (dt == byte[].class || dt == Byte[].class ||
-                dt == char[].class || dt == Character[].class)
+            Class<?> decl = getDeclaredType();
+            if (decl == byte[].class || decl == Byte[].class ||
+                decl == char[].class || decl == Character[].class)
                 _lobField = Boolean.TRUE;
             else
                 _lobField = Boolean.FALSE;
@@ -767,7 +768,7 @@
         if (_owner.getFetchGroup(fg) == null)
             throw new MetaDataException(_loc.get("unknown-fg", fg, this));
         if (in && _fgSet == null)
-            _fgSet = new HashSet();
+            _fgSet = new HashSet<String>();
         if ((in && _fgSet.add(fg))
             || (!in && _fgSet != null && _fgSet.remove(fg)))
             _fgs = null;
@@ -922,7 +923,7 @@
                     break;
             }
 
-            Collection inverses = null;
+            Collection<FieldMetaData> inverses = null;
             if (meta != null) {
                 // add mapped by and named inverse, if any
                 FieldMetaData field = getMappedByMetaData();
@@ -931,7 +932,7 @@
                     // inverses must be
                     if (field.getTypeCode() == JavaTypes.PC
                         || field.getElement().getTypeCode() == JavaTypes.PC) {
-                        inverses = new ArrayList(3);
+                        inverses = new ArrayList<FieldMetaData>(3);
                         inverses.add(field);
                     }
                 } else if (inv != null) {
@@ -939,13 +940,13 @@
                     if (field == null)
                         throw new MetaDataException(_loc.get("no-inverse",
                             this, inv));
-                    inverses = new ArrayList(3);
+                    inverses = new ArrayList<FieldMetaData>(3);
                     inverses.add(field);
                 }
 
                 // scan rel type for fields that name this field as an inverse
                 FieldMetaData[] fields = meta.getFields();
-                Class type = getDeclaringMetaData().getDescribedType();
+                Class<?> type = getDeclaringMetaData().getDescribedType();
                 for (int i = 0; i < fields.length; i++) {
                     // skip fields that aren't compatible with our owning class
                     switch (fields[i].getTypeCode()) {
@@ -969,7 +970,7 @@
                     if (_name.equals(fields[i].getMappedBy())
                         || _name.equals(fields[i].getInverse())) {
                         if (inverses == null)
-                            inverses = new ArrayList(3);
+                            inverses = new ArrayList<FieldMetaData>(3);
                         if (!inverses.contains(fields[i]))
                             inverses.add(fields[i]);
                     }
@@ -980,7 +981,7 @@
             if (inverses == null)
                 _inverses = repos.EMPTY_FIELDS;
             else
-                _inverses = (FieldMetaData[]) inverses.toArray
+                _inverses = inverses.toArray
                     (repos.newFieldMetaDataArray(inverses.size()));
         }
         return _inverses;
@@ -1224,17 +1225,17 @@
             return val;
 
         // create a comparator for the elements of the value
-        Comparator comp;
+        Comparator<?> comp;
         if (orders.length == 1)
             comp = orders[0].getComparator();
         else {
-            List comps = null;
-            Comparator curComp;
+            List<Comparator<?>> comps = null;
+            Comparator<?> curComp;
             for (int i = 0; i < orders.length; i++) {
                 curComp = orders[i].getComparator();
                 if (curComp != null) {
                     if (comps == null)
-                        comps = new ArrayList(orders.length);
+                        comps = new ArrayList<Comparator<?>>(orders.length);
                     if (i != comps.size())
                         throw new MetaDataException(_loc.get
                             ("mixed-inmem-ordering", this));
@@ -1584,8 +1585,8 @@
         String methodName = Strings.getClassName(method);
         String clsName = Strings.getPackageName(method);
 
-        Class cls = null;
-        Class owner = _owner.getDescribedType();
+        Class<?> cls = null;
+        Class<?> owner = _owner.getDescribedType();
 
         if (clsName.length() == 0)
             cls = getDeclaredType();
@@ -1597,14 +1598,14 @@
 
         // find the named method
         Method[] methods = cls.getMethods();
-        Class[] params;
+        Class<?>[] params;
         for (int i = 0; i < methods.length; i++) {
             if (methods[i].getName().equals(methodName)) {
                 params = methods[i].getParameterTypes();
 
                 // static factory methods require one argument or one argument
-                // plus a ctx; non-static methods require zero arguments or
-                // just a ctx
+                // plus a context; non-static methods require zero arguments or
+                // just a context
                 if (Modifier.isStatic(methods[i].getModifiers())
                     && (params.length == 1 || (params.length == 2
                     && isStoreContextParameter(params[1]))))
@@ -1624,7 +1625,7 @@
      * use the standard <code>isAssignableFrom</code> because of classloader
      * oddness.
      */
-    private static boolean isStoreContextParameter(Class type) {
+    private static boolean isStoreContextParameter(Class<?> type) {
         return StoreContext.class.getName().equals(type.getName());
     }
 
@@ -1717,7 +1718,7 @@
                 _owner.getDescribedType())
             || (validate & MetaDataRepository.VALIDATE_UNENHANCED) == 0)) {
             validateLRS();
-            if ((validate & repos.VALIDATE_RUNTIME) == 0)
+            if ((validate & MetaDataRepository.VALIDATE_RUNTIME) == 0)
                 validateSupportedType();
             validateValue();
             validateExtensionKeys();
@@ -1736,7 +1737,7 @@
         if (getTypeCode() == JavaTypes.ARRAY)
             throw new MetaDataException(_loc.get("bad-lrs-array", this));
 
-        // can't use lrs for extranalized vals
+        // can't use lrs for externalized vals
         if (getExternalizerMethod() != null)
             throw new MetaDataException(_loc.get("bad-lrs-extern", this));
 
@@ -1752,12 +1753,12 @@
     private void validateSupportedType() {
         // log warnings about things we don't handle
         OpenJPAConfiguration conf = getRepository().getConfiguration();
-        Collection opts = conf.supportedOptions();
-        Log log = conf.getLog(conf.LOG_METADATA);
+        Collection<String> opts = conf.supportedOptions();
+        Log log = conf.getLog(OpenJPAConfiguration.LOG_METADATA);
         switch (getTypeCode()) {
             case JavaTypes.PC:
-                if (isEmbedded() &&
-                    !opts.contains(conf.OPTION_EMBEDDED_RELATION)) {
+                if (isEmbedded() && !opts.contains(
+                	OpenJPAConfiguration.OPTION_EMBEDDED_RELATION)) {
                     setEmbedded(false);
                     if (log.isWarnEnabled())
                         log.warn(_loc.get("cant-embed", this));
@@ -1769,44 +1770,42 @@
                 }
                 break;
             case JavaTypes.COLLECTION:
-                if (!opts.contains(conf.OPTION_TYPE_COLLECTION))
+                if (!opts.contains(OpenJPAConfiguration.OPTION_TYPE_COLLECTION))
                     throw new UnsupportedException(
                         _loc.get("type-not-supported",
                             "Collection", this));
-                if (_elem.isEmbeddedPC()
-                    && !opts.contains(conf.OPTION_EMBEDDED_COLLECTION_RELATION))
-                {
+                if (_elem.isEmbeddedPC() && !opts.contains(
+                    OpenJPAConfiguration.OPTION_EMBEDDED_COLLECTION_RELATION)){
                     _elem.setEmbedded(false);
                     if (log.isWarnEnabled())
                         log.warn(_loc.get("cant-embed-element", this));
                 }
                 break;
             case JavaTypes.ARRAY:
-                if (!opts.contains(conf.OPTION_TYPE_ARRAY))
+                if (!opts.contains(OpenJPAConfiguration.OPTION_TYPE_ARRAY))
                     throw new UnsupportedException(
                         _loc.get("type-not-supported",
                             "Array", this));
-                if (_elem.isEmbeddedPC()
-                    && !opts.contains(conf.OPTION_EMBEDDED_COLLECTION_RELATION))
-                {
+                if (_elem.isEmbeddedPC() && !opts.contains(
+                    OpenJPAConfiguration.OPTION_EMBEDDED_COLLECTION_RELATION)) {
                     _elem.setEmbedded(false);
                     if (log.isWarnEnabled())
                         log.warn(_loc.get("cant-embed-element", this));
                 }
                 break;
             case JavaTypes.MAP:
-                if (!opts.contains(conf.OPTION_TYPE_MAP))
+                if (!opts.contains(OpenJPAConfiguration.OPTION_TYPE_MAP))
                     throw new UnsupportedException(
                         _loc.get("type-not-supported",
                             "Map", this));
-                if (_elem.isEmbeddedPC()
-                    && !opts.contains(conf.OPTION_EMBEDDED_MAP_RELATION)) {
+                if (_elem.isEmbeddedPC() && !opts.contains(
+                	OpenJPAConfiguration.OPTION_EMBEDDED_MAP_RELATION)) {
                     _elem.setEmbedded(false);
                     if (log.isWarnEnabled())
                         log.warn(_loc.get("cant-embed-element", this));
                 }
-                if (_key.isEmbeddedPC()
-                    && !opts.contains(conf.OPTION_EMBEDDED_MAP_RELATION)) {
+                if (_key.isEmbeddedPC() && !opts.contains(
+                	OpenJPAConfiguration.OPTION_EMBEDDED_MAP_RELATION)) {
                     _key.setEmbedded(false);
                     if (log.isWarnEnabled())
                         log.warn(_loc.get("cant-embed-key", this));
@@ -2056,23 +2055,19 @@
         _val.setValueMappedBy(mapped);
     }
 
-    public FieldMetaData getValueMappedByMetaData ()
-	{
+    public FieldMetaData getValueMappedByMetaData () {
 		return _val.getValueMappedByMetaData ();
 	}
 
-	public Class getTypeOverride ()
-	{
+	public Class<?> getTypeOverride () {
 		return _val.getTypeOverride ();
 	}
 
-	public void setTypeOverride (Class type)
-	{
+	public void setTypeOverride(Class type) {
 		_val.setTypeOverride (type);
 	}
 
-	public void copy (ValueMetaData vmd)
-	{
+	public void copy (ValueMetaData vmd) {
 		_val.copy (vmd);
 	}
 
@@ -2121,7 +2116,7 @@
         public void readExternal(ObjectInput in)
             throws IOException, ClassNotFoundException {
             boolean isField = in.readBoolean();
-            Class cls = (Class) in.readObject();
+            Class<?> cls = (Class<?>) in.readObject();
             String memberName = (String) in.readObject();
             try {
                 if (isField)
@@ -2129,7 +2124,7 @@
                         J2DoPrivHelper.getDeclaredFieldAction(
                             cls, memberName)); 
                 else {
-                    Class[] parameterTypes = (Class[]) in.readObject();
+                    Class<?>[] parameterTypes = (Class[]) in.readObject();
                     _member = AccessController.doPrivileged(
                         J2DoPrivHelper.getDeclaredMethodAction(
                             cls, memberName, parameterTypes));
@@ -2187,11 +2182,10 @@
     
     /**
      * Gets the access type used by this field. If no access type is set for
-     * this field then return the default access type used by the declaring 
-     * class.
+     * this field then return the access type used by the declaring class.
      */
     public int getAccessType() {
-        if (!AccessCode.isSet(_access)) {
+        if (AccessCode.isUnknown(_access)) {
         	int fCode = AccessCode.toFieldCode(getDeclaringMetaData()
         			.getAccessType());
         	return fCode;

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java?rev=768498&r1=768497&r2=768498&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java Sat Apr 25 09:11:11 2009
@@ -191,7 +191,7 @@
         _embeddedMeta = repos.newEmbeddedClassMetaData(this);
         _embeddedMeta.setDescribedType(_decType);
         repos.getMetaDataFactory().getDefaults().populate(_embeddedMeta,
-            ClassMetaData.ACCESS_UNKNOWN);
+            AccessCode.UNKNOWN);
 
         setEmbedded(true);
         return _embeddedMeta;

Modified: openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/meta/TestAccessCode.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/meta/TestAccessCode.java?rev=768498&r1=768497&r2=768498&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/meta/TestAccessCode.java (original)
+++ openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/meta/TestAccessCode.java Sat Apr 25 09:11:11 2009
@@ -38,8 +38,8 @@
 		isValidClassCode(true,  28, MIXED | EXPLICIT | PROPERTY);
 		isValidClassCode(false, 30, MIXED | EXPLICIT | FIELD | PROPERTY);
 		
-		// All odd codes are invalid
-		for (int i = 1; i < 32; i += 2)
+		// All odd codes other than 1 are invalid
+		for (int i = 3; i < 32; i += 2)
 			assertFalse("Not a valid Class Code: " + AccessCode.toString(i), 
 				AccessCode.isValidClassCode(i));
 	}

Modified: 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?rev=768498&r1=768497&r2=768498&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/AbstractUnenhancedClassTest.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/AbstractUnenhancedClassTest.java Sat Apr 25 09:11:11 2009
@@ -31,6 +31,7 @@
 import org.apache.openjpa.persistence.OpenJPAEntityManager;
 import org.apache.openjpa.persistence.JPAFacadeHelper;
 import org.apache.openjpa.kernel.OpenJPAStateManager;
+import org.apache.openjpa.meta.AccessCode;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.util.ImplHelper;
 import org.apache.openjpa.event.AbstractLifecycleListener;
@@ -307,8 +308,8 @@
         // 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)) {
+            || (!userDefined 
+            	&& AccessCode.isProperty(sm.getMetaData().getAccessType()))) {
 
             assertFalse(sm.getLoaded()
                 .get(sm.getMetaData().getField("stringField").getIndex()));
@@ -359,8 +360,7 @@
         // 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()
-            || (sm.getMetaData().getAccessType() != ClassMetaData.ACCESS_FIELD))
-        {
+            || AccessCode.isProperty(sm.getMetaData().getAccessType())) {
             assertFalse(sm.getLoaded()
                 .get(sm.getMetaData().getField("lazyField").getIndex()));
 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex6/FullName.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex6/FullName.java?rev=768498&r1=768497&r2=768498&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex6/FullName.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex6/FullName.java Sat Apr 25 09:11:11 2009
@@ -18,9 +18,12 @@
  */
 package org.apache.openjpa.persistence.jdbc.maps.m2mmapex6;
 
+import javax.persistence.Access;
+import javax.persistence.AccessType;
 import javax.persistence.Embeddable;
 
 @Embeddable
+@Access(AccessType.FIELD)
 public class FullName {
 
     String fName;

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml?rev=768498&r1=768497&r2=768498&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml Sat Apr 25 09:11:11 2009
@@ -110,6 +110,8 @@
         <class>org.apache.openjpa.persistence.embed.EmbedXml</class>
         <class>org.apache.openjpa.persistence.embed.CustomerXml</class>
         <class>org.apache.openjpa.persistence.embed.OrderXml</class>
+        <class>org.apache.openjpa.persistence.embed.attrOverrides.AddressXml</class>
+        <class>org.apache.openjpa.persistence.embed.attrOverrides.ZipcodeXml</class>
         <properties>
             <property name="openjpa.jdbc.SynchronizeMappings"
                   value="buildSchema(ForeignKeys=true)"/>

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?rev=768498&r1=768497&r2=768498&view=diff
==============================================================================
--- 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 Sat Apr 25 09:11:11 2009
@@ -87,6 +87,7 @@
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import java.util.Stack;
 import java.util.TreeSet;
 
 import javax.persistence.Basic;
@@ -146,6 +147,7 @@
 import org.apache.openjpa.lib.meta.SourceTracker;
 import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.meta.AccessCode;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.DelegatingMetaDataFactory;
 import org.apache.openjpa.meta.FieldMetaData;
@@ -247,7 +249,8 @@
     private final Map<Package, Integer> _pkgs = new HashMap<Package, Integer>();
 
     // the class we were invoked to parse
-    protected Class _cls = null;
+    protected Class<?> _cls = null;
+    protected Stack<Class<?>> _stack = new Stack<Class<?>>();
     private File _file = null;
 
     /**
@@ -393,6 +396,7 @@
      * Clear caches.
      */
     public void clear() {
+    	_stack.clear();
         _cls = null;
         _file = null;
         _pkgs.clear();
@@ -406,12 +410,14 @@
             _log.trace(_loc.get("parse-class", cls.getName()));
 
         _cls = cls;
+        _stack.push(cls);
         try {
             parsePackageAnnotations();
             ClassMetaData meta = parseClassAnnotations();
             updateSourceMode(meta);
         } finally {
-            _cls = null;
+        	_stack.pop();
+            _cls = _stack.isEmpty() ? null : _stack.peek();
             _file = null;
         }
     }
@@ -540,9 +546,11 @@
         if (meta == null)
             return null;
 
-        Entity entity = (Entity) _cls.getAnnotation(Entity.class);
+        Entity entity = _cls.getAnnotation(Entity.class);
+        MappedSuperclass mapped = _cls.getAnnotation(MappedSuperclass.class);
+        Embeddable embeddable = _cls.getAnnotation(Embeddable.class);
         if (isMetaDataMode()) {
-            meta.setAbstract(_cls.getAnnotation(MappedSuperclass.class) !=null);
+            meta.setAbstract(mapped != null);
             // while the spec only provides for embedded exclusive, it doesn't
             // seem hard to support otherwise
             if (entity == null)
@@ -696,9 +704,9 @@
      */    
     private void parseAccess(ClassMetaData meta, Access access) {
     	if (access != null) {
-    		meta.setAccessType(ClassMetaData.ACCESS_EXPLICIT 
+    		meta.setAccessType(AccessCode.EXPLICIT 
             | (access.value() == AccessType.FIELD ? 
-            	ClassMetaData.ACCESS_FIELD : ClassMetaData.ACCESS_PROPERTY));
+            	AccessCode.FIELD : AccessCode.PROPERTY));
     	}
     }
 
@@ -746,13 +754,13 @@
      * other entity classes or mapped super classes in the entity hierarchy.
      */
     private int getAccessCode(Class<?> cls) {
-        int accessCode = ClassMetaData.ACCESS_UNKNOWN;
+        int accessCode = AccessCode.UNKNOWN;
         Access access = AccessController.doPrivileged(
             J2DoPrivHelper.getAnnotationAction(cls, Access.class));
         if (access != null) {
-            accessCode |=  ClassMetaData.ACCESS_EXPLICIT | 
+            accessCode |=  AccessCode.EXPLICIT | 
                 (access.value() == AccessType.FIELD ? 
-                ClassMetaData.ACCESS_FIELD : ClassMetaData.ACCESS_PROPERTY);
+                AccessCode.FIELD : AccessCode.PROPERTY);
         }
         return accessCode;
     }
@@ -1839,9 +1847,9 @@
      */    
     private void parseAccess(FieldMetaData meta, Access access) {
     	if (access != null) {
-    		meta.setAccessType(ClassMetaData.ACCESS_EXPLICIT 
+    		meta.setAccessType(AccessCode.EXPLICIT 
             | (access.value() == AccessType.FIELD ? 
-            	ClassMetaData.ACCESS_FIELD : ClassMetaData.ACCESS_PROPERTY));
+            		AccessCode.FIELD : AccessCode.PROPERTY));
     	}
     }
 

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=768498&r1=768497&r2=768498&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 Sat Apr 25 09:11:11 2009
@@ -478,8 +478,6 @@
         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=768498&r1=768497&r2=768498&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 Sat Apr 25 09:11:11 2009
@@ -64,11 +64,14 @@
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.FieldMetaData;
 import org.apache.openjpa.meta.JavaTypes;
+import org.apache.openjpa.meta.MetaDataRepository;
 import org.apache.openjpa.meta.ValueMetaData;
 
 import static javax.persistence.AccessType.FIELD;
 import static javax.persistence.AccessType.PROPERTY;
 import static org.apache.openjpa.persistence.PersistenceStrategy.*;
+
+import org.apache.openjpa.util.InternalException;
 import org.apache.openjpa.util.MetaDataException;
 import org.apache.openjpa.util.UserException;
 import org.apache.openjpa.conf.OpenJPAConfiguration;
@@ -227,17 +230,28 @@
         if ("PROPERTY".equals(type.toUpperCase()))
             setDefaultAccessType(AccessCode.PROPERTY);
         else if ("FIELD".equals(type.toUpperCase()))
-            setDefaultAccessType(ClassMetaData.ACCESS_FIELD);
+            setDefaultAccessType(AccessCode.FIELD);
         else
         	throw new IllegalArgumentException(_loc.get("access-invalid", 
         	    type).toString());
     }
 
+    /**
+     * Populates the given class metadata. The access style determines which
+     * field and/or getter method will contribute as the persistent property
+     * of the given class. If the given access is unknown, then the access
+     * type is to be determined at first. 
+     * 
+     * @see #determineAccessType(ClassMetaData)
+     */
     @Override
     public void populate(ClassMetaData meta, int access) {
-    	if (!AccessCode.isSet(access)) {
+    	if (AccessCode.isUnknown(access)) {
     		access = determineAccessType(meta);
     	}
+    	if (AccessCode.isUnknown(access)) {
+    		error(meta, _loc.get("access-unknown", meta));
+    	}
         super.populate(meta, access);
         meta.setDetachable(true);
         // do not call get*Fields as it will lock down the fields.
@@ -263,63 +277,100 @@
     ClassMetaData getCachedSuperclassMetaData(ClassMetaData meta) {
     	if (meta == null)
     		return null;
-    	Class<?> sup = meta.getDescribedType().getSuperclass();
+    	Class<?> cls = meta.getDescribedType();
+    	Class<?> sup = cls.getSuperclass();
     	if (sup == null)
     		return null;
-    	return meta.getRepository().getCachedMetaData(sup);
+    	MetaDataRepository repos = meta.getRepository();
+    	ClassMetaData supMeta = repos.getCachedMetaData(sup);
+    	if (supMeta == null)
+    		supMeta = repos.getMetaData(sup, null, false);
+    	return supMeta;
     }
 
     /**
      * Recursive helper to determine access type based on annotation placement
      * on members for the given class without an explicit access annotation.
+     * 
+     * @return must return a not-unknown access code 
      */
     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()))
+    	if (!AccessCode.isUnknown(meta))
     		return meta.getAccessType();
-    	int access = determineImplicitAccessType(meta.getDescribedType());
-    	if (AccessCode.isSet(access))
+    	int access = determineExplicitAccessType(meta.getDescribedType());
+    	if (!AccessCode.isUnknown(access))
+    		return access;
+    	access = determineImplicitAccessType(meta.getDescribedType());
+    	if (!AccessCode.isUnknown(access))
     		return access;
     	
     	ClassMetaData sup = getCachedSuperclassMetaData(meta);
     	while (sup != null && sup.isExplicitAccess())
     		sup = getCachedSuperclassMetaData(sup);
-    	if (sup != null && AccessCode.isSet(sup.getAccessType()))
+    	if (sup != null && !AccessCode.isUnknown(sup))
     		return sup.getAccessType();
     	
-        return AccessCode.UNKNOWN;
+        return AccessCode.FIELD;
     }
     
     /**
      * Determines the access type for the given class by placement of 
-     * annotations on field or getter method.
+     * annotations on field or getter method. Does not consult the
+     * super class.
+     * 
+     * Annotation can be placed on either fields or getters but not on both.
+     * If no field or getter is annotated then UNKNOWN access code is returned.
      */
-    private int determineImplicitAccessType(Class cls) {
+    private int determineImplicitAccessType(Class<?> cls) {
+    	if (cls.isInterface()) // Managed interfaces
+    		return AccessCode.PROPERTY;
         Field[] allFields = AccessController.doPrivileged(J2DoPrivHelper.
                 getDeclaredFieldsAction(cls));
-        List<Field> fields = filter(allFields, nonTransientFilter, 
-        		annotatedFilter);
-		Method[] publicMethods = AccessController.doPrivileged(
+		Method[] methods = AccessController.doPrivileged(
 				J2DoPrivHelper.getDeclaredMethodsAction(cls));
+        List<Field> fields = filter(allFields, nonTransientFilter);
+        List<Method> getters = filter(methods, getterFilter, 
+        		nonTransientFilter);
+        if (fields.isEmpty() && getters.isEmpty())
+        	return AccessCode.EMPTY;
         
-		List<Method> getters = filter(publicMethods, getterFilter, 
-    		nonTransientFilter, annotatedFilter);
-		List<Method> setters = filter(publicMethods, setterFilter);
+        fields = filter(fields, annotatedFilter);
+        getters = filter(getters, annotatedFilter);
+        
+		List<Method> setters = filter(methods, setterFilter);
         getters =  matchGetterAndSetter(getters, setters);
+        
+        boolean mixed = !fields.isEmpty() && !getters.isEmpty();
+        if (mixed)
+        	throw new UserException(_loc.get("access-mixed", 
+        		cls, toFieldNames(fields), toMethodNames(getters)));
         if (!fields.isEmpty()) {
-        	if (!getters.isEmpty())
-        		throw new UserException(getters.toString());
-        	return ClassMetaData.ACCESS_FIELD;
-        } else if (!getters.isEmpty()) {
+        	return AccessCode.FIELD;
+        } 
+        if (!getters.isEmpty()) {
         	return AccessCode.PROPERTY;
         } 
         return AccessCode.UNKNOWN;
     }
     
     /**
+     * Explicit access type, if any, is generally detected by the parser. This
+     * is only used for metadata of an embeddable type which is encountered
+     * as a field during some other owning entity.
+     * 
+     * @see ValueMetaData#addEmbeddedMetaData()
+     */
+    private int determineExplicitAccessType(Class<?> cls) {
+    	Access access = cls.getAnnotation(Access.class);
+        return access == null ? AccessCode.UNKNOWN : (access.value() == 
+        	AccessType.FIELD ? AccessCode.FIELD : AccessCode.PROPERTY);
+    }
+    
+    /**
      * Matches the given getters with the given setters. Removes the getters
      * that do not have a corresponding setter.
      */
@@ -356,8 +407,8 @@
      */
     List<Field> getPersistentFields(ClassMetaData meta) {
     	boolean explicit = meta.isExplicitAccess();
-    	boolean unknown  = !AccessCode.isSet(meta.getAccessType());
-    	boolean isField  = AccessCode.isField(meta.getAccessType());
+    	boolean unknown  = AccessCode.isUnknown(meta);
+    	boolean isField  = AccessCode.isField(meta);
     	
     	if (explicit || unknown || isField) {
     		Field[] fields = AccessController.doPrivileged(J2DoPrivHelper.
@@ -376,7 +427,7 @@
      */
     List<Method> getPersistentMethods(ClassMetaData meta) {
     	boolean explicit = meta.isExplicitAccess();
-    	boolean unknown  = !AccessCode.isSet(meta.getAccessType());
+    	boolean unknown  = AccessCode.isUnknown(meta.getAccessType());
     	boolean isProperty  = AccessCode.isProperty(meta.getAccessType());
     	
     	if (explicit || unknown || isProperty) {
@@ -413,7 +464,7 @@
     	boolean isEmpty = fields.isEmpty() && getters.isEmpty();
 
     	boolean explicit    = meta.isExplicitAccess();
-    	boolean unknown     = !AccessCode.isSet(meta.getAccessType());
+    	boolean unknown     = AccessCode.isUnknown(meta.getAccessType());
     	
     	if (isEmpty) {
     		warn(meta, _loc.get("access-empty", meta));
@@ -435,7 +486,7 @@
     			meta.setAccessType(AccessCode.PROPERTY);
     			members.addAll(getters);
     		} else {
-    			meta.setAccessType(ClassMetaData.ACCESS_FIELD);
+    			meta.setAccessType(AccessCode.FIELD);
     			members.addAll(fields);
     		}
     	}
@@ -450,6 +501,7 @@
     	Log log = meta.getRepository().getConfiguration()
     		.getLog(OpenJPAConfiguration.LOG_RUNTIME);
     	log.error(message.toString());
+    	throw new UserException(message.toString());
     }
     
     void warn(ClassMetaData meta, Localizer.Message message) {
@@ -554,38 +606,39 @@
     @Override
     protected Member getMemberByProperty(ClassMetaData meta, String property) {
     	Class<?> cls = meta.getDescribedType();
-    	int classAccessCode = meta.getAccessType();
         Field field = Reflection.findField(cls, property, false);;
         Method getter = Reflection.findGetter(cls, property, false);
     	if (isAnnotated(field) && isAnnotated(getter))
     		throw new IllegalStateException(_loc.get("access-duplicate", 
     			field, getter).toString());
     	
-        if (AccessCode.isField(classAccessCode)) {
+        if (AccessCode.isField(meta)) {
            if (isAnnotatedAccess(getter, AccessType.PROPERTY)) {
         	   meta.setAccessType(AccessCode.MIXED | meta.getAccessType());
                return getter;
            }
            return field; 
-        } else if (AccessCode.isProperty(classAccessCode)) {
+        } else if (AccessCode.isProperty(meta)) {
             if (isAnnotatedAccess(field, AccessType.FIELD)) {
          	   meta.setAccessType(AccessCode.MIXED | meta.getAccessType());
                return field;
             }            
             return getter;
-        } else if (!AccessCode.isSet(classAccessCode)) {
+        } else if (AccessCode.isUnknown(meta)) {
         	if (isAnnotated(field)) {
         		meta.setAccessType(AccessCode.FIELD);
         		return field;
-        	}
-        	if (isAnnotated(getter)) {
+        	} else if (isAnnotated(getter)) {
         		meta.setAccessType(AccessCode.PROPERTY);
         		return getter;
+        	} else {
+        		warn(meta, _loc.get("access-none", meta, property));
+        		throw new IllegalStateException(
+                    _loc.get("access-none", meta, property).toString());
         	}
-        	throw new IllegalStateException("access-none " + property);
         } else {
-        	throw new IllegalStateException(meta + " " + 
-        			AccessCode.toString(classAccessCode));
+        	throw new InternalException(meta + " " + 
+        		AccessCode.toString(meta.getAccessType()));
         }
     }
     
@@ -625,6 +678,23 @@
         }
         return result;
     }
+    
+    <T extends AnnotatedElement> List<T> filter(List<T> list, 
+        	InclusiveFilter... filters) {
+        List<T> result = new ArrayList<T>();
+        for (T e : list) {
+            boolean include = true;
+            for (InclusiveFilter f : filters) {
+                if (f != null && !f.includes(e)) {
+                    include = false;
+                    break;
+                }
+            }
+            if (include)
+                result.add(e);
+        }
+        return result;
+    }
 
     /**
      * Selects getter method. A getter method name starts with 'get', returns a
@@ -745,4 +815,12 @@
         return meta.getRepository().getConfiguration()
             .getLog(OpenJPAConfiguration.LOG_METADATA);
     }
+    
+    String toFieldNames(List<Field> fields) {
+    	return fields.toString();
+    }
+    
+    String toMethodNames(List<Method> methods) {
+    	return methods.toString();
+    }
 }

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java?rev=768498&r1=768497&r2=768498&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java Sat Apr 25 09:11:11 2009
@@ -79,7 +79,7 @@
     private AnnotationPersistenceMetaDataParser _annoParser = null;
     private AnnotationPersistenceXMLMetaDataParser _annoXMLParser = null;
     private XMLPersistenceMetaDataParser _xmlParser = null;
-    private Map<URL, Set> _xml = null; // xml rsrc -> class names
+    private Map<URL, Set<String>> _xml = null; // xml rsrc -> class names
     private Set<URL> _unparsed = null; // xml rsrc
     private boolean _fieldOverride = true;
 
@@ -176,8 +176,8 @@
     protected XMLPersistenceMetaDataSerializer newXMLSerializer() {
         return new XMLPersistenceMetaDataSerializer(repos.getConfiguration());
     }
-
-    public void load(Class cls, int mode, ClassLoader envLoader) {
+    
+    public void load(Class<?> cls, int mode, ClassLoader envLoader) {
         if (mode == MODE_NONE)
             return;
         if (!strict && (mode & MODE_META) != 0)
@@ -237,7 +237,8 @@
     /**
      * Parse the given XML resource.
      */
-    private void parseXML(URL xml, Class cls, int mode, ClassLoader envLoader) {
+    private void parseXML(URL xml, Class<?> cls, int mode, 
+    	ClassLoader envLoader) {
         // spring needs to use the envLoader first for all class resolution,
         // but we must still fall back on application loader
         ClassLoader loader = repos.getConfiguration().
@@ -268,9 +269,9 @@
     /**
      * Locate the XML resource for the given class.
      */
-    private URL findXML(Class cls) {
+    private URL findXML(Class<?> cls) {
         if (_xml != null && cls != null)
-            for (Map.Entry<URL, Set> entry : _xml.entrySet())
+            for (Map.Entry<URL, Set<String>> entry : _xml.entrySet())
                 if (entry.getValue().contains(cls.getName()))
                     return entry.getKey();
         return null;
@@ -295,19 +296,19 @@
                 "map-persistent-type-names", rsrc, Arrays.asList(names)));
         
         if (_xml == null)
-            _xml = new HashMap<URL, Set>();
-        _xml.put((URL) rsrc, new HashSet(Arrays.asList(names)));
+            _xml = new HashMap<URL, Set<String>>();
+        _xml.put((URL) rsrc, new HashSet<String>(Arrays.asList(names)));
         if (_unparsed == null)
             _unparsed = new HashSet<URL>();
         _unparsed.add((URL) rsrc);
     }
 
     @Override
-    public Class getQueryScope(String queryName, ClassLoader loader) {
+    public Class<?> getQueryScope(String queryName, ClassLoader loader) {
         if (queryName == null)
             return null;
-        Collection classes = repos.loadPersistentTypes(false, loader);
-        for (Class cls : (Collection<Class>) classes) {
+        Collection<Class<?>> classes = repos.loadPersistentTypes(false, loader);
+        for (Class<?> cls :  classes) {
             if ((AccessController.doPrivileged(J2DoPrivHelper
                 .isAnnotationPresentAction(cls, NamedQuery.class)))
                 .booleanValue() && hasNamedQuery
@@ -336,13 +337,13 @@
     }
 
     @Override
-    public Class getResultSetMappingScope(String rsMappingName,
+    public Class<?> getResultSetMappingScope(String rsMappingName,
         ClassLoader loader) {
         if (rsMappingName == null)
             return null;
         
-        Collection classes = repos.loadPersistentTypes(false, loader);
-        for (Class cls : (Collection<Class>) classes) {
+        Collection<Class<?>> classes = repos.loadPersistentTypes(false, loader);
+        for (Class<?> cls : classes) {
 
             if ((AccessController.doPrivileged(J2DoPrivHelper
                 .isAnnotationPresentAction(cls, SqlResultSetMapping.class)))

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java?rev=768498&r1=768497&r2=768498&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java Sat Apr 25 09:11:11 2009
@@ -57,6 +57,7 @@
 import org.apache.openjpa.lib.meta.XMLVersionParser;
 import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.meta.AccessCode;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.DelegatingMetaDataFactory;
 import org.apache.openjpa.meta.FieldMetaData;
@@ -183,7 +184,7 @@
     private Class _cls = null;
     private int _fieldPos = 0;
     private int _clsPos = 0;
-    private int _access = ClassMetaData.ACCESS_UNKNOWN;
+    private int _access = AccessCode.UNKNOWN;
     private PersistenceStrategy _strategy = null;
     private Set<CascadeType> _cascades = null;
     private Set<CascadeType> _pkgCascades = null;
@@ -494,7 +495,7 @@
         _fieldPos = 0;
         _clsPos = 0;
 
-        _access = ClassMetaData.ACCESS_UNKNOWN;
+        _access = AccessCode.UNKNOWN;
         _strategy = null;
         _listener = null;
         _callbacks = null;
@@ -845,13 +846,13 @@
         // if we don't know the default access type, check to see if a 
         // superclass has already defined the access type
         int defaultAccess = _access;
-        if (defaultAccess == ClassMetaData.ACCESS_UNKNOWN) {
+        if (defaultAccess == AccessCode.UNKNOWN) {
             ClassMetaData sup = repos.getCachedMetaData(_cls.getSuperclass());
             if (sup != null)
                 defaultAccess = sup.getAccessType();
         }
 
-        int access = ClassMetaData.ACCESS_UNKNOWN;
+        int access = AccessCode.UNKNOWN;
         if (meta == null) {
             // add metadata for this type
             access = toAccessType(attrs.getValue("access"), defaultAccess);
@@ -934,7 +935,7 @@
      * Default access element.
      */
     private void endAccess() {
-        _access = toAccessType(currentText(), ClassMetaData.ACCESS_UNKNOWN);
+        _access = toAccessType(currentText(), AccessCode.UNKNOWN);
     }
 
     /**
@@ -945,8 +946,8 @@
         if (StringUtils.isEmpty(str))
             return def;
         if ("PROPERTY".equals(str))
-            return ClassMetaData.ACCESS_PROPERTY;
-        return ClassMetaData.ACCESS_FIELD;
+            return AccessCode.PROPERTY;
+        return AccessCode.FIELD;
     }
 
     /**
@@ -1206,8 +1207,8 @@
             Class type = null;
             try {
                 if ((field != null && 
-                    field.getAccessType() == ClassMetaData.ACCESS_PROPERTY) ||
-                    (fldAccess == ClassMetaData.ACCESS_PROPERTY)) {
+                    field.getAccessType() == AccessCode.PROPERTY) ||
+                    (fldAccess == AccessCode.PROPERTY)) {
                     String cap = StringUtils.capitalize(name);
                     type = meta.getDescribedType();
                     try {
@@ -1287,9 +1288,9 @@
         if (attrs != null) {
             String access = attrs.getValue("access");
             if ("PROPERTY".equals(access))
-                return ClassMetaData.ACCESS_PROPERTY;
+                return AccessCode.PROPERTY;
             if ("FIELD".equals(access))
-                return ClassMetaData.ACCESS_FIELD;
+                return AccessCode.FIELD;
         }
         // Check access defined on field, if provided
         if (field != null) {
@@ -1298,9 +1299,9 @@
         // Otherwise, get the default access type of the declaring class
         ClassMetaData meta = (ClassMetaData) currentElement();
         if (meta != null) {
-            return (meta.getAccessType() & ~ClassMetaData.ACCESS_EXPLICIT);
+            return AccessCode.toFieldCode(meta.getAccessType());
         }
-        return ClassMetaData.ACCESS_UNKNOWN;
+        return AccessCode.UNKNOWN;
     }
     
     /**

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataSerializer.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataSerializer.java?rev=768498&r1=768497&r2=768498&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataSerializer.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataSerializer.java Sat Apr 25 09:11:11 2009
@@ -47,6 +47,8 @@
 import org.apache.openjpa.meta.JavaTypes;
 import org.apache.openjpa.meta.MetaDataInheritanceComparator;
 import static org.apache.openjpa.meta.MetaDataModes.*;
+
+import org.apache.openjpa.meta.AccessCode;
 import org.apache.openjpa.meta.MetaDataRepository;
 import org.apache.openjpa.meta.Order;
 import org.apache.openjpa.meta.QueryMetaData;
@@ -452,7 +454,7 @@
             switch (type(meta)) {
                 case TYPE_META:
                     ClassMetaData cls = (ClassMetaData) meta;
-                    if (cls.getAccessType() == ClassMetaData.ACCESS_FIELD)
+                    if (AccessCode.isField(cls.getAccessType()))
                         fieldAccess = true;
                     else
                         propertyAccess = true;
@@ -480,9 +482,9 @@
             int def = getConfiguration().getMetaDataRepositoryInstance().
                 getMetaDataFactory().getDefaults().getDefaultAccessType();
             String access = null;
-            if (fieldAccess && def == ClassMetaData.ACCESS_PROPERTY)
+            if (fieldAccess && AccessCode.isProperty(def))
                 access = "FIELD";
-            else if (propertyAccess && def == ClassMetaData.ACCESS_FIELD)
+            else if (propertyAccess && AccessCode.isField(def))
                 access = "PROPERTY";
             if (access != null) {
                 startElement("access");
@@ -807,11 +809,11 @@
             return;
         int def = getConfiguration().getMetaDataRepositoryInstance().
             getMetaDataFactory().getDefaults().getDefaultAccessType();
-        if (meta.getAccessType() == ClassMetaData.ACCESS_FIELD
-            && def == ClassMetaData.ACCESS_PROPERTY)
+        if (AccessCode.isField(meta.getAccessType())
+            && AccessCode.isProperty(def))
             addAttribute("access", "FIELD");
-        else if (meta.getAccessType() == ClassMetaData.ACCESS_PROPERTY
-            && def == ClassMetaData.ACCESS_FIELD)
+        else if (AccessCode.isProperty(meta.getAccessType())
+            && AccessCode.isField(def))
             addAttribute("access", "PROPERTY");
     }
 

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=768498&r1=768497&r2=768498&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 Sat Apr 25 09:11:11 2009
@@ -16,6 +16,13 @@
 # under the License.
 
 access-empty: Found no persistent property in "{0}" 
+access-mixed: Class "{0}" annotated fields "{1}" with FIELD access and \
+	methods "{2}" with PROPERTY access. As class "{0}" is not using an  \
+	explicit access, it is not permitted to mix PROPERTY and FIELD access \
+	annotations.
+access-none: Property "{1}" in class "{0}" is not annotated an instance field \
+    or a getter method. It is not possible to determine its access type
+access-unknown: Access style for "{0}" can not be determined.
 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