Return-Path: Delivered-To: apmail-cayenne-commits-archive@www.apache.org Received: (qmail 86913 invoked from network); 8 Jul 2007 19:12:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 8 Jul 2007 19:12:35 -0000 Received: (qmail 75662 invoked by uid 500); 8 Jul 2007 19:12:37 -0000 Delivered-To: apmail-cayenne-commits-archive@cayenne.apache.org Received: (qmail 75638 invoked by uid 500); 8 Jul 2007 19:12:37 -0000 Mailing-List: contact commits-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cayenne.apache.org Delivered-To: mailing list commits@cayenne.apache.org Received: (qmail 75624 invoked by uid 99); 8 Jul 2007 19:12:37 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 08 Jul 2007 12:12:37 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 08 Jul 2007 12:12:27 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 761F71A982C; Sun, 8 Jul 2007 12:12:06 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r554413 [4/17] - in /cayenne/main/trunk/docs/doc/src/main/resources/doc: ./ Documentation/ Documentation/Cayenne Guide/ Documentation/Cayenne Guide/Ant Tasks/ Documentation/Cayenne Guide/Ant Tasks/cdataport/ Documentation/Cayenne Guide/Ant ... Date: Sun, 08 Jul 2007 19:11:53 -0000 To: commits@cayenne.apache.org From: aadamchik@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070708191206.761F71A982C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/Flattened Relationships/index.html URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/DataObjects/Flattened%20Relationships/index.html?view=auto&rev=554413 ============================================================================== --- cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/Flattened Relationships/index.html (added) +++ cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/Flattened Relationships/index.html Sun Jul 8 12:11:31 2007 @@ -0,0 +1,76 @@ + + + + Apache Cayenne Documentation - Flattened Relationships + + + +
+
+ Cayenne User Documentation
+ Flattened Relationships +
+ +
+

Flattened relationships represent relationship between two types of DataObjects that is not direct in the underlying relational storage. Instead it is mapped across one or more "join" tables. Still from the application point of view there is no diffrence in working with flattened relationships compared to the "normal" ones. Cayenne internally figures out how to build the needed query joins to retrieve related objects. On adding or removing an object to/from a flattened relationship via a corresponding "addTo..." / "removeFrom..." method an appropriate join record is created or removed.

+
Flattened Relationships Limitations
Currently only many-to-many flattened relatationships with a single join table can be modified. All other types of flattened relationships can be used as "read-only". This is reflected in the DataObject code generated for such relationships - no set/addTo/RemoveFrom methods are created for read-only relationships.
+ +
.
+
+ + + + + Propchange: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/Flattened Relationships/index.html ------------------------------------------------------------------------------ svn:eol-style = native Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/Generic Persistent Class/custom-generic-object.jpg URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/DataObjects/Generic%20Persistent%20Class/custom-generic-object.jpg?view=auto&rev=554413 ============================================================================== Binary file - no diff available. Propchange: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/Generic Persistent Class/custom-generic-object.jpg ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/Generic Persistent Class/index.html URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/DataObjects/Generic%20Persistent%20Class/index.html?view=auto&rev=554413 ============================================================================== --- cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/Generic Persistent Class/index.html (added) +++ cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/Generic Persistent Class/index.html Sun Jul 8 12:11:31 2007 @@ -0,0 +1,150 @@ + + + + Apache Cayenne Documentation - Generic Persistent Class + + + +
+
+ Cayenne User Documentation
+ Generic Persistent Class +
+ +

What Is "Generic Persistent Class"

+ +

Each kind of persistent objects (such as "Artist" or "Painting") is described in Cayenne by a single ObjEntity. The most common and useful scenario is mapping an ObjEntity to a "specialized" Java class, one class per entity. But there is an alternative - use a single generic persistent object class to map any entity.

+ +
Generic DataObject hints
+
    +
  • Accessing generic objects is done via DataObject API (see examples below).
  • +
  • The simplest "generic" object class for all practical purposes is CayenneDataObject.
  • +
  • "Concrete" DataObject classes are by definition "generic" as they implement DataObject.
  • +
+
+ +
When to Use Generic Objects
Generic objects are not type-safe and are not convenient for manual coding. Most applications should stick to concrete classes. Generic objects are useful in cases when all persistent properties are not fully known at compile time. It is also possible to use a hybrid approach when new persistent properties are added to the existing concrete class at runtime.
+ +

