labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r561766 - in /labs/fluid: ./ src/main/java/org/apache/openjpa/das/ src/main/java/org/apache/openjpa/sdo/ src/main/java/org/apache/openjpa/sdo/mapping/ src/site/apt/ src/test/java/example/das/ src/test/resources/META-INF/
Date Wed, 01 Aug 2007 11:36:00 GMT
Author: ppoddar
Date: Wed Aug  1 04:35:58 2007
New Revision: 561766

URL: http://svn.apache.org/viewvc?view=rev&rev=561766
Log:
Implementation of DAS

Added:
    labs/fluid/src/main/java/org/apache/openjpa/das/
    labs/fluid/src/main/java/org/apache/openjpa/das/FluidDAS.java
    labs/fluid/src/main/java/org/apache/openjpa/das/FluidDASFactory.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/IdenticalTypeMapping.java
      - copied, changed from r560710, labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/TypeMapping.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/SDOMappingStrategy.java
    labs/fluid/src/test/java/example/das/
    labs/fluid/src/test/java/example/das/DASTestCase.java
    labs/fluid/src/test/java/example/das/TestDAS.java
Removed:
    labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/TypeMapping.java
Modified:
    labs/fluid/pom.xml
    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/SDOEntityManager.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOInstanceMapping.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOMappingRepository.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/AbstractPropertyMapping.java
    labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/PropertyMapping.java
    labs/fluid/src/site/apt/download.apt
    labs/fluid/src/test/resources/META-INF/persistence.xml

Modified: labs/fluid/pom.xml
URL: http://svn.apache.org/viewvc/labs/fluid/pom.xml?view=diff&rev=561766&r1=561765&r2=561766
==============================================================================
--- labs/fluid/pom.xml (original)
+++ labs/fluid/pom.xml Wed Aug  1 04:35:58 2007
@@ -64,23 +64,32 @@
   <properties>
         <scm.dir>svn.apache.org/repos/asf/labs/fluid</scm.dir>
         <generated.src>src/test/generated</generated.src>
+        <javadoc.output.dir>src/site/resources</javadoc.output.dir>
+        <maven.sdocbook.src.dir>src/site/docbook</maven.sdocbook.src.dir>
   </properties>
+  
   <repositories>
         <repository>
             <id>central</id>
+            <name>Maven Repository Switchboard</name>
             <url>http://www.ibiblio.org/maven2</url>
         </repository>
         <repository>
+            <id>maven-central</id>
+            <name>Maven Plugin Repository</name>
+            <url>http://repo1.maven.org</url>
+        </repository>
+        <repository>
             <id>apache-snapshots</id>
             <url>http://people.apache.org/repo/m2-snapshot-repository</url>
         </repository>
         <repository>
             <id>apache-incubator</id>
-            <url>http://people.apache.org/repo/m2-incubating-repository/</url>
+            <url>http://people.apache.org/repo/m2-incubating-repository</url>
         </repository>
         <repository>
             <id>serp-rep</id>
-            <url>http://serp.sourceforge.net/m2repo/</url>
+            <url>http://serp.sourceforge.net/m2repo</url>
         </repository>
   </repositories>
     
@@ -133,8 +142,16 @@
       <version>3.8.1</version>
       <scope>test</scope>
     </dependency>
+    
+    <dependency>
+	    <groupId>org.apache.tuscany.das</groupId>
+		<artifactId>tuscany-das-rdb</artifactId>
+		<version>1.0-incubator-M2</version>
+	</dependency>
+	
   </dependencies>
   
+  
     <build>
         <plugins>
             <plugin>
@@ -155,7 +172,36 @@
           			<trimStackTrace>true</trimStackTrace>
         		</configuration>
       		</plugin>
-      		
+<!--      		
+      		<plugin>
+      			<groupId>org.apache.maven.plugins</groupId>
+      			<artifactId>maven-javadoc-plugin</artifactId>
+      			<version>2.2</version>
+				<configuration>
+                   <outputDirectory>${javadoc.output.dir}</outputDirectory>
+                   <reportOutputDirectory>${javadoc.output.dir}</reportOutputDirectory>
+                   <additionalparam>${javadoc.additionalparam}</additionalparam>
+                   <aggregate>true</aggregate>
+                   <verbose>false</verbose>
+                   <noqualifier>all</noqualifier>
+                   <maxmemory>512m</maxmemory>
+                   <links>
+                      <link>http://java.sun.com/j2se/1.5.0/docs/api</link>
+                      <link>http://java.sun.com/javaee/5/docs/api</link>
+                      <link>http://openjpa.apache.org/docs/latest/javadoc/</link>
+                      <link>http://jakarta.apache.org/commons/collections/api-release</link>
+                    </links>
+                </configuration>  
+                <executions>
+                  <execution>
+                     <goals>
+                       <goal>javadoc</goal>
+                       <goal>test-javadoc</goal>
+                     </goals>
+                   </execution>
+                 </executions>    			
+      		</plugin>
+-->      		
             <plugin>
                 <artifactId>maven-antrun-plugin</artifactId>
                 <executions>
@@ -209,6 +255,7 @@
                     </execution>
                 </executions>
             </plugin>
+            
         </plugins>
     </build>  
     
@@ -231,11 +278,14 @@
                                 <phase>process-classes</phase>
                                 <goals><goal>javadoc</goal></goals>
                                 <configuration>
+                                    <outputDirectory>${javadoc.output.dir}</outputDirectory>
+                                    <reportOutputDirectory>${javadoc.output.dir}</reportOutputDirectory>
                                     <additionalparam>
                                         ${javadoc.additionalparam}
                                     </additionalparam>
                                     <aggregate>true</aggregate>
-                                    <verbose>true</verbose>
+                                    <verbose>false</verbose>
+                                    <noqualifier>all</noqualifier>
                                     <!-- <linksource>true</linksource> -->
                                     <maxmemory>512m</maxmemory>
                                     <links>
