Sophie

Sophie

distrib > Mandriva > 2007.0 > x86_64 > media > main-release > by-pkgid > a4c98df40e78f6c892308fd6841f950a > files > 947

lib64db4.2-devel-4.2.52-11mdv2007.0.x86_64.rpm

<!--$Id: program.so,v 10.31 2003/11/21 02:11:37 gburd Exp $-->
<!--Copyright 1997-2003 by Sleepycat Software, Inc.-->
<!--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,b+tree,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><h3><dl><dt>Berkeley DB Reference Guide:<dd>Java API</dl></h3></td>
<td align=right><a href="../../db42-devel-4.2.52/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="../../db42-devel-4.2.52/java/faq.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p>
<h3 align=center>Java programming notes</h3>
<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/Db.html">Db</a>
 and
<a href="../../java/com/sleepycat/db/Dbc.html">Dbc</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/DbException.html">DbException</a>
 when an severe error
arises.  There are some notable
methods that do have a return value, and can also throw an exception.
<a href="../../java/com/sleepycat/db/Db.html#get">Db.get</a>
 and
<a href="../../java/com/sleepycat/db/Dbc.html#get">Dbc.get</a>
 both return 0 when a get succeeds,
return <a href="../../ref/program/errorret.html#DB_NOTFOUND">Db.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/DbDeadlockException.html">DbDeadlockException</a>
 is
thrown when a deadlock would occur.</p>
<p>An object of type 
<a href="../../java/com/sleepycat/db/DbMemoryException.html">DbMemoryException</a>
 is
thrown when the system cannot provide enough memory to complete the
operation (the ENOMEM system error on UNIX).</p>
<p>An object of type 
<a href="../../java/com/sleepycat/db/DbRunRecoveryException.html">DbRunRecoveryException</a>
,
a subclass of 
<a href="../../java/com/sleepycat/db/DbException.html">DbException</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.3/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><li>Berkeley DB always turns on the 
<a href="../../java/com/sleepycat/db/Db.html#DB_THREAD">Db.DB_THREAD</a>
flag because threads are expected in Java.
<p><li>Callbacks in Java manufacture 
<a href="../../java/com/sleepycat/db/Dbt.html">Dbt</a>
 objects
from internal data.  For efficiency, the <b>data</b> field in such Dbts is
not set in the Java object until a
<a href="../../java/com/sleepycat/db/Dbt.html#getData">Dbt.getData</a>
 method call.  This avoids the
creation of a potentially large Java byte array if it isn't needed.  If
callback code can be written to defer calling
<a href="../../java/com/sleepycat/db/Dbt.html#getData">Dbt.getData</a>
performance may be increased.  For example, a bt_compare method might
compare values returned by 
<a href="../../java/com/sleepycat/db/Dbt.html#getSize">Dbt.getSize</a>
before deciding whether a call to
<a href="../../java/com/sleepycat/db/Dbt.html#getData">Dbt.getData</a>
 is needed.
<p><li>If there are embedded null strings in the <b>curslist</b> argument for
<a href="../../java/com/sleepycat/db/Db.html#join">Db.join</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 strings in your array unless you intend to cut it short.
<p><li>The callback installed for
<a href="../../java/com/sleepycat/db/DbEnv.html#setErrorHandler">DbEnv.setErrorHandler</a>
 will run in the same
thread as the caller to
<a href="../../java/com/sleepycat/db/DbEnv.html#setErrorHandler">DbEnv.setErrorHandler</a>
.  Make sure that
thread remains running until your application exits or until
<a href="../../java/com/sleepycat/db/DbEnv.html#close">DbEnv.close</a>
is called.
<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="../../db42-devel-4.2.52/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="../../db42-devel-4.2.52/java/faq.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p><font size=1><a href="../../sleepycat/legal.html">Copyright (c) 1996-2003</a> <a href="http://www.sleepycat.com">Sleepycat Software, Inc.</a> - All rights reserved.</font>
</body>
</html>