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 2007/07/26 05:31:02 UTC

svn commit: r559681 - in /labs/fluid: ./ src/main/java/org/apache/openjpa/code/ src/main/java/org/apache/openjpa/sdo/ src/main/resources/org/apache/openjpa/code/ src/site/ src/site/apt/ src/test/java/example/basic/ src/test/java/test/ src/test/java/tes...

Author: ppoddar
Date: Wed Jul 25 20:31:01 2007
New Revision: 559681

URL: http://svn.apache.org/viewvc?view=rev&rev=559681
Log:
Clean up

Added:
    labs/fluid/src/test/java/example/basic/TestRelation.java
    labs/fluid/src/test/java/example/basic/TestSDO.java
      - copied, changed from r559330, labs/fluid/src/test/java/test/TestSDO.java
    labs/fluid/src/test/java/example/basic/TestSourceCode.java
      - copied, changed from r559330, labs/fluid/src/test/java/test/TestSourceCode.java
Removed:
    labs/fluid/src/test/java/test/TestModel.java
    labs/fluid/src/test/java/test/TestSDO.java
    labs/fluid/src/test/java/test/TestSourceCode.java
Modified:
    labs/fluid/.classpath
    labs/fluid/pom.xml
    labs/fluid/src/main/java/org/apache/openjpa/code/SDO2POJOGenerator.java
    labs/fluid/src/main/java/org/apache/openjpa/code/SourceCode.java
    labs/fluid/src/main/java/org/apache/openjpa/code/XMLReadWrite.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/DelegatingDataObject.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/ImplHelper.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/SDODelegatingResultList.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/SDOMetaDataFactory.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOProductDerivation.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/SDOTypeRepository.java
    labs/fluid/src/main/resources/org/apache/openjpa/code/localizer.properties
    labs/fluid/src/site/apt/design.apt
    labs/fluid/src/site/apt/manual.apt
    labs/fluid/src/site/site.xml
    labs/fluid/src/test/java/example/basic/TestCRUD.java
    labs/fluid/src/test/java/test/common/AbstractSDOTest.java

Modified: labs/fluid/.classpath
URL: http://svn.apache.org/viewvc/labs/fluid/.classpath?view=diff&rev=559681&r1=559680&r2=559681
==============================================================================
--- labs/fluid/.classpath (original)
+++ labs/fluid/.classpath Wed Jul 25 20:31:01 2007
@@ -24,7 +24,11 @@
 	<classpathentry kind="var" path="M2_REPO/org/apache/geronimo/specs/geronimo-jta_1.0.1B_spec/1.0.1/geronimo-jta_1.0.1B_spec-1.0.1.jar"/>
 	<classpathentry kind="var" path="M2_REPO/org/apache/tuscany/sdo/tuscany-sdo-impl/1.0-incubating-beta1/tuscany-sdo-impl-1.0-incubating-beta1.jar"/>
 	<classpathentry kind="var" path="M2_REPO/org/apache/geronimo/specs/geronimo-jpa_3.0_spec/1.0/geronimo-jpa_3.0_spec-1.0.jar"/>
-	<classpathentry kind="var" path="M2_REPO/org/apache/openjpa/openjpa/1.0.0-SNAPSHOT/openjpa-1.0.0-SNAPSHOT.jar" sourcepath="/OPENJPA_SRC"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/openjpa/openjpa/1.0.0-SNAPSHOT/openjpa-1.0.0-SNAPSHOT.jar" sourcepath="/OPENJPA_SRC">
+		<attributes>
+			<attribute name="javadoc_location" value="http://openjpa.apache.org/docs/latest/javadoc/index.html"/>
+		</attributes>
+	</classpathentry>
 	<classpathentry kind="var" path="M2_REPO/javax/activation/activation/1.1/activation-1.1.jar"/>
 	<classpathentry kind="var" path="M2_REPO/commons-pool/commons-pool/1.3/commons-pool-1.3.jar"/>
 	<classpathentry kind="var" path="M2_REPO/commonj/sdo-api-r2.1/1.0-incubating-beta1/sdo-api-r2.1-1.0-incubating-beta1.jar">

Modified: labs/fluid/pom.xml
URL: http://svn.apache.org/viewvc/labs/fluid/pom.xml?view=diff&rev=559681&r1=559680&r2=559681
==============================================================================
--- labs/fluid/pom.xml (original)
+++ labs/fluid/pom.xml Wed Jul 25 20:31:01 2007
@@ -137,8 +137,6 @@
                                   <classpath refid="cp"/>
                                   <arg value="-d"/>
                                   <arg value="${generated.src}"/>
-                                  <arg value="-mergeUnit"/>
-                                  <arg value="false"/>
                                   <arg value="META-INF/po.xsd"/>
                                   <arg value="META-INF/person.xsd"/>
                                 </java>
@@ -169,7 +167,7 @@
         <profile>
             <!--                        
                 Javadoc profile. Docs can be built by running:
-                    mvn process-resources -Dtest=false -Pjavadoc-profile
+                    mvn process-classes -Dtest=false -Pjavadoc-profile
             -->  
             <id>javadoc-profile</id>
             <build>

Modified: labs/fluid/src/main/java/org/apache/openjpa/code/SDO2POJOGenerator.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/code/SDO2POJOGenerator.java?view=diff&rev=559681&r1=559680&r2=559681
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/code/SDO2POJOGenerator.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/code/SDO2POJOGenerator.java Wed Jul 25 20:31:01 2007
@@ -23,32 +23,31 @@
 import java.io.InputStream;
 import java.io.PrintStream;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import javax.persistence.PersistenceUnit;
-
+import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.lib.log.Log;
-import org.apache.openjpa.lib.log.LogFactory;
 import org.apache.openjpa.lib.log.LogFactoryImpl;
 import org.apache.openjpa.lib.util.Files;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.lib.util.Options;
 import org.apache.openjpa.sdo.ImplHelper;
 import org.apache.openjpa.util.UserException;
-import org.w3c.dom.Document;
 
 import commonj.sdo.Property;
 import commonj.sdo.Type;
 import commonj.sdo.helper.XSDHelper;
 
 /**
- * Generates Java source code Java from SDO Type.
+ * Generates Java source code from SDO Type.
  * 
  * 
- * @author ppoddar
+ * @author Pinaki Poddar
+ * @since 0.1
  * 
  */
 public class SDO2POJOGenerator  {
@@ -56,56 +55,47 @@
 			.forPackage(SDO2POJOGenerator.class);
 	
 	private Map<Type, SourceCode> _cache = new HashMap<Type, SourceCode>();
-	private LogFactoryImpl logFactory;
-	private Log _log;
-	
-	private File _root;
-	private String rootDirectory;
-	private Flags flags;
-	private XMLReadWrite pUnit;
+	private Log 		 _log;
+	private Flags 		 flags;
 
+	/**
+	 * Construct with default options.
+	 *
+	 */
 	SDO2POJOGenerator() {
 		this(null);
 	}
 	
+	/**
+	 * Construct with given options.
+	 * 
+	 */
 	SDO2POJOGenerator(Flags flags) {
 		this.flags = (flags==null) ? new Flags() : flags;
-		logFactory = new LogFactoryImpl();
+		LogFactoryImpl logFactory = new LogFactoryImpl();
 		logFactory.setDefaultLevel(LogFactoryImpl.getLevel(flags.logLevel));
-		_log = logFactory.getLog("SDO2Java");
-
-		if (flags.mergeUnit) {
-			InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/persistence.xml");
-			if (is != null) {
-				try {
-					pUnit = new XMLReadWrite(is);
-				} catch (Exception e) {
-					pUnit = null;
-					this.flags.mergeUnit = false;
-				}
-			} else {
-				_log.warn(_loc.get("punit-not-found"));
-			}
-		}
-		setRootDirectory(flags.rootDir);
+		_log = logFactory.getLog(OpenJPAConfiguration.LOG_METADATA);
 	}
-
-
+	
 	/**
-	 * Get a Java class corresponding to a SDO Type. 
+	 * Get a Java class corresponding to the given SDO Type.
+	 * 
+	 * @param given Type can not be null, simple xsd data type or sequence.
+	 *  
 	 */
-	public SourceCode getJavaClass(Type type) {
+	SourceCode getJavaClass(Type type) {
 		if (type == null)
-			throw new NullPointerException("null-type");
+			throw new NullPointerException(_loc.get("null-type").toString());
+		String typeName = type.getName();
 		if (type.isDataType())
 			throw new IllegalArgumentException(
-				_loc.get("data-type-not-converted", type.getName()).toString());
+				_loc.get("data-type-not-converted", typeName).toString());
 		if (type.isSequenced())
 			throw new IllegalArgumentException(
-				_loc.get("data-type-not-converted", type.getName()).toString());
+				_loc.get("data-type-not-converted", typeName).toString());
 		if (ImplHelper.isContainer(type))
 			throw new IllegalArgumentException(
-					_loc.get("container-type-not-converted", type.getName()).toString());
+				_loc.get("container-type-not-converted", typeName).toString());
 		
 		SourceCode cls = _cache.get(type);
 		if (cls == null) {
@@ -114,26 +104,13 @@
 		return cls;
 	}
 	