@@ -280,6 +330,10 @@
      
      <reporting>
     <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-javadoc-plugin</artifactId>
+      </plugin>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-project-info-reports-plugin</artifactId>

Added: labs/fluid/src/main/java/org/apache/openjpa/das/FluidDAS.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/das/FluidDAS.java?view=auto&rev=561766
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/das/FluidDAS.java (added)
+++ labs/fluid/src/main/java/org/apache/openjpa/das/FluidDAS.java Wed Aug  1 04:35:58 2007
@@ -0,0 +1,296 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.das;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.sdo.SDOEntityManager;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+import org.apache.tuscany.das.rdb.Command;
+import org.apache.tuscany.das.rdb.DAS;
+import org.apache.tuscany.sdo.AnyTypeDataObject;
+import org.apache.tuscany.sdo.SDOFactory;
+
+import commonj.sdo.DataObject;
+
+/**
+ * Implements Tuscany DAS through delegation to OpenJPA EntityManager.
+ * 
+ * @author Pinaki Poddar
+ * @since 0.3.0
+ * 
+ */
+class FluidDAS implements DAS {
+	private static final Localizer _loc = Localizer.forPackage(FluidDAS.class);
+
+	private final SDOEntityManager em;
+
+	/**
+	 * Enumeration of available Commands.
+	 */
+	public enum COMMANDS {
+		INSERT, FIND, DELETE
+	};
+
+	/**
+	 * Constructed by <em>any</em> FluidDASFactory.createDAS() methods.
+	 * 
+	 */
+	FluidDAS(SDOEntityManager em) {
+		this.em = em;
+	}
+
+	/**
+	 * Apply the changes in the given DataObject.
+	 */
+	public void applyChanges(DataObject root) {
+		em.begin();
+		em.merge(root);
+		em.commit();
+	}
+
+	/**
+	 * Create a command.
+	 * @param Permissible values are <code>"INSERT"</code>, <code>"FIND"</code>,
+	 * <code>"SELECT"</code>, <code>"DELETE"</code>.
+	 */
+	public Command createCommand(String cmd) {
+		if (cmd==null)
+			return null;
+		COMMANDS command = null;
+		try {
+			command = COMMANDS.valueOf(cmd);
+		} catch (IllegalArgumentException ex) {
+			if (cmd.trim().length()>"SELECT ".length() &&
+				"SELECT ".equalsIgnoreCase(cmd.trim().substring(0, "SELECT ".length()))) 
+				return new QueryCommand(em, cmd);
+			throw new IllegalArgumentException(error("bad-command", cmd));
+		}
+		switch (command) {
+		case INSERT:
+			return new PersistCommand(em);
+		case FIND:
+			return new FindCommand(em);
+		case DELETE:
+			return new RemoveCommand(em);
+		}
+		return null;
+	}
+
+	/**
+	 * Get a command.
+	 * @param Permissible values are <code>"INSERT"</code>, <code>"FIND"</code>,
+	 * <code>"SELECT"</code>, <code>"DELETE"</code>.
+	 */
+	public Command getCommand(String name) {
+		return createCommand(name);
+	}
+
+	/**
+	 * Releases the resources by closing the underlying EntityManager.
+	 */
+	public void releaseResources() {
+		em.close();
+	}
+	
+	static String error(String key, Object... values) {
+		return _loc.get(key, values).toString();
+	}
+
+
+	static class AbstarctCommand implements Command {
+		protected final SDOEntityManager em;
+
+		protected Map<Integer, Object> params = new HashMap<Integer, Object>();
+
+		AbstarctCommand(SDOEntityManager em) {
+			this.em = em;
+		}
+
+		public void execute() {
+			throw new AbstractMethodError();
+		}
+
+		public DataObject executeQuery() {
+			throw new AbstractMethodError();
+		}
+
+		public void setParameter(int index, Object value) {
+			params.put(index, value);
+		}
+
+		public Object getParameter(int index) {
+			return params.get(index);
+		}
+
+		public int getGeneratedKey() {
+			throw new AbstractMethodError();
+		}
+
+	}
+
+	/**
+	 * Command for persisting SDO DataObjects.
+	 * <br>
+	 * This command accepts any DataObject or PersistenceCapable instance 
+	 * as parameter at any arbitray index.
+	 * <br>
+	 * This command is executed by invoking {@link #execute()} which 
+	 * persists all the instances set via <code>setParameter()</code> 
+	 * <br>
+	 * This command does not support {@link #executeQuery()}.
+	 */
+	public static class PersistCommand extends FluidDAS.AbstarctCommand {
+		PersistCommand(SDOEntityManager em) {
+			super(em);
+		}
+
+		/**
+		 * Persists all instances set via {@link #setParameter}.
+		 * Commits them to the database.
+		 * 
+		 */
+		public void execute() {
+			em.begin();
+			for (Object data : params.values()) {
+				if (data == null) continue;
+				em.persist(data);
+			}
+			em.commit();
+			params.clear();
+		}
+	}
+
+	/**
+	 * Command for finding SDO DataObjects through primary key.
+	 * <br>
+	 * This command accepts a DataObject identitifer as parameters at 
+	 * index 1.<br>
+	 * DataObject identitifer is a String of the form <code>Type:id</code>
+	 * where <code>Type</code> is the SDO Type name and <code>id</code> is 
+	 * value of identifier property.
+	 * <br>
+	 * This command is executed by invoking {@link #executeQuery()} which 
+	 * returns the instance of Type and id set via <code>setParameter()</code> 
+	 * <br>
+	 * This command does not support {@link #execute()}.
+	 */
+	public static class FindCommand extends FluidDAS.AbstarctCommand {
+		FindCommand(SDOEntityManager em) {
+			super(em);
+		}
+
+		public void setParameter(int index, Object value) {
+			if (index != 1)
+				throw new IllegalArgumentException(error("find-bad-index",
+						index, value));
+			if (!(value instanceof String))
+				throw new IllegalArgumentException(error("find-bad-value",
+						index, value));
+
+			super.setParameter(index, value);
+		}
+
+		public DataObject executeQuery() {
+			return em.find(DataObject.class, getParameter(1));
+		}
+	}
+
+	/**
+	 * Command for selecting SDO DataObjects through JPQL Query.
+	 * <br>
+	 * This query parameters can be set via index 1 or higher.<br>
+	 * <br>
+	 * This command is executed by invoking {@link #executeQuery()} which 
+	 * returns a DataObject whose 0-th property contains a list of
+	 * DataObjects that are the <em>actual</em> result of the query. 
+	 * <br>
+	 * This command supports {@link #execute()} whose semantics is to
+	 * excute the JPQL as it is.
+	 */
+	public static class QueryCommand extends FluidDAS.AbstarctCommand {
+		OpenJPAQuery query;
+
+		QueryCommand(SDOEntityManager em, String jpql) {
+			super(em);
+			query = em.createQuery(jpql);
+		}
+
+		public void setParameter(int index, Object value) {
+			if (index <= 0)
+				throw new IllegalArgumentException(error("query-bad-query",
+						index, value));
+			super.setParameter(index, value);
+		}
+
+		public void execute() {
+			for (Integer index : params.keySet()) {
+				Object value = params.get(index);
+				query.setParameter(index, value);
+			}
+			query.executeUpdate();
+		}
+
+		public DataObject executeQuery() {
+			for (Integer index : params.keySet()) {
+				Object value = params.get(index);
+				query.setParameter(index, value);
+			}
+			List<DataObject> list = query.getResultList();
+			return wrap(list);
+		}
+
+		DataObject wrap(List<DataObject> list) {
+			AnyTypeDataObject any = SDOFactory.eINSTANCE
+					.createAnyTypeDataObject();
+			any.set("list", list);
+			return any;
+		}
+	}
+
+	/**
+	 * Command for deleting SDO DataObjects.
+	 * <br>
+	 * This command accepts any DataObject or PersistenceCapable instance
+	 * as parameters at any arbitray index.
+	 * <br>
+	 * This command is executed by invoking {@link #execute()} which 
+	 * persists all the instances set via <code>setParameter()</code> 
+	 * <br>
+	 * This command does not support {@link #executeQuery()}.
+	 */
+	public static class RemoveCommand extends FluidDAS.AbstarctCommand {
+		RemoveCommand(SDOEntityManager em) {
+			super(em);
+		}
+
+		public void execute() {
+			em.begin();
+			for (Object data : params.values()) {
+				if (data == null) continue;
+				em.remove(data);
+			}
+			em.commit();
+			params.clear();
+		}
+	}
+}

