blob: e93d95fc33d2691bdde8800d403eedaef6fe2401 [file] [log] [blame]
Title: Queries
<P>Queries are Cayenne abstraction for communicating with an external data storage. Queries are Java objects that are generally independent from the SQL dialect used by the target database. Cayenne includes a number of standard queries in the <A href="http://objectstyle.org/cayenne/api/cayenne/org/objectstyle/cayenne/query/package-summary.html" class="external-link" rel="nofollow">org.objectstyle.cayenne.query</A> package. Many of them are only used internally. Here we describe the queries that can be useful in the application.</P>
<H3><A name="Queries-GeneralPurposeQueries"></A>General Purpose Queries</H3>
<UL>
<LI><A href="selectquery.html" title="SelectQuery">SelectQuery</A> is an &quot;object query&quot; based on some Java class. All its parameters are specified in terms of the properties of this Java class. It is completely portable and SQL-free. SelectQuery is the most commonly used out of the three queries discussed here, as it stays as close to the object model as possible. For most tasks it should be considered the first choice. Other types of queries should be used only if SelectQuery can't address a particular application need.</LI>
<LI><A href="sqltemplate-query.html" title="SQLTemplate Query">SQLTemplate Query</A> is a scriptable raw SQL query, that can be both selecting and non-selecting. Main use of SQLTemplate is to create complex SQL queries with structure that has no direct correspondence with the object model. SQLTemplate allows customizing SQL dialect code for more than one target database, encapsulating this fact from the callers. Just like other types of queries, SQLTemplates can be mapped in CayenneModeler, so the code can stay free from SQL building.</LI>
<LI><A href="stored-procedures.html" title="Stored Procedures">ProcedureQuery</A> is intended to invoke mapped stored procedures. It can be selecting or non-selecting, or even contain multiple result sets and update counts, depending on what the target procedure does.</LI>
</UL>
<H3><A name="Queries-OtherHelpfulQueries"></A>Other Helpful Queries</H3>
<UL>
<LI><A href="querychain.html" title="QueryChain">QueryChain</A> is a Query that is itself a collection of other queries. Its intention is to execute multiple queries in a single batch.</LI>
<LI><A href="objectidquery.html" title="ObjectIdQuery">ObjectIdQuery</A> is a query that selects objects matching an ObjectId.</LI>
<LI><A href="relationshipquery.html" title="RelationshipQuery">RelationshipQuery</A> is a query that fetches object(s) related to a single given object via a mapped ObjRelationship.</LI>
<LI><A href="namedquery.html" title="NamedQuery">NamedQuery</A> is a query that is a reference to another query stored in the DataMap.</LI>
</UL>
<H3><A name="Queries-CustomQueries"></A>Custom Queries</H3>
<P>To extend standard Query functionality, users can create <A href="customizing-queries.html" title="Customizing Queries">Custom Queries</A> that implement <TT>org.objectstyle.cayenne.query.Query</TT> interface.</P>