Mapping in CayenneModeler

+ +

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. First it will check whether a DataMap "Custom Superclass" is set. If so, runtime uses this class to instantiate new objects. If not, org.apache.cayenne.CayenneDataObject is used.

+ +

+ +

CayenneModeler and Ant class generators skip ObjEntities that are mapped to CayenneDataObject explicitly or have no class mapping (i.e. implicitly mapped to a generic class).

+ + +

How to Use Generic DataObjects

+ +

One difference between using a specific class per entity and using generic objects is that a String entity name is used in places where you would normally use a Java class. The examples below demonstrate this:

+ +

Create a new object:

+ +
+
DataContext context = ...;
+DataObject author = (DataObject) context.newObject("Person");
+
+ +

Create a new object when using a generic ObjectContext that does not define "newObject(String)" method. In this case we must set ObjectId explicitly - this will tell Cayenne what entity the generic object belongs to:

+ +
+
ObjectContext context = ...;
+DataObject author = new CayenneDataObject();
+author.setObjectId(new ObjectId("Person"));
+context.registerNewObject(author);
+
+ + +

Build SelectQuery:

+ +
+
Expression e = ExpressionFactory.likeIgnoreCaseExp("subject", "%first%");
+SelectQuery q = new SelectQuery("Message", e);
+
+ +

Use DataObject API to read/write the values instead or getters/setters.

+ +

Determine object entity name:

+ +
+
DataObject object = ...;
+String entityName = object.getObjectId().getEntityName();
+
+ +

Read a simple property value (attribute or relationship):

+ +
+
String subject = (String) object.readProperty("subject");
+
+ +

Read a "nested" property value spanning a chain of DataObjects:

+ +
+
String name = (String) object.readNestedProperty("author.lastName");
+
+ +

Modify a property value:

+ +
+
object.writeProperty("subject", "Post On Topic");
+
+ +
.
+
+ + + + + Propchange: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/Generic Persistent Class/index.html ------------------------------------------------------------------------------ svn:eol-style = native Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/Handling Inheritance/index.html URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/DataObjects/Handling%20Inheritance/index.html?view=auto&rev=554413 ============================================================================== --- cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/Handling Inheritance/index.html (added) +++ cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/Handling Inheritance/index.html Sun Jul 8 12:11:31 2007 @@ -0,0 +1,159 @@ + + + + Apache Cayenne Documentation - Handling Inheritance + + + +
+
+ Cayenne User Documentation
+ Handling Inheritance +
+ +
+

"Inheritance" is an Object Oriented concept absent in traditional RDBMS. Cayenne however allows to map a hierarchical class tree to a single base table (so called "single table inheritance"). Such mapping is described in detail in the Modeler Guide. The idea of single table inheritance is that a "class" of a database row is determined from the values in one or more columns of the base table. These columns are called "class designator columns".

+ +
Initial Values of the Classs Designator Columns
Assigning correct values to the "class designator columns" mentioned above is one task that is not yet automated in Cayenne and requires user code in the DataObject, as discussed in the next subsection. In the future versions this will likely be handled in the mapping and completely outside of the Java classes, so the advise below will become obsolete.
+ +

Inheritance and new DataObjects

+

Consider the following class hierarchy (also used in the Modeler Guide example):
+

+ +

If a class designator column is "PERSON_TYPE", AbstractPerson class should define an attribute (for instance called "personType") that maps to PERSON_TYPE. This attribute is redundant and meanigless in Java, since person type is defined already by the Java class of the object, however we still have to keep it around so that when the new objects are saved, correct PERSON_TYPE data is stored in the database. Currently it is a developer responsibility to set "personType" value (or values of any other attributes that map to "class designator columns") when the new object is registered with DataContext. One way to take care of this is to override "setPersistenceState(..)" method on each DataObject class in the inheritance hierarchy to catch when the object is registered with DataContext:

