<!--$Id: db_join.so,v 10.44 2002/08/29 03:24:30 bostic Exp $--> <!--Copyright 1997-2002 by Sleepycat Software, Inc.--> <!--All rights reserved.--> <!--See the file LICENSE for redistribution information.--> <html> <head> <title>Berkeley DB: Db.join</title> <meta name="description" content="Berkeley DB: An embedded database programmatic toolkit."> <meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,java,C,C++"> </head> <body bgcolor=white> <a name="2"><!--meow--></a> <table width="100%"><tr valign=top> <td> <h1>Db.join</h1> </td> <td align=right> <a href="../../db4-devel-4.1.25/api_java/c_index.html"><img src="../../db4-4.1.25/images/api.gif" alt="API"></a><a href="../reftoc.html"><img src="../../db4-4.1.25/images/ref.gif" alt="Ref"></a> </td></tr></table> <hr size=1 noshade> <tt> <h3><pre> import com.sleepycat.db.*; <p> public Dbc join(Dbc[] curslist, int flags) throws DbException; </pre></h3> <h1>Description</h1> <p>The Db.join method creates a specialized cursor for use in performing equality or natural joins on secondary indices. For information on how to organize your data to use this functionality, see <a href="../../db4-devel-4.1.25/ref/am/join.html">Equality join</a>. <p>The <b>primary</b> argument contains the <a href="../../db4-devel-4.1.25/api_java/db_class.html">Db</a> handle of the primary database, which is keyed by the data values found in entries in the <b>curslist</b>. <p>The <b>curslist</b> argument contains a null terminated array of cursors. Each cursor must have been initialized to refer to the key on which the underlying database should be joined. Typically, this initialization is done by a <a href="../../db4-devel-4.1.25/api_java/dbc_get.html">Dbc.get</a> call with the <a href="../../db4-devel-4.1.25/api_java/dbc_get.html#DB_SET">Db.DB_SET</a> flag specified. Once the cursors have been passed as part of a <b>curslist</b>, they should not be accessed or modified until the newly created join cursor has been closed, or else inconsistent results may be returned. <p>Joined values are retrieved by doing a sequential iteration over the first cursor in the <b>curslist</b> argument, and a nested iteration over each secondary cursor in the order they are specified in the <b>curslist</b> argument. This requires database traversals to search for the current datum in all the cursors after the first. For this reason, the best join performance normally results from sorting the cursors from the one that refers to the least number of data items to the one that refers to the most. By default, Db.join does this sort on behalf of its caller. <p>The <b>flags</b> value must be set to 0 or the following value: <p><dl compact> <p><dt><a name="Db.DB_JOIN_NOSORT">Db.DB_JOIN_NOSORT</a><dd>Do not sort the cursors based on the number of data items to which they refer. If the data are structured so that cursors with many data items also share many common elements, higher performance will result from listing those cursors before cursors with fewer data items; that is, a sort order other than the default. The Db.DB_JOIN_NOSORT flag permits applications to perform join optimization prior to calling Db.join. </dl> <p>The returned cursor supports only the <a href="../../db4-devel-4.1.25/api_java/dbc_get.html">Dbc.get</a> and <b>dbc_close</b> cursor functions: <p><dl compact> <p><dt><a href="../../db4-devel-4.1.25/api_java/dbc_get.html">Dbc.get</a><dd>Iterates over the values associated with the keys to which each item in <b>curslist</b> was initialized. Any data value that appears in all items specified by the <b>curslist</b> argument is then used as a key into the <b>primary</b>, and the key/data pair found in the <b>primary</b> is returned. <p>The <b>flags</b> value must be set to 0 or the following value: <p><dl compact> <p><dt><a name="Db.DB_JOIN_ITEM">Db.DB_JOIN_ITEM</a><dd>Do not use the data value found in all the cursors as a lookup key for the <b>primary</b>, but simply return it in the key parameter instead. The data parameter is left unchanged. </dl> <p>In addition, the following flag may be set by bitwise inclusively <b>OR</b>'ing it into the <b>flags</b> parameter: <p><dl compact> <p><dt><a name="Db.DB_DIRTY_READ">Db.DB_DIRTY_READ</a><dd>Read modified but not yet committed data. Silently ignored if the <a href="../../db4-devel-4.1.25/api_java/db_open.html#DB_DIRTY_READ">Db.DB_DIRTY_READ</a> flag was not specified when the underlying database was opened. <p><dt><a name="Db.DB_RMW">Db.DB_RMW</a><dd>Acquire write locks instead of read locks when doing the retrieval. Setting this flag can eliminate deadlock during a read-modify-write cycle by acquiring the write lock during the read part of the cycle so that another thread of control acquiring a read lock for the same item, in its own read-modify-write cycle, will not result in deadlock. </dl> <p><dt><a href="../../db4-devel-4.1.25/api_java/dbc_close.html">Dbc.close</a><dd>Close the returned cursor and release all resources. (Closing the cursors in <b>curslist</b> is the responsibility of the caller.) </dl> <p>For the returned join cursor to be used in a transaction-protected manner, the cursors listed in <b>curslist</b> must have been created within the context of the same transaction. <p>The Db.join method throws an exception that encapsulates a non-zero error value on failure. <h1>Errors</h1> <p>The Db.join method may fail and throw an exception encapsulating a non-zero error for the following conditions: <p><dl compact> <p><dt>Db.DB_SECONDARY_BAD<dd>A secondary index references a nonexistent primary key. </dl> <p><dl compact> <p><dt>EINVAL<dd>An invalid flag value or parameter was specified. <p>Cursor functions other than <a href="../../db4-devel-4.1.25/api_java/dbc_get.html">Dbc.get</a> or <a href="../../db4-devel-4.1.25/api_java/dbc_close.html">Dbc.close</a> were called. </dl> <p>The Db.join method may fail and throw an exception for errors specified for other Berkeley DB and C library or system methods. If a catastrophic error has occurred, the Db.join method may fail and throw a <a href="../../db4-devel-4.1.25/api_java/runrec_class.html">DbRunRecoveryException</a>, in which case all subsequent Berkeley DB calls will fail in the same way. <h1>Class</h1> <a href="../../db4-devel-4.1.25/api_java/db_class.html">Db</a> <h1>See Also</h1> <a href="../../db4-devel-4.1.25/api_java/db_list.html">Databases and Related Methods</a> </tt> <table width="100%"><tr><td><br></td><td align=right> <a href="../../db4-devel-4.1.25/api_java/c_index.html"><img src="../../db4-4.1.25/images/api.gif" alt="API"></a><a href="../reftoc.html"><img src="../../db4-4.1.25/images/ref.gif" alt="Ref"></a> </td></tr></table> <p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font> </body> </html>