You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by pp...@apache.org on 2009/12/03 11:13:19 UTC

svn commit: r886729 [1/2] - in /labs/fluid/src: main/java/org/apache/openjpa/sdo/ main/java/org/apache/openjpa/sdo/mapping/ test/java/example/basic/ test/java/org/apache/openjpa/sdo/

Author: ppoddar
Date: Thu Dec  3 10:13:07 2009
New Revision: 886729

URL: http://svn.apache.org/viewvc?rev=886729&view=rev
Log:
Refactor into SDOTypeParser from ImplHelper

Modified:
    labs/fluid/src/main/java/org/apache/openjpa/sdo/BiDiMapID.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/ImplHelper.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/SDO2POJOGenerator.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOEndTransactionListener.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOEntityManager.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOEntityManagerFactory.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOInstanceMapping.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOQuery.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOTypeParser.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/ContainerRelationMapping.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/IdenticalTypeMapping.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/PrimitiveListMapping.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/PrimitiveMapping.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/RelationListMapping.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/SDOMappingStrategyInstaller.java
    labs/fluid/src/test/java/example/basic/TestCRUD.java
    labs/fluid/src/test/java/org/apache/openjpa/sdo/TestSDO.java

Modified: labs/fluid/src/main/java/org/apache/openjpa/sdo/BiDiMapID.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/sdo/BiDiMapID.java?rev=886729&r1=886728&r2=886729&view=diff
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/BiDiMapID.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/BiDiMapID.java Thu Dec  3 10:13:07 2009
@@ -28,168 +28,171 @@
 import org.apache.commons.collections.keyvalue.DefaultMapEntry;
 
 import commonj.sdo.DataObject;
-import commonj.sdo.Type;
 
 class BiDiMapID {
 
-	private HashMap<String, HashMap<String,Map.Entry<DataObject, Object>>> mapid = new HashMap<String, HashMap<String,Map.Entry<DataObject, Object>>>();
-	private SDOEntityManager em = null;
-	private BiDiMap<DataObject, Object> mapobj = new BiDiMap<DataObject, Object>();
-	private BiDiMapID() {
-	    super();
-	}
-	
-	public BiDiMapID(SDOEntityManager em) {
-	    this();
-	    this.em = em;
-	}
-	
-	public void clear() {
-		mapid.clear();
-		mapobj.clear();
-	}
-//TODO:  this is an hack, we use toString but we should manage Openjpa ID
-	public boolean containsKey(DataObject key) {
-		return mapobj.containsKey(key) || mapid.containsKey(key.getType().getName()) && mapid.get(key.getType().getName()).containsKey(ImplHelper.getIdValue(key).toString());
-	}
-
-	public boolean containsValue(Object value) {
-	    	if (mapobj.containsValue(value)) {
-	    	    return true;
-	    	}
-	    	String t = em.getRepos().getSDOType(value.getClass()).getName();
-	    	Object oid = em.getBroker().getStateManager(value) != null ? em.getBroker().getStateManager(value).getId() : null;
-	    	if (oid == null) {
-	    	    return false;
-	    	}
-	    	String id = oid.toString();
-		return mapid.containsKey(t) && mapid.get(t).containsKey(id);
-	}
-
-	public Set<Map.Entry<DataObject, Object>> entrySet() {
-	    Set<Map.Entry<DataObject, Object>> ret = new HashSet<Map.Entry<DataObject, Object>>();
-	    for (HashMap<String,Map.Entry<DataObject, Object>> he:mapid.values()) {
-		ret.addAll(he.values());
-	    }
-	    ret.addAll(mapobj.entrySet());
-	    return ret;
-	}
-
-	public Object get(DataObject key) {
-	    if (mapobj.containsKey(key)) {
-		return mapobj.get(key);
-	    } else if (this.containsKey(key)) {
-		return mapid.get(key.getType().getName()).get(ImplHelper.getIdValue(key).toString()).getValue();
-	    } else {
-		return null;
-	    }
-	}
-
-	public boolean isEmpty() {
-		return mapobj.isEmpty();
-	}
-
-	public Set<DataObject> keySet() {
-	    Set<DataObject> ret = new HashSet<DataObject>();
-	    for (HashMap<String,Map.Entry<DataObject, Object>> he:mapid.values()) {
-		for (Map.Entry<DataObject, Object> e:he.values()) {
-		    ret.add(e.getKey());
-		}
-	    }
-	    ret.addAll(mapobj.keySet());
-	    return ret;
-	}
-
-	public Object put(DataObject key, Object value) {
-	    String t = key.getType().getName();
-	    Object oid = ImplHelper.getIdValue(key);
-	    if (oid == null && em.getBroker().getStateManager(value) != null) {
-		oid = em.getBroker().getStateManager(value).getId();
-	    } 
-	    if (oid == null) {
-		return mapobj.put(key, value);
-	    }
-	    String id = oid.toString();
-	    Map.Entry<DataObject, Object> e = new DefaultMapEntry(key,value);
-	    if (!mapid.containsKey(t)) {
-		HashMap<String,Map.Entry<DataObject, Object>> he = new HashMap<String,Map.Entry<DataObject, Object>>();
-		mapid.put(t, he);		
-	    }
-	    return mapid.get(t).put(id, e);
-	}
-
-	@SuppressWarnings("unchecked")
-	public void putAll(Map<DataObject, Object> t) {
-		for (DataObject k:t.keySet())
-			put(k, t.get(k));
-	}
-
-	public Object remove(DataObject key) {
-	    String t = key.getType().getName();
-	    Object oid = ImplHelper.getIdValue(key);
-	    Object ret = null;
-	    if (oid == null) {
-		return mapobj.remove(key);		
-	    }
-	    String id = oid.toString();
-	    if (this.containsKey(key)) {
-		ret = mapid.get(t).remove(id).getValue();
-		if (mapid.get(t).isEmpty()) {
-		    mapid.remove(t);
-		}
-	    }
-	    return ret;
-	}
-
-	public DataObject removeReverse(Object v) {
-	    String t = em.getRepos().getSDOType(v.getClass()).getName();
-	    Object oid = em.getBroker().getStateManager(v) != null ? em.getBroker().getStateManager(v).getId() : null;
-	    DataObject ret = null;
-	    if (oid == null) {
-		return mapobj.removeReverse(v);
-	    }
-	    String id = oid.toString();
-	    if (this.containsValue(v)) {
-		ret = mapid.get(t).remove(id).getKey();
-		if (mapid.get(t).isEmpty()) {
-		    mapid.remove(t);
-		}
-	    }
-	    return ret;
-	}
-	
-	public int size() {
-	    int ret = 0;
-	    for (HashMap<String,Map.Entry<DataObject, Object>> he:mapid.values()) {
-		ret += he.size();
-	    }
-	    return ret + mapobj.size();
-	}
-
-	public Collection<Object> values() {
-	    ArrayList<Object> ret = new ArrayList<Object>();
-	    for (HashMap<String,Map.Entry<DataObject, Object>> he:mapid.values()) {
-		for (Map.Entry<DataObject, Object> e:he.values()) {
-		    ret.add(e.getValue());
-		}
-	    }
-	    ret.addAll(mapobj.values());
-	    return ret;
-	}
-	
-	public DataObject getReverse(Object v) {
-	    if (mapobj.containsValue(v)) {
-		return mapobj.getReverse(v);
-	    } else if (this.containsValue(v)) {
-		String t = em.getRepos().getSDOType(v.getClass()).getName();
-		Object oid = em.getBroker().getStateManager(v) != null ? em.getBroker().getStateManager(v).getId() : null;
-		if (oid == null) {
-		    return null;
-		}
-		String id = oid.toString();
-		return mapid.get(t).get(id).getKey();
-	    } else {
-		return null;
-	    }
-	}
+    private HashMap<String, HashMap<String, Map.Entry<DataObject, Object>>> mapid = 
+        new HashMap<String, HashMap<String, Map.Entry<DataObject, Object>>>();
+    private SDOEntityManager em = null;
+    private BiDiMap<DataObject, Object> mapobj = new BiDiMap<DataObject, Object>();
+
+    private BiDiMapID() {
+        super();
+    }
+
+    public BiDiMapID(SDOEntityManager em) {
+        this();
+        this.em = em;
+    }
+
+    public void clear() {
+        mapid.clear();
+        mapobj.clear();
+    }
+
+    // TODO: this is an hack, we use toString but we should manage Openjpa ID
+    public boolean containsKey(DataObject key) {
+        return mapobj.containsKey(key) || mapid.containsKey(key.getType().getName())
+                && mapid.get(key.getType().getName()).containsKey(SDOTypeParser.getIdValue(key).toString());
+    }
+
+    public boolean containsValue(Object value) {
+        if (mapobj.containsValue(value)) {
+            return true;
+        }
+        String t = em.getRepos().getSDOType(value.getClass()).getName();
+        Object oid = em.getBroker().getStateManager(value) != null ? em.getBroker().getStateManager(value).getId()
+                : null;
+        if (oid == null) {
+            return false;
+        }
+        String id = oid.toString();
+        return mapid.containsKey(t) && mapid.get(t).containsKey(id);
+    }
+
+    public Set<Map.Entry<DataObject, Object>> entrySet() {
+        Set<Map.Entry<DataObject, Object>> ret = new HashSet<Map.Entry<DataObject, Object>>();
+        for (HashMap<String, Map.Entry<DataObject, Object>> he : mapid.values()) {
+            ret.addAll(he.values());
+        }
+        ret.addAll(mapobj.entrySet());
+        return ret;
+    }
+
+    public Object get(DataObject key) {
+        if (mapobj.containsKey(key)) {
+            return mapobj.get(key);
+        } else if (this.containsKey(key)) {
+            return mapid.get(key.getType().getName()).get(SDOTypeParser.getIdValue(key).toString()).getValue();
+        } else {
+            return null;
+        }
+    }
+
+    public boolean isEmpty() {
+        return mapobj.isEmpty();
+    }
+
+    public Set<DataObject> keySet() {
+        Set<DataObject> ret = new HashSet<DataObject>();
+        for (HashMap<String, Map.Entry<DataObject, Object>> he : mapid.values()) {
+            for (Map.Entry<DataObject, Object> e : he.values()) {
+                ret.add(e.getKey());
+            }
+        }
+        ret.addAll(mapobj.keySet());
+        return ret;
+    }
+
+    public Object put(DataObject key, Object value) {
+        String t = key.getType().getName();
+        Object oid = SDOTypeParser.getIdValue(key);
+        if (oid == null && em.getBroker().getStateManager(value) != null) {
+            oid = em.getBroker().getStateManager(value).getId();
+        }
+        if (oid == null) {
+            return mapobj.put(key, value);
+        }
+        String id = oid.toString();
+        Map.Entry<DataObject, Object> e = new DefaultMapEntry(key, value);
+        if (!mapid.containsKey(t)) {
+            HashMap<String, Map.Entry<DataObject, Object>> he = new HashMap<String, Map.Entry<DataObject, Object>>();
+            mapid.put(t, he);
+        }
+        return mapid.get(t).put(id, e);
+    }
+
+    public void putAll(Map<DataObject, Object> t) {
+        for (DataObject k : t.keySet())
+            put(k, t.get(k));
+    }
+
+    public Object remove(DataObject key) {
+        String t = key.getType().getName();
+        Object oid = SDOTypeParser.getIdValue(key);
+        Object ret = null;
+        if (oid == null) {
+            return mapobj.remove(key);
+        }
+        String id = oid.toString();
+        if (this.containsKey(key)) {
+            ret = mapid.get(t).remove(id).getValue();
+            if (mapid.get(t).isEmpty()) {
+                mapid.remove(t);
+            }
+        }
+        return ret;
+    }
+
+    public DataObject removeReverse(Object v) {
+        String t = em.getRepos().getSDOType(v.getClass()).getName();
+        Object oid = em.getBroker().getStateManager(v) != null ? em.getBroker().getStateManager(v).getId() : null;
+        DataObject ret = null;
+        if (oid == null) {
+            return mapobj.removeReverse(v);
+        }
+        String id = oid.toString();
+        if (this.containsValue(v)) {
+            ret = mapid.get(t).remove(id).getKey();
+            if (mapid.get(t).isEmpty()) {
+                mapid.remove(t);
+            }
+        }
+        return ret;
+    }
+
+    public int size() {
+        int ret = 0;
+        for (HashMap<String, Map.Entry<DataObject, Object>> he : mapid.values()) {
+            ret += he.size();
+        }
+        return ret + mapobj.size();
+    }
+
+    public Collection<Object> values() {
+        ArrayList<Object> ret = new ArrayList<Object>();
+        for (HashMap<String, Map.Entry<DataObject, Object>> he : mapid.values()) {
+            for (Map.Entry<DataObject, Object> e : he.values()) {
+                ret.add(e.getValue());
+            }
+        }
+        ret.addAll(mapobj.values());
+        return ret;
+    }
+
+    public DataObject getReverse(Object v) {
+        if (mapobj.containsValue(v)) {
+            return mapobj.getReverse(v);
+        } else if (this.containsValue(v)) {
+            String t = em.getRepos().getSDOType(v.getClass()).getName();
+            Object oid = em.getBroker().getStateManager(v) != null ? em.getBroker().getStateManager(v).getId() : null;
+            if (oid == null) {
+                return null;
+            }
+            String id = oid.toString();
+            return mapid.get(t).get(id).getKey();
+        } else {
+            return null;
+        }
+    }
 }