Added: labs/fluid/src/main/java/org/apache/openjpa/das/FluidDASFactory.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/das/FluidDASFactory.java?view=auto&rev=561766
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/das/FluidDASFactory.java (added)
+++ labs/fluid/src/main/java/org/apache/openjpa/das/FluidDASFactory.java Wed Aug  1 04:35:58 2007
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.das;
+
+import java.io.InputStream;
+import java.sql.Connection;
+
+import javax.persistence.Persistence;
+
+import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.sdo.SDOEntityManager;
+import org.apache.openjpa.sdo.SDOEntityManagerFactory;
+import org.apache.tuscany.das.rdb.DAS;
+import org.apache.tuscany.das.rdb.DASFactory;
+import org.apache.tuscany.das.rdb.config.Config;
+
+/**
+ * Implements Tuscany DASFactory through delegation to OpenJPA 
+ * EntityManagerFactory.
+ * 
+ * @author Pinaki Poddar
+ * @since 0.3.0
+ *
+ */
+public class FluidDASFactory implements DASFactory {
+	private static Localizer _loc = Localizer.forPackage(FluidDASFactory.class);
+	
+	private SDOEntityManagerFactory emf;
+	
+	/**
+	 * Construct a factory.
+	 * <br>
+	 * All persistence related configuration is specified in 
+	 * <code>META-INF/persistence.xml</code> which must be available as a 
+	 * resource in the invocation classpath.
+	 * <br>The <code>persistence.xml</code> must be configured for Fluid.
+	 * The persistence unit configuration is configured for Fluid by specifying
+	 * following properties:<br>
+	 *		&lt;property name="openjpa.EntityManagerFactory" value="sdo"/&gt;
+	 *		&lt;property name="openjpa.MetaDataFactory" value="sdo(Resources=META-INF/a.xsd;META-INF/b.xsd)"/&gt;
+	 * <br>
+	 * where <code>a.xsd</code>, <code>b.xsd</code> are the XML Schema 
+	 * Definition for SDO Types.
+	 * 
+	 * @param unitName name of a JPA Persistence Unit. 
+	 * The unit name must match one of the unit names specified therein.
+	 * 
+	 */
+	public FluidDASFactory(String unitName) {
+		try {
+			emf = (SDOEntityManagerFactory)Persistence
+			.createEntityManagerFactory(unitName);
+		} catch (ClassCastException ex) {
+			throw new RuntimeException(_loc.get("not-fluid").toString());
+		}
+	}
+	
+	private DAS createDAS() {
+		return new FluidDAS((SDOEntityManager)emf.createEntityManager());
+	}
+	
+	/**
+	 * Gets a new DAS.
+	 * 
+	 * <B>NOTE:</B> The input is ignored. You can pass a null. 
+	 */
+	public DAS createDAS(InputStream arg0) {
+		return createDAS();
+	}
+
+	/**
+	 * Gets a new DAS.
+	 * 
+	 * <B>NOTE:</B> The input is ignored. You can pass a null. 
+	 */
+	public DAS createDAS(Config arg0) {
+		return createDAS();
+	}
+
+	/**
+	 * Gets a new DAS.
+	 * 
+	 * <B>NOTE:</B> The input is ignored. You can pass a null. 
+	 */
+	public DAS createDAS(Connection arg0) {
+		return createDAS();
+	}
+
+	/**
+	 * Gets a new DAS.
+	 * 
+	 * <B>NOTE:</B> The input is ignored. You can pass a null. 
+	 */
+	public DAS createDAS(InputStream arg0, Connection arg1) {
+		return createDAS();
+	}
+
+	/**
+	 * Gets a new DAS.
+	 * 
+	 * <B>NOTE:</B> The input is ignored. You can pass a null. 
+	 */
+	public DAS createDAS(Config arg0, Connection arg1) {
+		return createDAS();
+	}
+	
+	/**
+	 * Gets the underlying implementation.
+	 * 
+	 * <B>NOTE:</B> The input is ignored. You can pass a null. 
+	 */
+	public SDOEntityManagerFactory getDelegate() {
+		return emf;
+	}
+}

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=561766&r1=561765&r2=561766
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/ImplHelper.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/ImplHelper.java Wed Aug  1 04:35:58 2007
@@ -30,13 +30,13 @@
 import commonj.sdo.Type;
 
 /**
- * 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 class ImplHelper {
+public final class ImplHelper {
 	private static Localizer _loc = Localizer.forPackage(ImplHelper.class);
 
 	/**
@@ -73,7 +73,8 @@
 	}
 	
 	/**
-	 * 
+	 * 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());
@@ -271,7 +272,7 @@
 	/**
 	 * Affirms if Eclipse Modeling Framework classes are available
 	 * as SDO implementation.
-	 * <b>
+	 * <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.

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?view=diff&rev=561766&r1=561765&r2=561766
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/SDO2POJOGenerator.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/SDO2POJOGenerator.java Wed Aug  1 04:35:58 2007
@@ -36,6 +36,7 @@
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.lib.util.Options;
 import org.apache.openjpa.sdo.mapping.PropertyMapping;
+import org.apache.openjpa.sdo.mapping.SDOMappingStrategy;
 import org.apache.openjpa.sdo.mapping.TypeMapping;
 import org.apache.openjpa.util.UserException;
 
@@ -152,7 +153,7 @@
 	 * 
 	 */
 	SourceCode generatePOJO(Type type) {
-		TypeMapping mapping = new TypeMapping(type, null);
+		TypeMapping mapping = SDOMappingStrategy.decideStrategy(type, null);
 		String pkgName       = mapping.getJavaPackageName();
 		String javaClassName = mapping.getJavaClassName();
 		SourceCode code = new SourceCode(pkgName, javaClassName);
@@ -207,7 +208,7 @@
 		return new File(pkgdir, code.getClassName() + ".java");
 	}
 