+ +
+
public class Employee extends _Employee {
+    public void setPersistenceState(int state) {
+        super.setPersistenceState(state);
+        
+        // if object was just created
+        if(state == PersistenceState.NEW) {
+           setPersonType("EMPLOYEE");
+        }
+    }
+...
+}
+
+public class Manager extends _Manager {
+    public void setPersistenceState(int state) {
+        super.setPersistenceState(state);
+        
+        // if object was just created
+        if(state == PersistenceState.NEW) {
+           setPersonType("MANAGER");
+        }
+    }
+...
+}
+
+public class CustomerContact extends _CustomerContact {
+    public void setPersistenceState(int state) {
+        super.setPersistenceState(state);
+        
+        // if object was just created
+        if(state == PersistenceState.NEW) {
+           setPersonType("CUSTOMER");
+        }
+    }
+...
+}
+
+ +

Inheritance and SelectQueries

+

When performing SelectQuery on a table that maps to inheritance hierarchy, Cayenne will only return rows that belong to root class of the query and all its subclasses. No superclasses or objects from parallel inheritance branches will be returned. For example executing a SelectQuery with Employee class as root will potentially return a mix of Employees and Managers (who are also Employees of course), but no CustomerContact objects:

+
+
DataContext context;
+...
+SelectQuery query = new SelectQuery(Employee.class);
+List employees = context.performQuery(query);
+ 
+// employees list will contain "regular" employees and managers
+Iterator it = employees.iterator();
+while(it.hasNext()) {
+   Employee e = (Employee) it.next();
+   if(e instanceof Manager) {
+   	// do something with manager...
+   }
+}
+
+ +

The need to determine the correct class for each fetched database row makes queries on entities that use inheritance less efficient than the regular queries. If an application doesn't care about the query root class subclasses, the query can be optimized by explicitly turning off inheritance resolution. If this is done, the example above will return all Managers as instances of Employee class, not Manager class:

+ +
+
DataContext context;
+...
+SelectQuery query = new SelectQuery(Employee.class);
+ 
+// *** explicitly turn off inheritance resolution
+query.setResolvingInherited(false);
+ 
+List employees = context.performQuery(query);
+ 
+// employees list will contain no Manager instances...
+// all Managers will be returned as regular Employees
+
+ +
Whenever an object is obtained via a relationship, it is always fully resolved to the lowest possible subclass in an entity inheritance tree.
+ +
Use setResolvingInherited(false) with caution, and only if you never plan to work with subclasses. The downside of it is that the DataContext may end up with two objects pointing to the same database row, thus violating uniquing principle. With the above example, this may happen if at a later time user decides to fetch Managers directly, or if a Manager object is obtained via a relationship.
+ +
.
+
+ + + + + Propchange: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/Handling Inheritance/index.html ------------------------------------------------------------------------------ svn:eol-style = native Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/Handling Inheritance/inheritance-diagram.jpg URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/DataObjects/Handling%20Inheritance/inheritance-diagram.jpg?view=auto&rev=554413 ============================================================================== Binary file - no diff available. Propchange: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/Handling Inheritance/inheritance-diagram.jpg ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/Relationships/index.html URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/DataObjects/Relationships/index.html?view=auto&rev=554413 ============================================================================== --- cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/Relationships/index.html (added) +++ cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/Relationships/index.html Sun Jul 8 12:11:31 2007 @@ -0,0 +1,115 @@ + + + + Apache Cayenne Documentation - Relationships + + + +
+
+ Cayenne User Documentation
+ Relationships +
+ +

Relationships are special DataObject properties that reference other "related" objects. Semantically there are two types of relationships - to-one pointing to just a single DataObjects (e.g. Painting.toArtist), and to-many pointing to a collection of DataObjects of the same base type (e.g. Artist.paintingArray).

+ +

To-One Relationships

+ +

"Get" methods for to-one relationships return the target DataObject. If the object is not in memory yet, it will be fetched on demand. Modifying to-one relationships is no different from modifying attributes - just a simple call to a "set" method:

+
+
Painting painting;
+
+// obtain artist for a given painting
+Artist originalArtist = painting.getToArtist();
+
+// replace with a new artist
+Artist newArtist = (Artist)context.createAndRegisterNewObject(Artist.class);
+painting.setToArtist(newArtist);
+
+// or remove Artist at all...
+// painting.setToArtist(null);
+
+
+

When adding or removing an object from any kind of relationship, Cayenne will locate and modify an existing reverse relationship as appropriate.