Modified: labs/fluid/src/main/java/org/apache/openjpa/sdo/ImplHelper.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/sdo/ImplHelper.java?rev=886729&r1=886728&r2=886729&view=diff
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/ImplHelper.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/ImplHelper.java Thu Dec  3 10:13:07 2009
@@ -19,20 +19,10 @@
 package org.apache.openjpa.sdo;
 
 import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
-
-import javax.persistence.EntityManager;
 
 import org.apache.commons.lang.StringUtils;
-import org.apache.openjpa.enhance.PersistenceCapable;
 import org.apache.openjpa.enhance.Reflection;
-import org.apache.openjpa.lib.util.Localizer;
-import org.apache.openjpa.meta.ClassMetaData;
-import org.apache.openjpa.util.UserException;
 
 import serp.bytecode.lowlevel.ConstantPoolTable;
 
@@ -41,439 +31,200 @@
 import commonj.sdo.Type;
 
 /**
- * Static helper utilities to create method name, extract field values via 
- * reflection and more importantly process identity and version property in DataObject.
+ * Static helper utilities to create method name, extract field values via
+ * reflection and more importantly process identity and version property in
+ * DataObject.
  * 
  * @author Pinaki Poddar
  * @since 0.1.0
  */
 public final class ImplHelper {
-	private static Localizer _loc = Localizer.forPackage(ImplHelper.class);
-	private static HashMap<Type,List<Property>> containments = null;
-	private static HashMap<Type,List<Property>> references = null;
-
-	/**
-	 * Get the name of a method for a given property name.
-	 */
-	public static String getMethodName(String prefix, String name) {
-		return prefix + StringUtils.capitalize(name);
-	}
-
-	/**
-	 * Get the name of a method for a given property.
-	 * The name of the method is suffixed with <code>List</code> if the 
-	 * property is multi-valued.
-	 */
-	public static String getMethodName(String prefix, Property p) {
-		String suffix = (p.isMany()) ? "List" : "";
-		return prefix + StringUtils.capitalize(p.getName()) + suffix;
-	}
-		
-	/**
-	 * Get the value of the given property from the given persistence capable
-	 * instance (not a DataObject). The property is used to determine the
-	 * get method that will be invoked reflectively on the persistence capable
-	 * instance to obtain the value.
-	 */
-//	public static Object getFieldValue(Property property, Object pc) {
-//		String methodName = getMethodName("get", property);
-//		try {
-//			Method method = pc.getClass().getMethod(methodName, (Class[])null);
-//			return method.invoke(pc, (Object[])null);
-//		} catch (Exception e) {
-//			throw new RuntimeException(e);
-//		} 
-//	}
-	
-	/**
-	 * Get the name of Java class given the Type. The Java class name is 
-	 * the type name with first letter capitalized. 
-	 */
-	public static String getClassName(Type type) {
-		return StringUtils.capitalize(type.getName());
-	}
-	
-	/**
-	 * Gets fully qualified Java class name for a given type.
-	 * Fully qualified Java class name is name of the given type prepended by
-	 * the package name, if {@link #isEMFImplementaionAvailable() available}.
-	 */
-	public static String getFullClassName(Type type) {
-		String pkg = getPackageName(type);
-		String cls = getClassName(type);
-		return (pkg==null || pkg.equals("")) ? cls : pkg + "." + cls;
-	}
-	
-	/**
-	 * Gets the package name for the given type, if 
-	 * {@link #isEMFImplementaionAvailable() possible}.
-	 */
-	public static String getPackageName(Type type) {
-		String result = "";
-		if (type != null && "org.apache.tuscany.sdo.impl.ClassImpl".equals(
-				type.getClass().getName()) && isEMFImplementaionAvailable()) {
-			try {
-				Object pkg = getEPackage.invoke(emfClass.cast(type), NULL_PARAMS);
-				result = (String)getPackageName.invoke(pkg, NULL_PARAMS);
-				if ("null".equals(result)) result = null; 
-			} catch (Throwable e) {
-				isEMFImplementation = Boolean.FALSE;
-			}
-		}
-		return result;
-	}
-	
-	/**
-	 * Get the identity Property of given type.
-	 * Identity property is either
-	 * <OL>
-	 * <LI>a) a property named <code>id</code> with simple xsd data type.
-	 * <LI>b) a property with type <code>xsd:ID</code>
-	 * </OL>
-	 * <br>
-	 * Note: Currently, multiple properties with <code>xsd:ID</code> is not
-	 * considered
-	 * 
-	 */
-	//TODO: Improve checking for identity property
-	public static Property getIdentityProperty(Type type) {
-		// If there is property named "id" of simple data type return it  
-		Property idProperty = type.getProperty("id");
-		if (idProperty != null && idProperty.getType().isDataType())
-			return idProperty;
-		
-		// Otherwise a property with xsd:ID type (only available if EMF Core
-		// implementation is available
-		if (isEMFImplementaionAvailable()) {
-			List properties = type.getProperties();
-			for (Object p:properties) {
-				Property property = (Property)p;
-				if (property.getType().isDataType()) {
-					try {
-						Object isID = getIDMethod.invoke(
-							property.getClass().cast(property), NULL_PARAMS);
-						if (Boolean.TRUE.equals(isID))
-							idProperty = property;
-					} catch (Throwable e) {
-						isEMFImplementation = Boolean.FALSE;
-					}
-				}
-			}
-		}
-		return idProperty;
-	}
-	
-	/**
-	 * Affirms if the given property is identity property.
-	 */
-	public static boolean isIdentity(Property property) {
-		if (property == null)
-			return false;
-		if (("id".equals(property.getName()) || property.getAliasNames().contains("id")) && property.getType().isDataType())
-				return true;
-		if (isEMFImplementaionAvailable() && property.getType().isDataType()) {
-			try {
-				Object isID = getIDMethod.invoke(
-						property.getClass().cast(property), NULL_PARAMS);
-				if (Boolean.TRUE.equals(isID))
-					return true;
-			} catch (Throwable e) {
-				isEMFImplementation = Boolean.FALSE;
-			}
-		}
-		return false;
-	}
-
-	/**
-	 * Affirms if the type has any referencing property.
-	 */
-	public static List<Property> getReferenceProperties(Type t) {
-		ArrayList<Property> ret = null;
-		Collection<Type> parsedtypes = SDOTypeParser.getParsedTypes();
-		for (Type type:parsedtypes) {
-			List<Property> properties = type.getProperties();
-			for (Property p : properties) {
-				if (p.getType().equals(t) && !p.getType().isDataType() && !p.isContainment()) {
-					if (ret == null)
-						ret = new ArrayList<Property>();
-					ret.add(p);
-				}
-			}
-		}
-		return ret;
-	}
-
-	public static Map<Type,List<Property>> getContainments(boolean refresh) {
-		if (containments == null) { 
-			containments = new HashMap<Type,List<Property>>();		
-			references = new HashMap<Type,List<Property>>();
-			refreshPropertyRelations();
-		} else if (refresh)
-			refreshPropertyRelations();
-		return containments;
-	}	
-	
-	public static Map<Type,List<Property>> getReferences(boolean refresh) {
-		if (containments == null) { 
-			containments = new HashMap<Type,List<Property>>();		
-			references = new HashMap<Type,List<Property>>();
-			refreshPropertyRelations();
-		} else if (refresh)
-			refreshPropertyRelations();
-		return references;
-	}	
-
-	public static void refreshPropertyRelations () {
-		containments.clear();
-		references.clear();
-		Collection<Type> parsedtypes = SDOTypeParser.getParsedTypes();
-		for (Type t : parsedtypes) {
-			List<Property> c = getContainerProperties(t);
-			if (c != null) {
-				containments.put(t, c);
-			}				
-			List<Property> r = getReferenceProperties(t);
-			if (r != null) {
-				references.put(t, r);
-			}				
-		}		
-		
-	}
-	
-	public static Map<Type,List<Property>> getContainments() {
-		return getContainments(false);
-	}
-
-	public static Map<Type,List<Property>> getReferences() {
-		return getReferences(false);
-	}
-	
-	
-	/**
-	 * Return the property that contains the given type.
-	 */
-	public static List<Property> getContainerProperties(Type type) {
-		ArrayList<Property> ret = null;
-		Collection<Type> parsedtypes = SDOTypeParser.getParsedTypes();
-		for (Type t : parsedtypes) {
-			List<Property> properties = t.getProperties();
-			for (Property p : properties) {
-				if (!p.isContainment())
-					continue;
-				Property cp = getComponentProperty(p.getType());
-				if ((p.getType().equals(type)) 
-						|| (cp != null && cp.isContainment() && cp.getType().equals(type))) {
-					if (ret == null)
-						ret = new ArrayList<Property>();
-					ret.add(p);
-				}
-			}	
-		}
-		return ret;
-	}
-	
-	/**
-	 * Gets the property that represents version information.
-	 * Version property is a property named <code>version</code> and declared
-	 * as <code>xsd:int</code> type.
-	 */
-	public static Property getVersionProperty(Type type) {
-		Property version = type.getProperty("version");
-		if (!isVersion(version))
-			throw new UserException(_loc.get("missing-version", type.getName())
-					.toString());
-		return version;
-	}
-	
-	/**
-	 * Affirms if the property represents version.
-	 * Version property is a property named <code>version</code> and declared
-	 * as <code>xsd:int</code> type.
-	 */
-	public static boolean isVersion(Property property) {
-		return (property != null && property.getName().equals("version") &&
-				property.getType().isDataType() &&
-				property.getType().getInstanceClass()==int.class);
-	}
-	
-	/**
-	 * Affirms if the property represents a LOB type.
-	 * LOB types are property or types that have alias named "LOB"
-	 */
-	public static boolean isLOB(Property property) {
-		return (property != null && property.getType().isDataType() && 
-				(property.getAliasNames().contains("LOB") || property.getType().getAliasNames().contains("LOB"))); 
-	}
-	
-	/**
-	 * Gets the value of the {@link #getIdentityProperty(Type) identity property}
-	 * of the given DataObject.
-	 */
-	public static Object getIdValue(DataObject data) {
-		return data.get(getIdentityProperty(data.getType()));
-	}
-	
-	/**
-	 * Sets the value of the {@link #getIdentityProperty(Type) identity property}
-	 * of the given DataObject.
-	 */
-	public static void setIdValue(DataObject data, Object idValue) {
-		data.set(getIdentityProperty(data.getType()), idValue);
-	}
-	
-	/**
-	 * Gets the version of the given DataObject.
-	 * @see #getVersionProperty(Type)
-	 */
-	public static int getVersion(DataObject data) {
-		return data.getInt(getVersionProperty(data.getType()));
-	}
-	
-	/**
-	 * Sets the version of the given DataObject.
-	 * @see #getVersionProperty(Type)
-	 */
-	public static void setVersion(DataObject data, int version) {
-		data.setInt(getVersionProperty(data.getType()), version);
-	}
-	
-	/**
-	 * Affirms if this type is <em>Container</em> type. 
-	 * A Type is defined as a container if 
-	 * <LI>it has one and only one property and 
-	 * <LI>that property is many-valued and 
-	 * <LI>type of that single property is <em>not</em> a basic data type.
-	 */
-	public static boolean isContainer(Type type) {
-		List properties = type.getProperties();
-		if (properties.size()==1) {
-			Property p = (Property)properties.get(0);
-			return p.isMany();
-		}
-		return false;
-	}
-	
-	/**
-	 * If the given type is a {@link #isContainer(Type) container type} then 
-	 * return the type of its one 
-	 * and only one property. Otherwise null.
-	 */
-	public static Type getComponentType(Type type) {
-		if (isContainer(type)) {
-			return ((Property)type.getProperties().get(0)).getType();
-		}
-		return null;
-	}
-	
-	/**
-	 * If the given type is a {@link #isContainer(Type) container type} then 
-	 * return the one and only one property it contains. Otherwise null.
-	 */
-	public static Property getComponentProperty(Type type) {
-		if (isContainer(type)) {
-			return (Property)type.getProperties().get(0);
-		}
-		return null;
-	}
-	
-	/**
-	 * Affirms if Eclipse Modeling Framework classes are available
-	 * as SDO implementation.
-	 * <br>
-	 * These implementation classes are used to find specific information that
-	 * SDO API hides; for example, whether a type has <code>xsd:ID</code> 
-	 * property or package name specified in *.xsd header.
-	 * <br>
-	 * EMF implementation is not assumed to keep compile-time dependency at
-	 * minimum. So EMF implementation is accessed via reflection at runtime.
-	 * 
-	 */
-	public static boolean isEMFImplementaionAvailable() {
-		if (isEMFImplementation != null)
-			return isEMFImplementation.booleanValue();
-		
-		try {
-			emfClass = Class.forName(EMF_CLASS);
-			emfProperty = Class.forName(EMF_PROPERTY);
-			getEPackage = emfClass.getMethod("getEPackage", NULL_ARGS);
-			getPackageName = getEPackage.getDeclaringClass()
-				.getMethod("getName", NULL_ARGS);
-			getIDMethod = emfProperty.getMethod("isID", NULL_ARGS);
-			isEMFImplementation = getPackageName != null;
-		} catch (Exception e) {
-			isEMFImplementation = Boolean.FALSE;
-		}
-		return isEMFImplementation.booleanValue();
-	}
-	
-	public static Class getEnhancedClass(Object o) {
-		Class cls = o.getClass();
-		String name;
-		if (cls.getPackage() == null) {
-			name = cls.getName();
-			int index = name.lastIndexOf('.');
-			name = name.substring(0, index);
+    /**
+     * Get the name of a method for a given property name.
+     */
+    public static String getMethodName(String prefix, String name) {
+        return prefix + StringUtils.capitalize(name);
+    }
+
+    /**
+     * Get the name of a method for a given property. The name of the method is
+     * suffixed with <code>List</code> if the property is multi-valued.
+     */
+    public static String getMethodName(String prefix, Property p) {
+        String suffix = (p.isMany()) ? "List" : "";
+        return prefix + StringUtils.capitalize(p.getName()) + suffix;
+    }
+
+    /**
+     * Get the name of Java class given the Type. The Java class name is the
+     * type name with first letter capitalized.
+     */
+    public static String getClassName(Type type) {
+        return StringUtils.capitalize(type.getName());
+    }
+
+    /**
+     * Gets fully qualified Java class name for a given type. Fully qualified
+     * Java class name is name of the given type prepended by the package name,
+     * if {@link #isEMFImplementaionAvailable() available}.
+     */
+    public static String getFullClassName(Type type) {
+        String pkg = getPackageName(type);
+        String cls = getClassName(type);
+        return (pkg == null || pkg.equals("")) ? cls : pkg + "." + cls;
+    }
+
+    /**
+     * Gets the package name for the given type, if
+     * {@link #isEMFImplementaionAvailable() possible}.
+     */
+    public static String getPackageName(Type type) {
+        String result = "";
+        if (type != null && "org.apache.tuscany.sdo.impl.ClassImpl".equals(type.getClass().getName())
+                && isEMFImplementaionAvailable()) {
+            try {
+                Object pkg = getEPackage.invoke(emfClass.cast(type), NULL_PARAMS);
+                result = (String) getPackageName.invoke(pkg, NULL_PARAMS);
+                if ("null".equals(result))
+                    result = null;
+            } catch (Throwable e) {
+                isEMFImplementation = Boolean.FALSE;
+            }
+        }
+        return result;
+    }
+
+    /**
+     * Get the identity Property of given type. Identity property is either
+     * <OL>
+     * <LI>a) a property named <code>id</code> with simple xsd data type.
+     * <LI>b) a property with type <code>xsd:ID</code>
+     * </OL>
+     * <br>
+     * Note: Currently, multiple properties with <code>xsd:ID</code> is not
+     * considered
+     * 
+     */
+    // TODO: Improve checking for identity property
+    public static Property getIdentityProperty(Type type) {
+        // If there is property named "id" of simple data type return it
+        Property idProperty = type.getProperty("id");
+        if (idProperty != null && idProperty.getType().isDataType())
+            return idProperty;
+
+        // Otherwise a property with xsd:ID type (only available if EMF Core
+        // implementation is available
+        if (isEMFImplementaionAvailable()) {
+            List<?> properties = type.getProperties();
+            for (Object p : properties) {
+                Property property = (Property) p;
+                if (property.getType().isDataType()) {
+                    try {
+                        Object isID = getIDMethod.invoke(property.getClass().cast(property), NULL_PARAMS);
+                        if (Boolean.TRUE.equals(isID))
+                            idProperty = property;
+                    } catch (Throwable e) {
+                        isEMFImplementation = Boolean.FALSE;
+                    }
+                }
+            }
+        }
+        return idProperty;
+    }
+
+
+
+    /**
+     * Affirms if Eclipse Modeling Framework classes are available as SDO
+     * implementation. <br>
+     * These implementation classes are used to find specific information that
+     * SDO API hides; for example, whether a type has <code>xsd:ID</code>
+     * property or package name specified in *.xsd header. <br>
+     * EMF implementation is not assumed to keep compile-time dependency at
+     * minimum. So EMF implementation is accessed via reflection at runtime.
+     * 
+     */
+    private static boolean isEMFImplementaionAvailable() {
+        if (isEMFImplementation != null)
+            return isEMFImplementation.booleanValue();
+
+        try {
+            emfClass = Class.forName(EMF_CLASS);
+            emfProperty = Class.forName(EMF_PROPERTY);
+            getEPackage = emfClass.getMethod("getEPackage", NULL_ARGS);
+            getPackageName = getEPackage.getDeclaringClass().getMethod("getName", NULL_ARGS);
+            getIDMethod = emfProperty.getMethod("isID", NULL_ARGS);
+            isEMFImplementation = getPackageName != null;
+        } catch (Exception e) {
+            isEMFImplementation = Boolean.FALSE;
+        }
+        return isEMFImplementation.booleanValue();
+    }
+
+    public static Class<?> getEnhancedClass(Object o) {
+        Class<?> cls = o.getClass();
+        String name;
+        if (cls.getPackage() == null) {
+            name = cls.getName();
+            int index = name.lastIndexOf('.');
+            name = name.substring(0, index);
         } else {
-        	name = cls.getPackage().getName();
+            name = cls.getPackage().getName();
+        }
+        if (name.equals("org.apache.openjpa.enhance"))
+            cls = cls.getSuperclass();
+        return cls;
+    }
+
+    public static boolean idMatch(DataObject data, Object pc) {
+        Class<?> cls = pc.getClass();
+        Property idprop = ImplHelper.getIdentityProperty(data.getType());
+        Method getter = Reflection.findGetter(cls, idprop.getName(), true);
+        try {
+            String pcid = getter.invoke(pc, NULL_PARAMS).toString();
+            String id = data.get(idprop).toString();
+            // this is an hack for ldap stores that trims DN
+            return (id.equalsIgnoreCase(pcid) || id.trim().equalsIgnoreCase(pcid));
+        } catch (Exception e) {
+            return false;
         }
-		if (name.equals("org.apache.openjpa.enhance"))
-			cls = cls.getSuperclass();
-		return cls;
-	}
-	
-  public static boolean idMatch(DataObject data, Object pc) {
-    Class cls = pc.getClass();
-    Property idprop = ImplHelper.getIdentityProperty(data.getType());
-    Method getter = Reflection.findGetter(cls, idprop.getName(), true);
-    try {
-      String pcid = getter.invoke(pc, NULL_ARGS).toString();
-      String id = data.get(idprop).toString();
-      return (id.equalsIgnoreCase(pcid) || id.trim().equalsIgnoreCase(pcid)); // this is an hack for ldap stores that trims DN 
-    } catch (Exception e) {
-      return false;
-    }    
-  }
-
-  public static boolean idMatch(SDOEntityManager em, DataObject data, Object pc) {
-    String pcid = (String) em.getObjectId(pc);
-    Property idprop = ImplHelper.getIdentityProperty(data.getType());
-    String id = data.get(idprop).toString();
-    return (id.equalsIgnoreCase(pcid) || id.trim().equalsIgnoreCase(pcid)); // this is an hack for ldap stores that trims DN 
-  }
-  
-  public static boolean isPersistenceCapable(Class cls) {
-  	return PersistenceCapable.class.isAssignableFrom(cls);
-  }
-  
-  public static boolean isEnhanced(byte[] b) {
-      ConstantPoolTable table = new ConstantPoolTable(b);
-      int idx = table.getEndIndex();
-
-      idx += 6; // skip access, cls, super
-      int ifaces = table.readUnsignedShort(idx);
-      int clsEntry, utfEntry;
-      String name;
-      for (int i = 0; i < ifaces; i++) {
-          idx += 2;
-          clsEntry = table.readUnsignedShort(idx);
-          utfEntry = table.readUnsignedShort(table.get(clsEntry));
-          name = table.readString(table.get(utfEntry));
-          if ("org/apache/openjpa/enhance/PersistenceCapable".equals(name))
-              return true;
-      }
-      return false;
-  }
-  
-	private static Boolean isEMFImplementation = null;
-	private static final String EMF_CLASS = 
-		"org.apache.tuscany.sdo.impl.ClassImpl";
-	private static final String EMF_PROPERTY = 
-		"org.apache.tuscany.sdo.impl.AttributeImpl";
-	private static Class emfClass = null;
-	private static Class emfProperty = null;
-	private static Method getEPackage = null;
-	private static Method getPackageName = null;
-	private static Method getIDMethod = null;
-	private static Class[] NULL_ARGS = {};
-	private static Object[] NULL_PARAMS = {};
+    }
+
+    public static boolean idMatch(SDOEntityManager em, DataObject data, Object pc) {
+        Object pcid = em.getObjectId(pc);
+        Property idprop = ImplHelper.getIdentityProperty(data.getType());
+        Object id = data.get(idprop);
+        // this is an hack for ldap stores that trims DN
+        return (pcid.equals(id) || id.toString().trim().equalsIgnoreCase(pcid.toString()));
+    }
+
+    public static boolean isEnhanced(byte[] b) {
+        ConstantPoolTable table = new ConstantPoolTable(b);
+        int idx = table.getEndIndex();
+
+        idx += 6; // skip access, cls, super
+        int ifaces = table.readUnsignedShort(idx);
+        int clsEntry, utfEntry;
+        String name;
+        for (int i = 0; i < ifaces; i++) {
+            idx += 2;
+            clsEntry = table.readUnsignedShort(idx);
+            utfEntry = table.readUnsignedShort(table.get(clsEntry));
+            name = table.readString(table.get(utfEntry));
+            if ("org/apache/openjpa/enhance/PersistenceCapable".equals(name))
+                return true;
+        }
+        return false;
+    }
+
+    private static Boolean isEMFImplementation = null;
+    private static final String EMF_CLASS = "org.apache.tuscany.sdo.impl.ClassImpl";
+    private static final String EMF_PROPERTY = "org.apache.tuscany.sdo.impl.AttributeImpl";
+    private static Class<?> emfClass = null;
+    private static Class<?> emfProperty = null;
+    private static Method getEPackage = null;
+    private static Method getPackageName = null;
+    private static Method getIDMethod = null;
+    private static Class<?>[] NULL_ARGS = {};
+    private static Object[] NULL_PARAMS = {};
 }

Modified: labs/fluid/src/main/java/org/apache/openjpa/sdo/SDO2POJOGenerator.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/sdo/SDO2POJOGenerator.java?rev=886729&r1=886728&r2=886729&view=diff
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/SDO2POJOGenerator.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/SDO2POJOGenerator.java Thu Dec  3 10:13:07 2009
@@ -103,7 +103,7 @@
 		if (type.isSequenced())
 			throw new IllegalArgumentException(
 				_loc.get("data-type-not-converted", typeName).toString());
-		if (ImplHelper.isContainer(type))
+		if (SDOTypeParser.isContainer(type))
 			throw new IllegalArgumentException(
 				_loc.get("container-type-not-converted", typeName).toString());
 		

Modified: labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOEndTransactionListener.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOEndTransactionListener.java?rev=886729&r1=886728&r2=886729&view=diff
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOEndTransactionListener.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOEndTransactionListener.java Thu Dec  3 10:13:07 2009
@@ -18,25 +18,17 @@
  */
 package org.apache.openjpa.sdo;
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Iterator;
-import java.util.List;
-import java.util.Collections;
 import java.util.Set;
 
-import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.event.EndTransactionListener;
+import org.apache.openjpa.event.RemoteCommitListener;
 import org.apache.openjpa.event.TransactionEvent;
 import org.apache.openjpa.kernel.Broker;
 import org.apache.openjpa.kernel.OpenJPAStateManager;
-import org.apache.openjpa.lib.util.Closeable;
 import org.apache.openjpa.lib.util.Localizer;
-import org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager;
-import org.apache.openjpa.util.UserException;
-
-import commonj.sdo.DataObject;
 
 /**
  * Manager that can be used to track and notify
@@ -49,8 +41,7 @@
 public class SDOEndTransactionListener
     implements EndTransactionListener {
 
-    private static final Localizer _loc = Localizer.forPackage
-        (SDOEndTransactionListener.class);
+    private static final Localizer _loc = Localizer.forPackage(SDOEndTransactionListener.class);
 	SDOEntityManager em;
 	private Set<Object> cacheremove = new HashSet<Object>();
 	private Set<Object> cachesync = new HashSet<Object>();

Modified: labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOEntityManager.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOEntityManager.java?rev=886729&r1=886728&r2=886729&view=diff
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOEntityManager.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOEntityManager.java Thu Dec  3 10:13:07 2009
@@ -63,12 +63,12 @@
     private static final Localizer _loc = Localizer.forPackage(SDOEntityManager.class);
 	
 	private SDOMetaDataFactory repos;
+	private String applyChangesMode;
 
   public SDOMetaDataFactory getRepos() {
 	    return repos;
 	}
 
-private String applyChangesMode;
 	
 	public SDOEntityManager(SDOEntityManagerFactory emf, Broker broker) {
 		super(emf, broker);
@@ -160,7 +160,7 @@
      * Creates a Query using JPQL that will return list of DataObject as result. 
      */
 	@Override
-	public OpenJPAQuery createQuery(String jpql) {
+	public OpenJPAQuery<DataObject> createQuery(String jpql) {
 		Query kernelQuery = getBroker().newQuery(JPQLParser.LANG_JPQL, jpql);
         return new SDOQuery(this, kernelQuery); 
 	}
@@ -210,11 +210,11 @@
 	 * identity.
 	 */
 	DataObject scanLocalCache(Type type, String id) {
-		Set dataObjects = cache.keySet();
+		Set<DataObject> dataObjects = cache.keySet();
 		for (Object d:dataObjects) {
 			DataObject data = (DataObject)d;
 			if (data.getType().equals(type)) {
-				Object idValue = ImplHelper.getIdValue(data);
+				Object idValue = SDOTypeParser.getIdValue(data);
 				if (id.equals(idValue.toString()))
 					return data;
 			}
@@ -275,11 +275,11 @@
      }
   
 	
-	public Type getSDOType(Class cls) {
+	public Type getSDOType(Class<?> cls) {
 		return repos.getSDOType(cls);
 	}
 	
-    public Type getSDOType(Class cls, boolean mustExist) {
+    public Type getSDOType(Class<?> cls, boolean mustExist) {
         return repos.getSDOType(cls);
     }
   
@@ -315,8 +315,8 @@
 		}
 	}
 
-  public String getApplyChangesMode() {
-    return applyChangesMode;
-  }
+    public String getApplyChangesMode() {
+       return applyChangesMode;
+    }
 	
 }

Modified: labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOEntityManagerFactory.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOEntityManagerFactory.java?rev=886729&r1=886728&r2=886729&view=diff
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOEntityManagerFactory.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOEntityManagerFactory.java Thu Dec  3 10:13:07 2009
@@ -33,7 +33,7 @@
  */
 @SuppressWarnings("serial")
 public class SDOEntityManagerFactory extends EntityManagerFactoryImpl {
-  private String applyChanges;
+    private String applyChanges;
 	public SDOEntityManagerFactory() {
 		super();
 	}

Modified: labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOInstanceMapping.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOInstanceMapping.java?rev=886729&r1=886728&r2=886729&view=diff
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOInstanceMapping.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOInstanceMapping.java Thu Dec  3 10:13:07 2009
@@ -39,283 +39,275 @@
  * Conversion is essentially copying data from one representation to another.
  * Two aspects are a) maintaining identity/version correspondence between
  * DataObject and PersistenceCapable representation b) closure of the instance
- * being converted. 
+ * being converted.
  * 
  * @author Pinaki Poddar
  * @since 0.2.0
- *
+ * 
  */
 public class SDOInstanceMapping {
-	private final SDOMetaDataFactory repos;
-	private final SDOEntityManager em;
-	private final BiDiMap<DataObject,Object> closure;
-    protected static final Object[] NULL_ARGS = new Object[]{};
-
-	public SDOInstanceMapping(SDOEntityManager em, SDOMetaDataFactory repos) {
-		this.repos = repos;
-		this.em = em;
-		this.closure = new BiDiMap<DataObject,Object>();
-	}
-	
-	/**
-	 * Populates a DataObject from the field values of the given object.  
-	 */
-	public DataObject populateDataObject(Object pc, boolean findCached) {
-		Class<?> cls = ImplHelper.getEnhancedClass(pc);
-		Type type = repos.getSDOType(cls);
-		DataObject data = (DataObject) closure.getReverse(pc);
-		if (data != null) {
-			return data;
-		}
-		TypeMapping tm = repos.getMapping(type, true);
-		if (findCached) {
-    		if ((data = em.findCached(pc)) == null)	{
-    			data = tm.newDataObject();
-    			cache(data, pc);
-    		} else {
-    			closure.put(data, pc);
-    		}
-		} else {
+    private final SDOMetaDataFactory repos;
+    private final SDOEntityManager em;
+    private final BiDiMap<DataObject, Object> closure;
+    protected static final Object[] NULL_ARGS = new Object[] {};
+
+    public SDOInstanceMapping(SDOEntityManager em, SDOMetaDataFactory repos) {
+        this.repos = repos;
+        this.em = em;
+        this.closure = new BiDiMap<DataObject, Object>();
+    }
+
+    /**
+     * Populates a DataObject from the field values of the given object.
+     */
+    public DataObject populateDataObject(Object pc, boolean findCached) {
+        Class<?> cls = ImplHelper.getEnhancedClass(pc);
+        Type type = repos.getSDOType(cls);
+        DataObject data = (DataObject) closure.getReverse(pc);
+        if (data != null) {
+            return data;
+        }
+        TypeMapping tm = repos.getMapping(type, true);
+        if (findCached) {
+            if ((data = em.findCached(pc)) == null) {
+                data = tm.newDataObject();
+                cache(data, pc);
+            } else {
+                closure.put(data, pc);
+            }
+        } else {
             data = tm.newDataObject();
             cache(data, pc);
-		}
-		Collection<PropertyMapping> properties = tm.getMappings();
-		for (PropertyMapping pm : properties) {
-			try {
-				pm.populateDataObject(data, pc, this);
-			} catch (InvocationTargetException e) {
-				if (e.getTargetException() instanceof EntityNotFoundException) {
-					EntityNotFoundException en = (EntityNotFoundException) e.getTargetException();
-					throw en;
-				} else
-					throw new PersistenceException(e);					
-			} catch (Exception e) {
-				throw new PersistenceException(e);
-			}
-		}
-		return data;
-	}
-	
-	/**
-	 * Populates a cached or new Object with the given DataObject.
-	 * 
-	 */
-	public Object populatePC(DataObject data) {
-		Type type = data.getType();
-		Class<?> cls = repos.getJavaClass(type);
-		
-		Object pc = closure.get(data);
-		if (pc != null) {
-//			sync(pc, data);
-			return pc;
-		}
-		TypeMapping tm = repos.getMapping(type, true);
-		if ((pc = em.findCached(data)) == null)
-		{
-			pc = tm.newPC();
-			cache(data, pc);
-		} else 
-			closure.put(data, pc);
-		Collection<PropertyMapping> properties = tm.getMappings();
-		try {
-			for (PropertyMapping pm : properties) {
-/*				if (pm.getProperty() != null && !data.isSet(pm.getProperty())) {
-					continue;
-				} */
-				pm.populatePC(pc, data, this);
-			} 
-		} catch (Exception ex) {
-			throw new PersistenceException(ex);
-		}
-		return pc;
-	}
-
-   /**
-   * Populate the given object with DataObjet changes taken from  a DataGraph change summary
-   */
-  public Object applyChanges(DataObject data) {
-    Object pc = closure.get(data);
-    if (pc != null) {
-      return pc;
-    }
-    ChangeSummary changeSummary = data.getDataGraph().getChangeSummary();
-    boolean changed = changeSummary.isCreated(data) || changeSummary.isDeleted(data) || changeSummary.isModified(data);
-    pc = em.findCached(data);
-    if (pc == null) {
-      pc = em.findPC(data);
-    }
-    if (!changed) {
-      if (pc == null && "merge".equals(em.getApplyChangesMode())) {
-        pc = applyChangesCreate(data, pc);
-      }
-    } else if (changeSummary.isCreated(data) && !changeSummary.isDeleted(data)) {
-      if (pc == null || "merge".equals(em.getApplyChangesMode())) {
-        pc = applyChangesCreate(data, pc);      
-      }
-    } else if (!changeSummary.isCreated(data) && !changeSummary.isDeleted(data)) {
-      if (pc != null) {
-        applyChangesModify(data, pc, changeSummary.getOldValues(data));                    
-      } else if ("merge".equals(em.getApplyChangesMode())) {
-        pc = applyChangesCreate(data, pc);
-      }
-    } else if (changeSummary.isDeleted(data)) {
-      if (pc != null) {
-        em.remove(pc);            
-        em.removeCached(pc);
-        pc = null;
-      }
-    }    
-    if (pc != null && !pc.equals(closure.get(data))) {
-      closure.put(data, pc);
-    }
-    return pc;
-  }	
-	
-  /**
-	 * Populate the given object with DataObjet changes taken from  a DataGraph change summary
-	 */
-	public Object applyChangesCreate(DataObject data, Object pc) {
-    Type type = data.getType();
-    Class cls = repos.getJavaClass(type);
-    TypeMapping tm = repos.getMapping(type, true);
-    if (pc == null)
-    {
-      pc = tm.newPC();
-      closure.put(data, pc);
-    }
-    Collection<PropertyMapping> properties = tm.getMappings();
-    try {
-      for (PropertyMapping pm:properties) {
-/*        if (pm.getProperty() != null && !data.isSet(pm.getProperty())) {
-          continue;
-        } */
-        pm.applyChangesCreate(data, pc, this);
-      } 
-    } catch (Exception ex) {
-      throw new PersistenceException(ex);
-    }
-    em.persist(pc);
-    return pc;
-	}
-	
-  /**
-   * Populate the given object with DataObjet changes taken from  a DataGraph change summary
-   */
-  public Object applyChangesModify(DataObject data, Object pc, List<ChangeSummary.Setting> changes) {
-    Type type = data.getType();
-    TypeMapping tm = repos.getMapping(type, true);
-    for (ChangeSummary.Setting change:changes) {
-      PropertyMapping pm = tm.getMapping(change.getProperty());     
-      try {
-        pm.applyChangesModify(data, pc, change, this);
-      } catch (Exception e) {
-        throw new PersistenceException(e);
-      }
-    }
-    return pc;
-  }
-  
-	/**
-	 * Create a new instance of the given Class and synchronize identity/version
-	 * information with the given DataObject.
-	 */
-	Object newPC(Class cls, DataObject data) {
-		try {
-			Object pc = cls.newInstance();
-//			sync(pc, data);
-			return pc;
-		} catch (Exception e) {
-			throw new PersistenceException(e);
-		} 
-	}
-	
-	/**
-	 * Create a new DataObject of the given Type and synchronize identity/version
-	 * information with the given object.
-	 */
-	DataObject newDataObject(Type type, Object pc) {
-		try {
-			DataObject data = DataFactory.INSTANCE.create(type); 
-//			sync(pc, data);
-			return data;
-		} catch (Exception e) {
-			throw new PersistenceException(e);
-		} 
-	}
-	
-	/**
-	 * Get the closure of DataObjects and PersistenceCapable instances.
-	 */
-	public BiDiMap<DataObject,Object> getClosure() {
-		return closure;
-	}
-	
-	/**
-	 * Clears the state of this receiver.
-	 *
-	 */
-	public void reset() {
-		closure.clear();
-	}
-
-	/**
-	 * Find a PersistenceCapable instance given a DataObject. Looks in its own
-	 * closure and if not found looks up in the managed cahche.
-	 * Can be null.
-	 */
-	Object findCached(DataObject data) {
-		Object pc = closure.get(data);
-		if (pc == null) 
-			return em.findCached(data);
-		return pc;
-	}
-	
-	/**
-	 * Find a DataObject given a PersistenceCapable instance. Looks in its own
-	 * closure and if not found looks up in the managed cahche.
-	 * Can be null.
-	 */
-	DataObject findCached(Object pc) {
-		DataObject data = (DataObject)closure.getReverse(pc);
-		if (data == null) 
-			return em.findCached(pc);
-		return data;
-	}
-	
-	/**
-	 * Caches the pair in its own closure and also in the managed cache.
-	 * @param data
-	 * @param pc
-	 */
-	void cache(DataObject data, Object pc) {
-		closure.put(data, pc);
-		em.cache(data, pc);
-	}
-	
-	/**
-	 * Checks id/version of PersistenceCapable instance with the id/version values 
-	 * from the given DataObject.
-	 */
-	void sync(Object pc, DataObject data) {
-		Object idValue = ImplHelper.getIdValue(data);
-		int version = ImplHelper.getVersion(data);
-		int pcversion = (Integer)em.getVersion(pc); 
-		if (version != 0) { // existing Data
-			if (pcversion!=0 && !em.getVersion(pc).equals(version))
-				throw new OptimisticException(pc);
-		} else if (pcversion!=0) {
-			try {
-				repos.getMapping(data.getType(), true).getIdentityMapping()
-					.populateDataObject(data, pc, this);
-				repos.getMapping(data.getType(), true).getVersionMapping()
-					.populateDataObject(data, pc, this);
-			} catch (Exception e) {
-				throw new PersistenceException(e);
-			}
-		}
-	}
-  
-	public SDOEntityManager getEm() {
-		return em;
-	}
+        }
+        Collection<PropertyMapping> properties = tm.getMappings();
+        for (PropertyMapping pm : properties) {
+            try {
+                pm.populateDataObject(data, pc, this);
+            } catch (InvocationTargetException e) {
+                if (e.getTargetException() instanceof EntityNotFoundException) {
+                    EntityNotFoundException en = (EntityNotFoundException) e.getTargetException();
+                    throw en;
+                } else {
+                    throw new PersistenceException(e);
+                }
+            } catch (Exception e) {
+                throw new PersistenceException(e);
+            }
+        }
+        return data;
+    }
+
+    /**
+     * Populates a cached or new Object with the given DataObject.
+     * 
+     */
+    public Object populatePC(DataObject data) {
+        Type type = data.getType();
+
+        Object pc = closure.get(data);
+        if (pc != null) {
+            return pc;
+        }
+        TypeMapping tm = repos.getMapping(type, true);
+        if ((pc = em.findCached(data)) == null) {
+            pc = tm.newPC();
+            cache(data, pc);
+        } else {
+            closure.put(data, pc);
+        }
+        Collection<PropertyMapping> properties = tm.getMappings();
+        try {
+            for (PropertyMapping pm : properties) {
+                pm.populatePC(pc, data, this);
+            }
+        } catch (Exception ex) {
+            throw new PersistenceException(ex);
+        }
+        return pc;
+    }
+
+    /**
+     * Populate the given object with DataObjet changes taken from a DataGraph
+     * change summary
+     */
+    public Object applyChanges(DataObject data) {
+        Object pc = closure.get(data);
+        if (pc != null) {
+            return pc;
+        }
+        ChangeSummary changeSummary = data.getDataGraph().getChangeSummary();
+        boolean changed = changeSummary.isCreated(data) || changeSummary.isDeleted(data)
+                || changeSummary.isModified(data);
+        pc = em.findCached(data);
+        if (pc == null) {
+            pc = em.findPC(data);
+        }
+        if (!changed) {
+            if (pc == null && "merge".equals(em.getApplyChangesMode())) {
+                pc = applyChangesCreate(data, pc);
+            }
+        } else if (changeSummary.isCreated(data) && !changeSummary.isDeleted(data)) {
+            if (pc == null || "merge".equals(em.getApplyChangesMode())) {
+                pc = applyChangesCreate(data, pc);
+            }
+        } else if (!changeSummary.isCreated(data) && !changeSummary.isDeleted(data)) {
+            if (pc != null) {
+                applyChangesModify(data, pc, changeSummary.getOldValues(data));
+            } else if ("merge".equals(em.getApplyChangesMode())) {
+                pc = applyChangesCreate(data, pc);
+            }
+        } else if (changeSummary.isDeleted(data)) {
+            if (pc != null) {
+                em.remove(pc);
+                em.removeCached(pc);
+                pc = null;
+            }
+        }
+        if (pc != null && !pc.equals(closure.get(data))) {
+            closure.put(data, pc);
+        }
+        return pc;
+    }
+
+    /**
+     * Populate the given object with DataObjet changes taken from a DataGraph
+     * change summary
+     */
+    public Object applyChangesCreate(DataObject data, Object pc) {
+        Type type = data.getType();
+        TypeMapping tm = repos.getMapping(type, true);
+        if (pc == null) {
+            pc = tm.newPC();
+            closure.put(data, pc);
+        }
+        Collection<PropertyMapping> properties = tm.getMappings();
+        try {
+            for (PropertyMapping pm : properties) {
+                pm.applyChangesCreate(data, pc, this);
+            }
+        } catch (Exception ex) {
+            throw new PersistenceException(ex);
+        }
+        em.persist(pc);
+        return pc;
+    }
+
+    /**
+     * Populate the given object with DataObjet changes taken from a DataGraph
+     * change summary
+     */
+    public Object applyChangesModify(DataObject data, Object pc, List<ChangeSummary.Setting> changes) {
+        Type type = data.getType();
+        TypeMapping tm = repos.getMapping(type, true);
+        for (ChangeSummary.Setting change : changes) {
+            PropertyMapping pm = tm.getMapping(change.getProperty());
+            try {
+                pm.applyChangesModify(data, pc, change, this);
+            } catch (Exception e) {
+                throw new PersistenceException(e);
+            }
+        }
+        return pc;
+    }
+
+    /**
+     * Create a new instance of the given Class and synchronize identity/version
+     * information with the given DataObject.
+     */
+    Object newPC(Class<?> cls, DataObject data) {
+        try {
+            Object pc = cls.newInstance();
+            return pc;
+        } catch (Exception e) {
+            throw new PersistenceException(e);
+        }
+    }
+
+    /**
+     * Create a new DataObject of the given Type and synchronize
+     * identity/version information with the given object.
+     */
+    DataObject newDataObject(Type type, Object pc) {
+        try {
+            DataObject data = DataFactory.INSTANCE.create(type);
+            return data;
+        } catch (Exception e) {
+            throw new PersistenceException(e);
+        }
+    }
+
+    /**
+     * Get the closure of DataObjects and PersistenceCapable instances.
+     */
+    public BiDiMap<DataObject, Object> getClosure() {
+        return closure;
+    }
+
+    /**
+     * Clears the state of this receiver.
+     * 
+     */
+    public void reset() {
+        closure.clear();
+    }
+
+    /**
+     * Find a PersistenceCapable instance given a DataObject. Looks in its own
+     * closure and if not found looks up in the managed cahche. Can be null.
+     */
+    Object findCached(DataObject data) {
+        Object pc = closure.get(data);
+        if (pc == null)
+            return em.findCached(data);
+        return pc;
+    }
+
+    /**
+     * Find a DataObject given a PersistenceCapable instance. Looks in its own
+     * closure and if not found looks up in the managed cahche. Can be null.
+     */
+    DataObject findCached(Object pc) {
+        DataObject data = (DataObject) closure.getReverse(pc);
+        if (data == null)
+            return em.findCached(pc);
+        return data;
+    }
+
+    /**
+     * Caches the pair in its own closure and also in the managed cache.
+     * 
+     * @param data
+     * @param pc
+     */
+    void cache(DataObject data, Object pc) {
+        closure.put(data, pc);
+        em.cache(data, pc);
+    }
+
+    /**
+     * Checks version of PersistenceCapable instance with the version values
+     * from the given DataObject.
+     */
+    void sync(Object pc, DataObject data) {
+        Integer version = SDOTypeParser.getVersion(data);
+        Integer pcversion = (Integer) em.getVersion(pc);
+        if (version == null)
+            return;
+        if (version != 0) { // existing Data
+            if (pcversion != 0 && !em.getVersion(pc).equals(version)) {
+                throw new OptimisticException(pc);
+            }
+        } else if (pcversion != 0) {
+            try {
+                repos.getMapping(data.getType(), true).getIdentityMapping().populateDataObject(data, pc, this);
+                repos.getMapping(data.getType(), true).getVersionMapping().populateDataObject(data, pc, this);
+            } catch (Exception e) {
+                throw new PersistenceException(e);
+            }
+        }
+    }
+
+    public SDOEntityManager getEntityManager() {
+        return em;
+    }
 }

Modified: labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOQuery.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOQuery.java?rev=886729&r1=886728&r2=886729&view=diff
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOQuery.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOQuery.java Thu Dec  3 10:13:07 2009
@@ -28,6 +28,8 @@
 import org.apache.openjpa.persistence.PersistenceExceptions;
 import org.apache.openjpa.persistence.QueryImpl;
 
+import commonj.sdo.DataObject;
+
 /**
  * A Query that returns SDO DataObjects instead of PersistenceCapable POJOs.
  * 

Modified: labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOTypeParser.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOTypeParser.java?rev=886729&r1=886728&r2=886729&view=diff
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOTypeParser.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOTypeParser.java Thu Dec  3 10:13:07 2009
@@ -13,120 +13,308 @@
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.meta.ClassArgParser;
 import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.util.UserException;
 
+import commonj.sdo.DataObject;
+import commonj.sdo.Property;
 import commonj.sdo.Type;
 import commonj.sdo.helper.XSDHelper;
 
 /**
- * Parses XML Schema definition for SDO Types.
- * Statically caches the parsed types indexed by their SDO Type name as well as fully-qualified Java class names.
- * Avoids repeated parse of the same resource.
+ * Parses XML Schema definition for SDO Types. Statically caches the parsed
+ * types indexed by their SDO Type name as well as fully-qualified Java class
+ * names. Avoids repeated parse of the same resource.
  * 
  * @author Pinaki Poddar
  * @since 0.1.0
  */
 public class SDOTypeParser extends ClassArgParser {
-	private static final Localizer _loc = Localizer.forPackage(SDOTypeParser.class);
-	private static Map<String, List<Type>> parsedResource = new HashMap<String, List<Type>>();
-	private static Map<String, Type> parsedTypes = new HashMap<String, Type>();
-	private Log _log;	
-	
-	/**
-	 * Supply configuration.
-	 */
-	public SDOTypeParser(OpenJPAConfiguration conf) {
-		_log = conf.getLog(OpenJPAConfiguration.LOG_METADATA);
-	}
-	
-	public List<Type> parseXSDResource(String resource) {
-		if (parsedResource.containsKey(resource)) {
-			if (_log.isWarnEnabled())
-				_log.warn(_loc.get("repeat-parse", resource));
-			return parsedResource.get(resource);
-		}
-		
-		_log.info(_loc.get("parse-xml-schema", resource));
-		ClassLoader loader = Thread.currentThread().getContextClassLoader();
-		InputStream xsdInputStream = loader.getResourceAsStream(resource);
-		if (xsdInputStream == null) {
-			if (_log.isWarnEnabled()) {
-				_log.warn(_loc.get("xsd-not-found", resource, getClassLoader()).toString());
-			}
-			return Collections.emptyList();
-		}
-		List<Type> userTypes = new ArrayList<Type>();
-		try {
-			if (XSDHelper.INSTANCE == null)
-				throw new RuntimeException("no-sdo-provider");
-			List types = XSDHelper.INSTANCE.define(xsdInputStream, null);
-			for (Object t : types) {
-				if (t instanceof Type == false)
-					continue;
-				Type type = (Type) t;
-				if (!(type.isDataType() || "DocumentRoot".equals(type.getName())
-						|| ImplHelper.isContainer(type))) {
-					userTypes.add(type);
-					parsedTypes.put(type.getName(), type);
-				}
-			}
-		} finally {
-			try {
-				parsedResource.put(resource, userTypes);
-				xsdInputStream.close();
-			} catch (IOException e) {
-				//ignore
-			}
-		}
-		return userTypes;
-		
-	}
-	
-	/**
-	 * Parse the given resource if it has not been parsed already.
-	 * If resource is null or does not end with ".xsd", delegate to superclass
-	 * for processing.
-	 * 
-	 */
-	@Override
-	public String[] parseTypeNames(String resource) {
-		if (resource == null || !resource.endsWith(".xsd"))
-			return super.parseTypeNames(resource);
-		return toJavaClassNames(parseXSDResource(resource));
-	}
-	
-	/**
-	 * Gets fully-qualified Java class names for the given list of SDO Types. 
-	 */
-	public static String[] toJavaClassNames(Collection<Type> types) {
-	    if (types == null)
-	        return new String[0];
-		String[] names = new String[types.size()];
-		int i = 0;
-		for (Type type : types) {
-			names[i++] = ImplHelper.getFullClassName(type);
-		}
-		return names;
-	}
-	
-	/**
-	 * Find a SDO type of given name from all the currently parsed types.
-	 */
-	public static Type findType(String name) {
-	    return parsedTypes.get(name);
-	}
-	
-	/**
-	 * Gets all SDO types parsed so far.
-	 * @return
-	 */
-	public static Collection<Type> getParsedTypes() {
-	    return parsedTypes.values();
-	}
-	
-	/**
-	 * Get SDO Types parsed from the given resource.
-	 */
-	public static List<Type> getParsedTypes(String resource) {
-		return parsedResource.get(resource); 
-	}
+    private static final Localizer _loc = Localizer.forPackage(SDOTypeParser.class);
+    private static Map<String, List<Type>> parsedResource = new HashMap<String, List<Type>>();
+    private static Map<String, Type> parsedTypes = new HashMap<String, Type>();
+    private Log _log;
+    private static HashMap<Type, List<Property>> containments = new HashMap<Type, List<Property>>();
+    private static HashMap<Type, List<Property>> references   = new HashMap<Type, List<Property>>();
+    private static HashMap<Type, Property> identity = new HashMap<Type, Property>();
+    /**
+     * Supply configuration.
+     */
+    public SDOTypeParser(OpenJPAConfiguration conf) {
+        _log = conf.getLog(OpenJPAConfiguration.LOG_METADATA);
+    }
+
+    public List<Type> parseXSDResource(String resource) {
+        if (parsedResource.containsKey(resource)) {
+            if (_log.isWarnEnabled())
+                _log.warn(_loc.get("repeat-parse", resource));
+            return parsedResource.get(resource);
+        }
+
+        _log.info(_loc.get("parse-xml-schema", resource));
+        ClassLoader loader = Thread.currentThread().getContextClassLoader();
+        InputStream xsdInputStream = loader.getResourceAsStream(resource);
+        if (xsdInputStream == null) {
+            if (_log.isWarnEnabled()) {
+                _log.warn(_loc.get("xsd-not-found", resource, getClassLoader()).toString());
+            }
+            return Collections.emptyList();
+        }
+        List<Type> userTypes = new ArrayList<Type>();
+        try {
+            if (XSDHelper.INSTANCE == null)
+                throw new RuntimeException("no-sdo-provider");
+            List types = XSDHelper.INSTANCE.define(xsdInputStream, null);
+            for (Object t : types) {
+                if (t instanceof Type == false)
+                    continue;
+                Type type = (Type) t;
+                if (!(type.isDataType() || "DocumentRoot".equals(type.getName()) || isContainer(type))) {
+                    assertIdentity(type);
+                    userTypes.add(type);
+                    parsedTypes.put(type.getName(), type);
+                }
+                refreshPropertyRelations();
+            }
+        } finally {
+            try {
+                parsedResource.put(resource, userTypes);
+                xsdInputStream.close();
+            } catch (IOException e) {
+                // ignore
+            }
+        }
+        return userTypes;
+    }
+    
+    static void assertIdentity(Type type) {
+        if (identity.containsKey(type))
+            return;
+        Property id = ImplHelper.getIdentityProperty(type);
+        if (id == null)
+            throw new RuntimeException(_loc.get("no-id-property", type.getName()).getMessage());
+        identity.put(type, id);
+    }
+    
+    public static Property getIdentityProperty(Type type) {
+        assertIdentity(type);
+        return identity.get(type);
+    }
+    
+    /**
+     * Affirms if the given property is identity property.
+     */
+    public static boolean isIdentity(Property property) {
+        return property != null && identity.containsValue(property);
+    }
+
+    /**
+     * Gets the value of the {@link #getIdentityProperty(Type) identity
+     * property} of the given DataObject.
+     */
+    public static Object getIdValue(DataObject sdo) {
+        return sdo.get(getIdentityProperty(sdo.getType()));
+    }
+    /**
+     * Gets the property that represents version information. Version property
+     * is a property named <code>version</code> and declared as
+     * <code>xsd:int</code> type.
+     */
+    public static Property getVersionProperty(Type type) {
+        Property version = type.getProperty("version");
+        if (!isVersion(version))
+            throw new UserException(_loc.get("missing-version", type.getName()).toString());
+        return version;
+    }
+
+    /**
+     * Affirms if the property represents version. Version property is a
+     * property named <code>version</code> and declared as <code>xsd:int</code>
+     * type.
+     */
+    public static boolean isVersion(Property property) {
+        return (property != null && property.getName().equals("version") && property.getType().isDataType() && property
+                .getType().getInstanceClass() == int.class);
+    }
+
+    /**
+     * Affirms if the property represents a LOB type. LOB types are property or
+     * types that have alias named "LOB".
+     */
+    public static boolean isLOB(Property property) {
+        return (property != null && property.getType().isDataType() && (property.getAliasNames().contains("LOB") 
+                || property.getType().getAliasNames().contains("LOB")));
+    }
+
+    /**
+     * Gets the version of the given DataObject.
+     * 
+     * @see #getVersionProperty(Type)
+     */
+    public static Integer getVersion(DataObject data) {
+        Property version = getVersionProperty(data.getType());
+        return version == null ? null : data.getInt(version);
+    }
+
+    /**
+     * Parse the given resource if it has not been parsed already. If resource
+     * is null or does not end with ".xsd", delegate to superclass for
+     * processing.
+     * 
+     */
+    @Override
+    public String[] parseTypeNames(String resource) {
+        if (resource == null || !resource.endsWith(".xsd"))
+            return super.parseTypeNames(resource);
+        return toJavaClassNames(parseXSDResource(resource));
+    }
+
+    /**
+     * Gets fully-qualified Java class names for the given list of SDO Types.
+     */
+    public static String[] toJavaClassNames(Collection<Type> types) {
+        if (types == null)
+            return new String[0];
+        String[] names = new String[types.size()];
+        int i = 0;
+        for (Type type : types) {
+            names[i++] = ImplHelper.getFullClassName(type);
+        }
+        return names;
+    }
+
+    /**
+     * Find a SDO type of given name from all the currently parsed types.
+     */
+    public static Type findType(String name) {
+        return parsedTypes.get(name);
+    }
+
+    /**
+     * Gets all SDO types parsed so far.
+     * 
+     * @return
+     */
+    public static Collection<Type> getParsedTypes() {
+        return parsedTypes.values();
+    }
+
+    /**
+     * Get SDO Types parsed from the given resource.
+     */
+    public static List<Type> getParsedTypes(String resource) {
+        return parsedResource.get(resource);
+    }
+
+    /**
+     * Gets the properties that has the given referencing property.
+     */
+    public static List<Property> getReferenceProperties(Type t) {
+        ArrayList<Property> ret = null;
+        for (Type type : parsedTypes.values()) {
+            List<Property> properties = type.getProperties();
+            for (Property p : properties) {
+                if (p.getType().equals(t) && !p.getType().isDataType() && !p.isContainment()) {
+                    if (ret == null)
+                        ret = new ArrayList<Property>();
+                    ret.add(p);
+                }
+            }
+        }
+        return ret;
+    }
+
+    public static Map<Type, List<Property>> getContainments() {
+//        if (containments == null) {
+//            containments = new HashMap<Type, List<Property>>();
+//            references = new HashMap<Type, List<Property>>();
+//            refreshPropertyRelations();
+//        } else if (refresh)
+//            refreshPropertyRelations();
+        return containments;
+    }
+
+    public static Map<Type, List<Property>> getReferences() {
+//        if (containments == null) {
+//            containments = new HashMap<Type, List<Property>>();
+//            references = new HashMap<Type, List<Property>>();
+//            refreshPropertyRelations();
+//        } else if (refresh)
+//            refreshPropertyRelations();
+        return references;
+    }
+
+    private static void refreshPropertyRelations() {
+        containments.clear();
+        references.clear();
+        for (Type t : parsedTypes.values()) {
+            List<Property> c = getContainerProperties(t);
+            if (c != null) {
+                containments.put(t, c);
+            }
+            List<Property> r = getReferenceProperties(t);
+            if (r != null) {
+                references.put(t, r);
+            }
+        }
+
+    }
+
+    /**
+     * Gets the properties that contains the given type.
+     */
+    public static List<Property> getContainerProperties(Type type) {
+        ArrayList<Property> ret = null;
+        for (Type t : parsedTypes.values()) {
+            List<Property> properties = t.getProperties();
+            for (Property p : properties) {
+                if (!p.isContainment())
+                    continue;
+                Property cp = getComponentProperty(p.getType());
+                if ((p.getType().equals(type)) || (cp != null && cp.isContainment() && cp.getType().equals(type))) {
+                    if (ret == null)
+                        ret = new ArrayList<Property>();
+                    ret.add(p);
+                }
+            }
+        }
+        return ret;
+    }
+
+    /**
+     * If the given type is a {@link #isContainer(Type) container type} then
+     * return the type of its one and only one property. Otherwise null.
+     */
+    public static Type getComponentType(Type type) {
+        if (isContainer(type)) {
+            return ((Property) type.getProperties().get(0)).getType();
+        }
+        return null;
+    }
+
+    /**
+     * If the given type is a {@link #isContainer(Type) container type} then
+     * return the one and only one property it contains. Otherwise null.
+     */
+    public static Property getComponentProperty(Type type) {
+        if (isContainer(type)) {
+            return (Property) type.getProperties().get(0);
+        }
+        return null;
+    }
+
+    /**
+     * Affirms if this type is <em>Container</em> type. A Type is defined as a
+     * container if <LI>it has one and only one property and <LI>that property
+     * is many-valued and <LI>type of that single property is <em>not</em> a
+     * basic data type.
+     */
+    public static boolean isContainer(Type type) {
+        List properties = type.getProperties();
+        if (properties.size() == 1) {
+            Property p = (Property) properties.get(0);
+            return p.isMany();
+        }
+        return false;
+    }
+
 }

Modified: labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/ContainerRelationMapping.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/ContainerRelationMapping.java?rev=886729&r1=886728&r2=886729&view=diff
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/ContainerRelationMapping.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/ContainerRelationMapping.java Thu Dec  3 10:13:07 2009
@@ -27,6 +27,7 @@
 import org.apache.openjpa.sdo.ImplHelper;
 import org.apache.openjpa.sdo.SDOInstanceMapping;
 import org.apache.openjpa.sdo.SDOMetaDataFactory;
+import org.apache.openjpa.sdo.SDOTypeParser;
 
 import serp.bytecode.Annotation;
 import serp.bytecode.Annotations;
@@ -72,7 +73,7 @@
 	
 	public String[] getAnnotationStrings() {
 		// Right now we need only for SDO2POJOGenerator
-		if (property.isMany() || ImplHelper.isContainer(property.getType()))
+		if (property.isMany() || SDOTypeParser.isContainer(property.getType()))
 			return new String[] {"@ManyToOne(cascade={CascadeType.PERSIST,CascadeType.REFRESH,CascadeType.MERGE})"};
 		else
 			return new String[] {"@OneToOne(cascade={CascadeType.PERSIST,CascadeType.REFRESH,CascadeType.MERGE})"};			
@@ -81,7 +82,7 @@
 	public void annotate(BCMember field) {
 		Annotations annos = field.getDeclaredRuntimeAnnotations(true);
 		Annotation r;
-		if (property.isMany() || ImplHelper.isContainer(property.getType())) {
+		if (property.isMany() || SDOTypeParser.isContainer(property.getType())) {
 			r = annos.addAnnotation(ManyToOne.class);
 		} else {
 			r = annos.addAnnotation(OneToOne.class);
@@ -104,7 +105,7 @@
 		Object result = null;
 		DataObject value = data.getContainer();
 		if (data.getContainer() != null) {
-			if (ImplHelper.isContainer(property.getType()))
+			if (SDOTypeParser.isContainer(property.getType()))
 			{
 				value = data.getContainer().getContainer();
 			}
@@ -128,8 +129,7 @@
     Object result = null;
     DataObject value = data.getContainer();
     if (value != null) {
-      if (ImplHelper.isContainer(property.getType()))
-      {
+      if (SDOTypeParser.isContainer(property.getType())) {
         value = value.getContainer();
       }
       if (value != null)

Modified: labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/IdenticalTypeMapping.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/IdenticalTypeMapping.java?rev=886729&r1=886728&r2=886729&view=diff
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/IdenticalTypeMapping.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/IdenticalTypeMapping.java Thu Dec  3 10:13:07 2009
@@ -35,6 +35,7 @@
 import org.apache.openjpa.meta.FieldMetaData;
 import org.apache.openjpa.persistence.DetachedState;
 import org.apache.openjpa.sdo.ImplHelper;
+import org.apache.openjpa.sdo.SDOTypeParser;
 
 import serp.bytecode.Annotation;
 import serp.bytecode.Annotations;
@@ -61,14 +62,12 @@
 	protected Property owner = null;
 	protected List<Property> embedded = null;
 	
-	protected SDOMappingStrategyInstaller mappingStrategy = new SDOMappingStrategyInstaller();
-	
 	protected Map<Property, PropertyMapping> _propertyMappings = new HashMap<Property, PropertyMapping>();
 	
 	public IdenticalTypeMapping(Type type, Class<?> cls) {
 		this.type = type;
 		this.cls  = cls;
-		this.idType = (ImplHelper.getIdentityProperty(type) == null) ? 
+		this.idType = (SDOTypeParser.getIdentityProperty(type) == null) ? 
 				ClassMetaData.ID_DATASTORE : ClassMetaData.ID_APPLICATION;
 		
 		List properties = type.getProperties();
@@ -78,7 +77,6 @@
 		}
 	}
 	
-    
     public Class<?> getJavaClass() {
         return cls;
     }
@@ -98,7 +96,7 @@
 	public void resolve(ClassMetaData cm) {
 		if (resolved) return;
 		cls = cm.getDescribedType();
-		for (PropertyMapping p:_propertyMappings.values()) {
+		for (PropertyMapping p : _propertyMappings.values()) {
 			FieldMetaData fm = cm.getField(p.getFieldName());
 			p.resolve(fm);
 		}
@@ -178,22 +176,22 @@
 		List<String> l = new ArrayList<String>();
 		String[] ret = new String[] {};
 		l.add("@DetachedState(enabled=false)");
-		if (type.isAbstract() && !ImplHelper.getReferences().containsKey(type))
+		if (type.isAbstract() && !SDOTypeParser.getReferences().containsKey(type)) {
 			l.add("@MappedSuperclass");
-		else
-			l.add("@Entity");			
+		} else {
+			l.add("@Entity");
+		}
 		if (type.getBaseTypes() == null || type.getBaseTypes().size() == 0)
 			l.add("@Inheritance(strategy=InheritanceType.JOINED)");	
 		return l.toArray(ret);
 	}
 	
 	public void annotate(BCClass bcls) {
-		
 		Annotations classAnns = bcls.getDeclaredRuntimeAnnotations(true);
 		Annotation entityAnno;
 		entityAnno = classAnns.addAnnotation(DetachedState.class);
 		entityAnno.addProperty("enabled").setValue(false);
-		if (type.isAbstract() && !ImplHelper.getReferences().containsKey(type))
+		if (type.isAbstract() && !SDOTypeParser.getReferences().containsKey(type))
 			entityAnno = classAnns.addAnnotation(MappedSuperclass.class);
 		else
 			entityAnno = classAnns.addAnnotation(Entity.class);

Modified: labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/PrimitiveListMapping.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/PrimitiveListMapping.java?rev=886729&r1=886728&r2=886729&view=diff
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/PrimitiveListMapping.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/PrimitiveListMapping.java Thu Dec  3 10:13:07 2009
@@ -32,6 +32,7 @@
 import org.apache.openjpa.sdo.ImplHelper;
 import org.apache.openjpa.sdo.SDOInstanceMapping;
 import org.apache.openjpa.sdo.SDOMetaDataFactory;
+import org.apache.openjpa.sdo.SDOTypeParser;
 
 import serp.bytecode.Annotation;
 import serp.bytecode.Annotations;
@@ -58,18 +59,18 @@
 	}
 	
 	public String getFieldTypeName() {
-		Type elementType = ImplHelper.getComponentType(property.getType());
+		Type elementType = SDOTypeParser.getComponentType(property.getType());
 		if (elementType==null) 
 			elementType = property.getType();
 		return  "java.util.List<" + elementType.getInstanceClass().getName() + ">";
 	}
 	
 	public Class getFieldType(SDOMetaDataFactory repos) {
-//		Class componentType = ImplHelper.getComponentType(property.getType()).getInstanceClass();
 		return List.class;
 	}
+	
 	public String[] getAnnotationStrings() {
-		if (ImplHelper.isLOB(property))
+		if (SDOTypeParser.isLOB(property))
 			return new String[]{"@Lob", "@PersistentCollection"};
 		return new String[]{"@PersistentCollection"};
 	}
@@ -77,11 +78,11 @@
 	public void annotate(BCMember field) {
 		Annotations annos = field.getDeclaredRuntimeAnnotations(true);
 		Annotation r = annos.addAnnotation(PersistentCollection.class);
-    Type elementType = ImplHelper.getComponentType(property.getType());
-    if (elementType==null) 
-      elementType = property.getType();
-    r.addProperty("elementType").setClassNameValue(elementType.getInstanceClass().getName());		
-		if (ImplHelper.isLOB(property))
+        Type elementType = SDOTypeParser.getComponentType(property.getType());
+        if (elementType==null) 
+           elementType = property.getType();
+        r.addProperty("elementType").setClassNameValue(elementType.getInstanceClass().getName());		
+		if (SDOTypeParser.isLOB(property))
 			annos.addAnnotation(Lob.class);		
 	}
 

Modified: labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/PrimitiveMapping.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/PrimitiveMapping.java?rev=886729&r1=886728&r2=886729&view=diff
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/PrimitiveMapping.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/PrimitiveMapping.java Thu Dec  3 10:13:07 2009
@@ -25,6 +25,7 @@
 import org.apache.openjpa.sdo.ImplHelper;
 import org.apache.openjpa.sdo.SDOInstanceMapping;
 import org.apache.openjpa.sdo.SDOMetaDataFactory;
+import org.apache.openjpa.sdo.SDOTypeParser;
 
 import serp.bytecode.Annotations;
 import serp.bytecode.BCMember;
@@ -57,7 +58,7 @@
 	}
 	
 	public String[] getAnnotationStrings() {
-		if (ImplHelper.isLOB(property))
+		if (SDOTypeParser.isLOB(property))
 			return new String[]{"@Lob","@Basic"};
 		return new String[]{};
 	}
@@ -65,7 +66,7 @@
 	public void annotate(BCMember field) {
 		Annotations annos = field.getDeclaredRuntimeAnnotations(true);
 		annos.addAnnotation(Basic.class);
-		if (ImplHelper.isLOB(property))
+		if (SDOTypeParser.isLOB(property))
 			annos.addAnnotation(Lob.class);		
 	}
 	



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org