Modified: db/jdo/site/docs/jdo_v_jpa_orm.html URL: http://svn.apache.org/viewvc/db/jdo/site/docs/jdo_v_jpa_orm.html?rev=949989&r1=949988&r2=949989&view=diff ============================================================================== --- db/jdo/site/docs/jdo_v_jpa_orm.html (original) +++ db/jdo/site/docs/jdo_v_jpa_orm.html Tue Jun 1 10:02:44 2010 @@ -1,13 +1,13 @@ Java Data Objects (JDO) - JDO .v. JPA : Object/Relational Mapping

Which ORM specification ?

+ @import url("./style/maven-theme.css");

Which ORM specification ?

There are 2 prevalent specification in the Java ORM world. JDO provides the most complete definition, whilst JPA is the most recent.

Relationships

In this guide we show the different types of ORM relation commonly used, and mark against it which specification supports it. This list is not yet complete but will be added to to provide a comprehensive list of relationship type and where you can find it. -

Field TypeRelationJDOJPA
PC1-1 Unidirectional
PC1-1 Bidirectional
PC1-1 serialised
PC1-1 CompoundIdentity Unidirectional
PC1-N CompoundIdentity Collection Bidirectional
PC1-N CompoundIdentity Map Bidirectional
Interface1-1 Unidirectional
Interface1-1 Bidirectional
Interface1-1 serialised?
Collection<PC>1-N ForeignKey Unidirectional Collection
Collection<PC>1-N ForeignKey Bidirectional Collection
Collection<PC>1-N JoinTable Unidir ectional Collection
Collection<PC>1-N JoinTable Bidirectional Collection
Collection<Non-PC>1-N JoinTable Collection
Collection<PC>1-N JoinTable Collection using shared JoinTable
Collection<PC>1-N ForeignKey Collection using shared ForeignKey
Collection<PC>M-N JoinTable
Collection<PC>1-N CompoundIdentity Unidirectional
Collection<PC>1-N serialised Collection
Collection<PC>1-N JoinTable Collection of serialised elements
List<PC>1-N ForeignKey Unidirectional Indexed List
List<PC>1-N ForeignKey Bidirectional Indexed List
List<PC>1-N JoinTable Unidirectional Indexed List
List<PC>1-N JoinTable Bidirectional Indexed List
List<Non-PC>1-N JoinTable Indexed List
List<PC>1-N ForeignKey Unidirectional Ordered List
List<PC>1-N ForeignKey Bidirectional Ordered List
List<PC>1-N JoinTable Unidirectional Ordered List
List<PC>1-N JoinTable Bidirectional Ordered List
Map<PC, PC>1-N JoinTable Map
Map<Non-PC, PC>1-N JoinTable Map
Map<PC, Non-PC>1-N JoinTable Map
Map<Non-PC, Non-PC>1-N JoinTable Map
Map<Non-PC, PC>1-N ForeignKey Map Unidirectional (key stored in value)
Map<Non-PC, PC>1-N ForeignKey Map Bidirectional (key stored in value)
Map<PC, Non-PC>1-N ForeignKey Map Unidirectional (value stored in key)
Map<PC, PC>1-N serialised Map
Map<PC, PC>1-N JoinTable Map of serialised keys/values
PC[ ]1-N ForeignKey Unidirectional Array
PC[ ]1-N JoinTable Unidirectional Array
PC[ ]1-N serialised Array
Non-PC[ ]1-N JoinTable Unidirectional Array


\ No newline at end of file Modified: db/jdo/site/docs/jdocentral.html URL: http://svn.apache.org/viewvc/db/jdo/site/docs/jdocentral.html?rev=949989&r1=949988&r2=949989&view=diff ============================================================================== --- db/jdo/site/docs/jdocentral.html (original) +++ db/jdo/site/docs/jdocentral.html Tue Jun 1 10:02:44 2010 @@ -1,7 +1,7 @@ Java Data Objects (JDO) - Home
\ No newline at end of file Modified: db/jdo/site/docs/jdohelper.html URL: http://svn.apache.org/viewvc/db/jdo/site/docs/jdohelper.html?rev=949989&r1=949988&r2=949989&view=diff ============================================================================== --- db/jdo/site/docs/jdohelper.html (original) +++ db/jdo/site/docs/jdohelper.html Tue Jun 1 10:02:44 2010 @@ -1,7 +1,7 @@ Java Data Objects (JDO) - JDOHelper