+ +

To-Many Relationships

+ +

"Get" methods for to-many relationships return Lists of DataObjects. Just like individual DataObjects, such lists are also resolved on demand (e.g. when a user tries to read an element from the list). For modification there are special "addTo..." and "removeFrom..." methods:

+
+
Artist artist;
+
+// obtain a list of paintings
+List paintings = artist.getPaintingArray();
+
+// remove the first painting
+if(paintings.size() > 0) {
+   Painting firstPainting = (Painting)paintings.get(0);
+   artist.removeFromPaintingArray(firstPainting);
+}
+
+// add a new painting
+Painting newPainting = (Painting)context.createAndRegisterNewObject(Painting.class);
+artist.addToPaintingArray(newPainting);
+
+
+

While to-many relationships in Cayenne are represented by Lists, they are really ordered Sets, as they are not allowed to contain the same object more than once.

+ +
.
+
+ + + + + Propchange: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/Relationships/index.html ------------------------------------------------------------------------------ svn:eol-style = native Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/index.html URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/DataObjects/index.html?view=auto&rev=554413 ============================================================================== --- cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/index.html (added) +++ cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/index.html Sun Jul 8 12:11:31 2007 @@ -0,0 +1,93 @@ + + + + Apache Cayenne Documentation - DataObjects + + + +
+
+ Cayenne User Documentation
+ DataObjects +
+ +

DataObjects

+

DataObjects (Cayenne persistent objects) are composed of attributes and relationships. Attributes are the simplest object properties (as in "java bean properties") that can be stored in the columns in the database. Those are usually string, numeric, binary or date values. Another type of properties is relationships. They represent related DataObjects (to-one relationships) or collections of DataObjects (to-many relationships). To read and modify attributes and relationships, application code would simply invoke corresponding get or set methods. In case of to-many relationships represented by collections there are also add and remove methods.

+ +

Queries discussed in the previous chapter are used to obtain the initial sets of DataObjects. After that a graph of persistent objects is navigated and modified via relationship methods, thus hiding the underlying relational storage complexity and giving application a nice object view of the relevant subset of the database data.

+ +

Examples of working with attributes and relationships are given later in this chapter.

+ +

Sections

+ +
    +
  1. Relationships
  2. +
  3. Flattened Relationships
  4. +
  5. DataObjects Example
  6. +
  7. Accessing PK and FK Values
  8. +
  9. DataObjectUtils
  10. +
  11. DataObject Validation
  12. +
  13. Handling Inheritance
  14. +
  15. Deleting Objects
  16. +
  17. Generic Persistent Class
  18. +
+ +
+ +
.
+
+ + + + + Propchange: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataObjects/index.html ------------------------------------------------------------------------------ svn:eol-style = native Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DVModeler GUI Tool/index.html URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/DataViews/DVModeler%20GUI%20Tool/index.html?view=auto&rev=554413 ============================================================================== --- cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DVModeler GUI Tool/index.html (added) +++ cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DVModeler GUI Tool/index.html Sun Jul 8 12:11:31 2007 @@ -0,0 +1,82 @@ + + + + Apache Cayenne Documentation - DVModeler GUI Tool + + + +
+
+ Cayenne User Documentation
+ DVModeler GUI Tool +
+ +

DVModeler is a Java GUI tool to work with DataViews configuration included in Cayenne projects. Steps needed to start DVModeler are similar to that of CayenneModeler. Main class is org.apache.cayenne.dataview.dvmodeler.Main. For convenience Cayenne distribution provides run scripts to start DVModeler on Windows and UNIX platforms. To take advantage of these scripts, user must set CAYENNE_HOME (optional) and JAVA_HOME environment variables as described in Installation.

+ +

To run DVModeler, simply doubleclick the appropriate script. Alternatively it can be run from the command line.

+ +

Windows:

+
+
%CAYENNE_HOME%\bin\dvmodeler.bat
+
+
+

UNIX:

+
+
$CAYENNE_HOME/bin/dvmodeler.sh
+
+
+ +
.
+
+ + + + + Propchange: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DVModeler GUI Tool/index.html ------------------------------------------------------------------------------ svn:eol-style = native Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DataView Concepts/cell-editors1.gif URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/DataViews/DataView%20Concepts/cell-editors1.gif?view=auto&rev=554413 ============================================================================== Binary file - no diff available. Propchange: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DataView Concepts/cell-editors1.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DataView Concepts/cell-renderers.gif URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/DataViews/DataView%20Concepts/cell-renderers.gif?view=auto&rev=554413 ============================================================================== Binary file - no diff available. Propchange: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DataView Concepts/cell-renderers.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DataView Concepts/dataview-structure.gif URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/DataViews/DataView%20Concepts/dataview-structure.gif?view=auto&rev=554413 ============================================================================== Binary file - no diff available. Propchange: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DataView Concepts/dataview-structure.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DataView Concepts/dataview-usecases.gif URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/DataViews/DataView%20Concepts/dataview-usecases.gif?view=auto&rev=554413 ============================================================================== Binary file - no diff available. Propchange: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DataView Concepts/dataview-usecases.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DataView Concepts/domodels.gif URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/DataViews/DataView%20Concepts/domodels.gif?view=auto&rev=554413 ============================================================================== Binary file - no diff available. Propchange: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DataView Concepts/domodels.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DataView Concepts/format-factory.gif URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/DataViews/DataView%20Concepts/format-factory.gif?view=auto&rev=554413 ============================================================================== Binary file - no diff available. Propchange: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DataView Concepts/format-factory.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DataView Concepts/index.html URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/DataViews/DataView%20Concepts/index.html?view=auto&rev=554413 ============================================================================== --- cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DataView Concepts/index.html (added) +++ cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DataView Concepts/index.html Sun Jul 8 12:11:31 2007 @@ -0,0 +1,115 @@ + + + + Apache Cayenne Documentation - DataView Concepts + + + +
+
+ Cayenne User Documentation
+ DataView Concepts +
+ +
+

DataView Hierarchy

+ +

The class diagram on the figure below captures the structure of Data Views and how they rely on the classes in the Cayenne subpackages. Single DataView object is the root of the hierarchy. It serves as a container for ObjEntityViews from one or more DataView configuration files. Just like entities in the DataMaps, ObjEntityViews can freely refer to each other whether they are defined in the same configuration file or different ones. The recommended practice is to store closely related ObjEntityViews in the same XML "module" and define several "modules" based on the criterion of such closeness. When you load the list of XML files into the DataView, all the relationships are resolved automatically and the ObjEntityViews share the same namespace (so they must have different names even if they are located in different XML files).

+ +

The diagram also shows that DataView is associated with several classes such as EntityResolver, DataTypeSpec, FormatFactory. The instances of these classes participate in the process of loading actual Data View files.

+ +

The main unit of any Data View is ObjEntityView. It always refers to an ObjEntity defined in one of the used DataMaps and defines various presentation rules for this entity. There can be several ObjEntityViews for an ObjEntity, each of them utilized by an application when appropriate. EntityResolver finds the corresponding ObjEntities by the names as the Data View is being loaded. Every ObjEntityView must have a name unique in the DataView context.

+ +

ObjEntityViews contain fields called ObjEntityViewFields. They must be named uniquely within an ObjEntityView. The fields can be of two sorts. The regular "nocalc" fields reference ObjAttributes in the ObjEntity referred by the parent ObjEntityView. There may be several fields for a given ObjAttribute in the ObjEntityView. A field describes the following view parameters:

+ +
    +
  • How the related ObjAttribute should be rendered and edited.
  • +
  • The data type and the formats to use in the presentation layer.
  • +
  • The caption that is usually used to name a table column or to label an input control in a form.
  • +
  • Editability and visibility of the attribute
  • +
  • An order in which the fields appear as columns in a JTable or in a form with the preferred index.
  • +
+ + +

The other type of ObjEntityViewFields is "lookup" fields. They point to the fields defined in other ObjEntityViews so the actual values to display, edit, or select from come from those referenced fields. Such a lookup field corresponds to an ObjRelationship with the ObjEntity referred by this its ObjEntityView as a source and the ObjEntity referred by the lookup ObjEntityView as a target instead of an ObjAttribute. Next the field identifies which lookup ObjEntityView and which particular field it wants to use as a lookup. These dependencies are resolved when the data views are loaded into memory. Class LookupCache helps maintain and map to data objects lists of values used in lookup combo boxes and lists. Thus you can describe the rules of visual editing the relationships or make aggregated views base on the related entities.
+

