Import BSDDB 4.7.25 (as of svn r89086)
This commit is contained in:
117
docs/gsg/JAVA/dataaccessorclass.html
Normal file
117
docs/gsg/JAVA/dataaccessorclass.html
Normal file
@@ -0,0 +1,117 @@
|
||||
<?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>DataAccessor.class</title>
|
||||
<link rel="stylesheet" href="gettingStarted.css" type="text/css" />
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.62.4" />
|
||||
<link rel="home" href="index.html" title="Getting Started with Berkeley DB" />
|
||||
<link rel="up" href="dpl_example.html" title="Chapter 6. A DPL Example" />
|
||||
<link rel="previous" href="mydbenv-persist.html" title="MyDbEnv" />
|
||||
<link rel="next" href="dpl_exampledatabaseput.html" title="ExampleDatabasePut.class" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="navheader">
|
||||
<table width="100%" summary="Navigation header">
|
||||
<tr>
|
||||
<th colspan="3" align="center">DataAccessor.class</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="20%" align="left"><a accesskey="p" href="mydbenv-persist.html">Prev</a> </td>
|
||||
<th width="60%" align="center">Chapter 6. A DPL Example</th>
|
||||
<td width="20%" align="right"> <a accesskey="n" href="dpl_exampledatabaseput.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="dataaccessorclass"></a>DataAccessor.class</h2>
|
||||
</div>
|
||||
</div>
|
||||
<div></div>
|
||||
</div>
|
||||
<p>
|
||||
Now that we have implemented our data classes,
|
||||
we can write a class that will provide
|
||||
convenient access to our primary and
|
||||
secondary indexes.
|
||||
Note that like our data classes, this class is shared by both our
|
||||
example programs.
|
||||
</p>
|
||||
<p>
|
||||
If you compare this class against our
|
||||
<tt class="classname">Vendor</tt> and
|
||||
<tt class="classname">Inventory</tt>
|
||||
class implementations, you will see that the
|
||||
primary and secondary indices declared there are
|
||||
referenced by this class.
|
||||
</p>
|
||||
<p>
|
||||
See <a href="dpl_example.html#vendorclass">Vendor.class</a>
|
||||
and
|
||||
<a href="inventoryclass.html">Inventory.class</a>
|
||||
for those implementations.
|
||||
</p>
|
||||
<pre class="programlisting">package persist.gettingStarted;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.sleepycat.db.DatabaseException;
|
||||
import com.sleepycat.persist.EntityStore;
|
||||
import com.sleepycat.persist.PrimaryIndex;
|
||||
import com.sleepycat.persist.SecondaryIndex;
|
||||
|
||||
public class DataAccessor {
|
||||
// Open the indices
|
||||
public DataAccessor(EntityStore store)
|
||||
throws DatabaseException {
|
||||
|
||||
// Primary key for Inventory classes
|
||||
inventoryBySku = store.getPrimaryIndex(
|
||||
String.class, Inventory.class);
|
||||
|
||||
// Secondary key for Inventory classes
|
||||
// Last field in the getSecondaryIndex() method must be
|
||||
// the name of a class member; in this case, an Inventory.class
|
||||
// data member.
|
||||
inventoryByName = store.getSecondaryIndex(
|
||||
inventoryBySku, String.class, "itemName");
|
||||
|
||||
// Primary key for Vendor class
|
||||
vendorByName = store.getPrimaryIndex(
|
||||
String.class, Vendor.class);
|
||||
}
|
||||
|
||||
// Inventory Accessors
|
||||
PrimaryIndex<String,Inventory> inventoryBySku;
|
||||
SecondaryIndex<String,String,Inventory> inventoryByName;
|
||||
|
||||
// Vendor Accessors
|
||||
PrimaryIndex<String,Vendor> vendorByName;
|
||||
} </pre>
|
||||
</div>
|
||||
<div class="navfooter">
|
||||
<hr />
|
||||
<table width="100%" summary="Navigation footer">
|
||||
<tr>
|
||||
<td width="40%" align="left"><a accesskey="p" href="mydbenv-persist.html">Prev</a> </td>
|
||||
<td width="20%" align="center">
|
||||
<a accesskey="u" href="dpl_example.html">Up</a>
|
||||
</td>
|
||||
<td width="40%" align="right"> <a accesskey="n" href="dpl_exampledatabaseput.html">Next</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="40%" align="left" valign="top">MyDbEnv </td>
|
||||
<td width="20%" align="center">
|
||||
<a accesskey="h" href="index.html">Home</a>
|
||||
</td>
|
||||
<td width="40%" align="right" valign="top"> ExampleDatabasePut.class</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user