Author: aadamchik Date: Wed Dec 26 19:20:15 2012 New Revision: 1425994 URL: http://svn.apache.org/viewvc?rev=1425994&view=rev Log: updating the docs formatted per CAY-1733 Added: cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/css/highlight.css cayenne/site/cms/trunk/content/docs/3.1/tutorial/css/highlight.css Modified: cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/cayenne-guide-part2.html cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/cayennemodeler-application.html cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/client-configuration-properties.html cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/css/cayenne-doc.css cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/customizing-cayenne-runtime.html cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/expressions-bnf.html cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/expressions.html cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/including-cayenne-in-project.html cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/index.html cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/orderings.html cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/performance-tuning.html cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/persistent-objects-objectcontext.html cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/queries.html cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/rop-deployment.html cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/server-configuration-properties.html cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/setup.html cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/starting-cayenne.html cayenne/site/cms/trunk/content/docs/3.1/tutorial/ch04.html cayenne/site/cms/trunk/content/docs/3.1/tutorial/ch05.html cayenne/site/cms/trunk/content/docs/3.1/tutorial/ch06.html cayenne/site/cms/trunk/content/docs/3.1/tutorial/ch07.html cayenne/site/cms/trunk/content/docs/3.1/tutorial/ch08.html cayenne/site/cms/trunk/content/docs/3.1/tutorial/ch09.html cayenne/site/cms/trunk/content/docs/3.1/tutorial/css/cayenne-doc.css Modified: cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/cayenne-guide-part2.html URL: http://svn.apache.org/viewvc/cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/cayenne-guide-part2.html?rev=1425994&r1=1425993&r2=1425994&view=diff ============================================================================== --- cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/cayenne-guide-part2.html (original) +++ cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/cayenne-guide-part2.html Wed Dec 26 19:20:15 2012 @@ -1,3 +1,3 @@ - Part II. Cayenne Framework

Part II. Cayenne Framework

Table of Contents

4. Including Cayenne in a Project
Jar Files and Dependencies
Maven Projects
Ant Projects
5. Starting Cayenne
Starting and Stopping ServerRuntime
Merging Multiple Projects
Web Applications
6. Persistent Objects and ObjectContext
ObjectContext
Persistent Object and its Lifecycle
ObjectContext Persistence API
Cayenne Helper Class
ObjectContext Nesting
Generic Persistent Objects
Transactions
7. Expressions
Expressions Overview
Path Expressions
Creating Expressions from Strings
Creating Expressions with API
Evaluating Expressions in Memory
8. Orderings
9. Queries
SelectQuery
EJBQLQuery
SQLTemplateQuery
ProcedureQuery
NamedQuery
Custom Queries
10. Lifecycle Events
Types of Lifecyc le Events
Lifecycle Callbacks and Listeners
11. Performance Tuning
Prefetching
Data Rows
Iterated Queries
Paginated Queries
Caching and Fresh Data
Turning off Synchronization of ObjectContexts
12. Customizing Cayenne Runtime
Dependency Injection Container
Customization Strategies
Noteworthy Built-in Services
\ No newline at end of file + Part II. Cayenne Framework

Part II. Cayenne Framework

Table of Contents

4. Including Cayenne in a Project
Jar Files and Dependencies
Maven Projects
Ant Projects
5. Starting Cayenne
Starting and Stopping ServerRuntime
Merging Multiple Projects
Web Applications
6. Persistent Objects and ObjectContext
ObjectContext
Persistent Object and its Lifecycle
ObjectContext Persistence API
Cayenne Helper Class
ObjectContext Nesting
Generic Persistent Objects
Transactions
7. Expressions
Expressions Overview
Path Expressions
Creating Expressions from Strings
Creating Expressions with API
Evaluating Expressions in Memory
8. Orderings
9. Queries
SelectQuery
EJBQLQuery
SQLTemplateQuery
ProcedureQuery
NamedQuery
Custom Queries
10. Lifecycle Events
Types of Lifecyc le Events
Lifecycle Callbacks and Listeners
11. Performance Tuning
Prefetching
Data Rows
Iterated Queries
Paginated Queries
Caching and Fresh Data
Turning off Synchronization of ObjectContexts
12. Customizing Cayenne Runtime
Dependency Injection Container
Customization Strategies
Noteworthy Built-in Services
\ No newline at end of file Modified: cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/cayennemodeler-application.html URL: http://svn.apache.org/viewvc/cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/cayennemodeler-application.html?rev=1425994&r1=1425993&r2=1425994&view=diff ============================================================================== --- cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/cayennemodeler-application.html (original) +++ cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/cayennemodeler-application.html Wed Dec 26 19:20:15 2012 @@ -1,13 +1,13 @@ Chapter 3. CayenneModeler Application

Chapter 3. CayenneModeler Application

Table of Contents

Working with Mapping Projects
Reverse Engineering Database
Generating Database Schema
Migrations
Generating Java Classes
Modeling Inheritance
Modeling Generic Persistent Classes
Modeling Primary Key Generation Strategy

Working with Mapping Projects

Reverse Engineering Database

Generating Database Schema

Migrations

Generating Java Classes

Modeling Inheritance