+ + +

Field Data Types

+

Cayenne defines the mapping between several Java Class types and JDBC types. It is convenient to use and sufficient in many cases but there are all sorts of situations when one would like to define more specific data types to make use of, especially for the presentation purposes. In many cases when Integer is used as a flag you would like to map it to Boolean. Or you may have a Money type or Date type that holds only year, month, and day values, and so forth.

+ +

ObjEntityViewFields address that by providing an easily extensible system of data types often used in the business applications. This system takes care of converting values back and forth between Cayenne data types and application specific data types. It relies on two classes DataTypeEnum and DataTypeSpec, both of them can be extended to define new types of any sorts. While the entire thing may seem redundant at the first glance, actually, it is a powerful concept that can save a lot of time spent on the manual conversions.

+ +

FormatFactory

+

FormatFactory shown on the next figure provides the means to create instances of the edit and display formats used by ObjEntityViewFields. There are several formats defined in the java.text package. In addition the dataview library defines convenient MapFormat somewhat similar to java.text.ChoiceFormat. instead of formatting doubles by inclusion in range criterion as ChoiceFormat does it maps a set of objects of any type to string values. For example you can map Booleans to "Sure" and "No way" strings or you can map String keys to some descriptive String values, etc. It is easy for users to add custom formats of their own. They should subclass FormatFactory and create new Builders for their formats. That done, all they need is to configure the display and edit formats in ObjEntityViewFields with the class names of their Format classes and the patterns (and, maybe, some other properties).
+

+ + +

CellRenderers and CellEditors

+

The following figure presents the utility class CellRenderers and several ready-to-use cell renderers for different types of ObjEntityViewFields. They are used in JTables, JLists, and JComboBoxes. The methods defined in the CellRenderers class will save your time when configuring a JTable to render values of the types available for use with ObjEntityViewFields
+

+ +

The purpose of CellEditors is the same as that of CellRenderers. The editors are used when there is a need to edit data in JTables and such.
+

+ +

The convenient notion of DataObjectList is defined in the library. It is a specialized container to store Cayenne DataObjects (usually of the same type). It fires events when modified and DOTableModel, DOListModel, DOComboBoxModel wrap it and being configured with an ObjEntityView / Field are handy to provide access to these data objects with JTables, JLists, and JComboBoxes. In fact, they make the visual components data aware.
+

+ + +

Miscellaneous Features

+

One more useful feature is a centralized EventDispatcher within the DataView class. It is used by the fields to fire the events whenever their values are changed. Thus the ObjAttribute/ObjRelationship modifications can be easily propagated to all the listening components.

+ +
.
+
+ + + + + Propchange: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DataView Concepts/index.html ------------------------------------------------------------------------------ svn:eol-style = native Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DataViews in Action/index.html URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/DataViews/DataViews%20in%20Action/index.html?view=auto&rev=554413 ============================================================================== --- cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DataViews in Action/index.html (added) +++ cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DataViews in Action/index.html Sun Jul 8 12:11:31 2007 @@ -0,0 +1,119 @@ + + + + Apache Cayenne Documentation - DataViews in Action + + + +
+
+ Cayenne User Documentation
+ DataViews in Action +
+ +
+

Here we illustrate the discussion of DataViews with configuration samples and code snippets. Cayenne project DTD file supports references to data view configuration files. This information is loaded into the Cayenne Configuration instance along with the DataDomain, DataNode, and DataMap entries. Since the DataView functionality is optional and would not be very useful in some deployment scenarios (server-side applications) the DataView configiuration itself is not loaded at the time of initialization. Neither DataView instances are created by the configuration process. A DataView can be created in a Swing application with the code similar to the following:

+
+
//Assume, this is your Cayenne Configuration instance.
+Configuration cayenneConfiguration = ...;
+
+//You will need to setup a Cayenne EntityResolver in your DataView
+//For example you can retrieve it from the DataContext in use
+//with dataContext.getEntityResolver();
+//or construct your own composite one, spanning several Data Domains.
+EntityResolver entityResolver = ...;
+
+//Create new DataView instance, and set its entityResolver
+//*before* loading the actual configuration
+DataView dataView = new DataView();
+dataView.setEntityResolver(entityResolver);
+
+//Load the configuration
+cayenneConfiguration.loadDataView(dataView);
+
+//Here we go. Our Data View is ready to be used in the application
+//This way you can create several of them, completely separated if needed.
+
+ +