-	public String getRootDirectory() {
-		return rootDirectory;
-	}
-	
-	public String[] parseTypeNames(String resource) {
-		List<Type> types = findTypes(resource);
-		List<String> result = new ArrayList<String>();
-		for (Type type : types) {
-			result.add(ImplHelper.getFullClassName(type));
-		}
-		return result.toArray(new String[result.size()]);
-	}
-	
-	public void setLogLevel(String logLevel) {
-		logFactory.setDefaultLevel(logLevel);
-		_log = logFactory.getLog("SDO2Java");
-	}
-	
-	
+	/**
+	 * Find user-defined SDO types in the given resource.  
+	 * 
+	 */
 	List<Type> findTypes(String resource) {
+		if (resource == null || !resource.endsWith(".xsd"))
+			return Collections.EMPTY_LIST;
 		if (_log.isInfoEnabled())
 			_log.info(_loc.get("parse-xml-schema", resource));
 		List<Type> result = new ArrayList<Type>();
@@ -151,7 +128,8 @@
 			for (Object t : types) {
 				if (t instanceof Type) {
 					Type type = (Type) t;
-					if (!(type.isDataType() || "DocumentRoot".equals(type.getName())))
+					if (!(type.isDataType() || 
+						"DocumentRoot".equals(type.getName())))
 						result.add(type);
 				}
 			}
@@ -165,13 +143,15 @@
 	}
 
 	/**
-	 * Generate the closure of POJO.
+	 * Generate source code for a Java Class corresponding to the given type.
+	 * <br>
+	 * The given type must declare a {@link ImplHelper#getIdentity(Type) 
+	 * identity property and a {@link ImplHelper#getVersionProperty(Type)
+	 * version property}.
 	 * 
-	 * @param type
-	 * @return
 	 */
 	SourceCode generatePOJO(Type type) {
-		String pkgName = ImplHelper.getPackageName(type);
+		String pkgName       = ImplHelper.getPackageName(type);
 		String fullClassName = ImplHelper.getFullClassName(type);
 		String javaClassName = type.getName();
 		if (_log.isInfoEnabled())
@@ -189,47 +169,42 @@
 		// annotate the class as @Entity
 		// enforce id and version fields are present
 		// TODO: relax these constraints
-		if (flags.annotate) {
-			code.addImport("javax.persistence.*");
-			cls.addAnnotation("@Entity");
-			
-			// TODO: currently raise exception if no id property defined
-			Property id = ImplHelper.getIdentity(type);
-			
-			String idType = id.getType().getInstanceClass().getName();
-			String idName = id.getName();
-			SourceCode.Field idField = code.addField(idName, idType);
-			idField.addGetter();
-			idField.addAnnotation("@Id");
-			idField.addAnnotation("@GeneratedValue");
-			
-			
-			// TODO: currently raise exception if no version property defined
-			// Version can only be int
-			Property version = ImplHelper.getVersionProperty(type);
-			SourceCode.Field versionField = code.addField("version", "int");
-			versionField.addGetter();
-			versionField.addAnnotation("@Version");
-		}
-		if (flags.mergeUnit) {
-			pUnit.insertClass(fullClassName);
-		}
+		code.addImport("javax.persistence.*");
+		cls.addAnnotation("@Entity");
+		
+		// TODO: currently raise exception if no id property defined
+		Property id = ImplHelper.getIdentity(type);
+		
+		String idType = id.getType().getInstanceClass().getName();
+		String idName = id.getName();
+		SourceCode.Field idField = code.addField(idName, idType);
+		idField.addGetter();
+		idField.addAnnotation("@Id");
+		idField.addAnnotation("@GeneratedValue");
+		
+		// TODO: currently raise exception if no version property defined
+		// Version can only be int
+		Property version = ImplHelper.getVersionProperty(type);
+		SourceCode.Field versionField = code.addField(version.getName(), 
+				version.getType().getInstanceClass().getName());
+		versionField.addGetter();
+		versionField.addAnnotation("@Version");
+		
 		// add private field with bean-style get/set methods for each property
 		List properties = type.getProperties();
 		for (Object p : properties) {
-			Property property = (Property) p;
-			Type propertyType = property.getType();
-			String propertyName = property.getName();
-			String javaTypeName = null;
+			Property property    = (Property) p;
+			Type propertyType    = property.getType();
+			String propertyName  = property.getName();
+			String javaTypeName  = null;
 			SourceCode javaClass = null;
 			SourceCode.Field javaField = null;
-			if (ImplHelper.isIdentity(property) || ImplHelper.isVersion(property))
+			if (ImplHelper.isIdentity(property) || 
+				ImplHelper.isVersion(property))
 				continue;
 			if (propertyType.isDataType()) {
 				javaTypeName = propertyType.getInstanceClass().getName();
 				code.addImport(javaTypeName);
-				if (property.isMany())
-					javaTypeName = "List<" + javaTypeName + ">";
 				javaField = code.addField(propertyName, javaTypeName);
 			} else if (ImplHelper.isContainer(propertyType)) {
 				Type componentType = ImplHelper.getComponentType(propertyType);
@@ -257,7 +232,6 @@
 			if (!property.isReadOnly())
 				javaField.addSetter();
 		}
-		write(code);
 		return code;
 	}
 	
@@ -269,96 +243,98 @@
 			"@author " + this.getClass().getName());
 	}
 