Modeling Generic Persistent Classes

Normally each ObjEntity is map ped to a specific Java class (such as Artist or - Painting) that explicitly declare all entity properties as pairs of getters and setters. - However Cayenne allows to map a completly generic class to any number of entities. The - only expectation is that a generic class implements - org.apache.cayenne.DataObject. So an ideal candidate for a - generic class is CayenneDataObject, or some custom subclass of CayenneDataObject.

If you don't enter anything for Java Class of an ObjEntity, Cayenne assumes generic - mapping and uses the following implicit rules to determine a class of a generic object. - If DataMap "Custom Superclass" is set, runtime uses this class to instantiate new - objects. If not, org.apache.cayenne.CayenneDataObject is used.

Class generation procedures (either done in the Modeler or with Ant or Maven) would - skip entities that are mapped to CayenneDataObject explicitly or have no class - mapping.

Modeling Primary Key Generation Strategy

\ No newline at end of file + Painting) that explicitly declare all entity properties as pairs of getters and setters. + However Cayenne allows to map a completly generic class to any number of entities. The + only expectation is that a generic class implements + org.apache.cayenne.DataObject. So an ideal candidate for a + generic class is CayenneDataObject, or some custom subclass of CayenneDataObject.

If you don't enter anything for Java Class of an ObjEntity, Cayenne assumes generic + mapping and uses the following implicit rules to determine a class of a generic object. + If DataMap "Custom Superclass" is set, runtime uses this class to instantiate new + objects. If not, org.apache.cayenne.CayenneDataObject is used.

Class generation procedures (either done in the Modeler or with Ant or Maven) would + skip entities that are mapped to CayenneDataObject explicitly or have no class + mapping.

Modeling Primary Key Generation Strategy

\ No newline at end of file Modified: cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/client-configuration-properties.html URL: http://svn.apache.org/viewvc/cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/client-configuration-properties.html?rev=1425994&r1=1425993&r2=1425994&view=diff ============================================================================== --- cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/client-configuration-properties.html (original) +++ cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/client-configuration-properties.html Wed Dec 26 19:20:15 2012 @@ -1,47 +1,47 @@ Appendix B. Service Collections

Appendix B. Service Collections

Note that the collection keys below are - defined as constants in org.apache.cayenne.configuration.Constants - interface.

-

- - - - - - - - - - - - - - - -
Table B.1. Service Collection Keys Present in ServerRuntime and/or ClientRuntime
cayenne.properties - Map<String,String> of properties used by built-in - Cayenne services. The keys in this map are the property names from the table - in Appendix A. Separate copies of this map exist on the server and ROP - client.
cayenne.server.adapter_detectors - List<DbAdapterDetector> that contains - objects that can discover the type of current database and install the - correct DbAdapter in runtime.
cayenne.server.domain_filters - List<DataChannelFilter> storing DataDomain - filters.
cayenne.server.project_locations - List<String> storing - locations of the one of more project configuration files.
cayenne.server.default_types - List<ExtendedType> storing - default adapter-agnostic ExtendedTypes. Default ExtendedTypes can be - overridden / extended by DB-specific DbAdapters as well as by user-provided - types configured in another colltecion (see - "cayenne.server.user_types").
cayenne.server.user_types - List<ExtendedType> storing a - user-provided ExtendedTypes. This collection will be merged into a full list - of ExtendedTypes and would override any ExtendedTypes defined in a default - list, or by a DbAdapter.
cayenne.server.type_factories - List<ExtendedTypeFactory> - storing default and user-provided ExtendedTypeFactories. ExtendedTypeFactory - allows to define ExtendedTypes dynamically for the whole group of Java - classes. E.g. Cayenne supplies a factory to map all Enums regardless of - their type.
cayenne.server.rop_event_bridge_properties - Map<String, - String> storing event bridge properties passed to the ROP client on - bootstrap. This means that the map is configured by server DI, and passed to - the client via the wire. The properties in this map are specific to - EventBridgeFactory implementation (e.g JMS or XMPP connection prameters). - One common property is "cayenne.server.rop_event_bridge_factory" that - defines the type of the factory.

-

\ No newline at end of file + defined as constants in org.apache.cayenne.configuration.Constants + interface.

+

+ + + + + + + + + + + + + + + +
Table B.1. Service Collection Keys Present in ServerRuntime and/or ClientRuntime
cayenne.properties - Map<String,String> of properties used by built-in + Cayenne services. The keys in this map are the property names from the table + in Appendix A. Separate copies of this map exist on the server and ROP + client.
cayenne.server.adapter_detectors - List<DbAdapterDetector> that contains + objects that can discover the type of current database and install the + correct DbAdapter in runtime.
cayenne.server.domain_filters - List<DataChannelFilter> storing DataDomain + filters.
cayenne.server.project_locations - List<String> storing + locations of the one of more project configuration files.
cayenne.server.default_types - List<ExtendedType> storing + default adapter-agnostic ExtendedTypes. Default ExtendedTypes can be + overridden / extended by DB-specific DbAdapters as well as by user-provided + types configured in another colltecion (see + "cayenne.server.user_types").
cayenne.server.user_types - List<ExtendedType> storing a + user-provided ExtendedTypes. This collection will be merged into a full list + of ExtendedTypes and would override any ExtendedTypes defined in a default + list, or by a DbAdapter.
cayenne.server.type_factories - List<ExtendedTypeFactory> + storing default and user-provided ExtendedTypeFactories. ExtendedTypeFactory + allows to define ExtendedTypes dynamically for the whole group of Java + classes. E.g. Cayenne supplies a factory to map all Enums regardless of + their type.
cayenne.server.rop_event_bridge_properties - Map<String, + String> storing event bridge properties passed to the ROP client on + bootstrap. This means that the map is configured by server DI, and passed to + the client via the wire. The properties in this map are specific to + EventBridgeFactory implementation (e.g JMS or XMPP connection prameters). + One common property is "cayenne.server.rop_event_bridge_factory" that + defines the type of the factory.

