blob: e31faa53a9ea912d92f6089845e82966b5597a0f [file] [log] [blame]
Title: Path Expressions
<P>Before we start discussing how to build expressions, it is important to understand one group of expressions widely used in Cayenne: path expressions. There are two types of path expressions: object path used to navigate graphs of Java objects that follow Java Bean property naming conventions and database path used to navigate the database schema.</P>
<H3><A name="PathExpressions-ObjectPathExpressions"></A>Object Path Expressions</H3>
<P>An Object Path Expression is a property navigation path. Such path is represented by a String made of dot-separated names of properties of a Java Bean class. E.g. a path expression &quot;toArtist.artistName&quot; is a valid property path for a Painting class, pointing to the name of the Artist who created a given Painting. A few more examples:</P>
<UL>
<LI><B>paintingTitle</B><BR>
Can be used to navigate to the value of &quot;paintingTitle&quot; property of the Painting class.</LI>
<LI><B>toArtist.exhibitArray.closingDate</B><BR>
Can be used to navigate to a closing date of any of the exhibits of a Painting's Artist object.</LI>
</UL>
<DIV class="panelMacro"><TABLE class="infoMacro"><COLGROUP><COL width="24"><COL></COLGROUP><TR><TD valign="top"><IMG src="http://cayenne.apache.org/docs/1.2/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></TD><TD><B>What Does 'navigation' Means</B><BR>The term &quot;navigation&quot; in the description above could mean different things depending on the context. For instance, when evaluating an expression in memory, &quot;navigating&quot; an object path would simply return the value of a corresponding object property. When the same expression is used in a select query qualifier, it resolves to the name of a table column used in a WHERE clause of a generated SQL statement.</TD></TR></TABLE></DIV>
<H3><A name="PathExpressions-DatabasePathExpressions"></A>Database Path Expressions</H3>
<P>Database Path Expressions provide an easy way to navigate through DB table joins. Instead of complex join semantics such expressions utilize the names of DbRelationships defined in Cayenne DataMap. Translating the above object path examples into the DB realm, database path expressions might look like this:</P>
<UL>
<LI><B>PAINTING_TITLE</B><BR>
Can be used to match the value of &quot;PAINTING_TITLE&quot; column of a PAINTING table.</LI>
<LI><B>toArtist.artistExhibitArray.toExhibit.CLOSING_DATE</B><BR>
Can be used to match a closing date of any of the exhibits of a related artist record.</LI>
</UL>
<P>Though database path expressions are widely used by Cayenne framework internally, they are rarely used in applications. There are only a few cases when their explicit use is justified.</P>
<H3><A name="PathExpressions-MatchingPathExpressions"></A>Matching Path Expressions</H3>
<P>As described in the following chapters a path expression is usually matched against some value (see for example <A href="expression-factory-utilities.html" title="Expression Factory Utilities">ExpressionFactory API</A> - the first argument to each method is a path, and a second - an Object value that is matched against the path). Such value type must be compatible with the type of the property pointed to by the path. E.g. toArtist.artistName can only be matched against a String, and toArtist - against instances of Artist. </P>