JDOHelper

+ @import url("./style/maven-theme.css");

JDOHelper

JDO provides a standard utility that gives access to useful parts of the JDO persistence process. This is known as JDOHelper (javax.jdo.JDOHelper) @@ -64,4 +64,4 @@ returns whether the passed object is detached


\ No newline at end of file + © 2005-2010 Apache Software Foundation
\ No newline at end of file Modified: db/jdo/site/docs/jdoql.html URL: http://svn.apache.org/viewvc/db/jdo/site/docs/jdoql.html?rev=949989&r1=949988&r2=949989&view=diff ============================================================================== --- db/jdo/site/docs/jdoql.html (original) +++ db/jdo/site/docs/jdoql.html Tue Jun 1 10:02:44 2010 @@ -1,7 +1,7 @@ Java Data Objects (JDO) - JDOQL

JDOQL

+ @import url("./style/maven-theme.css");

JDOQL

JDO defines ways of querying objects persisted into the datastore. It provides its own object-based query language (JDOQL). JDOQL is designed as the Java developers way of having the power of SQL queries, yet retaining the Java Added: db/jdo/site/docs/jdoql_methods.html URL: http://svn.apache.org/viewvc/db/jdo/site/docs/jdoql_methods.html?rev=949989&view=auto ============================================================================== --- db/jdo/site/docs/jdoql_methods.html (added) +++ db/jdo/site/docs/jdoql_methods.html Tue Jun 1 10:02:44 2010 @@ -0,0 +1,59 @@ +Java Data Objects (JDO) - JDOQL - Methods

JDOQL : Methods

+ When writing the "filter" for a JDOQL Query you can make use of some methods on the various + Java types. The range of methods included as standard in JDOQL is not as flexible as with + the true Java types, but the ones that are available are typically of much use. +



String Methods

MethodDescription
startsWith(String)Returns if the string starts with the passed string
endsWith(String)Returns if the string ends with the passed string
indexOf(String)Returns the first position of the passed string
indexOf(String,int)Returns the position of the passed string, after the passed position
substring(int)Returns the substring starting from the passed position
substring(int,int)Returns the substring between the passed positions
toLowerCase()Returns the string in lowercase
toUpperCase()Retuns the string in UPPERCASE
matches(String pattern)Returns whether string matches the passed expression. The pattern argument follows the rules of + java.lang.String.matches method.

+ Here's an example using a Product class, looking for objects which their abreviation is the + beginning of a trade name. The trade name is provided as parameter. +

+
+Declarative JDOQL :
+Query query = pm.newQuery(mydomain.Product.class);
+query.setFilter(":tradeName.startsWith(this.abbreviation)");
+List results = (List)query.execute("Workbook Advanced");
+
+Single-String JDOQL :
+Query query = pm.newQuery(
+    "SELECT FROM mydomain.Product " +
+    "WHERE :tradeName.startsWith(this.abbreviation)");
+List results = (List)query.execute("Workbook Advanced");
+

Collection Methods

MethodDescription
isEmpty()Returns whether the collection is empty
contains(value)Returns whether the collection contains the passed element
size()Returns the number of elements in the collection

+ Here's an example demonstrating use of contains(). We have an Inventory class that has a + Collection of Product objects, and we want to find the Inventory objects with 2 particular + Products in it. Here we make use of a variable (prd to represent the Product being + contained +

+
+Declarative JDOQL :
+Query query = pm.newQuery(mydomain.Inventory.class);
+query.setFilter("products.contains(prd) && (prd.name==\"product 1\" || prd.name==\"product 2\")");
+List results = (List)query.execute();
+
+Single-String JDOQL:
+Query query = pm.newQuery(
+    "SELECT FROM mydomain.Inventory EXCLUDE SUBCLASSES " + 
+    "WHERE products.contains(prd) && (prd.name==\"product 1\" || prd.name==\"product 2\")");
+List results = (List)query.execute();
+

Map Methods

MethodDescription
isEmpty()Returns whether the map is empty
containsKey(key)Returns whether the map contains the passed key
containsValue(value)Returns whether the map contains the passed value
get(key)Returns the value from the map with the passed key
size()Returns the number of entries in the map

+ Here's an example using a Product class as a value in a Map. Our example represents an + organisation that has several Inventories of products. Each Inventory of products is stored + using a Map, keyed by the Product name. The query searches for all Inventories that contain a + product with the name "product 1". +