+

\ No newline at end of file Modified: cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/css/cayenne-doc.css URL: http://svn.apache.org/viewvc/cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/css/cayenne-doc.css?rev=1425994&r1=1425993&r2=1425994&view=diff ============================================================================== --- cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/css/cayenne-doc.css (original) +++ cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/css/cayenne-doc.css Wed Dec 26 19:20:15 2012 @@ -0,0 +1,134 @@ +@IMPORT url("highlight.css"); + +html { + padding: 0pt; + margin: 0pt; +} + +body, td { + margin-left: 10%; + margin-right: 10%; + font-family: "Lucida Grande","Trebuchet MS",Verdana,sans-serif; + font-size: small; +} + +div { + margin: 0pt; +} + +p { + text-align: justify; +} + +hr { + border: 1px solid gray; + background: gray; +} + +h1, h2, h3, h4 { + font-family: "Trebuchet MS","Lucida Grande",Verdana,sans-serif; + font-weight: normal; + line-height: normal; + margin: 1em 0 0.5em; +} + +h2 { + color: #660000; + font-size: 170%; + padding: 0; +} + +h3 { + border-bottom: 1px solid #EAEAEA; + color: #CC4400; + font-size: 135%; + padding-bottom: 3px; +} + +h4 { + color: #AAAA99; + font-size: 130%; +} + +pre { + line-height: 1.0; + color: black; + + -moz-tab-size: 4; + -o-tab-size: 4; + tab-size: 4; +} + +pre.programlisting { + font-size: 10pt; + padding: 7pt 3pt; + border: 1pt solid black; + background: #F9F9F6; + clear: both; +} + +div.table { + margin: 1em; + padding: 0.5em; + text-align: center; +} + +table[frame=void] { + display: table; + width: 100%; + border: 1px black solid; + border-collapse: collapse; + border-spacing: 0; +} + +table[frame=void] td { + padding-left: 7px; + padding-right: 7px; + border: 1px black solid; +} + +table[frame=void] th { + padding-left: 7px; + padding-right: 7px; + border: 1px black solid; +} + +.sidebar { + float: right; + margin: 10px 0 10px 30px; + padding: 10px 20px 20px 20px; + width: 33%; + border: 1px solid black; + background-color: #F4F4F4; + font-size: 14px; +} + +.code { + font-family: Courier New,monospace; +} + +.mediaobject { + padding-top: 30px; + padding-bottom: 30px; +} + +.legalnotice { + font-size: 12px; + font-style: italic; +} + +p.releaseinfo { + font-size: 100%; + font-weight: bold; + padding-top: 10px; +} + +p.pubdate { + font-size: 120%; + font-weight: bold; +} + +span.productname { + font-size: 200%; + font-weight: bold; +} \ No newline at end of file Added: cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/css/highlight.css URL: http://svn.apache.org/viewvc/cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/css/highlight.css?rev=1425994&view=auto ============================================================================== --- cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/css/highlight.css (added) +++ cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/css/highlight.css Wed Dec 26 19:20:15 2012 @@ -0,0 +1,35 @@ +/* + code highlight CSS resemblign the Eclipse IDE default color schema + @author Costin Leau +*/ + +.hl-keyword { + color: #7F0055; + font-weight: bold; +} + +.hl-comment { + color: #3F5F5F; + font-style: italic; +} + +.hl-multiline-comment { + color: #3F5FBF; + font-style: italic; +} + +.hl-tag { + color: #3F7F7F; +} + +.hl-attribute { + color: #7F007F; +} + +.hl-value { + color: #2A00FF; +} + +.hl-string { + color: #2A00FF !important; +} \ No newline at end of file Modified: cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/customizing-cayenne-runtime.html URL: http://svn.apache.org/viewvc/cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/customizing-cayenne-runtime.html?rev=1425994&r1=1425993&r2=1425994&view=diff ============================================================================== --- cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/customizing-cayenne-runtime.html (original) +++ cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/customizing-cayenne-runtime.html Wed Dec 26 19:20:15 2012 @@ -1,189 +1,189 @@ Chapter 12. Customizing Cayenne Runtime

Chapter 12. Customizing Cayenne Runtime

Table of Contents

Dependency Injection Container
Customization Strategies
Noteworthy Built-in Services

Dependency Injection Container