-	public File getRootDirectory() {
+	File getRootDirectory() {
 		File rootDir = new File(flags.rootDir);
 		if (rootDir.exists() && rootDir.isDirectory()) {
 			return rootDir;
@@ -240,7 +241,7 @@
 	 * Generates and writes Java source files for SDO Types found in given
 	 * resources.
 	 */
-	public void run(String[] args) {
+	void run(String[] args) {
 		_cache.clear();
 		for (int i=0; args!=null && i<args.length; i++) {
 			List<Type> types = findTypes(args[i]);

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=561766&r1=561765&r2=561766
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOEntityManager.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOEntityManager.java Wed Aug  1 04:35:58 2007
@@ -19,9 +19,7 @@
 package org.apache.openjpa.sdo;
 
 
-import java.util.ArrayList;
 import java.util.Collection;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -30,12 +28,9 @@
 import org.apache.openjpa.kernel.jpql.JPQLParser;
 import org.apache.openjpa.persistence.EntityManagerImpl;
 import org.apache.openjpa.persistence.OpenJPAQuery;
-import org.apache.openjpa.util.OptimisticException;
 
 import commonj.sdo.DataObject;
-import commonj.sdo.Property;
 import commonj.sdo.Type;
-import commonj.sdo.helper.DataFactory;
 
 /**
  * A specialized EntityManager that accepts SDO DataObject as 

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?view=diff&rev=561766&r1=561765&r2=561766
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOInstanceMapping.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOInstanceMapping.java Wed Aug  1 04:35:58 2007
@@ -32,17 +32,30 @@
 import commonj.sdo.Type;
 import commonj.sdo.helper.DataFactory;
 
+/**
+ * Converts SDO DataObject to PersistenceCapable instance and vice versa.
+ * Conversion is essentially copying data from one represnetaion to another.
+ * Two aspects are a) maintaining indentity/version correspondence between
+ * DataObject and PersistenceCapable representation b) closure of the instance
+ * being converted. 
+ * 
+ * @author Pinaki Poddar
+ * @since 0.2.0
+ *
+ */
 public class SDOInstanceMapping {
 	SDOMappingRepository repos;
 	SDOEntityManager em;
 	BiDiMap<DataObject, Object> closure = new BiDiMap<DataObject, Object>();
-//	Map<DataObject,Object> closure = new HashMap<DataObject,Object>();
 
 	public SDOInstanceMapping(SDOEntityManager em, SDOMappingRepository repos) {
 		this.repos = repos;
 		this.em = em;
 	}
 	
+	/**
+	 * Populates a DataObject from the field values of the given object.  
+	 */
 	public DataObject populateDataObject(Object pc) {
 		Class cls = pc.getClass();
 		Type type = repos.getSDOType(cls, true);
@@ -68,10 +81,8 @@
 	}
 	
 	/**
-	 * Populate a cached or new Object with the given DataObject.
+	 * Populates a cached or new Object with the given DataObject.
 	 * 
-	 * @param source
-	 * @param target
 	 */
 	public Object populatePC(DataObject data) {
 		Type type = data.getType();
@@ -102,6 +113,10 @@
 		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();
@@ -112,6 +127,10 @@
 		} 
 	}
 	
+	/**
+	 * 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); 
@@ -122,32 +141,24 @@
 		} 
 	}
 	
+	/**
+	 * Get the closure of DataObjects and PersistenceCapable instances.
+	 */
 	public Map getClosure() {
 		return closure;
 	}
-
 	
 	/**
-	 * Gets a PersistenceCapable instance for a given DataObject.
-	 * First looks up the local cache, then EntityManager's cache, and if 
-	 * not found constructs a new PersistenceCapable, initializes with the
-	 * id/version values from the DataObject and then returns.
-	 * @param data
-	 * @return
+	 * Clears the state of this receiver.
+	 *
 	 */
-//	Object getPCForDataObject(DataObject data) {
-//		Object pc = findCached(data);
-//		if (pc != null)
-//			return pc;
-//		
-//		Class cls = repos.getJavaClass(data.getType(), true);
-//		pc = initializePC(cls, null, data);
-//		cache(data, pc);
-//		return pc;
-//	}
-	
+	public void reset() {
+		closure.clear();
+	}
+
 	/**
-	 * Find a PersistenceCapable instance given a DataObject.
+	 * 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) {
@@ -157,6 +168,11 @@
 		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) 
@@ -164,6 +180,11 @@
 		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);
@@ -182,8 +203,10 @@
 				throw new OptimisticException(pc);
 		} else {
 			try {
-				repos.getMapping(data.getType()).getIdentityMapping().populateDataObject(data, pc, this);
-				repos.getMapping(data.getType()).getVersionMapping().populateDataObject(data, pc, this);
+				repos.getMapping(data.getType()).getIdentityMapping()
+					.populateDataObject(data, pc, this);
+				repos.getMapping(data.getType()).getVersionMapping()
+					.populateDataObject(data, pc, this);
 			} catch (Exception e) {
 				throw new PersistenceException(e);
 			}

Modified: labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOMappingRepository.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOMappingRepository.java?view=diff&rev=561766&r1=561765&r2=561766
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOMappingRepository.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/SDOMappingRepository.java Wed Aug  1 04:35:58 2007
@@ -28,12 +28,13 @@
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.meta.ClassMetaData;
+import org.apache.openjpa.sdo.mapping.SDOMappingStrategy;
 import org.apache.openjpa.sdo.mapping.TypeMapping;
 
 import commonj.sdo.Type;
 
 /**
- * Maps Identity Property.
+ * Maintains mapping information for SDO Types to Java classes.
  * 
  * @author Pinaki Poddar
  * @since 0.2.0
@@ -54,16 +55,19 @@
 		_log = conf.getLog(OpenJPAConfiguration.LOG_METADATA);
 	}
 	
+	/**
+	 * Gets the strategy used for mapping of the given Type.
+	 * Constructs if necessary. 
+	 */
 	public TypeMapping getMapping(Type type) {
 		TypeMapping mapping = mappings.get(type);
 		if (mapping == null) {
 			Class cls = getJavaClass(type, true);
-			ClassMetaData cm = conf.getMetaDataRepositoryInstance().getCachedMetaData(cls);
-			if (cm instanceof ClassMapping) {
-				mapping = new TypeMapping(type, (ClassMapping)cm);
-			} else {
-				mapping = new TypeMapping(type, null);
-			}
+			ClassMetaData cm = conf.getMetaDataRepositoryInstance()
+				.getCachedMetaData(cls);
+			ClassMapping cmd = (cm instanceof ClassMapping) ? 
+					(ClassMapping)cm : null;
+			mapping = SDOMappingStrategy.decideStrategy(type, cmd);
 			mappings.put(type, mapping);
 		}
 		return mapping;
@@ -106,12 +110,16 @@
 	
 	/**
 	 * Gets SDO Type corresponding to the given Java class.
+	 * Will trigger parsing configured XML 
+	 * Schema definitions if the named Type has not been cached.
 	 */
 	public Type getSDOType(Class cls, boolean mustExist) {
 		Type type = _cache.getReverse(cls);
 		if (type == null && mustExist) {
-			SDOMetaDataFactory mdf = (SDOMetaDataFactory)conf.getMetaDataRepositoryInstance().getMetaDataFactory();
-			mdf.getPersistentTypeNames(true, Thread.currentThread().getContextClassLoader());
+			SDOMetaDataFactory mdf = (SDOMetaDataFactory)conf
+				.getMetaDataRepositoryInstance().getMetaDataFactory();
+			mdf.getPersistentTypeNames(true, Thread.currentThread()
+					.getContextClassLoader());
 			type = _cache.getReverse(cls);
 			if (type == null)
 				throw new RuntimeException(_loc.get("no-type-for-class",
@@ -120,22 +128,26 @@
 		return type;
 	}
 	
-	public Type getType(String name) {
+	/**
+	 * Get the SDO Type of given name. Will trigger parsing configured XML 
+	 * Schema definitions if the named Type has not been cached.
+	 */
+	public Type getType(String name) throws TypeNotFoundException {
 		for (Type t:parsedTypes)
 			if (t.getName().equals(name))
 				return t;
 		
-		
-		SDOMetaDataFactory mdf = (SDOMetaDataFactory)conf.getMetaDataRepositoryInstance().getMetaDataFactory();
-		mdf.getPersistentTypeNames(true, Thread.currentThread().getContextClassLoader());
+		SDOMetaDataFactory mdf = (SDOMetaDataFactory)conf
+			.getMetaDataRepositoryInstance().getMetaDataFactory();
+		mdf.getPersistentTypeNames(true, Thread.currentThread()
+				.getContextClassLoader());
 		
 		for (Type t:parsedTypes)
 				if (t.getName().equals(name))
 					return t;
 		
-		
-		throw new RuntimeException(_loc.get("no-type-for-name", name).toString());
-		
+		throw new TypeNotFoundException(_loc.get("no-type-for-name", name)
+			.toString());
 	}
 
 }

Modified: labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/AbstractPropertyMapping.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/AbstractPropertyMapping.java?view=diff&rev=561766&r1=561765&r2=561766
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/AbstractPropertyMapping.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/AbstractPropertyMapping.java Wed Aug  1 04:35:58 2007
@@ -48,6 +48,10 @@
 		}
 	}
 	
+	public final Property getProperty() {
+		return property;
+	}
+	
 	public String getFieldName() {
 		return property.getName();
 	}

Copied: labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/IdenticalTypeMapping.java (from r560710, labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/TypeMapping.java)
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/IdenticalTypeMapping.java?view=diff&rev=561766&p1=labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/TypeMapping.java&r1=560710&p2=labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/IdenticalTypeMapping.java&r2=561766
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/TypeMapping.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/IdenticalTypeMapping.java Wed Aug  1 04:35:58 2007
@@ -31,12 +31,12 @@
 import commonj.sdo.Type;
 
 /**
- * Maps SDO Type interms of constituent Property.
+ * Maps SDO Type in terms of constituent Property.
  * 
  * @author Pinaki Poddar
  * @since 0.2.0
  */
-public class TypeMapping {
+public class IdenticalTypeMapping implements TypeMapping {
 	protected final Type type;
 	protected final Class cls;
 	protected IdentityMapping identityMapping;
@@ -47,7 +47,7 @@
 	protected Map<Property, PropertyMapping> _propertyMappings = 
 		new HashMap<Property, PropertyMapping>();
 	
-	public TypeMapping(Type type, ClassMapping clsMeta) {
+	public IdenticalTypeMapping(Type type, ClassMapping clsMeta) {
 		this.type = type;
 		this.cls  = (clsMeta==null) ? null : clsMeta.getDescribedType();
 		List properties = type.getProperties();
@@ -59,7 +59,11 @@
 		}
 	}
 	
-	public PropertyMapping addMapping(Property p, FieldMapping field) {
+	public Type getType() {
+		return type;
+	}
+	
+	PropertyMapping addMapping(Property p, FieldMapping field) {
 		if (p.getContainingType() != type)
 			throw new IllegalArgumentException(p.getName());
 		PropertyMapping mapping = SDOMappingStrategy.decideStrategy(p, field);

Modified: labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/PropertyMapping.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/PropertyMapping.java?view=diff&rev=561766&r1=561765&r2=561766
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/PropertyMapping.java (original)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/PropertyMapping.java Wed Aug  1 04:35:58 2007
@@ -21,6 +21,7 @@
 import org.apache.openjpa.sdo.SDOInstanceMapping;
 
 import commonj.sdo.DataObject;
+import commonj.sdo.Property;
 
 /**
  * Defines protocol of mapping between DataObject instance and Persistence
@@ -30,14 +31,71 @@
  * @since 0.2.0
  */
 public interface PropertyMapping  {
+	/**
+	 * Get the Property being mapped by this receiver.
+	 */
+	public Property getProperty();
+	
+	/**
+	 * Gets a logical name of this receiver. This name is only used for
+	 * descriptiove purpose.
+	 */
+	public String getName();
+	
+	/**
+	 * Gets the name of target Java field. 
+	 * 
+	 */
+	public String getFieldName();
+	
+	/**
+	 * Gets the name of the type of target Java Field.
+	 */
+	public String getFieldTypeName();
+	
+	/**
+	 * Gets the persistent annotations for the target Java field.
+	 */
+	public String[] getAnnotations();
+	
+	/**
+	 * Populate the given <code>target</code> DataObject from the field value
+	 * of the given <code>source</code> PersistenceCapable instance.
+	 * 
+	 * @param target the DataObject whose value of the property to be set.
+	 * @param source the PersistenceCapable instance whose field value
+	 * is to be extracted.
+	 * @param ctx The context this receiver is activated.
+	 * 
+	 * @return the DataObject which has been modified. For primitive field
+	 * it is the given <code>target</code> DataObject itself. But for
+	 * relation mapping, it can be another DataObject.
+	 * 
+	 * @throws Exception if the value can be set for some reason.
+	 */
 	public DataObject populateDataObject(DataObject target, Object source, 
 			SDOInstanceMapping ctx) throws Exception;
+	
+	
+	/**
+	 * Populate the given <code>target</code> PersistenceCapable instance from 
+	 * the property value of the given <code>source</code> DataObject .
+	 * 
+	 * @param target the PersistenceCapable instance whose field value 
+	 * to be set.
+	 * @param source the DataObject whose property value
+	 * is to be extracted.
+	 * @param ctx The context this receiver is activated.
+	 * 
+	 * @return the PersistenceCapable instance which has been modified. 
+	 * For primitive field, it is the given <code>target</code> 
+	 * PersistenceCapable instance itself. But for
+	 * relation mapping, it can be another PersistenceCapable instance.
+	 * 
+	 * @throws Exception if the value can be set for some reason.
+	 */
 	public Object populatePC(Object target, DataObject source, 
 			SDOInstanceMapping ctx) throws Exception;
 	
-	public String getFieldName();
-	public String getFieldTypeName();
-	public String[] getAnnotations();
-	public String getName();
 	
 }

Added: labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/SDOMappingStrategy.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/SDOMappingStrategy.java?view=auto&rev=561766
==============================================================================
--- labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/SDOMappingStrategy.java (added)
+++ labs/fluid/src/main/java/org/apache/openjpa/sdo/mapping/SDOMappingStrategy.java Wed Aug  1 04:35:58 2007
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.sdo.mapping;
+
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.meta.FieldMapping;
+import org.apache.openjpa.sdo.ImplHelper;
+
+import commonj.sdo.Property;
+import commonj.sdo.Type;
+
+/**
+ * Decides appropariate mapping strategy for any given Property.
+ * 
+ * @author Pinaki Poddar
+ * @since 0.2.0
+ */
+public class SDOMappingStrategy {
+	/**
+	 * Decides the mapping strategy  to be used for the given Type.
+	 *  
+	 * @param type the Type  to be mapped.
+	 * @param cmd The class with database mapping information. This is
+	 * null i.e. not available during code generation and available
+	 * during runtime.
+	 * 
+	 * @return the mapping to be used for the given Type.
+	 */
+	public static TypeMapping decideStrategy(Type type, ClassMapping cmd) {
+		return new IdenticalTypeMapping(type, cmd);
+	}
+	
+	/**
+	 * Decides the mapping strategy to be used for the given Property.
+	 * 
+	 * @param p the Property to be mapped.
+	 * @param fmd The field with database mapping information. This is
+	 * null i.e. not available during code generation and available
+	 * during runtime.
+	 * 
+	 * @return the mapping to be used for the given Property.
+	 * 
+	 */
+	public static PropertyMapping decideStrategy(Property p, FieldMapping fmd) {
+		if (ImplHelper.isIdentity(p))
+			return new IdentityMapping(p, fmd);
+		if (ImplHelper.isVersion(p))
+			return new VersionMapping(p, fmd);
+
+		if (p.getType().isDataType()) {
+			if (p.isMany()) {
+				return new PrimitiveListMapping(p, fmd);
+			} else {
+				return new PrimitiveMapping(p, fmd);
+			}
+		}
+		if (ImplHelper.isContainer(p.getType())) {
+			Type componentType = ImplHelper.getComponentType(p.getType());
+			if (componentType.isDataType())
+				return new PrimitiveListMapping(p, fmd);
+			else
+				return new RelationListMapping(p, fmd);
+		}
+		if (p.isMany()) {
+			return new RelationListMapping(p, fmd);
+		} else {
+			return new RelationMapping(p, fmd);
+		}
+	}
+}

Modified: labs/fluid/src/site/apt/download.apt
URL: http://svn.apache.org/viewvc/labs/fluid/src/site/apt/download.apt?view=diff&rev=561766&r1=561765&r2=561766
==============================================================================
--- labs/fluid/src/site/apt/download.apt (original)
+++ labs/fluid/src/site/apt/download.apt Wed Aug  1 04:35:58 2007
@@ -1,8 +1,14 @@
 Download 
 
  Fluid is available as a single jar.
- You can download the jar from 
- {{{http://svn.apache.org/repos/asf/labs/fluid/sdo-persistence-0.1.0-SNAPSHOT.jar}here}}
+
+*----------+---------------------------------------------------------------*
+|  Version |                                                               
+*----------+---------------------------------------------------------------*
+|  0.1.0   | {{{http://svn.apache.org/repos/asf/labs/fluid/sdo-persistence-0.1.0-SNAPSHOT.jar}sdo-persistence-0.1.0-SNAPSHOT.jar}} |
+*----------+---------------------------------------------------------------*
+|  0.2.0   | {{{http://svn.apache.org/repos/asf/labs/fluid/sdo-persistence-0.2.0-SNAPSHOT.jar}sdo-persistence-0.2.0-SNAPSHOT.jar}} |
+*-------------------------------------|-----------------------------------*
 
 * Build from Source Code
 
@@ -23,7 +29,7 @@
 +---------------------------------------------------------
 
   will compile the source code, run the tests
-  and create a sdo-persistence-0.1.0-SNAPSHOT.jar. 
+  and create a sdo-persistence-<<<\<VERSION\>>>>.jar. 
   
 +----------------------------------------------------------
  $ mvn install

Added: labs/fluid/src/test/java/example/das/DASTestCase.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/test/java/example/das/DASTestCase.java?view=auto&rev=561766
==============================================================================
--- labs/fluid/src/test/java/example/das/DASTestCase.java (added)
+++ labs/fluid/src/test/java/example/das/DASTestCase.java Wed Aug  1 04:35:58 2007
@@ -0,0 +1,53 @@
+package example.das;
+
+import java.io.InputStream;
+
+import javax.persistence.Query;
+
+import org.apache.openjpa.das.FluidDASFactory;
+import org.apache.openjpa.meta.MetaDataFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.sdo.SDOEntityManagerFactory;
+import org.apache.openjpa.sdo.SDOMappingRepository;
+import org.apache.openjpa.sdo.SDOMetaDataFactory;
+import org.apache.tuscany.das.rdb.DAS;
+import org.apache.tuscany.das.rdb.DASFactory;
+
+import commonj.sdo.Type;
+
+import junit.framework.TestCase;
+
+abstract class DASTestCase extends TestCase {
+	public static final String UNIT_NAME = 
+		System.getProperty("persistence.unit", "test");
+	
+	protected static FluidDASFactory dasFactory;
+	
+	protected void setUp() throws Exception {
+		super.setUp();
+		if (dasFactory == null)
+			dasFactory = new FluidDASFactory(UNIT_NAME);
+	}
+
+	protected DAS getDAS() {
+		return dasFactory.createDAS((InputStream)null);
+	}
+	
+	/**
+	 * Count number of persistent instances of the given alias.
+	 */
+	public int count(String alias) {
+		OpenJPAEntityManager em = dasFactory.getDelegate().createEntityManager();
+		Query query = em.createQuery("SELECT COUNT(o) FROM " + alias + " o");
+		return ((Long)query.getSingleResult()).intValue();
+	}
+	
+	public Type getType(String name) {
+		SDOEntityManagerFactory emf = dasFactory.getDelegate();
+		MetaDataFactory mdf = emf.getConfiguration()
+			.getMetaDataRepositoryInstance().getMetaDataFactory();
+		assertTrue(mdf instanceof SDOMetaDataFactory);
+		SDOMappingRepository repos = ((SDOMetaDataFactory)mdf).getSDOMappingRepository();
+		return repos.getType(name);
+	}
+}

Added: labs/fluid/src/test/java/example/das/TestDAS.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/test/java/example/das/TestDAS.java?view=auto&rev=561766
==============================================================================
--- labs/fluid/src/test/java/example/das/TestDAS.java (added)
+++ labs/fluid/src/test/java/example/das/TestDAS.java Wed Aug  1 04:35:58 2007
@@ -0,0 +1,161 @@
+package example.das;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.sdo.ImplHelper;
+import org.apache.tuscany.das.rdb.Command;
+import org.apache.tuscany.das.rdb.DAS;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Type;
+import commonj.sdo.helper.DataFactory;
+
+
+public class TestDAS extends DASTestCase {
+	/**
+	 * 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");
+
+		String ssn = ""+System.currentTimeMillis();
+		DataObject person = createPerson(ssn, "Fluid", "Guy", 17);
+		DAS das = getDAS();
+		Command insert = das.getCommand("INSERT");
+		insert.setParameter(0, person);
+		insert.execute();
+		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
+		String id = "Person:"+ssn;
+		Command find = das.getCommand("FIND");
+		find.setParameter(1, id);
+		DataObject result = find.executeQuery();
+		assertNotNull(result);
+		assertEquals(person,result);
+	}
+	
+
+	/**
+	 * Query using JPQL. The query results should be DataObjects. The related
+	 * DataObjects should also be fetched.
+	 */
+	public void testQuery() {
+		DAS das = getDAS();
+		String jpql = "SELECT o FROM Person o WHERE o.firstName=?1 AND o.age=?2";
+		Command query = das.getCommand(jpql);
+		query.setParameter(1, "Fluid");
+		query.setParameter(2, 17);
+		DataObject list = query.executeQuery();
+		List result = (List)list.get(0);
+		assertFalse(result.isEmpty());
+		for (Object o : result) {
+			assertTrue(o instanceof DataObject);
+			DataObject dataObject = (DataObject) o;
+			assertEquals("Person", dataObject.getType().getName());
+			String firstName = dataObject.getString("firstName");
+			assertEquals("Fluid", firstName);
+			String lastName = dataObject.getString("lastName");
+			assertEquals("Guy", lastName);
+		}
+	}
+	
+	/**
+	 * Tests that DataObject can be modified and merged. The changes are 
+	 * persisted and the merged DataObjects returned reflect the modifications
+	 * as well as the version updates.
+	 */
+	public void testUpdate() {
+		DAS das = getDAS();
+		String jpql = "SELECT o FROM Person o WHERE o.firstName=?1 AND o.age=?2";
+		Command query = das.getCommand(jpql);
+		query.setParameter(1, "Fluid");
+		query.setParameter(2, 17);
+		DataObject list = query.executeQuery();
+		List result = list.getList(0);
+		assertFalse(result.isEmpty());
+		for (Object o : result) {
+			assertTrue(o instanceof DataObject);
+			DataObject dataObject = (DataObject) o;
+			assertEquals("Person", dataObject.getType().getName());
+			String firstName = dataObject.getString("firstName");
+			assertEquals("Fluid", firstName);
+			String lastName = dataObject.getString("lastName");
+			assertEquals("Guy", lastName);
+		}
+		for (Object o : result) {
+			int before = count("Person");
+			DataObject dataObject = (DataObject) o;
+			int v0 = ImplHelper.getVersion(dataObject);
+			assertTrue(v0>0);
+			assertNotNull(ImplHelper.getIdValue(dataObject));
+			
+			dataObject.setString("firstName", "Solid");
+			das.applyChanges(dataObject);
+			int v1 = ImplHelper.getVersion(dataObject);
+			assertTrue(v1>v0);
+			assertEquals("Solid", dataObject.getString("firstName"));
+			int after = count("Person");
+			assertEquals(before, after);
+		}
+	}
+	
+	/**
+	 * Tests that DataObjects can be deleted from persistent store via remove()
+	 * method.
+	 *
+	 */
+	public void testDelete() {
+		DAS das = getDAS();
+		String jpql = "SELECT o FROM Person o WHERE o.lastName=?1 AND o.age=?2";
+		Command query = das.getCommand(jpql);
+		query.setParameter(1, "Guy");
+		query.setParameter(2, 17);
+		DataObject list = query.executeQuery();
+		List result = list.getList(0);
+		assertFalse(result.isEmpty());
+		Command delete = das.createCommand("DELETE");
+		for (Object o : result) {
+			int before = count("Person");
+			DataObject dataObject = (DataObject) o;
+			delete.setParameter(0, dataObject);
+			delete.execute();
+			int after = count("Person");
+			assertEquals(before-1, after);
+		}
+	}
+	
+	public void testUnknownCommand() {
+		DAS das = getDAS();
+		try {
+			Command bad = das.getCommand("UNKNOWN");
+			fail("Expected exception on UNKNOWN command");
+		} catch (RuntimeException e) {
+			// good;
+		}
+	}
+	
+	/**
+	 * Helper method to create and populate a Person DataObject.
+	 */
+	DataObject createPerson(String ssn, String first, String last, int age) {
+		Type type = getType("Person");
+		DataObject data = DataFactory.INSTANCE.create(type);
+		data.set("ssn", ssn);
+		data.setString("firstName", first);
+		data.setString("lastName", last);
+		data.setInt("age", age);
+		return data;
+	}
+}

Modified: labs/fluid/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/labs/fluid/src/test/resources/META-INF/persistence.xml?view=diff&rev=561766&r1=561765&r2=561766
==============================================================================
--- labs/fluid/src/test/resources/META-INF/persistence.xml (original)
+++ labs/fluid/src/test/resources/META-INF/persistence.xml Wed Aug  1 04:35:58 2007
@@ -11,7 +11,7 @@
 			<property name="openjpa.ConnectionPassword" value="hello"/>
 			<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
    			<property name="openjpa.QueryCompilationCache" value="false"/>
-   			<property name="openjpa.Log" value="DefaultLevel=INFO"/>
+   			<property name="openjpa.Log" value="DefaultLevel=INFO, SQL=TRACE"/>
   			<property name="openjpa.BrokerImpl" value="non-finalizing"/>
    			
       	</properties>



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


Mime
View raw message