program.html   [plain text]


<!--$Id: program.so,v 10.35 2004/09/10 13:04:01 bostic Exp $-->
<!--Copyright (c) 1997,2008 Oracle.  All rights reserved.-->
<!--See the file LICENSE for redistribution information.-->
<html>
<head>
<title>Berkeley DB Reference Guide: Java programming notes</title>
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
</head>
<body bgcolor=white>
<table width="100%"><tr valign=top>
<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Java API</dl></b></td>
<td align=right><a href="../java/compat.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../java/faq.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p align=center><b>Java programming notes</b></p>
<p>Although the Java API parallels the Berkeley DB C++/C interface in many ways,
it differs where the Java language requires.  For example, the handle
method names are camel-cased and conform to Java naming patterns.  (The
C++/C method names are currently provided, but are deprecated.)</p>
<ol>
<p><li>The Java runtime does not automatically close Berkeley DB objects on
finalization.  There are several reasons for this.  One is that
finalization is generally run only when garbage collection occurs, and
there is no guarantee that this occurs at all, even on exit.  Allowing
specific Berkeley DB actions to occur in ways that cannot be replicated seems
wrong.  Second, finalization of objects may happen in an arbitrary
order, so we would have to do extra bookkeeping to make sure that
everything was closed in the proper order.  The best word of advice is
to always do a close() for any matching open() call.  Specifically, the
Berkeley DB package requires that you explicitly call close on each individual
<a href="../../java/com/sleepycat/db/Database.html">Database</a> and
<a href="../../java/com/sleepycat/db/Cursor.html">Cursor</a> object that you opened.  Your database
activity may not be synchronized to disk unless you do so.
<p><li>Some methods in the Java API have no return type, and throw a
<a href="../../java/com/sleepycat/db/DatabaseException.html">DatabaseException</a> when an severe error
arises.  There are some notable methods that do have a return value, and
can also throw an exception.  The "get" methods in
<a href="../../java/com/sleepycat/db/Database.html">Database</a> and
<a href="../../java/com/sleepycat/db/Cursor.html">Cursor</a> both return 0 when a get
succeeds, <a href="../../ref/program/errorret.html#DB_NOTFOUND">DB_NOTFOUND</a> when the key is not found, and throw an
error when there is a severe error.  This approach allows the programmer
to check for typical data-driven errors by watching return values
without special casing exceptions.
<p>An object of type <a href="../../java/com/sleepycat/db/MemoryException.html">MemoryException</a> is
thrown when a Dbt is too small to hold the corresponding key or data item.</p>
<p>An object of type <a href="../../java/com/sleepycat/db/DeadlockException.html">DeadlockException</a> is
thrown when a deadlock would occur.</p>
<p>An object of type <a href="../../java/com/sleepycat/db/RunRecoveryException.html">RunRecoveryException</a>, a
subclass of <a href="../../java/com/sleepycat/db/DatabaseException.html">DatabaseException</a>, is thrown when
there is an error that requires a recovery of the database using
<a href="../../utility/db_recover.html">db_recover</a>.</p>
<p>An object of type <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/IllegalArgumentException.html">IllegalArgumentException</a>
a standard Java Language exception, is thrown when there is an error in
method arguments.</p>
<p>An object of type <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/OutOfMemoryError.html">OutOfMemoryError</a> is thrown
when the system cannot provide enough memory to complete the operation
(the ENOMEM system error on UNIX).</p>
<p><li>If there are embedded nulls in the <b>curslist</b> argument for
<a href="../../java/com/sleepycat/db/Database.html#pathsubst(join(com.sleepycat.db.Cursor__BRACKETS__, com.sleepycat.db.JoinConfig), ' ', '%20')">Database.join(com.sleepycat.db.Cursor__BRACKETS__, com.sleepycat.db.JoinConfig)</a>,
they will be treated as the end of the list of cursors, even if you
may have allocated a longer array.  Fill in all the cursors in your
array unless you intend to cut it short.
<p><li>If you are using custom class loaders in your application, make sure
that the Berkeley DB classes are loaded by the system class loader, not a
custom class loader. This is due to a JVM bug that can cause an access
violation during finalization (see the bug 4238486 in Sun Microsystem's
Java Bug Database).
</ol>
<table width="100%"><tr><td><br></td><td align=right><a href="../java/compat.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../java/faq.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
</body>
</html>