Cayenne runtime is built around a small powerful dependency injection (DI) container. Just - like other popular DI technologies, such as Spring or Guice, Cayenne DI container - manages sets of interdependent objects and allows users to configure them. These - objects are regular Java objects. We are calling them "services" in this document to - distinguish from all other objects that are not configured in the container and are not - managed. DI container is responsible for service instantiation, injecting correct - dependencies, maintaining service instances scope, and dispatching scope events to - services.

The services are configured in special Java classes called "modules". Each module - defines binding of service interfaces to implementation instances, implementation types - or providers of implementation instances. There are no XML configuration files, and all - the bindings are type-safe. The container supports injection into instance variables and - constructor parameters based on the @Inject annotation. This mechanism is - very close to Google Guice.

The discussion later in this chapter demonstrates a standalone DI container. But keep in - mind that Cayenne already has a built-in Injector, and a set of default modules. A - Cayenne user would normally only use the API below to write custom extension modules - that will be loaded in that existing container when creating ServerRuntime. See - "Starting and Stopping ServerRuntime" chapter for an example of passing an extension - module to Cayenne.

Cayenne DI probably has ~80% of the features expected in a DI container and has no - dependency on the rest of Cayenne, so in theory can be used as an application-wide DI - engine. But it's primary purpose is still to serve Cayenne. Hence there are no plans to - expand it beyond Cayenne needs. It is an ideal "embedded" DI that does not interfere - with Spring, Guice or any other such framework present elsewhere in the - application.

DI Bindings API

To have a working DI container, we need three things: service interfaces and - classes, a module that describes service bindings, a container that loads the - module, and resolves the depedencies. Let's start with service interfaces and - classes:

public interface Service1 {
-	public String getString();
-}
public interface Service2 {
-	public int getInt();
+            like other popular DI technologies, such as Spring or Guice, Cayenne DI container
+            manages sets of interdependent objects  and allows users to configure them. These
+            objects are regular Java objects. We are calling them "services" in this document to
+            distinguish from all other objects that are not configured in the container and are not
+            managed. DI container is responsible for service instantiation, injecting correct
+            dependencies, maintaining service instances scope, and dispatching scope events to
+            services. 

The services are configured in special Java classes called "modules". Each module + defines binding of service interfaces to implementation instances, implementation types + or providers of implementation instances. There are no XML configuration files, and all + the bindings are type-safe. The container supports injection into instance variables and + constructor parameters based on the @Inject annotation. This mechanism is + very close to Google Guice.

The discussion later in this chapter demonstrates a standalone DI container. But keep in + mind that Cayenne already has a built-in Injector, and a set of default modules. A + Cayenne user would normally only use the API below to write custom extension modules + that will be loaded in that existing container when creating ServerRuntime. See + "Starting and Stopping ServerRuntime" chapter for an example of passing an extension + module to Cayenne.

Cayenne DI probably has ~80% of the features expected in a DI container and has no + dependency on the rest of Cayenne, so in theory can be used as an application-wide DI + engine. But it's primary purpose is still to serve Cayenne. Hence there are no plans to + expand it beyond Cayenne needs. It is an ideal "embedded" DI that does not interfere + with Spring, Guice or any other such framework present elsewhere in the + application.

DI Bindings API

To have a working DI container, we need three things: service interfaces and + classes, a module that describes service bindings, a container that loads the + module, and resolves the depedencies. Let's start with service interfaces and + classes:

public interface Service1 {
+    public String getString();
+}
public interface Service2 {
+    public int getInt();
 }

A service implementation using instance variable - injection:

public class Service1Impl implements Service1 {
-	@Inject
-	private Service2 service2;
-	
-	public String getString() {
-		return service2.getInt() + "_Service1Impl";
-	}
+                injection:

public class Service1Impl implements Service1 {
+    @Inject
+    private Service2 service2;
+
+    public String getString() {
+        return service2.getInt() + "_Service1Impl";
+    }
 }

Same - thing, but using constructor - injection:

public class Service1Impl implements Service1 {
+                thing, but using constructor
+                injection:

public class Service1Impl implements Service1 {
 
-	private Service2 service2;
+    private Service2 service2;
 
-	public Service1Impl(@Inject Service2 service2) {
-		this.service2 = service2;
-	}
-
-	public String getString() {
-		return service2.getInt() + "_Service1Impl";
-	}
+    public Service1Impl(@Inject Service2 service2) {
+        this.service2 = service2;
+    }
+
+    public String getString() {
+        return service2.getInt() + "_Service1Impl";
+    }
 }
-
public class Service2Impl implements Service2 {
-	private int i;
+
public class Service2Impl implements Service2 {
+    private int i;
 
-	public int getInt() {
-		return i++;
-	}
+    public int getInt() {
+        return i++;
+    }
 }

Now let's create a module implementing - org.apache.cayenne.tutorial.di.Module interface that will contain - DI configuration. A module binds service objects to keys that are reference. Binder - provided by container implements fluent API to connect the key to implementation, - and to configure various binding options (the options, such as scope, are - demonstrated later in this chapter). The simplest form of a key is a Java Class - object representing service interface. Here is a module that binds Service1 and - Service2 to corresponding default implementations:

-

public class Module1 implements Module {
-
-	public void configure(Binder binder) {
-		binder.bind(Service1.class).to(Service1Impl.class);
-		binder.bind(Service2.class).to(Service2Impl.class);
-	}
+                    org.apache.cayenne.tutorial.di.Module interface that will contain
+                DI configuration. A module binds service objects to keys that are reference. Binder
+                provided by container implements fluent API to connect the key to implementation,
+                and to configure various binding options (the options, such as scope, are
+                demonstrated later in this chapter). The simplest form of a key is a Java Class
+                object representing service interface. Here is a module that binds Service1 and
+                Service2 to corresponding default implementations:

+

public class Module1 implements Module {
+
+    public void configure(Binder binder) {
+        binder.bind(Service1.class).to(Service1Impl.class);
+        binder.bind(Service2.class).to(Service2Impl.class);
+    }
 }

-

Once we have at least one module, we can create a DI container. - org.apache.cayenne.di.Injector is the container class in - Cayenne:

Injector injector = DIBootstrap.createInjector(new Module1());

Now that we have created the container, we can obtain services from it and call - their - methods:

Service1 s1 = injector.getInstance(Service1.class);
-for (int i = 0; i < 5; i++) {
-	System.out.println("S1 String: " + s1.getString());
+            

Once we have at least one module, we can create a DI container. + org.apache.cayenne.di.Injector is the container class in + Cayenne:

Injector injector = DIBootstrap.createInjector(new Module1());

Now that we have created the container, we can obtain services from it and call + their + methods:

Service1 s1 = injector.getInstance(Service1.class);
+for (int i = 0; i < 5; i++) {
+    System.out.println("S1 String: " + s1.getString());
 }

This outputs the following lines, demonstrating that s1 was Service1Impl and - Service2 injected into it was - Service2Impl:

0_Service1Impl
-1_Service1Impl
-2_Service1Impl
-3_Service1Impl
-4_Service1Impl

There are more flavors of bindings: -

// binding to instance - allowing user to create and configure instance
-// inside the module class
-binder.bind(Service2.class).toInstance(new Service2Impl());
-
-// binding to provider - delegating instance creation to a special
-// provider class
-binder.bind(Service1.class).toProvider(Service1Provider.class);
-
-// binding to provider instance
-binder.bind(Service1.class).toProviderInstance(new Service1Provider());
-
-// multiple bindings of the same type using Key
-// injection can reference the key name in annotation:
-// @Inject("i1")
-// private Service2 service2;
-binder.bind(Key.get(Service2.class, "i1")).to(Service2Impl.class);
-binder.bind(Key.get(Service2.class, "i2")).to(Service2Impl.class);

Another types of confiuguration that can be bound in the container are lists and - maps. They will be discussed in the following chapters.

Service Lifecycle

An important feature of the Cayenne DI container is instance scope. The default scope (implicitly used in all examples above) is - "singleton", meaning that a binding would result in creation of only one service - instance, that will be repeatedly returned from - Injector.getInstance(..), as well as injected into classes that - declare it as a dependency.

Singleton scope dispatches a "BeforeScopeEnd" event to interested services. This - event occurs before the scope is shutdown, i.e. when - Injector.shutdown() is called. Note that the built-in Cayenne - injector is shutdown behind the scenes when ServerRuntime.shutdown() - is invoked. Services may register as listeners for this event by annotating a - no-argument method with @BeforeScopeEnd annotation. Such method should - be implemented if a service needs to clean up some resources, stop threads, - etc.

Another useful scope is "no scope", meaning that every time a container is asked to provide - a service instance for a given key, a new instance will be created and - returned:

binder.bind(Service2.class).to(Service2Impl.class).withoutScope();

Users - can also create their own scopes, e.g. a web application request scope or a session - scope. Most often than not custom scopes can be created as instances of - org.apache.cayenne.di.spi.DefaultScope with startup and shutdown - managed by the application (e.g. singleton scope is a DefaultScope managed by the - Injector) .

Overriding Services

Cayenne DI allows to override services already definied in the current module, or - more commonly - some other module in the the same container. Actually there's no - special API to override a service, you'd just bind the service key again with a new - implementation or provider. The last binding for a key takes precedence. This means - that the order of modules is important when configuring a container. The built-in - Cayenne injector ensures that Cayenne standard modules are loaded first, followed by - optional user extension modules. This way the application can override the standard - services in Cayenne.

Customization Strategies

The previous section discussed how Cayenne DI works in general terms. Since Cayenne users - will mostly be dealing with an existing Injector provided by ServerRuntime, it is - important to understand how to build custom extensions to a preconfigured container. As - shown in "Starting and Stopping ServerRuntime" chapter, custom extensions are done by - writing an aplication DI module (or multiple modules) that configures service overrides. - This section shows all the configuration possibilities in detail, including changing - properties of the existing services, contributing services to standard service lists and - maps, and overriding service implementations. All the code examples later in this - section are assumed to be placed in an application module "configure" method:

public class MyExtensionsModule implements Module {
-	public void configure(Binder binder) {
-		// customizations go here...
-	}	
-}
Module extensions = new MyExtensionsModule();
+                Service2 injected into it was
+                Service2Impl:

0_Service1Impl
+1_Service1Impl
+2_Service1Impl
+3_Service1Impl
+4_Service1Impl

There are more flavors of bindings: +

// binding to instance - allowing user to create and configure instance
+// inside the module class
+binder.bind(Service2.class).toInstance(new Service2Impl());
+
+// binding to provider - delegating instance creation to a special
+// provider class
+binder.bind(Service1.class).toProvider(Service1Provider.class);
+
+// binding to provider instance
+binder.bind(Service1.class).toProviderInstance(new Service1Provider());
+
+// multiple bindings of the same type using Key
+// injection can reference the key name in annotation:
+// @Inject("i1")
+// private Service2 service2;
+binder.bind(Key.get(Service2.class, "i1")).to(Service2Impl.class);
+binder.bind(Key.get(Service2.class, "i2")).to(Service2Impl.class);

Another types of confiuguration that can be bound in the container are lists and + maps. They will be discussed in the following chapters.

Service Lifecycle

An important feature of the Cayenne DI container is instance scope. The default scope (implicitly used in all examples above) is + "singleton", meaning that a binding would result in creation of only one service + instance, that will be repeatedly returned from + Injector.getInstance(..), as well as injected into classes that + declare it as a dependency.

Singleton scope dispatches a "BeforeScopeEnd" event to interested services. This + event occurs before the scope is shutdown, i.e. when + Injector.shutdown() is called. Note that the built-in Cayenne + injector is shutdown behind the scenes when ServerRuntime.shutdown() + is invoked. Services may register as listeners for this event by annotating a + no-argument method with @BeforeScopeEnd annotation. Such method should + be implemented if a service needs to clean up some resources, stop threads, + etc.

Another useful scope is "no scope", meaning that every time a container is asked to provide + a service instance for a given key, a new instance will be created and + returned:

binder.bind(Service2.class).to(Service2Impl.class).withoutScope();

Users + can also create their own scopes, e.g. a web application request scope or a session + scope. Most often than not custom scopes can be created as instances of + org.apache.cayenne.di.spi.DefaultScope with startup and shutdown + managed by the application (e.g. singleton scope is a DefaultScope managed by the + Injector) .

Overriding Services

Cayenne DI allows to override services already definied in the current module, or + more commonly - some other module in the the same container. Actually there's no + special API to override a service, you'd just bind the service key again with a new + implementation or provider. The last binding for a key takes precedence. This means + that the order of modules is important when configuring a container. The built-in + Cayenne injector ensures that Cayenne standard modules are loaded first, followed by + optional user extension modules. This way the application can override the standard + services in Cayenne.

Customization Strategies

The previous section discussed how Cayenne DI works in general terms. Since Cayenne users + will mostly be dealing with an existing Injector provided by ServerRuntime, it is + important to understand how to build custom extensions to a preconfigured container. As + shown in "Starting and Stopping ServerRuntime" chapter, custom extensions are done by + writing an aplication DI module (or multiple modules) that configures service overrides. + This section shows all the configuration possibilities in detail, including changing + properties of the existing services, contributing services to standard service lists and + maps, and overriding service implementations. All the code examples later in this + section are assumed to be placed in an application module "configure" method:

public class MyExtensionsModule implements Module {
+    public void configure(Binder binder) {
+        // customizations go here...
+    }
+}
Module extensions = new MyExtensionsModule();
 ServerRuntime runtime = 
-	new ServerRuntime("com/example/cayenne-mydomain.xml", extensions);

Changing Properties of Existing Services

Many built-in Cayenne services change their behavior based on a value of some - environment property. A user may change Cayenne behavior without even knowing which - services are responsible for it, but setting a specific value of a known property. - Supported property names are listed in "Appendix A".

There are two ways to set service properties. The most obvious one is to pass it - to the JVM with -D flag on startup. - E.g.

java -Dorg.apache.cayenne.sync_contexts=false ...

A second one is to contribute a property to - org.apache.cayenne.configuration.DefaultRuntimeProperties.properties - map (see the next section on how to do that). This map contains the default - property values and can accept application-specific values, overrding the defaults.

Note that if a property value is a name of a Java class, when this Java class is - instantiated by Cayenne, the container performs injection of instance variables. So - even the dynamically specified Java classes can use @Inject annotation to get a hold - of other Cayenne services.

If the same property is specified both in the command line and in the properties - map, the command-line value takes precedence. The map value will be ignored. This - way Cayenne runtime can be reconfigured during deployment.

Contributing to Service Collections

Cayenne can be extended by adding custom objects to named maps or lists bound in - DI. We are calling these lists/maps "service collections". A service collection - allows things like appending a custom strategy to a list of built-in strategies. - E.g. an application that needs to install a custom DbAdapter for some database type - may contribute an instance of custom DbAdapterDetector to a - org.apache.cayenne.configuration.server.DefaultDbAdapterFactory.detectors - list:

public class MyDbAdapterDetector implements DbAdapterDetector {
-	public DbAdapter createAdapter(DatabaseMetaData md) throws SQLException {
-		// check if we support this database and retun custom adapter
-		...
-	}
-}
// since build-in list for this key is a singleton, repeated
-// calls to 'bindList' will return the same instance 
+    new ServerRuntime("com/example/cayenne-mydomain.xml", extensions);

Changing Properties of Existing Services

Many built-in Cayenne services change their behavior based on a value of some + environment property. A user may change Cayenne behavior without even knowing which + services are responsible for it, but setting a specific value of a known property. + Supported property names are listed in "Appendix A".

There are two ways to set service properties. The most obvious one is to pass it + to the JVM with -D flag on startup. + E.g.

java -Dorg.apache.cayenne.sync_contexts=false ...

A second one is to contribute a property to + org.apache.cayenne.configuration.DefaultRuntimeProperties.properties + map (see the next section on how to do that). This map contains the default + property values and can accept application-specific values, overrding the defaults.

Note that if a property value is a name of a Java class, when this Java class is + instantiated by Cayenne, the container performs injection of instance variables. So + even the dynamically specified Java classes can use @Inject annotation to get a hold + of other Cayenne services.

If the same property is specified both in the command line and in the properties + map, the command-line value takes precedence. The map value will be ignored. This + way Cayenne runtime can be reconfigured during deployment.

Contributing to Service Collections

Cayenne can be extended by adding custom objects to named maps or lists bound in + DI. We are calling these lists/maps "service collections". A service collection + allows things like appending a custom strategy to a list of built-in strategies. + E.g. an application that needs to install a custom DbAdapter for some database type + may contribute an instance of custom DbAdapterDetector to a + org.apache.cayenne.configuration.server.DefaultDbAdapterFactory.detectors + list:

public class MyDbAdapterDetector implements DbAdapterDetector {
+    public DbAdapter createAdapter(DatabaseMetaData md) throws SQLException {
+        // check if we support this database and retun custom adapter
+        ...
+    }
+}
// since build-in list for this key is a singleton, repeated
+// calls to 'bindList' will return the same instance 
 binder.bindList(DefaultDbAdapterFactory.DETECTORS_LIST)
-       .add(MyDbAdapterDetector.class);

Maps are customized using a similar "bindMap" method.

The names of built-in collections are listed in "Appendix B".

Alternative Service Implementations

As mentioned above, custom modules are loaded by ServerRuntime after the built-in - modules. So it is easy to redefine a built-in service in Cayenne by rebinding - desired implementations or providers. To do that, first we need to know what those - services to redefine are. While we describe some of them in the following sections, - the best way to get a full list is to check the source code of the Cayenne version - you are using and namely look in - org.apache.cayenne.configuration.server.ServerModule - the main - built-in module in Cayenne.

Now an example of overriding QueryCache service. The default - implementation of this service is provided by MapQueryCacheProvider. - But if we want to use EhCacheQueryCache (a Cayenne wrapper for the - EhCache framework), we can define it like - this:

binder.bind(QueryCache.class).to(EhCacheQueryCache.class);

Noteworthy Built-in Services

JdbcEventLogger

org.apache.cayenne.log.JdbcEventLogger is the service that defines - logging API for Cayenne internals. It provides facilities for logging queries, - commits, transactions, etc. The default implementation is - org.apache.cayenne.log.CommonsJdbcEventLogger that performs logging - via commons-logging library. Cayenne library includes another potentially useful - logger - org.apache.cayenne.log.FormattedCommonsJdbcEventLogger that - produces formatted multiline SQL output that can be easier to read.

DataSourceFactory

DataChannelFilter

QueryCache

ExtendedTypes

\ No newline at end of file + .add(MyDbAdapterDetector.class);

Maps are customized using a similar "bindMap" method.

The names of built-in collections are listed in "Appendix B".

Alternative Service Implementations

As mentioned above, custom modules are loaded by ServerRuntime after the built-in + modules. So it is easy to redefine a built-in service in Cayenne by rebinding + desired implementations or providers. To do that, first we need to know what those + services to redefine are. While we describe some of them in the following sections, + the best way to get a full list is to check the source code of the Cayenne version + you are using and namely look in + org.apache.cayenne.configuration.server.ServerModule - the main + built-in module in Cayenne.

Now an example of overriding QueryCache service. The default + implementation of this service is provided by MapQueryCacheProvider. + But if we want to use EhCacheQueryCache (a Cayenne wrapper for the + EhCache framework), we can define it like + this:

binder.bind(QueryCache.class).to(EhCacheQueryCache.class);

Noteworthy Built-in Services

JdbcEventLogger

org.apache.cayenne.log.JdbcEventLogger is the service that defines + logging API for Cayenne internals. It provides facilities for logging queries, + commits, transactions, etc. The default implementation is + org.apache.cayenne.log.CommonsJdbcEventLogger that performs logging + via commons-logging library. Cayenne library includes another potentially useful + logger - org.apache.cayenne.log.FormattedCommonsJdbcEventLogger that + produces formatted multiline SQL output that can be easier to read.

DataSourceFactory

DataChannelFilter

QueryCache

ExtendedTypes

\ No newline at end of file Modified: cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/expressions-bnf.html URL: http://svn.apache.org/viewvc/cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/expressions-bnf.html?rev=1425994&r1=1425993&r2=1425994&view=diff ============================================================================== --- cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/expressions-bnf.html (original) +++ cayenne/site/cms/trunk/content/docs/3.1/cayenne-guide/expressions-bnf.html Wed Dec 26 19:20:15 2012 @@ -56,8 +56,10 @@ TOKENS * Integer or real Numeric literal, whose object value is stored in the token manager's * "literalValue" field. */<DEFAULT> TOKEN : { -<INT_LITERAL: ("0" (["0"-"7"])* | ["1"-"9"] (["0"-"9"])* | "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+) (["l","L","h","H"])?> : { -| <FLOAT_LITERAL: <DEC_FLT> (<EXPONENT>)? (<FLT_SUFF>)? | <DEC_DIGITS> <EXPONENT> (<FLT_SUFF>)? | <DEC_DIGITS> <FLT_SUFF>> : { +<INT_LITERAL: ("0" (["0"-"7"])* | ["1"-"9"] (["0"-"9"])* | "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+) + (["l","L","h","H"])?> : { +| <FLOAT_LITERAL: <DEC_FLT> (<EXPONENT>)? (<FLT_SUFF>)? | <DEC_DIGITS> <EXPONENT> (<FLT_SUFF>)? +| <DEC_DIGITS> <FLT_SUFF>> : { | <#DEC_FLT: (["0"-"9"])+ "." (["0"-"9"])* | "." (["0"-"9"])+> | <#DEC_DIGITS: (["0"-"9"])+> | <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+> @@ -65,14 +67,14 @@ TOKENS } NON-TERMINALS - expression := orCondition <EOF> - orCondition := andCondition ( "or" andCondition )* - andCondition := notCondition ( "and" notCondition )* - notCondition := ( "not" | "!" ) simpleCondition - | simpleCondition - simpleCondition := <TRUE> - | <FALSE> - | scalarConditionExpression + expression := orCondition <EOF> + orCondition := andCondition ( "or" andCondition )* + andCondition := notCondition ( "and" notCondition )* + notCondition := ( "not" | "!" ) simpleCondition + | simpleCondition + simpleCondition := <TRUE> + | <FALSE> + | scalarConditionExpression ( simpleNotCondition | ( "=" | "==" ) scalarExpression | ( "!=" | "<>" ) scalarExpression @@ -84,39 +86,39 @@ NON-TERMINALS | "in" ( namedParameter | "(" scalarCommaList ")" ) | "between" scalarExpression "and" scalarExpression )? - simpleNotCondition := ( "not" | "!" ) + simpleNotCondition := ( "not" | "!" ) ( "like" scalarExpression | "likeIgnoreCase" scalarExpression | "in" ( namedParameter | "(" scalarCommaList ")" ) | "between" scalarExpression "and" scalarExpression ) - scalarCommaList := ( scalarConstExpression ( "," scalarConstExpression )* ) - scalarConditionExpression := scalarNumericExpression - | <SINGLE_QUOTED_STRING> - | <DOUBLE_QUOTED_STRING> - | <NULL> - scalarExpression := scalarConditionExpression - | <TRUE> - | <FALSE> - scalarConstExpression := <SINGLE_QUOTED_STRING> - | <DOUBLE_QUOTED_STRING> - | namedParameter - | <INT_LITERAL> - | <FLOAT_LITERAL> - | <TRUE> - | <FALSE> - scalarNumericExpression := multiplySubtractExp + scalarCommaList := ( scalarConstExpression ( "," scalarConstExpression )* ) + scalarConditionExpression := scalarNumericExpression + | <SINGLE_QUOTED_STRING> + | <DOUBLE_QUOTED_STRING> + | <NULL> + scalarExpression := scalarConditionExpression + | <TRUE> + | <FALSE> + scalarConstExpression := <SINGLE_QUOTED_STRING> + | <DOUBLE_QUOTED_STRING> + | namedParameter + | <INT_LITERAL> + | <FLOAT_LITERAL> + | <TRUE> + | <FALSE> + scalarNumericExpression := multiplySubtractExp ( "+" multiplySubtractExp | "-" multiplySubtractExp )* - multiplySubtractExp := numericTerm ( "*" numericTerm | "/" numericTerm )* - numericTerm := ( "+" )? numericPrimary - | "-" numericPrimary - numericPrimary := "(" orCondition ")" - | pathExpression - | namedParameter - | <INT_LITERAL> - | <FLOAT_LITERAL> - namedParameter := "$" <PROPERTY_PATH> - pathExpression := ( <PROPERTY_PATH> + multiplySubtractExp := numericTerm ( "*" numericTerm | "/" numericTerm )* + numericTerm := ( "+" )? numericPrimary + | "-" numericPrimary + numericPrimary := "(" orCondition ")" + | pathExpression + | namedParameter + | <INT_LITERAL> + | <FLOAT_LITERAL> + namedParameter := "$" <PROPERTY_PATH> + pathExpression := ( <PROPERTY_PATH> | "obj:" <PROPERTY_PATH> | "db:" <PROPERTY_PATH> | "enum:" <PROPERTY_PATH> )