It is worth mentioning one instance of DataView serves to incorporate several Data View configurations saved in different files. Therefore it defines single namespace and easily resolves inter-configuration references among the ObjEntityViews

+ +

Next, let us see how a Swing table model and JTable can be configured with our Data View to display and edit a list of data objects.

+ +
+
DataView dataView = ...;
+
+JTable featureTable = ...;
+ObjEntityView featureView = dataView.getObjEntityView("ProductFeatureView");
+
+// This is a descendant of javax.swing.table.AbstractTableModel
+DOTableModel tableModel = new DOTableModel();
+tableModel.setView(featureView);
+
+// Retrieve a list of data objects (with SelectQuery, say)
+// and initialize the model with it
+DataObjectList featureDataObjects = ...;
+tableModel.setDataObjects(matrixEntries);
+
+featureTable.setModel(tableModel);
+
+// set the apropriate TableCellRenderers and Editors
+new CellRenderers().installRenderers(featureTable);
+new CellEditors().installEditors(featureTable);
+
+ +

In fact, there is many more cool things you could do with DataViews to build your Cayenne enabled Swing rich client faster and cleaner, and separate the GUI related stuff from your domain logic defining the clear declarative rules telling the framework how to interprete, render, and edit the ObjEntities and DataObjects your application relies upon.

+ +
.
+
+ + + + + Propchange: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/DataViews in Action/index.html ------------------------------------------------------------------------------ svn:eol-style = native Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/Swing Applications/dataview-usecases.gif URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/DataViews/Swing%20Applications/dataview-usecases.gif?view=auto&rev=554413 ============================================================================== Binary file - no diff available. Propchange: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/Swing Applications/dataview-usecases.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/Swing Applications/index.html URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/DataViews/Swing%20Applications/index.html?view=auto&rev=554413 ============================================================================== --- cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/Swing Applications/index.html (added) +++ cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/Swing Applications/index.html Sun Jul 8 12:11:31 2007 @@ -0,0 +1,77 @@ + + + + Apache Cayenne Documentation - Swing Applications + + + +
+
+ Cayenne User Documentation
+ Swing Applications +
+ +
+

Those who have experience of Swing GUI development knows how much time it takes to work out all the minutest details of formatting, in-place input validation, handling the interactive data modification, enforcing naming, order, and formatting consistensy, etc. Whenever the domain or requirements change (e.g. new attributes are added to an ObjEntity, formats or captions of data are modified, or relationships change their meaning) developers are faced with the necessity to go through the number of Swing data models, panels, various helpers fishing out the bits of code to be corrected.

+ +

Another problem is the need for quick and easy prototyping of data aware GUIs. Those who, at one time or another, worked with Borland VCL for C++ or Delphi or DataExpress/dbSwing for Java and similar frameworks can recall how painless it was to create a rough prototype of the GUI working with the relational database and bind it to the actual data. That was possible due to the layer of easily configured data aware classes and components. And once the working prototype had been ready, refinining it used to be a very simple task.

+ +

Cayenne DataViews solve these problems. Data Views act as a bridge between the domain defined in terms of Cayenne DataObjects and a presentation layer built with Swing. Potentially they can be used in the Web environment as well, but Swing integration is the main direction. Conceptually, Data Views are close to the application facades described, for instance, by Martin Fowler. The following figure shows the area where Data Views can be applied.
+

+ +
Validation
The validation rules mentioned in the Use Cases are meant to be "lightweght", i.e. it is generally agreed the validation related code to enforce the business rules should be located in the domain area but, still, there are various checks one could prefer to perform right in the presentation layer like inclusion in a predefined range of values, correct input format, sometimes, even preliminary credit card number validity check with the well known Luhn algorithm, the other kinds of sanity checks. Presently the validation is on the list of the features to be added.
+ +
.
+
+ + + + + Propchange: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne Guide/DataViews/Swing Applications/index.html ------------------------------------------------------------------------------ svn:eol-style = native