+
+Declarative JDOQL :
+Query query = pm.newQuery(mydomain.Inventory.class, "products.containsKey(\"product 1\")");
+List results = (List)query.execute();
+
+Single-String JDOQL :
+Query query = pm.newQuery(
+    "SELECT FROM mydomain.Inventory EXCLUDE SUBCLASSES " +
+    "WHERE products.containsKey(\"product 1\")");
+List results = (List)query.execute();
+

Other Methods

MethodDescription
Math.abs(number)Returns the absolute value of the passed number
Math.sqrt(number)Returns the square root of the passed number
JDOHelper.getObjectId(object)Returns the object identity of the passed persistent object

\ No newline at end of file Added: db/jdo/site/docs/jdoql_result.html URL: http://svn.apache.org/viewvc/db/jdo/site/docs/jdoql_result.html?rev=949989&view=auto ============================================================================== --- db/jdo/site/docs/jdoql_result.html (added) +++ db/jdo/site/docs/jdoql_result.html Tue Jun 1 10:02:44 2010 @@ -0,0 +1,79 @@ +Java Data Objects (JDO) - JDOQL - Result

JDOQL : Result

+ As we have seen, a JDOQL query is made up of different parts. In this section we look at the + result part of the query. The result is what we want returning. By default (when not specifying + the result) the objects returned will be of the candidate class type, where they match the query + filter. Firstly let's look at what you can include in the result clause. +

    +
  • this - the candidate instance
  • +
  • A field name
  • +
  • A variable
  • +
  • A parameter (though why you would want a parameter returning is hard to see since you input + the value in the first place)
  • +
  • An aggregate (count(), avg(), sum(), min(), max())
  • +
  • An expression involving a field (e.g "field1 + 1")
  • +
  • A navigational expression (navigating from one field to another ... e.g "field1.field4")
  • +

+ The result is specified in JDOQL like this +

+
query.setResult("count(field1), field2");
+

+ In Single-String JDOQL you would specify it directly. +



Result type

+ What you specify in the result defines what form of result you get back. +

    +
  • Object - this is returned if you have only a single row in the results and a single + column. This is achived when you specified either UNIQUE, or just an aggregate + (e.g "max(field2)")
  • +
  • Object[] - this is returned if you have only a single row in the results, but more + than 1 column (e.g "max(field1), avg(field2)")
  • +
  • List<Object> - this is returned if you have only a single column in the result, + and you don't have only aggregates in the result (e.g "field2")
  • +
  • List<Object[]> - this is returned if you have more than 1 column in the result, + and you don't have only aggregates in the result (e.g "field2, avg(field3)")
  • +

Aggregates

+ There are situations when you want to return a single number for a column, representing an + aggregate of the values of all records. There are 5 standard JDO2 aggregate functions available. + These are +

    +
  • avg(val) - returns the average of "val". "val" can be a field, numeric field expression + or "distinct field".
  • +
  • sum(val) - returns the sum of "val". "val" can be a field, numeric field expression, + or "distinct field".
  • +
  • count(val) - returns the count of records of "val". "val" can be a field, or can be + "this", or "distinct field".
  • +
  • min(val) - returns the minimum of "val". "val" can be a field
  • +
  • max(val) - returns the maximum of "val". "val" can be a field
  • +

+ So to utilise these you could specify something like +

+
+Query q = pm.newQuery("SELECT max(price), min(price) FROM org.datanucleus.samples.store.Product WHERE status == 1");
+

+ This will return a single row of results with 2 values, the maximum price and the minimum price of + all products that have status code of 1. +



Example - Use of aggregates

+ JDO 2 introduces the ability to use aggregates in queries. Here's another example using the + same Product class as above, but this time looking for the maximum price of products that are + CD Players. Note that the result for this particular query will be of type Double since there + is a single double precision value being returned via the "result". +

+
+Declarative JDOQL :
+Query query = pm.newQuery(org.datanucleus.samples.store.Product.class);
+query.setFilter("name == \"CD Player\"");
+query.setResult("max(this.price)");
+List results = (List)query.execute();
+Iterator iter = c.iterator();
+Double max_price = (Double)iter.next();
+
+Single-String JDOQL :
+Query query = pm.newQuery("SELECT max(price) FROM org.datanucleus.samples.store.Product WHERE name == \"CD Player\"");
+List results = (List)query.execute();
+Iterator iter = c.iterator();
+Double max_price = (Double)iter.next();
+


\ No newline at end of file