Return-Path: Delivered-To: apmail-openjpa-commits-archive@www.apache.org Received: (qmail 89345 invoked from network); 29 Oct 2009 14:27:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 29 Oct 2009 14:27:57 -0000 Received: (qmail 28056 invoked by uid 500); 29 Oct 2009 14:27:57 -0000 Delivered-To: apmail-openjpa-commits-archive@openjpa.apache.org Received: (qmail 28014 invoked by uid 500); 29 Oct 2009 14:27:57 -0000 Mailing-List: contact commits-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list commits@openjpa.apache.org Received: (qmail 28005 invoked by uid 99); 29 Oct 2009 14:27:57 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Oct 2009 14:27:57 +0000 X-ASF-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Oct 2009 14:27:54 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C6E7E23888FF; Thu, 29 Oct 2009 14:27:32 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r830961 - /openjpa/trunk/openjpa-project/src/doc/manual/jpa_overview_criteria.xml Date: Thu, 29 Oct 2009 14:27:32 -0000 To: commits@openjpa.apache.org From: ppoddar@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091029142732.C6E7E23888FF@eris.apache.org> Author: ppoddar Date: Thu Oct 29 14:27:32 2009 New Revision: 830961 URL: http://svn.apache.org/viewvc?rev=830961&view=rev Log: Doc for metamodel generation Modified: openjpa/trunk/openjpa-project/src/doc/manual/jpa_overview_criteria.xml Modified: openjpa/trunk/openjpa-project/src/doc/manual/jpa_overview_criteria.xml URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-project/src/doc/manual/jpa_overview_criteria.xml?rev=830961&r1=830960&r2=830961&view=diff ============================================================================== --- openjpa/trunk/openjpa-project/src/doc/manual/jpa_overview_criteria.xml (original) +++ openjpa/trunk/openjpa-project/src/doc/manual/jpa_overview_criteria.xml Thu Oct 29 14:27:32 2009 @@ -40,7 +40,7 @@ JPA 2.0 Specification introduces a new API to define queries dynamically via construction of an object-based - javax.persistence.QueryDefinition instance, rather + javax.persistence.CriteriaQuery instance, rather than string-based approach used in JPQL (Java Persistence Query Language). This dynamic query definition capability, referred as Criteria API, is based on the abstract persistent schema of the entities, their embedded @@ -51,68 +51,72 @@
- Constructing a QueryDefinition + Constructing a CriteriaQuery - The QueryBuilder interface is the factory for QueryDefinition. A - QueryBuilder is obtained from either the EntityManagerFactory or - the EntityManager as follows: + The CriteriaBuilder interface is the factory for CriteriaQuery. A + CriteriaBuilder is obtained from either an EntityManagerFactory or + an EntityManager as follows: EntityManager em = ... ; -QueryBuilder queryBuilder = em.getQueryBuilder(); -QueryDefinition qdef = queryBuilder.createQueryDefinition(); +CriteriaBuilder queryBuilder = em.getCriteriaBuilder(); +CriteriaQuery qdef = queryBuilder.createCriteriaQuery(); The first step in constructing a query definition is specification of query roots. Query roots specify the domain objects on which the query - is evaluated. Query root is an instance of the DomainObject interface. A - query root is added to a QueryDefinition by + is evaluated. Query root is an instance of the Root<T> interface. A + query root is added to a CriteriaQuery by addRoot(Class c) method. - DomainObject customer = qdef.addRoot(Customer.class); - - Often a query definition has a single root, so the - QueryBuilder interface allows to construct and add - a root via a single method. - -DomainObject customer = queryBuilder.createQueryDefinition(Customer.class); + Root<Customer> customer = qdef.from(Customer.class); A query domain can be further refined by joining to other domain objects. For example, for the above query definition to operate over customers and their orders, use join(String attribute): -DomainObject order = customer.join("orders"); +Root<Order> order = customer.join(customer.get(Customer_.orders)); + where Customer_.orders represent a field of canonical metamodel class for Customer. + These canonical metamodel classes are generated during compilation by processing + the persistent annotation in the source code of Customer.java. + + The condition of a query definition is set via where(Predicate p) where the argument designates a conditional predicate. Conditional predicates are often composed of one or more comparisons between the attribute values of the domain objects and some variable. For example, to select the - Customers whose name is John Doe and has + Customer whose name is "John Doe" and has orders that are not yet delivered, you can build the predicate and set it to the query definition as: -qdef.where(customer.get("name").equal("John Doe") - .and(order.get("status").equal(OrderStatus.DELIVERED).not())); + qdef.where(customer.get(Customer_.name).equal("John Doe") + .and(order.get(Order_.status).equal(OrderStatus.DELIVERED).not())); The select() method defines the result of the query. If left unspecified, the select projection is assumed to be the root domain object. However, you can specify the selected projections explicitly as a list: -qdef.select(customer.get("name"), order.get("status")); + qdef.select(customer.get(Customer_.name), order.get(Order_.status)); - An attribute of a domain object is specified by navigating via + + + + An attribute of a domain object can also be specified by navigating via get(String attr). The attribute should refer to a valid persistent property of the receiving domain object, however no such validation is enforced during the construction of the query definition. All validation is deferred until the query is actually executed. + On the other hand, using canonical metamodel for path navigate enforces + compile type checking.
- Executing a QueryDefinition + Executing a CriteriaQuery - A QueryDefinition is executed in a similar fashion of a string-based JPQL + A CriteriaQuery is executed in a similar fashion of a string-based JPQL query via the EntityManager and Query interfaces. EntityManager em = ... @@ -126,11 +130,15 @@ - The JPA 2.0 Specification on Criteria API is evolving and hence for an - up-to-date version of the API, please consult the + The JPA 2.0 Specification on Criteria API can be found at public draft. + + + A developerworks article + explains details and further usage of Criteria API and its OpenJPA extensions. +
@@ -138,19 +146,80 @@ Criteria API has provided an alternative means to string-based JPQL to execute a query. However, JPA 2.0 Specification has not explicitly specified - any equivalence between a dynamically constructed QueryDefinition and - a JPQL string. OpenJPA provides a mechanism to convert a QueryDefinition to - an equivalent JPQL query string via the extended OpenJPAQueryBuilder API. + any equivalence between a dynamically constructed CriteriaQuery and + a JPQL string. OpenJPA provides a mechanism to convert a CriteriaQuery to + an equivalent JPQL query string via the extended OpenJPACriteriaQuery API. - public interface OpenJPAQueryBuilder extends QueryBuilder { + public interface OpenJPACriteriaQuery extends CriteriaQuery { /** - * Gets equivalent JPQL String for the given QueryDefinition. + * Gets equivalent JPQL String for the given CriteriaQuery. */ - public String toJPQL(QueryDefinition qdef); + public String toCQL(); }
+ +
+ Generation of Canonical MetaModel classes + +Annotation processing tool generates source code for a metamodel class given +the annotated source code of persistent entity. +This tool is invoked during compilation for JDK6 compiler if OpenJPA and JPA +libraries are specified in the compiler -processorpath option. + + $ javac -processorpath path/to/openjpa-all.jar mypackage/MyEntity.java + +will generate source code for canonical meta-model class mypackage.MyEntity_.java. + + + +The Annotation Processor recognizes the following options (none of them are mandatory): + + + + -Alog=TRACE|INFO|WARN|ERROR : The logging level. Default is WARN. + + + + + -Asource=<n> : where <n> denotes the integral number for Java source + version of the generated code. Default is 6. + + + + + -Anaming=class name : fully-qualified name of a class implementing + org.apache.openjpa.meta.MetaDataFactory that determines +the name of a meta-class given the name of the original persistent Java entity class. Defaults to +org.apache.openjpa.persistence.PersistenceMetaDataFactory which appends a underscore character +(_) to the original Java class name. + + + + + -Aheader=<url> : A url whose content will appear as comment header to the generated file(s). + Recognizes special value ASL for Apache Source License header as comment. + By default, adds a OpenJPA proprietary text as comment block. + + + + + -Aout=dir : A directory in the local file system. The generated files will be written + relative to this directory according to the package structure i.e. if dir + is specified as /myproject/generated-src then the generated source code will be + written to /myproject/generated-src/mypackage/MyEntity_.java. + If this option is not specified, then an attempt will be made to write the generated source file + in the same directory of the source code of original class mypackage.MyEntity. + The source code location for mypackage.MyEntity can only be determined for Sun JDK6 + and when tools.jar being available to the compiler classpath. If the source code + location for the original class can not be determined, and the option is not specified, then the + generated source code is written relative to the current directory according to the package structure. + + + + +