je/docs/collections/tutorial/developing.html

187 lines
8 KiB
HTML
Raw Normal View History

2021-06-06 17:46:45 +00:00
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Developing a JE Collections Application</title>
<link rel="stylesheet" href="gettingStarted.css" type="text/css" />
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
<link rel="start" href="index.html" title="Berkeley DB Java Edition Collections Tutorial" />
<link rel="up" href="intro.html" title="Chapter 1.  Introduction" />
<link rel="prev" href="intro.html" title="Chapter 1.  Introduction" />
<link rel="next" href="tutorialintroduction.html" title="Tutorial Introduction" />
</head>
<body>
<div xmlns="" class="navheader">
<div class="libver">
<p>Library Version 12.2.7.5</p>
</div>
<table width="100%" summary="Navigation header">
<tr>
<th colspan="3" align="center">Developing a JE Collections Application</th>
</tr>
<tr>
<td width="20%" align="left"><a accesskey="p" href="intro.html">Prev</a> </td>
<th width="60%" align="center">Chapter 1. 
Introduction
</th>
<td width="20%" align="right"> <a accesskey="n" href="tutorialintroduction.html">Next</a></td>
</tr>
</table>
<hr />
</div>
<div class="sect1" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both"><a id="developing"></a>Developing a JE Collections Application</h2>
</div>
</div>
</div>
<p>
There are several important choices to make when developing an
application using the JE JE Collections API.
</p>
<div class="orderedlist">
<ol type="1">
<li>
<p>
Choose the Format for Keys and Values
</p>
<p>
For each database you may choose a binding format for the keys
and values. For example, the tuple format is useful for keys
because it has a deterministic sort order. The serial format is
useful for values if you want to store arbitrary Java objects. In
some cases a custom format may be appropriate. For details on
choosing a binding format see
<a class="xref" href="collectionOverview.html#UsingDataBindings" title="Using Data Bindings">
Using Data Bindings
</a>.
</p>
</li>
<li>
<p>
Choose the Binding for Keys and Values
</p>
<p>
With the serial data format you do not have to create a binding
for each Java class that is stored since Java serialization is
used. But for other formats a binding must be defined that
translates between stored byte arrays and Java objects. For details
see
<a class="xref" href="collectionOverview.html#UsingDataBindings" title="Using Data Bindings">
Using Data Bindings
</a>.
</p>
</li>
<li>
<p>
Choose Secondary Indices<span> and Foreign Key Indices</span>
</p>
<p>
Any database that has unique keys may have any number of
secondary indices. A secondary index has keys that are derived from
data values in the primary database. This allows lookup and
iteration of objects in the database by its index keys.
<span>
A foreign key index is a special type of secondary index where the index keys
are also the primary keys of another primary database.
</span>
For each index you must define how the index keys are derived from the data
values using a
<span>
<a class="ulink" href="../../java/com/sleepycat/je/SecondaryKeyCreator.html" target="_top">SecondaryKeyCreator</a>.
</span>
For details see the
<span>
<a class="ulink" href="../../java/com/sleepycat/je/SecondaryDatabase.html" target="_top">SecondaryDatabase</a>,
</span>
<a class="ulink" href="../../java/com/sleepycat/je/SecondaryConfig.html" target="_top">SecondaryConfig</a>
and
<a class="ulink" href="../../java/com/sleepycat/je/SecondaryKeyCreator.html" target="_top">SecondaryKeyCreator</a>
classes.
</p>
</li>
<li>
<p>
Choose the Collection Interface for each Database
</p>
<p>
The standard Java Collection interfaces are used for accessing
databases and secondary indices. The Map and Set interfaces may be
used for any type of database. The Iterator interface is used
through the Set interfaces. For more information on the collection
interfaces see
<a class="xref" href="UsingStoredCollections.html" title="Using Stored Collections">
Using Stored Collections
</a>.
</p>
</li>
</ol>
</div>
<p>
Any number of bindings and collections may be created for the
same database. This allows multiple views of the same stored data.
For example, a data store may be viewed as a Map of keys to values,
a Set of keys, or a Collection of values. String values, for
example, may be used with the built-in binding to the String class,
or with a custom binding to another class that represents the
string values differently.
</p>
<p>
It is sometimes desirable to use a Java class that encapsulates
both a data key and a data value. For example, a Part object might
contain both the part number (key) and the part name (value). Using
the JE JE Collections API this type of object is called an
"entity". An entity binding is used to translate between the Java
object and the stored data key and value. Entity bindings may be
used with all Collection types.
</p>
<p>
Please be aware that the provided JE JE Collections API collection classes
do not conform completely to the interface contracts
defined in the <code class="literal">java.util</code> package. For example, all
iterators must be explicitly closed and the <code class="methodname">size()</code>
method is not available. The differences between the JE JE Collections API
collections and the standard Java collections are
documented in
<a class="xref" href="UsingStoredCollections.html#StoredVersusStandardCollections" title="Stored Collections Versus Standard Java Collections">
Stored Collections Versus Standard Java Collections
</a>.
</p>
</div>
<div class="navfooter">
<hr />
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left"><a accesskey="p" href="intro.html">Prev</a> </td>
<td width="20%" align="center">
<a accesskey="u" href="intro.html">Up</a>
</td>
<td width="40%" align="right"> <a accesskey="n" href="tutorialintroduction.html">Next</a></td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Chapter 1. 
Introduction
 </td>
<td width="20%" align="center">
<a accesskey="h" href="index.html">Home</a>
</td>
<td width="40%" align="right" valign="top"> Tutorial Introduction</td>
</tr>
</table>
</div>
</body>
</html>