cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [CONF] Apache Cayenne Documentation > Path Expressions
Date Sun, 10 Jan 2010 12:59:00 GMT
    <base href="">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAYDOC&amp;forWysiwyg=true"
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="">Path
     <h4>Page <b>edited</b> by             <a href="">Andrus
     <div class="notificationGreySide">
         <p>Before we start discussing how to build expressions, it is important to
understand one group of expressions widely used in Cayenne: <em>path expressions</em>.
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. General form of path expressions is the following:</p>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent

	<li>"db:" an optional prefix indicating the the following path is a DB path.</li>
	<li>"segment" - a name of a relationship or an attribute in the path. Path must have
at least one segment; segments are separated by dot (".").</li>
	<li>"+" - OUTER JOIN indicator: a plus sign at the end of a segment name indicates
that when a JOIN is created for the path, it must be an OUTER JOIN.</li>

<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
"toArtist.artistName" 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>

	<li><tt>paintingTitle</tt> Can be used to navigate to the value of "paintingTitle"
property of the Painting class.</li>
	<li><tt>toArtist.exhibitArray.closingDate</tt> Can be used to navigate
to a closing date of any of the exhibits of a Painting's Artist object.</li>
	<li><tt>toArtist.exhibitArray+.closingDate</tt> Same with an OUTER JOIN
on exhibits</li>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/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 "navigation" in the description above could
mean different things depending on the context. For instance, when evaluating an expression
in memory, "navigating" 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
<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>

	<li><tt>db:PAINTING_TITLE</tt> Can be used to match the value of "PAINTING_TITLE"
column of a PAINTING table.</li>
	<li><tt>db:toArtist.artistExhibitArray.toExhibit.CLOSING_DATE</tt> Can
be used to match a closing date of any of the exhibits of a related artist record.</li>

<p>Though database path expressions are widely used by Cayenne framework internally,
they are rarely used in applications. Although there are a few cases when their explicit use
is justified.</p>

<h3><a name="PathExpressions-AliasesinPathExpressions"></a>Aliases in Path

<p>Cayenne supports "aliases" in path Expressions, allowing user to control how SQL
joins are generated if the same path is encountered more than once in the same Expression.
E.g. the same expression can be written using explicit path or an alias:</p>

	<li>Full path: <tt>toArtist.exhibitArray.closingDate</tt></li>
	<li>Using alias "e": <tt>e.closingDate</tt></li>

<p>SelectQuery using the second form of the path expression must be made aware of the
alias via <tt>"SelectQuery.aliasPathSplits(..)"</tt>. Each alias for any given
path would result in separate joins. Without aliases, a single join will be used for a group
of matching paths.</p>

<h3><a name="PathExpressions-MatchingPathExpressions"></a>Matching Path

<p>As described in the following chapters a path expression is usually matched against
some value (see for example <a href="/confluence/display/CAYDOC/Expression+Factory+Utilities"
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).
A type of such value must be compatible with the type of the property pointed to by the path.
E.g. <tt>toArtist.artistName</tt> can only be matched against a <tt>String</tt>,
and <tt>toArtist</tt> - against instances of <tt>Artist</tt>.</p>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href=""
class="grey">Change Notification Preferences</a>

       <a href="">View
       <a href="">View
       <a href=";showCommentArea=true#addcomment">Add

View raw message