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 23:07:31 UTC
svn commit: r559976 - in /labs/fluid/src: site/apt/manual.apt
test/java/example/basic/TestCRUD.java
test/java/example/basic/TestRelation.java
test/java/example/basic/TestSDO.java
test/java/example/basic/TestSourceCode.java
Author: ppoddar
Date: Thu Jul 26 14:07:29 2007
New Revision: 559976
URL: http://svn.apache.org/viewvc?view=rev&rev=559976
Log:
Preparing Site links
Modified:
labs/fluid/src/site/apt/manual.apt
labs/fluid/src/test/java/example/basic/TestCRUD.java
labs/fluid/src/test/java/example/basic/TestRelation.java
labs/fluid/src/test/java/example/basic/TestSDO.java
labs/fluid/src/test/java/example/basic/TestSourceCode.java
Modified: labs/fluid/src/site/apt/manual.apt
URL: http://svn.apache.org/viewvc/labs/fluid/src/site/apt/manual.apt?view=diff&rev=559976&r1=559975&r2=559976
==============================================================================
--- labs/fluid/src/site/apt/manual.apt (original)
+++ labs/fluid/src/site/apt/manual.apt Thu Jul 26 14:07:29 2007
@@ -1,5 +1,45 @@
User Documentation
+ [[1]] Introduction
+
+ [[1.1]] How is this organized
+
+ [[1.2]] References
+
+ [[2]] {{{Usage}}Usage}
+
+ [[2.1]] {{{generate_type.html}Decorating SDO Type for persistence}}
+
+ [[2.2.1]] {{{generate_type.html#basic}Basics of SDO Types}}
+
+ [[2.2.1]] {{{generate_type.html#prepare}Adding Property to SDO Types for persistence}}
+
+ [[2.2.1.1]] {{{generate_type.html#identity}Adding Identity Property
+
+ [[2.2.1.2]] {{{generate_type.html#version}Adding Version Property
+
+ [[2.2]] {{{convert_type.html}Mapping SDO Types to Java source code}}
+
+ [[2.3]] {{{enhance_type.html}Enhancing Java source code for persistence}}
+
+ [[2.4]] {{{persist_type.html}Persistence operations with SDO DataObjects}}
+
+ [[2.4.1]] {{{persist_type.html#store}Storing SDO DataObjects}}
+
+ [[2.4.2]] {{{persist_type.html#query}Querying SDO DataObjects
+
+ [[2.4.3]] {{{persist_type.html#merge}Updating SDO DataObjects
+
+ [[2.4.4]] {{{persist_type.html#remove}Deleting SDO DataObjects
+
+ [[2.4.5]] {{{persist_type.html#find}Finding SDO DataObjects
+
+ [[3]] Examples
+
+ [[3.1]] Basic persistence operations with a single DataObject
+
+ [[3.2]] Basic persistence operations with a graph of DataObjects
+
* Getting Started
We will begin with a small example. We will define a simple Service Data
@@ -92,20 +132,22 @@
*
-Identity:
-Datastore Identity:
-define a property named "id" and simple xsd data type.
+ 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
-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
-Version can be int only now
+ Container type
-Container type
+ Implementation
+ xsd:id
+ package name
-Implementation
-xsd:id
-package name
+ {Usage} this is usage anchor.
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=559976&r1=559975&r2=559976
==============================================================================
--- labs/fluid/src/test/java/example/basic/TestCRUD.java (original)
+++ labs/fluid/src/test/java/example/basic/TestCRUD.java Thu Jul 26 14:07:29 2007
@@ -31,20 +31,23 @@
int before = count("Person");
String ssn = ""+System.currentTimeMillis();
- System.err.println("Persisting " + ssn);
+ // START SNIPPET:persistPerson
DataObject data = createPerson(ssn, "John", "Doe", 42);
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(data);
em.getTransaction().commit();
-
+ // END SNIPPET:persistPerson
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);
+ // START SNIPPET:find
+ String id = "Person:"+ssn;
+ DataObject result = em.find(DataObject.class, id);
+ // END SNIPPET:find
assertNotNull(result);
assertEquals(data,result);
}
Modified: 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=diff&rev=559976&r1=559975&r2=559976
==============================================================================
--- labs/fluid/src/test/java/example/basic/TestRelation.java (original)
+++ labs/fluid/src/test/java/example/basic/TestRelation.java Thu Jul 26 14:07:29 2007
@@ -12,31 +12,33 @@
import commonj.sdo.DataObject;
import commonj.sdo.helper.DataFactory;
+/**
+ * Tests basic create/read/update/delete operations on DataObject that is
+ * related to other DataObjects.
+ *
+ * @author Pinaki Poddar
+ *
+ */
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.
+ * Persist a DataObject. Persisting a root DataObject also persists its
+ * closure. Verifies that related USAddress instances are persisted also.
*/
public void testPersist() {
- int before = count("PurchaseOrderType");
+ int poCountBefore = count("PurchaseOrderType");
+ int addressCountBefore = count("USAddress");
- long ssn = System.currentTimeMillis();
DataObject data = createPurchaseOrder();
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(data);
em.getTransaction().commit();
- int after = count("PurchaseOrderType");
+ int poCountAfter = count("PurchaseOrderType");
+ int addressCountAfter = count("USAddress");
- assertEquals(before+1, after);
+ assertEquals(poCountBefore+1, poCountAfter);
+ assertEquals(addressCountBefore+2, addressCountAfter);
}
@@ -45,11 +47,13 @@
* DataObjects should also be fetched.
*/
public void testQuery() {
+ // START SNIPPET:createQuery
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();
+ // END SNIPPET:createQuery
assertFalse(result.isEmpty());
for (Object o : result) {
assertTrue(o.getClass() + " is not DataObject", o instanceof DataObject);
@@ -64,16 +68,22 @@
}
}
+ /**
+ * Modifies part of an existing DataGraph, merges the changes and verifies
+ * that merged ojects reflect the changes. Also verifies that no new
+ * instances are created as a result of merging.
+ *
+ */
public void testUpdate() {
+ // START SNIPPET:merge
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();
+ List<DataObject> result = query.getResultList();
assertFalse(result.isEmpty());
- for (Object o : result) {
+ for (DataObject dataObject : result) {
int before = count("USAddress");
- DataObject dataObject = (DataObject) o;
dataObject.getDataObject("billTo").setString("name", "John Doe");
em.begin();
DataObject merged = em.merge(dataObject);
@@ -83,8 +93,13 @@
int after = count("USAddress");
assertEquals(before, after);
}
+ // START SNIPPET:merge
}
+ /**
+ * Tests that related DataObjects are fetched.
+ *
+ */
public void testEagerRelationFetchedInDefaultFetch() {
DataObject data = createPurchaseOrder();
EntityManager em = emf.createEntityManager();
@@ -108,6 +123,11 @@
}
}
+ /**
+ * Deletes a DataGraph. Verifies that all realted instances are deleted
+ * also.
+ *
+ */
public void testDelete() {
OpenJPAEntityManager em = emf.createEntityManager();
String jpql = "SELECT o FROM PurchaseOrderType o WHERE o.shipTo.name=:name";
@@ -127,7 +147,7 @@
}
/**
- * Create a SDO MetaData Model from a XML Schema.
+ * Create a SDO DataGraph and returns the root DataObject.
*
*/
DataObject createPurchaseOrder() {
@@ -174,5 +194,4 @@
return purchaseOrder;
}
-
}
Modified: labs/fluid/src/test/java/example/basic/TestSDO.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/test/java/example/basic/TestSDO.java?view=diff&rev=559976&r1=559975&r2=559976
==============================================================================
--- labs/fluid/src/test/java/example/basic/TestSDO.java (original)
+++ labs/fluid/src/test/java/example/basic/TestSDO.java Thu Jul 26 14:07:29 2007
@@ -28,10 +28,10 @@
import commonj.sdo.helper.DataFactory;
/**
- * JUnit Tests to read a meta-model from XML Schema and create instances
+ * Tests to read a SDO meta-model from XML Schema and create instances
* according to the meta-model.
*
- * @author ppoddar
+ * @author Pinaki Poddar
*
*/
public class TestSDO extends AbstractSDOTest {
Modified: labs/fluid/src/test/java/example/basic/TestSourceCode.java
URL: http://svn.apache.org/viewvc/labs/fluid/src/test/java/example/basic/TestSourceCode.java?view=diff&rev=559976&r1=559975&r2=559976
==============================================================================
--- labs/fluid/src/test/java/example/basic/TestSourceCode.java (original)
+++ labs/fluid/src/test/java/example/basic/TestSourceCode.java Thu Jul 26 14:07:29 2007
@@ -4,6 +4,12 @@
import junit.framework.TestCase;
+/**
+ * Tests sanity of Source Code generation.
+ *
+ * @author Pinaki Poddar
+ *
+ */
public class TestSourceCode extends TestCase {
public void testImport() {
assertTrue(SourceCode.isValidImportName("java.util.*"));
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org