-	File getClassFile(SourceCode bcls) {
-		File pkgdir = Files.getPackageFile(_root, bcls.getPackageName(), true);
-		return new File(pkgdir, bcls.getClassName() + ".java");
+	File getTargetFile(File rootDir, SourceCode code) {
+		File pkgdir = Files.getPackageFile(rootDir, code.getPackageName(), true);
+		return new File(pkgdir, code.getClassName() + ".java");
 	}
 
-	public void setRootDirectory(String rootDirPath) {
-		File currentDir = new File(System.getProperty("user.dir"));
-		_root = currentDir;
-		rootDirectory = rootDirPath;
-		if (rootDirPath != null) {
-			File file = new File(rootDirPath);
-			File rootDir = (file.isAbsolute()) ? file : new File(currentDir, rootDirPath);
-			if (rootDir.exists() && rootDir.isDirectory()) {
-				_root = rootDir;
-			} else {
-				throw new IllegalArgumentException(_loc.get("wrong-root-dir", 
-					"-rootDirectory", rootDirPath, _root.getAbsolutePath()).toString());
-			}
+	public File getRootDirectory() {
+		File rootDir = new File(flags.rootDir);
+		if (rootDir.exists() && rootDir.isDirectory()) {
+			return rootDir;
+		} else {
+			throw new IllegalArgumentException(_loc.get("wrong-root-dir", 
+				"-rootDirectory", rootDir.getAbsolutePath()).toString());
 		}
 	}
 	
-	void write(SourceCode bcls) {
-		if (rootDirectory == null) {
-			bcls.write(System.out);
-			return;
-		}
-		File classFile = getClassFile(bcls);
-		if (_log.isInfoEnabled()) {
-			_log.info(_loc.get("write-class", bcls.getClassName(), 
-					classFile.getAbsolutePath()).toString());
+	/**
+	 * Writes all the cahced SourceCode to file.
+	 *
+	 */
+	void record() {
+		File rootDir = getRootDirectory();
+		for (SourceCode code:_cache.values()) {
+			File sourceFile = getTargetFile(rootDir, code);
+			if (_log.isInfoEnabled()) 
+				_log.info(_loc.get("write-class", 
+					sourceFile.getAbsolutePath()).toString());
+			try {
+				code.write(new PrintStream(sourceFile));
+			} catch (IOException e) {
+				throw new UserException(e);
+			}
 		}
-		try {
-			bcls.write(new PrintStream(classFile));
-		} catch (IOException e) {
-			throw new UserException(e);
+	}
+
+	/**
+	 * Generates and writes Java source files for SDO Types found in given
+	 * resources.
+	 */
+	public void run(String[] args) {
+		_cache.clear();
+		for (int i=0; args!=null && i<args.length; i++) {
+			List<Type> types = findTypes(args[i]);
+			for (Type type:types) {
+				if (!ImplHelper.isContainer(type))
+					getJavaClass(type);
+			}
 		}
+		record();
 	}
-	
+
+	/**
+	 * Generates Java Source Code for SDO Types found in given XML resource
+	 * argument(s).
+	 * <br>
+	 * Accepts following options:
+	 * <LI><code>-rootDir|-d</code>: the directory under which source files
+	 * will be written. Default is current directory. Accepts both absolute
+	 * or relative (to current directory) path to a directory.
+	 * <LI><code>-log</code>: the logging level. Allowed values are TRACE,
+	 * INFO, WARN, ERROR. Default is INFO.
+	 *  
+	 * @param args one or more XML Schema Definition (*.xsd) files defining
+	 * SDO Types.
+	 * 
+	 */
 	public static void main(String[] args) throws Exception {
 		Options options = new Options();
 		args = options.setFromCmdLine(args);
 		
-		Flags flags = new Flags();
-		flags.annotate        = options.removeBooleanProperty("annotate", "anno", flags.annotate);
-		flags.generateMapping = options.removeBooleanProperty("generateORM", "map", flags.generateMapping);
-		flags.mappingFile     = options.removeProperty("mappingFile", flags.mappingFile);
-		flags.mergeUnit       = options.removeBooleanProperty("mergeUnit", "mergeUnit", flags.mergeUnit);
-		flags.rootDir         = options.removeProperty("rootDir", "d", flags.rootDir);
+		Flags flags   = new Flags();
+		flags.logLevel = options.removeProperty("log", "log", flags.logLevel);
+		flags.rootDir  = options.removeProperty("rootDir", "d", flags.rootDir);
 		
-		SDO2POJOGenerator test = new SDO2POJOGenerator(flags);
+		if (!options.isEmpty())
+			throw new RuntimeException("Unrecognized options " + options);
 		
-		Options extra = options.setInto(test);
-		if (!extra.isEmpty())
-			throw new RuntimeException("Unrecognized options " + extra);
-		
-		for (int i=0; args!=null && i<args.length; i++) {
-			List<Type> types = test.findTypes(args[i]);
-			for (Type type:types) {
-				if (!ImplHelper.isContainer(type))
-					test.getJavaClass(type);
-			}
-		}
-		if (test.pUnit != null) {
-			ClassLoader loader = Thread.currentThread().getContextClassLoader();
-			test._log.info(_loc.get("punit-save", Files.getFile("META-INF/persistence.xml", loader).getAbsolutePath()));
-			test.pUnit.save(Files.getOutputStream("META-INF/persistence.xml", loader));
-		}
+		SDO2POJOGenerator generator = new SDO2POJOGenerator(flags);
+		generator.run(args);
 	}
 	
+	/**
+	 * Configures SDO2POJO Generation process.
+	 * <br>
+	 * Currently only options are:
+	 * <LI><code>-rootDir|-d</code>: the directory under which source files
+	 * will be written. Default is current directory.
+	 * <LI><code>-log</code>: the logging level. Allowed values are TRACE,
+	 * INFO, WARN, ERROR. Default is INFO.
+	 * 
+	 */
 	public static class Flags {
-		/**
-		 * Annotate generated classes 
-		 */
-		public boolean annotate        = true;
-		/**
-		 * Generate mapping file
-		 */
-		public boolean generateMapping = false;
-		/**
-		 * Name of the mapping file
-		 */
-		public String mappingFile = null;
-		
-		/**
-		 * Merge generated class names in persistence.xml
-		 */
-		public boolean mergeUnit = true;
-		
-		public String rootDir = null;
-		
+		public String rootDir  = System.getProperty("user.dir");
 		public String logLevel = "INFO";
 	}
 

Modified: labs/fluid/src/main/java/org/apache/openjpa/code/SourceCode.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/code/SourceCode.java?view=diff&rev=559681&r1=559680&r2=559681
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/code/SourceCode.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/code/SourceCode.java Wed Jul 25 20:31:01 2007
@@ -26,10 +26,15 @@
 
 /**
  * Eases writing Java Source code.
+ * Provides basic elements of Java Source Code e.g. Package, Class, Field, 
+ * Method, Import, Annotation, Argument.
+ * <br>
+ * Mutator methods return the operating element for easy chaining. 
  * 
  * @author Pinaki Poddar
  *
  */
+@SuppressWarnings("unchecked")
 public class SourceCode {
 	private static Localizer _loc = Localizer.forPackage(SourceCode.class);
 	
@@ -75,22 +80,31 @@
 		return getPackageName()+"."+cls.name;
 	}
 	
+	/**
+	 * Get the top level class name, without the package name.
+	 */
 	public String getClassName() {
 		return cls.name;
 	}
 	
+	/**
+	 * Sets the tab size. Tabs are always written as spaces.
+	 */
 	public SourceCode setTabSize(int t) {
 		if (t>0) TABSIZE = Math.max(t, 8);
 		return this;
 	}
 	/**
-	 * Get the package name.
+	 * Gets the package name.
 	 * Default package is represented as empty String.
 	 */
 	public String getPackageName() {
 		return (pkg==null) ? EMPTY_STRING : pkg.name;
 	}
 	
+	/**
+	 * Gets the top level class represnted by this receiver.
+	 */
 	public Class getTopLevelClass() {
 		return cls;
 	}
@@ -106,9 +120,11 @@
 	 */
 	private SourceCode setPackage(String p) {
 		if (pkg != null)
-			throw new IllegalStateException(_loc.get("pkg-set",pkg.name, p).toString());
+			throw new IllegalStateException(_loc.get("pkg-set",pkg.name, p)
+					.toString());
 		if (!isValidPackageName(p)) 
-			throw new IllegalArgumentException(_loc.get("invalid-pkg",p).toString());
+			throw new IllegalArgumentException(_loc.get("invalid-pkg",p)
+					.toString());
 		this.pkg = new Package(p);
 		return this;
 	}
@@ -121,9 +137,11 @@
 	 */
 	private Class setClass(String c) {
 		if (cls != null)
-			throw new IllegalStateException(_loc.get("cls-set",cls.name,c).toString());
+			throw new IllegalStateException(_loc.get("cls-set",cls.name,c)
+					.toString());
 		if (!isValidToken(c)) {
-			throw new IllegalArgumentException(_loc.get("invalid-cls",c).toString());
+			throw new IllegalArgumentException(_loc.get("invalid-cls",c)
+					.toString());
 		}
 		this.cls = new Class(c);
 		
@@ -144,7 +162,8 @@
 			return false;
 			
 		if (!isValidImportName(i))
-			throw new IllegalArgumentException(_loc.get("invalid-import",i).toString());
+			throw new IllegalArgumentException(_loc.get("invalid-import",i)
+					.toString());
 		String pkgName = extractPackageName(i);
 		if ("java.lang".equals(pkgName))
 			return false;
@@ -161,19 +180,23 @@
 	 * @param type is a valid name of declared type of the field.
 	 * If the type name is fully-qualified class name, then the package is
 	 * added to the import.
-	 * If the type name uses generic style e.g. <code>java.util.List&lt;Item&gt;</code>
+	 * If the type name uses generic style e.g. 
+	 * <code>java.util.List&lt;Item&gt;</code>
 	 * then the type is used as it is and no import statement is added.
 	 * 
 	 */
 	public Field addField(String f, String type) {
 		if (isEmpty(f) || !isValidToken(f)) {
-			throw new IllegalArgumentException(_loc.get("invalid-field-name",f).toString());
+			throw new IllegalArgumentException(_loc.get("invalid-field-name",f)
+				.toString());
 		}
 		if (!isValidTypeName(type)) 
-			throw new IllegalArgumentException(_loc.get("invalid-field-type",f, type).toString());
+			throw new IllegalArgumentException(_loc.get("invalid-field-type",f, 
+				type).toString());
 		Field field = new Field(f, extractClassName(type));
 		if (!fields.add(field))
-			throw new IllegalArgumentException(_loc.get("duplicate-field",field, this).toString());
+			throw new IllegalArgumentException(_loc.get("duplicate-field",
+				field, this).toString());
 		return field;
 	}
 	
@@ -197,19 +220,22 @@
 	 * Set a method declaration. 
 	 * 
 	 * @param m a valid method name.
-	 * @param ret is a valid name of return type of the method.
+	 * @param retType is a valid name of return type of the method.
 	 * 
 	 */
 	public Method addMethod(String m, String retType) {
 		if (isEmpty(m) || !isValidToken(m)) {
-			throw new IllegalArgumentException(_loc.get("invalid-method",m).toString());
+			throw new IllegalArgumentException(_loc.get("invalid-method",m)
+				.toString());
 		}
 		if (!isValidTypeName(retType)) {
-			throw new IllegalArgumentException(_loc.get("invalid-ret-type",retType,m).toString());
+			throw new IllegalArgumentException(_loc.get("invalid-ret-type",
+				retType,m).toString());
 		}
 		Method method = new Method(m, retType);
 		if (!methods.add(method)) 
-			throw new IllegalArgumentException(_loc.get("duplicate-method",method, this).toString());
+			throw new IllegalArgumentException(_loc.get("duplicate-method",
+				method, this).toString());
 		return method;
 	}
 	
@@ -239,7 +265,8 @@
 		}
 	}
 	
-	static void writeList(PrintStream out, String header, List list, boolean bracket) {
+	static void writeList(PrintStream out, String header, List list, 
+			boolean bracket) {
 		if (list == null || list.isEmpty()) {
 			if (bracket) out.append(BRACKET_START+BRACKET_END);
 			return;
@@ -290,14 +317,16 @@
 		                    s.indexOf(">")==s.lastIndexOf(">"); /// once
 		
 		if (isGeneric) {
-			String cls = s.substring(0, s.indexOf("<"));
-			String gen = s.substring(s.indexOf("<")+1,s.indexOf(">"));
+			//TODO: validate generic type names
+//			String cls = s.substring(0, s.indexOf("<"));
+//			String gen = s.substring(s.indexOf("<")+1,s.indexOf(">"));
 			return true;
 			
 		} else {
 			String pkg = extractPackageName(s);
 			String cls = extractClassName(s);
-			return isValidPackageName(pkg) && (isValidToken(cls) || isKnownType(cls));
+			return isValidPackageName(pkg) && 
+			      (isValidToken(cls) || isKnownType(cls));
 		}
 	}
 
@@ -305,15 +334,15 @@
 		return !reserved.contains(s) && isJavaIdentifier(s);
 	}
 	
-	static boolean isKnownType(String s) {
+	public static boolean isKnownType(String s) {
 		return knownTypes.contains(s);
 	}
 	
-	public static boolean isEmpty(String s) {
+	static boolean isEmpty(String s) {
 		return s == null || s.length()==0;
 	}
 	
-	private static LinkedList<String> tokenize(String s, String delim) {
+	static LinkedList<String> tokenize(String s, String delim) {
 		StringTokenizer tokenizer = new StringTokenizer(s, delim, false);
 		LinkedList<String> tokens = new LinkedList<String>();
 		while (tokenizer.hasMoreTokens())
@@ -335,12 +364,12 @@
     }
 	
 	
-	public static String extractPackageName(String c) {
+	static String extractPackageName(String c) {
 		int i = c.lastIndexOf('.');
 		return (i == -1) ? null : c.substring(0,i);
 	}
 	
-	public static String extractClassName(String c) {
+	static String extractClassName(String c) {
 		int i = c.lastIndexOf('.');
 		return (i == -1) ? c : c.substring(i+1);
 	}

Modified: labs/fluid/src/main/java/org/apache/openjpa/code/XMLReadWrite.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/code/XMLReadWrite.java?view=diff&rev=559681&r1=559680&r2=559681
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/code/XMLReadWrite.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/code/XMLReadWrite.java Wed Jul 25 20:31:01 2007
@@ -20,7 +20,7 @@
 
 import com.sun.org.apache.xpath.internal.XPathAPI;
 
-public class XMLReadWrite {
+class XMLReadWrite {
 	private Document doc;
 	public XMLReadWrite(InputStream is) throws Exception {
 		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

Modified: labs/fluid/src/main/java/org/apache/openjpa/sdo/DelegatingDataObject.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/sdo/DelegatingDataObject.java?view=diff&rev=559681&r1=559680&r2=559681
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/DelegatingDataObject.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/DelegatingDataObject.java Wed Jul 25 20:31:01 2007
@@ -2,8 +2,6 @@
 
 import java.math.BigDecimal;
 import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 
@@ -19,9 +17,10 @@
  * for persistence: identity and version.
  * 
  * @author Pinaki Poddar
- *
+ * @since 0.1.0
+ * @deprecated
  */
-public class DelegatingDataObject implements DataObject {
+class DelegatingDataObject implements DataObject {
 	private final DataObject _delegate;
 	
 	private Object id;

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?view=diff&rev=559681&r1=559680&r2=559681
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/ImplHelper.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/ImplHelper.java Wed Jul 25 20:31:01 2007
@@ -30,11 +30,11 @@
 import commonj.sdo.Type;
 
 /**
- * Helper utilities to create method name, extract field values via reflection
- * etc.
+ * Helper utilities to create method name, extract field values via reflection,
+ * and more importantly process identity and version property in DataObject.
  * 
- * @author ppoddar
- *
+ * @author Pinaki Poddar
+ * @since 0.1.0
  */
 public class ImplHelper {
 	private static Localizer _loc = Localizer.forPackage(ImplHelper.class);
@@ -103,12 +103,26 @@
 	
 	/**
 	 * 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 getIdentity(Type type) {
-		Property idProperty = null;
-		if (!isEMFImplementaionAvailable()) {
-			idProperty = type.getProperty("id");
-		} else {
+		// 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;
@@ -124,19 +138,21 @@
 				}
 			}
 		}
-		if (idProperty == null || !idProperty.getType().isDataType())
+		if (idProperty == null)
 			throw new UserException(_loc.get("missing-identity", type.getName())
 					.toString());
 		return idProperty;
 	}
 	
 	/**
-	 * Affirms if the given property is identity.
+	 * Affirms if the given property is identity property.
 	 */
 	public static boolean isIdentity(Property property) {
 		if (property == null)
 			return false;
-		if (property.getType().isDataType()) {
+		if ("id".equals(property.getName()) && property.getType().isDataType())
+				return true;
+		if (isEMFImplementaionAvailable() && property.getType().isDataType()) {
 			try {
 				Object isID = getIDMethod.invoke(
 						property.getClass().cast(property), NULL_PARAMS);
@@ -149,6 +165,11 @@
 		return false;
 	}
 	
+	/**
+	 * 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))
@@ -157,31 +178,55 @@
 		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);
 	}
 	
+	/**
+	 * Gets the value of the {@link #getIdentity(Type) identity property}
+	 * of the given DataObject.
+	 */
 	public static Object getIdValue(DataObject data) {
 		return data.get(getIdentity(data.getType()));
 	}
 	
+	/**
+	 * Sets the value of the {@link #getIdentity(Type) identity property}
+	 * of the given DataObject.
+	 */
 	public static void setIdValue(DataObject data, Object idValue) {
 		data.set(getIdentity(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 has one and only one property and that property
-	 * type is not a basic data type and the property is many-valued.
+	 * 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();
@@ -193,7 +238,8 @@
 	}
 	
 	/**
-	 * If the given type is a container type then return the type of its one 
+	 * 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) {
@@ -203,7 +249,30 @@
 		return null;
 	}
 	
-	private static boolean isEMFImplementaionAvailable() {
+	/**
+	 * 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.
+	 * <b>
+	 * 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();
 		

Modified: labs/fluid/src/main/java/org/apache/openjpa/sdo/SDODelegatingResultList.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/sdo/SDODelegatingResultList.java?view=diff&rev=559681&r1=559680&r2=559681
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/SDODelegatingResultList.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/SDODelegatingResultList.java Wed Jul 25 20:31:01 2007
@@ -24,6 +24,13 @@
 import org.apache.openjpa.lib.rop.ResultList;
 import org.apache.openjpa.util.RuntimeExceptionTranslator;
 
+/**
+ * A ResultList that converts the persistent Java Objects to SDO DataObjects
+ * before returning to the caller.
+ * 
+ * @author Pinaki Poddar
+ * @since 0.1.0
+ */
 @SuppressWarnings("serial")
 class SDODelegatingResultList extends DelegatingResultList {
 	private final SDOEntityManager em;

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?view=diff&rev=559681&r1=559680&r2=559681
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOEntityManager.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOEntityManager.java Wed Jul 25 20:31:01 2007
@@ -26,10 +26,13 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+
+import javax.persistence.PersistenceException;
 
 import org.apache.openjpa.kernel.Broker;
+import org.apache.openjpa.kernel.Query;
 import org.apache.openjpa.kernel.jpql.JPQLParser;
-import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.persistence.EntityManagerImpl;
 import org.apache.openjpa.persistence.OpenJPAQuery;
 import org.apache.openjpa.util.OptimisticException;
@@ -40,13 +43,20 @@
 import commonj.sdo.helper.DataFactory;
 
 /**
- * A specialized EntityManager that accepts SDO DataObject/DataGraph as 
+ * A specialized EntityManager that accepts SDO DataObject as 
  * arguments for persistence operation.
  * <br>
- * Currently only supports persist() and createQuery()
+ * If argument to the persistent operations is DataObject, then this receiver
+ * converts them to strongly-typed Java objects, otherwise acts as a mere
+ * pass-through to the base function.
+ * <br>
+ * For query operation, always converts the returned list of objects as 
+ * DataObjects before returning to the caller.
+ * <br>
+ * Currently supports persist(), merge(), find(), remove() and createQuery().
  * 
  * @author Pinaki Poddar
- *
+ * @since 0.1.0
  */
 public class SDOEntityManager extends EntityManagerImpl {
 	// TODO: Change to a smarter cache
@@ -61,6 +71,36 @@
 			.getMetaDataFactory();
 	}
 	
+	/**
+	 * Finds if the given DataObject is cached, if <code>type</code> equals
+	 * <code>DataObject.class</code>, else functions normally for
+	 * for strongly-typed Java objects.
+	 * 
+	 * @param cls if <code>DataObject.class</code> then the <code>id</code>
+	 * parameter has to be prefixed with SDO Type name.
+	 * <br>
+	 * <code> em.find(DataObject.class, "Customer:1234") will return a Customer
+	 * DataObject.
+	 * @param oid of the identity property prefixed with SDO Type name.
+	 * 
+	 * This is bit flaky, because to comply with JPA API method signature.
+	 */
+	@Override
+	public <T> T find(Class<T> cls, Object oid) {
+		if (cls==DataObject.class) {
+			Type type = extractType(oid.toString());
+			String id = extractId(oid.toString());
+			DataObject data = scanLocalCache(type, id);
+			return (T)data;
+		} 
+		return super.find(cls, oid);
+	}
+	
+	/**
+	 * Persist the given entity. If the entity is a DataObject instance then the
+	 * closure of the entity i.e. all related entities are persisted too. 
+	 */
+	@Override
 	public void persist(Object entity) {
 		if (entity instanceof DataObject) {
 			DataObject delegate = (DataObject)entity;
@@ -71,7 +111,11 @@
 		super.persist(entity);
 	}
 	
+	/**
+	 * Merges the given entity to the database.
+	 */
     @SuppressWarnings("unchecked")
+	@Override
     public <T> T merge(T entity) {
     	if (entity instanceof DataObject) {
     		DataObject delegate = (DataObject)entity;
@@ -90,6 +134,9 @@
         return super.merge(entity);
     }
     
+    /**
+     * Removes the DataObject and all DataObjects reachable from it.
+     */
     @Override
     public void remove(Object entity) {
     	if (entity instanceof DataObject) {
@@ -101,15 +148,16 @@
     	super.remove(entity);
     }
 
+    /**
+     * Creates a Query using JPQL that will return list of DataObject as result. 
+     */
+	@Override
 	public OpenJPAQuery createQuery(String jpql) {
-		return this.createQuery(JPQLParser.LANG_JPQL, jpql);
-	}
-
-	public OpenJPAQuery createQuery(String language, String jpql) {
-        return new SDOQuery(this, getBroker().newQuery(language, jpql));
+		Query kernelQuery = getBroker().newQuery(JPQLParser.LANG_JPQL, jpql);
+        return new SDOQuery(this, kernelQuery); 
 	}
 
-	Map<DataObject,Object> getPCClosure(DataObject dataObject) {
+	private Map<DataObject,Object> getPCClosure(DataObject dataObject) {
 		Map<DataObject,Object> closure = 
 			new HashMap<DataObject,Object>();
 		return convertAndtraverse(dataObject, closure);
@@ -155,11 +203,9 @@
 							propertyType.getInstanceClass());
 					setter.invoke(pc, value);
 				} else if (ImplHelper.isContainer(propertyType)) {
-					Class componentClass = factory.getJavaClass(ImplHelper.getComponentType(propertyType), true);
 					DataObject container = (DataObject)value;
-					Property elementProperty = (Property)container.getInstanceProperties().get(0);
-					Iterator dataList = container.getList(elementProperty).iterator();
-//					Iterator dataList = dataObject.getList(property).iterator();
+					Property elemProperty = ImplHelper.getComponentProperty(propertyType);
+					Iterator dataList = container.getList(elemProperty).iterator();
 					List objList  = new ArrayList();
 					for (;dataList.hasNext();) {
 						DataObject dataElement = (DataObject)dataList.next();
@@ -190,33 +236,29 @@
 			} 
 			
 		} catch (Exception e) {
-			throw new RuntimeException(e);
+			throw new PersistenceException(e);
 		}
 		return closure;
 	}
 	
-	DataObject initialize(DataObject data, Object pc) {
+	/**
+	 * Initialize the given DataObject with the id/version values from the
+	 * given PersistenceCapable instance.
+	 */
+	DataObject initializeDataObject(DataObject data, Object pc) {
 		ImplHelper.setIdValue(data, this.getObjectId(pc));
 		ImplHelper.setVersion(data, ((Integer)this.getVersion(pc)).intValue());
 		return data;
 	}
 
 	/**
-	 * Initialize a PC instance from the given DataObject.
+	 * Initialize a PersistenceCapable instance  with the id/version values 
+	 * from the given DataObject.
 	 */
 	Object initializePC(Class cls, DataObject data) {
 		Object pc = null;
 		try {
-			Type type = data.getType();
-			Class idClass = factory.getIdentityClass(type);
-			ClassMetaData meta = getConfiguration().getMetaDataRepositoryInstance().getCachedMetaData(cls);
 			Object idValue = ImplHelper.getIdValue(data);
-			switch (meta.getIdentityType()) {
-			case ClassMetaData.ID_APPLICATION:
-				break;
-			case ClassMetaData.ID_DATASTORE:
-				break;
-			}
 			Object version = ImplHelper.getVersion(data);
 			if (idValue != null) { // existing persistent instance?
 				pc = find(cls, idValue);
@@ -235,6 +277,9 @@
 		return pc;
 	}
 	
+	/**
+	 * Create a DataObject from the given PersistenceCapable instance.
+	 */
 	@SuppressWarnings("unchecked")
 	DataObject createDataObject(Object pc) {
 		if (pc == null)
@@ -244,7 +289,7 @@
 			return null;
 		}
 		DataObject dataObject = DataFactory.INSTANCE.create(type);
-		dataObject = initialize(dataObject, pc);
+		dataObject = initializeDataObject(dataObject, pc);
 		List properties = dataObject.getInstanceProperties();
 		for (Object o:properties) {
 			Property property = (Property)o;
@@ -278,5 +323,27 @@
 		return dataObject;
 	}
 	
+	/**
+	 * Scans local cache for a DataObject of given type and stringified identity.
+	 */
+	DataObject scanLocalCache(Type type, String id) {
+		for (DataObject data:cache.keySet()) {
+			if (data.getType().equals(type)) {
+				Object idValue = ImplHelper.getIdValue(data);
+				if (id.equals(idValue.toString()))
+					return data;
+			}
+		}
+		return null;
+	}
 	
+	protected Type extractType(String s) {
+		int colon = s.indexOf(':');
+		return (colon == -1) ? null : factory.getType(s.substring(0,colon)); 
+	}
+	
+	protected String extractId(String s) {
+		int colon = s.indexOf(':');
+		return (colon == -1) ? "" : s.substring(colon+1); 
+	}
 }

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?view=diff&rev=559681&r1=559680&r2=559681
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOEntityManagerFactory.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOEntityManagerFactory.java Wed Jul 25 20:31:01 2007
@@ -18,7 +18,6 @@
  */
 package org.apache.openjpa.sdo;
 
-import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.kernel.Broker;
 import org.apache.openjpa.kernel.BrokerFactory;
 import org.apache.openjpa.persistence.EntityManagerFactoryImpl;
@@ -26,16 +25,14 @@
 
 
 /**
- * A specialized factory to convert SDO DataObject/DataGraph to collection of
- * strongly-typed Java instances.
+ * A specialized factory to convert SDO DataObject to collection of
+ * strongly-typed, PersistenceCapable Java instances.
  * 
- * @author ppoddar
- *
+ * @author Pinaki Poddar
+ * @since 0.1.0
  */
 @SuppressWarnings("serial")
 public class SDOEntityManagerFactory extends EntityManagerFactoryImpl {
-	private SDOTypeRepository repos;
-	
 	public SDOEntityManagerFactory() {
 		super();
 	}
@@ -44,16 +41,6 @@
     	super(factory);
     }
     
-//    public SDOTypeRepository getTypeRepository() {
-//    	if (repos == null) {
-//    		OpenJPAConfiguration conf = getConfiguration();
-//    		SDOMetaDataFactory factory = (SDOMetaDataFactory)conf
-//    			.getMetaDataRepositoryInstance().getMetaDataFactory();
-//    		repos = new SDOTypeRepository(conf, factory);
-//    	}
-//    	return repos;
-//    }
-	
     /**
      * Create a new entity manager around the given broker.
      */
@@ -61,7 +48,4 @@
     protected EntityManagerImpl newEntityManagerImpl(Broker broker) {
         return new SDOEntityManager(this, broker);
     }
-	
-	
-	
 }

Modified: labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOMetaDataFactory.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOMetaDataFactory.java?view=diff&rev=559681&r1=559680&r2=559681
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOMetaDataFactory.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOMetaDataFactory.java Wed Jul 25 20:31:01 2007
@@ -34,25 +34,23 @@
 import org.apache.openjpa.persistence.PersistenceMetaDataFactory;
 import org.apache.openjpa.util.InternalException;
 
-import commonj.sdo.Property;
 import commonj.sdo.Type;
 
 /**
  * A specialized MetaDataFactory to process XML Schema based SDO MetaModel.
- * Uses a {@link SDOTypeParser parser} to find SDO Types defined in *.xsd XML
+ * <br>
+ * Caches bi-directional maps of SDO Type and Java Class.
+ * <br>
+  * Uses a {@link SDOTypeParser parser} to find SDO Types defined in *.xsd XML
  * Schema Definition resources. These resources are specified via configuration
  * as<br>
  * <pre>
  * &lt;property name="openjpa.MetaDataFactory" value="sdo(Resources=my.xsd"/&gt;
  * </pre>
  * and resolved against the thread context's classloader.
- * <br>
- * Caches bi-directional maps of SDO Type and Java Class. Also for each SDO
- * Type maintains its <em>identity property</em>, if any. Identity property ,
- * is declared as <code>xsd:ID</code> type in XML Schema Definition.
- * 
- * @author Pinaki Poddar
  *
+ * @author Pinaki Poddar
+ * @since 0.1.0
  */
 public class SDOMetaDataFactory extends PersistenceMetaDataFactory {
 	private static final Localizer _loc = 
@@ -62,11 +60,10 @@
 	private List<String> resourceList;
 	private SDOTypeParser sdoTypeParser;
 	private Set<String> _typeNames = new HashSet<String>();
-	private Map<Type, Property> _identityMap = new HashMap<Type, Property>();
-	private List<Type> _nonidentityList = new ArrayList<Type>();
 	private Log _log;
 	private Map<Type, Class> _cache = new HashMap<Type, Class>();
 	private Map<Class, Type> _rcache = new HashMap<Class, Type>();
+	private boolean initialized = false;
 
 	@Override
 	public void setConfiguration(Configuration conf) {
@@ -87,6 +84,10 @@
 		return sdoTypeParser;
 	}
 	
+	/**
+	 * Cache the given SDO Type and PersistenceCapable Java class in 
+	 * bi-directional map.
+	 */
 	void cache(Type type, Class cls) {
 		if (!isEnhanced(cls)) {
 			throw new InternalException(_loc.get("cache-unenhanced", 
@@ -138,14 +139,22 @@
 		return type;
 	}
 
-	void initialize() {
+	/**
+	 * Forces scanning of SDO Schema Definitions to initialize the classes.
+	 * Useful for initial query when the classes are not loaded prior to
+	 * query.
+	 *
+	 */
+	protected void initialize() {
+		if (initialized) return;
+		initialized = true;
 		getPersistentTypeNames(true, null);
 		Set<Type> types = getSDOTypeParser().getUserTypes();
 		for (Type type:types)
 			getJavaClass(type, false);
 	}
 	
-	boolean isEnhanced(Class cls) {
+	protected boolean isEnhanced(Class cls) {
 		return PersistenceCapable.class.isAssignableFrom(cls);
 	}
 
@@ -171,6 +180,7 @@
 	/**
 	 * Get the fully-qualified, persistent Java class names.
 	 */
+	@Override
     public Set getPersistentTypeNames(boolean devpath, ClassLoader envLoader) {
     	if (resourceList == null || resourceList.isEmpty()) 
     		return _typeNames;
@@ -188,30 +198,12 @@
     	_typeNames.add(name);
     }
     
-    public Property getIdentityProperty(Type type) {
-    	Property id = _identityMap.get(type);
-    	if (id == null) {
-    		if (_nonidentityList.contains(type))
-    			return null;
-    		id = ImplHelper.getIdentity(type);
-    		if (id != null)
-    			_identityMap.put(type, id);
-    		else
-    			_nonidentityList.add(type);
-    	}
-    	return id;
-    }
-    
-    /**
-     * Get Java class that represents identity property for the given Type.
-     * If the type has no property with xsd:ID, then returns long.class
-     */
-    public Class getIdentityClass(Type type) {
-    	Property id = getIdentityProperty(type);
-    	return (id == null) ? long.class : id.getType().getInstanceClass();
-    }
-    
-    public boolean hasIdentityProperty(Type type) {
-    	return getIdentityProperty(type)!=null;
-    }
+	public Type getType(String name) {
+		initialize();
+		for (Type t:_cache.keySet())
+			if (t.getName().equals(name))
+				return t;
+		return null;
+	}
+
 }

Modified: labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOProductDerivation.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOProductDerivation.java?view=diff&rev=559681&r1=559680&r2=559681
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOProductDerivation.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOProductDerivation.java Wed Jul 25 20:31:01 2007
@@ -28,15 +28,15 @@
 
 /**
  * Configures SDO-enabled JPA Runtime.
- * To use SDO-enabled JPA Runtime, configure <code>META-INF/persistence.xml</code>
- * as:<br>
+ * To activate SDO-enabled JPA Runtime, configure 
+ * <code>META-INF/persistence.xml</code> as:<br>
  * <pre>
  *  &lt;property name="openjpa.EntityManagerFactory" value="sdo"/&gt;
  * </pre>
  * 
  * 
- * @author ppoddar
- *
+ * @author Pinaki Poddar
+ * @since 0.1.0
  */
 public class SDOProductDerivation extends AbstractProductDerivation {
 	
@@ -62,10 +62,10 @@
         value.setAlias(SDO, SDOEntityManagerFactory.class.getName());
         
         conf.metaFactoryPlugin.setAlias(SDO, SDOMetaDataFactory.class.getName());
-        
-        conf.addString("openjpa.sdo.DynamicClassDir");
-        
-        
+//        
+//        conf.addString("openjpa.sdo.DynamicClassDir");
+//        
+//        
         return true;
     }	
     

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?view=diff&rev=559681&r1=559680&r2=559681
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOQuery.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOQuery.java Wed Jul 25 20:31:01 2007
@@ -28,6 +28,12 @@
 import org.apache.openjpa.persistence.PersistenceExceptions;
 import org.apache.openjpa.persistence.QueryImpl;
 
+/**
+ * A Query that returns SDO DataObjects instead of PersistenceCapable POJOs.
+ * 
+ * @author Pinaki Poddar
+ * @since 0.1.0
+ */
 @SuppressWarnings("serial")
 class SDOQuery extends QueryImpl implements OpenJPAQuery {
     public SDOQuery(EntityManagerImpl em, org.apache.openjpa.kernel.Query query) {

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?view=diff&rev=559681&r1=559680&r2=559681
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOTypeParser.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOTypeParser.java Wed Jul 25 20:31:01 2007
@@ -20,16 +20,18 @@
 /**
  * Parses XML Schema definition for SDO Types.
  * 
- * @author ppoddar
- *
+ * @author Pinaki Poddar
+ * @since 0.1.0
  */
 public class SDOTypeParser extends ClassArgParser {
-	private static final Localizer _loc = Localizer.forPackage(SDOTypeRepository.class);
+	private static final Localizer _loc = Localizer
+		.forPackage(SDOTypeRepository.class);
 	private static final String[] EMPTY_STRING = {};
 	private Log _log;	
 	private Set<Type> parsedTypes       = new HashSet<Type>();
 	private Set<Type> userTypes         = new HashSet<Type>();
-	private Map<String,String[]> userClassNames  = new HashMap<String,String[]>();
+	private Map<String,String[]> userClassNames  = 
+		new HashMap<String,String[]>();
 	
 	/**
 	 * Supply configuration.
@@ -89,31 +91,6 @@
 		return userClassNames.get(resource);
 	}
 	
-	
-	private Set<Type> findTypes(InputStream xsdInputStream, boolean filter) {
-		Set<Type> result = new HashSet<Type>();
-		try {
-			List types = XSDHelper.INSTANCE.define(xsdInputStream, null);
-			for (Object t : types) {
-				if (t instanceof Type == false)
-					continue;
-				Type type = (Type) t;
-				if (!filter) {
-					result.add(type);
-				} else if (!(type.isDataType() || 
-						"DocumentRoot".equals(type.getName()) ||
-						ImplHelper.isContainer(type)))
-					result.add(type);
-			}
-		} finally {
-			try {
-				xsdInputStream.close();
-			} catch (IOException e) {
-				//ignore
-			}
-		}
-		return result;
-	}
 	
 	/**
 	 * Gets all the types parsed so far.

Modified: labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOTypeRepository.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOTypeRepository.java?view=diff&rev=559681&r1=559680&r2=559681
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOTypeRepository.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOTypeRepository.java Wed Jul 25 20:31:01 2007
@@ -64,8 +64,9 @@
  * Repository of dynamic Java classes generated from SDO Type.
  * 
  * 
- * @author ppoddar
- * 
+ * @author Pinaki Poddar
+ * @since 0.1.0
+ * @deprecated
  */
 class SDOTypeRepository extends ClassArgParser {
 	private static final Localizer _loc = Localizer

Modified: labs/fluid/src/main/resources/org/apache/openjpa/code/localizer.properties
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/resources/org/apache/openjpa/code/localizer.properties?view=diff&rev=559681&r1=559680&r2=559681
==============================================================================
--- labs/fluid/src/main/resources/org/apache/openjpa/code/localizer.properties (original)
+++ labs/fluid/src/main/resources/org/apache/openjpa/code/localizer.properties Wed Jul 25 20:31:01 2007
@@ -23,7 +23,7 @@
 register-sdo: Dynamic class "{0}" is loaded by "{1}"
 sdo-repos-init: Dynamic Java classes will be written to "{0}". Make sure that \
 	these files are available in runtime classpath. 
-write-class: Writing "{0}" to "{1}"
+write-class: Writing "{0}"
 wrong-root-dir: Property "{0}" value "{1}" is either does not exist or not a \
 	directory. The dynamic classes will be written to "{2}"
 xsd-not-found:Can not find "{0}" as resource in current classpath.

Modified: labs/fluid/src/site/apt/design.apt
URL: http://svn.apache.org/viewvc/labs/fluid/src/site/apt/design.apt?view=diff&rev=559681&r1=559680&r2=559681
==============================================================================
--- labs/fluid/src/site/apt/design.apt (original)
+++ labs/fluid/src/site/apt/design.apt Wed Jul 25 20:31:01 2007
@@ -25,16 +25,6 @@
   Java Persistence Architecture API captures the essential persistence services
   for Java objects in a well-designed, compact EntityManager interface. 
   
-  +-------------------------------------------------------------------------
-  package javax.persistence;
-  
-  public interface EntityManager {
-     public void persist(Object entity);
-     public void remove(Object entity);
-     public <T>  merge(T entity);
-     
-  +-------------------------------------------------------------------------
-  
   The 
   EntityManager interface methods accept Object (or collection of them) as
   arguments. At runtime, OpenJPA ascertains that the given object argument

Modified: labs/fluid/src/site/apt/manual.apt
URL: http://svn.apache.org/viewvc/labs/fluid/src/site/apt/manual.apt?view=diff&rev=559681&r1=559680&r2=559681
==============================================================================
--- labs/fluid/src/site/apt/manual.apt (original)
+++ labs/fluid/src/site/apt/manual.apt Wed Jul 25 20:31:01 2007
@@ -89,4 +89,23 @@
 
 * Generate POJO 
 
-* 
\ No newline at end of file
+* 
+
+
+Identity: 
+Datastore Identity:
+define a property named "id" and simple xsd data type. 
+
+Application Identity: 
+define any property with xsd:ID type (String)
+will only work if underlying EMF Core
+All values are autogenerated
+
+Version can be int only now
+
+
+Container type
+
+Implementation
+xsd:id
+package name

Modified: labs/fluid/src/site/site.xml
URL: http://svn.apache.org/viewvc/labs/fluid/src/site/site.xml?view=diff&rev=559681&r1=559680&r2=559681
==============================================================================
--- labs/fluid/src/site/site.xml (original)
+++ labs/fluid/src/site/site.xml Wed Jul 25 20:31:01 2007
@@ -3,6 +3,7 @@
 	<menu name="Main Menu">
       <item name="Introduction"  href="index.html"/>
       <item name="User Manual"   href="manual.html"/>
+      <item name="JavaDoc"       href="apidocs/index.html"/>
       <item name="Design"        href="design.html"/>
       <item name="Download"      href="download.html"/>
       <item name="Configuration" href="configuration.html"/>

Modified: labs/fluid/src/test/java/example/basic/TestCRUD.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/test/java/example/basic/TestCRUD.java?view=diff&rev=559681&r1=559680&r2=559681
==============================================================================
--- labs/fluid/src/test/java/example/basic/TestCRUD.java (original)
+++ labs/fluid/src/test/java/example/basic/TestCRUD.java Wed Jul 25 20:31:01 2007
@@ -5,7 +5,6 @@
 import javax.persistence.EntityManager;
 import javax.persistence.Query;
 import org.apache.openjpa.persistence.OpenJPAEntityManager;
-import org.apache.openjpa.sdo.DelegatingDataObject;
 import org.apache.openjpa.sdo.ImplHelper;
 
 import commonj.sdo.DataObject;
@@ -21,22 +20,18 @@
  *
  */
 public class TestCRUD extends AbstractSDOTest {
-	protected String getXSDResource() {
-		return "META-INF/person.xsd";
-	}
-
-	public String getPersistenceUnitName() {
-		return System.getProperty("persistence.unit", "test");
-	}
-
 	/**
 	 * Persist a DataObject. 
+	 * Verifies that the instance count is increased.
+	 * Also verifies that the DataObject is cached.
+	 * <br>
+	 * Shows persist() and find() call with DataObjects.
 	 */
 	public void testPersist() {
 		int before = count("Person");
 		
-		long ssn = System.currentTimeMillis();
-		DataObject data = createPerson(""+ssn, "John", "Doe", 42);
+		String ssn = ""+System.currentTimeMillis();
+		DataObject data = createPerson(ssn, "John", "Doe", 42);
 		EntityManager em = emf.createEntityManager();
 		em.getTransaction().begin();
 		em.persist(data);
@@ -45,6 +40,12 @@
 		int after = count("Person");
 		
 		assertEquals(before+1, after);
+		
+		// Shows how to find DataObject via em.find()
+		// Notice how the identity is prefixed with Type name
+		DataObject result = em.find(DataObject.class, "Person:"+ssn);
+		assertNotNull(result);
+		assertEquals(data,result);
 	}
 	
 

Added: labs/fluid/src/test/java/example/basic/TestRelation.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/test/java/example/basic/TestRelation.java?view=auto&rev=559681
==============================================================================
--- labs/fluid/src/test/java/example/basic/TestRelation.java (added)
+++ labs/fluid/src/test/java/example/basic/TestRelation.java Wed Jul 25 20:31:01 2007
@@ -0,0 +1,178 @@
+package example.basic;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+import test.common.AbstractSDOTest;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.DataFactory;
+
+public class TestRelation extends AbstractSDOTest {
+	protected String getXSDResource() {
+		return "META-INF/person.xsd";
+	}
+
+	public String getPersistenceUnitName() {
+		return System.getProperty("persistence.unit", "test");
+	}
+
+	/**
+	 * Persist a DataObject. 
+	 */
+	public void testPersist() {
+		int before = count("PurchaseOrderType");
+		
+		long ssn = System.currentTimeMillis();
+		DataObject data = createPurchaseOrder();
+		EntityManager em = emf.createEntityManager();
+		em.getTransaction().begin();
+		em.persist(data);
+		em.getTransaction().commit();
+		
+		int after = count("PurchaseOrderType");
+		
+		assertEquals(before+1, after);
+	}
+	
+
+	/**
+	 * Query using JPQL. The query results should be DataObjects. The related
+	 * DataObjects should also be fetched.
+	 */
+	public void testQuery() {
+		EntityManager em = emf.createEntityManager();
+		String jpql = "SELECT o FROM PurchaseOrderType o WHERE o.shipTo.name=:name";
+		Query query = em.createQuery(jpql);
+		query.setParameter("name", "Alice Smith");
+		List result = query.getResultList();
+		assertFalse(result.isEmpty());
+		for (Object o : result) {
+			assertTrue(o.getClass() + " is not DataObject", o instanceof DataObject);
+			DataObject dataObject = (DataObject) o;
+			assertEquals("PurchaseOrderType", dataObject.getType().getName());
+			DataObject shipTo = dataObject.getDataObject("shipTo");
+			String name = shipTo.getString("name");
+			assertEquals("Alice Smith", name);
+			DataObject billTo = dataObject.getDataObject("billTo");
+			String state = billTo.getString("state");
+			assertEquals("PA", state);
+		}
+	}
+	
+	public void testUpdate() {
+		OpenJPAEntityManager em = emf.createEntityManager();
+		String jpql = "SELECT o FROM PurchaseOrderType o WHERE o.shipTo.name=:name";
+		Query query = em.createQuery(jpql);
+		query.setParameter("name", "Alice Smith");
+		List result = query.getResultList();
+		assertFalse(result.isEmpty());
+		for (Object o : result) {
+			int before = count("USAddress");
+			DataObject dataObject = (DataObject) o;
+			dataObject.getDataObject("billTo").setString("name", "John Doe");
+			em.begin();
+			DataObject merged = em.merge(dataObject);
+			em.commit();
+			String changedName = merged.getDataObject("billTo").getString("name");
+			assertEquals("John Doe", changedName);
+			int after = count("USAddress");
+			assertEquals(before, after);
+		}
+	}
+	
+	public void testEagerRelationFetchedInDefaultFetch() {
+		DataObject data = createPurchaseOrder();
+		EntityManager em = emf.createEntityManager();
+		em.getTransaction().begin();
+		em.persist(data);
+		em.getTransaction().commit();
+		em.clear();
+		
+		em = emf.createEntityManager();
+		String jpql = "SELECT o FROM PurchaseOrderType o";
+		Query query = em.createQuery(jpql);
+		List result = query.getResultList();
+		assertFalse(result.isEmpty());
+		for (Object o : result) {
+			assertTrue(o.getClass() + " is not DataObject", o instanceof DataObject);
+			DataObject dataObject = (DataObject) o;
+			List items = dataObject.getDataObject("items").getList(0);
+			assertNotNull(items);
+			for (Object item:items)
+				assertNotNull(item);
+		}
+	}
+	
+	public void testDelete() {
+		OpenJPAEntityManager em = emf.createEntityManager();
+		String jpql = "SELECT o FROM PurchaseOrderType o WHERE o.shipTo.name=:name";
+		Query query = em.createQuery(jpql);
+		query.setParameter("name", "Alice Smith");
+		List result = query.getResultList();
+		assertFalse(result.isEmpty());
+		for (Object o : result) {
+			int before = count("USAddress");
+			DataObject dataObject = (DataObject) o;
+			em.begin();
+			em.remove(dataObject);
+			em.commit();
+			int after = count("USAddress");
+			assertEquals(before-2, after); // 2 address /PurchaseOrder
+		}
+	}
+	
+	/**
+	 * Create a SDO MetaData Model from a XML Schema.
+	 * 
+	 */
+	DataObject createPurchaseOrder() {
+		DataObject purchaseOrder = DataFactory.INSTANCE.create(
+				getType("PurchaseOrderType"));
+
+		purchaseOrder.setString("orderDate", "1999-10-20");
+
+		DataObject shipTo = purchaseOrder.createDataObject("shipTo");
+		purchaseOrder.set("shipTo", shipTo);
+		shipTo.set("country", "US");
+		shipTo.set("name", "Alice Smith");
+		shipTo.set("street", "123 Maple Street");
+		shipTo.set("city", "Mill Valley");
+		shipTo.set("state", "CA");
+		shipTo.setString("zip", "90952");
+
+		 DataObject billTo = purchaseOrder.createDataObject("billTo");
+		 purchaseOrder.set("billTo", billTo);
+		 billTo.set("country", "US");
+		 billTo.set("name", "Robert Smith");
+		 billTo.set("street", "8 Oak Avenue");
+		 billTo.set("city", "Mill Valley");
+		 billTo.set("state", "PA");
+		 billTo.setString("zip", "95819");
+
+		 purchaseOrder.set("comment", "Hurry, my lawn is going wild!");
+
+		 DataObject items = purchaseOrder.createDataObject("items");
+		
+		 DataObject item1 = items.createDataObject("item");
+		 item1.set("partNum", "872-AA");
+		 item1.set("productName", "Lawnmower");
+		 item1.setInt("quantity", 1);
+		 item1.setString("USPrice", "148.95");
+		 item1.set("comment", "Confirm this is electric");
+		
+		 DataObject item2 = items.createDataObject("item");
+		 item2.set("partNum", "926-AA");
+		 item2.set("productName", "Baby Monitor");
+		 item2.setInt("quantity", 1);
+		 item2.setString("USPrice", "39.98");
+		 item2.setString("shipDate", "1999-05-21");
+
+		return purchaseOrder;
+	}
+
+}

Copied: labs/fluid/src/test/java/example/basic/TestSDO.java (from r559330, labs/fluid/src/test/java/test/TestSDO.java)
URL: http://svn.apache.org/viewvc/labs/fluid/src/test/java/example/basic/TestSDO.java?view=diff&rev=559681&p1=labs/fluid/src/test/java/test/TestSDO.java&r1=559330&p2=labs/fluid/src/test/java/example/basic/TestSDO.java&r2=559681
==============================================================================
--- labs/fluid/src/test/java/test/TestSDO.java (original)
+++ labs/fluid/src/test/java/example/basic/TestSDO.java Wed Jul 25 20:31:01 2007
@@ -16,15 +16,9 @@
  * specific language governing permissions and limitations
  * under the License.    
  */
-package test;
+package example.basic;
 
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.Set;
-
-import org.apache.openjpa.sdo.DelegatingDataObject;
 import org.apache.openjpa.sdo.ImplHelper;
-import org.apache.tuscany.sdo.impl.ClassImpl;
 
 import test.common.AbstractSDOTest;
 
@@ -32,8 +26,6 @@
 import commonj.sdo.Property;
 import commonj.sdo.Type;
 import commonj.sdo.helper.DataFactory;
-import commonj.sdo.helper.TypeHelper;
-import commonj.sdo.helper.XMLHelper;
 
 /**
  * JUnit Tests to read a meta-model from XML Schema and create instances
@@ -43,36 +35,12 @@
  * 
  */
 public class TestSDO extends AbstractSDOTest {
-	private static final String SDO_MODEL_NAMESPACE  = "http://www.example.com/PO";
-
-	public void setUp() throws Exception {
-		super.setUp();
-		sdoTypeParser.parseTypeNames(getXSDResource());
-		assertFalse(sdoTypeParser.getAllTypes().isEmpty());
-		assertFalse(sdoTypeParser.getUserTypes().isEmpty());
-	}
-	
-	protected String getXSDResource() {
-		return "META-INF/po.xsd";
-	}
-
-	public String getPersistenceUnitName() {
-		// does not require JPA
-		return null;
-	}
-
-	public Type getType(String name) {
-		Set<Type> types = sdoTypeParser.getAllTypes();
-		for (Type t:types)
-			if (t.getName().equals(name))
-				return t;
-		return null;
-	}
 	
 	public void testPackage() {
 		Type addressType = getType("USAddress");
-		assertTrue(addressType instanceof ClassImpl);
-		assertEquals("example.domain",((ClassImpl)addressType).getEPackage().getName());
+		assertNotNull(addressType);
+		String pkg = ImplHelper.getPackageName(addressType);
+		assertEquals("example.domain",pkg);
 	}
 	
 	public void testInstanceClassIsNullForUserType() {
@@ -97,7 +65,7 @@
 	 */
 	public void testCreateModel() {
 		DataObject purchaseOrder = DataFactory.INSTANCE.create(
-				SDO_MODEL_NAMESPACE, "PurchaseOrderType");
+				getType("PurchaseOrderType"));
 
 		purchaseOrder.setString("orderDate", "1999-10-20");
 
@@ -136,9 +104,9 @@
 		assertEquals("1999-10-20", purchaseOrder.get("orderDate"));
 		assertEquals("Alice Smith", purchaseOrder.getDataObject("shipTo").getString("name"));
 		
-		DelegatingDataObject delegate = new DelegatingDataObject(purchaseOrder);
-		assertEquals("1999-10-20", delegate.get("orderDate"));
-		assertEquals("Alice Smith", delegate.getDataObject("shipTo").getString("name"));
+//		DelegatingDataObject delegate = new DelegatingDataObject(purchaseOrder);
+//		assertEquals("1999-10-20", delegate.get("orderDate"));
+//		assertEquals("Alice Smith", delegate.getDataObject("shipTo").getString("name"));
 //		try {
 //			OutputStream stream = System.err;
 //			XMLHelper.INSTANCE.save(purchaseOrder, SDO_MODEL_NAMESPACE,

Copied: labs/fluid/src/test/java/example/basic/TestSourceCode.java (from r559330, labs/fluid/src/test/java/test/TestSourceCode.java)
URL: http://svn.apache.org/viewvc/labs/fluid/src/test/java/example/basic/TestSourceCode.java?view=diff&rev=559681&p1=labs/fluid/src/test/java/test/TestSourceCode.java&r1=559330&p2=labs/fluid/src/test/java/example/basic/TestSourceCode.java&r2=559681
==============================================================================
--- labs/fluid/src/test/java/test/TestSourceCode.java (original)
+++ labs/fluid/src/test/java/example/basic/TestSourceCode.java Wed Jul 25 20:31:01 2007
@@ -1,4 +1,4 @@
-package test;
+package example.basic;
 
 import org.apache.openjpa.code.SourceCode;
 

Modified: labs/fluid/src/test/java/test/common/AbstractSDOTest.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/test/java/test/common/AbstractSDOTest.java?view=diff&rev=559681&r1=559680&r2=559681
==============================================================================
--- labs/fluid/src/test/java/test/common/AbstractSDOTest.java (original)
+++ labs/fluid/src/test/java/test/common/AbstractSDOTest.java Wed Jul 25 20:31:01 2007
@@ -25,19 +25,26 @@
 import javax.persistence.Query;
 
 import org.apache.openjpa.lib.meta.ClassArgParser;
+import org.apache.openjpa.meta.MetaDataFactory;
 import org.apache.openjpa.persistence.OpenJPAEntityManager;
 import org.apache.openjpa.sdo.SDOEntityManagerFactory;
+import org.apache.openjpa.sdo.SDOMetaDataFactory;
 import org.apache.openjpa.sdo.SDOTypeParser;
 
-import com.sun.corba.se.spi.legacy.connection.GetEndPointInfoAgainException;
-
 import commonj.sdo.Type;
 
 import junit.framework.TestCase;
 
+/**
+ * Abstract Test case sets up JPA persitence unt and SDO metadata from XML
+ * schema.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
 public abstract class AbstractSDOTest extends TestCase {
 	protected static SDOEntityManagerFactory emf;
-	protected static SDOTypeParser sdoTypeParser;
+	protected static SDOMetaDataFactory factory;
 	
 	/**
 	 * Obtain a EntityManagerFactory and initialize SDO Types.
@@ -49,41 +56,33 @@
 			assertNotNull(tmp);
 			assertTrue(tmp instanceof SDOEntityManagerFactory);
 			emf = (SDOEntityManagerFactory)tmp;
-			
-			ClassArgParser parser = emf.getConfiguration()
-				.getMetaDataRepositoryInstance()
-				.getMetaDataFactory()
-				.newClassArgParser();
-			assertTrue(parser instanceof SDOTypeParser);
-			sdoTypeParser = (SDOTypeParser)parser;
-			parser.parseTypeNames(getXSDResource());
+			MetaDataFactory mdf = emf.getConfiguration()
+				.getMetaDataRepositoryInstance().getMetaDataFactory();
+			assertTrue(mdf instanceof SDOMetaDataFactory);
+			factory = (SDOMetaDataFactory)mdf;
 		}
 	}
 	
+	/**
+	 * Gets the type of given name.
+	 */
 	protected Type getType(String name) {
-		Set<Type> types = sdoTypeParser.getAllTypes();
-		for (Type t:types)
-			if (t.getName().equals(name))
-				return t;
-		return null;
+		return factory.getType(name);
 	}
 	
+	/**
+	 * Count number of persistent instances of the given alias.
+	 */
 	public int count(String alias) {
 		OpenJPAEntityManager em = emf.createEntityManager();
 		Query query = em.createQuery("SELECT COUNT(o) FROM " + alias + " o");
 		return ((Long)query.getSingleResult()).intValue();
 	}
-
 	
 	/**
 	 * Get the name of the persistence unit to be used by this receiver.
-	 * Return null if this test case does not use JPA.
 	 */
 	protected String getPersistenceUnitName() {
 		return System.getProperty("persistence.unit", "test");
-	}
-	
-	protected String getXSDResource() {
-		return System.getProperty("xsd.unit", "null");
 	}
 }



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