1<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml">
4  <head>
5    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6    <title>SimpleDA.class</title>
7    <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
8    <meta name="generator" content="DocBook XSL Stylesheets V1.62.4" />
9    <link rel="home" href="index.html" title="Getting Started with Berkeley DB" />
10    <link rel="up" href="persist_access.html" title="Chapter��5.��Saving and Retrieving Objects" />
11    <link rel="previous" href="persist_access.html" title="Chapter��5.��Saving and Retrieving Objects" />
12    <link rel="next" href="simpleput.html" title="Placing Objects in an Entity Store" />
13  </head>
14  <body>
15    <div class="navheader">
16      <table width="100%" summary="Navigation header">
17        <tr>
18          <th colspan="3" align="center">SimpleDA.class</th>
19        </tr>
20        <tr>
21          <td width="20%" align="left"><a accesskey="p" href="persist_access.html">Prev</a>��</td>
22          <th width="60%" align="center">Chapter��5.��Saving and Retrieving Objects</th>
23          <td width="20%" align="right">��<a accesskey="n" href="simpleput.html">Next</a></td>
24        </tr>
25      </table>
26      <hr />
27    </div>
28    <div class="sect1" lang="en" xml:lang="en">
29      <div class="titlepage">
30        <div>
31          <div>
32            <h2 class="title" style="clear: both"><a id="simpleda"></a>SimpleDA.class</h2>
33          </div>
34        </div>
35        <div></div>
36      </div>
37      <p>
38                            As mentioned above, we organize our primary and
39                            secondary indexes using a specialize data
40                            accessor class. The main reason for this class
41                            to exist is to provide convenient access to all
42                            the indexes in use for our entity class (see
43                            the previous section, <a href="persist_access.html#simpleentity">A Simple Entity Class</a>, for that
44                            implementation).
45                    </p>
46      <p>
47                            For a description on retrieving primary and
48                            secondary indexes under the DPL, see
49                            <a href="persist_index.html">Working with Indices</a>
50                    </p>
51      <pre class="programlisting">package persist.gettingStarted;
52
53import java.io.File;
54
55import com.sleepycat.db.DatabaseException;
56import com.sleepycat.persist.EntityStore;
57import com.sleepycat.persist.PrimaryIndex;
58import com.sleepycat.persist.SecondaryIndex;
59
60public class SimpleDA {
61    // Open the indices
62    public SimpleDA(EntityStore store)
63        throws DatabaseException {
64
65        // Primary key for SimpleEntityClass classes
66        pIdx = store.getPrimaryIndex(
67            String.class, SimpleEntityClass.class);
68
69        // Secondary key for SimpleEntityClass classes
70        // Last field in the getSecondaryIndex() method must be
71        // the name of a class member; in this case, an 
72        // SimpleEntityClass.class data member.
73        sIdx = store.getSecondaryIndex(
74            pIdx, String.class, "sKey");
75    }
76
77    // Index Accessors
78    PrimaryIndex&lt;String,SimpleEntityClass&gt; pIdx;
79    SecondaryIndex&lt;String,String,SimpleEntityClass&gt; sIdx;
80} </pre>
81    </div>
82    <div class="navfooter">
83      <hr />
84      <table width="100%" summary="Navigation footer">
85        <tr>
86          <td width="40%" align="left"><a accesskey="p" href="persist_access.html">Prev</a>��</td>
87          <td width="20%" align="center">
88            <a accesskey="u" href="persist_access.html">Up</a>
89          </td>
90          <td width="40%" align="right">��<a accesskey="n" href="simpleput.html">Next</a></td>
91        </tr>
92        <tr>
93          <td width="40%" align="left" valign="top">Chapter��5.��Saving and Retrieving Objects��</td>
94          <td width="20%" align="center">
95            <a accesskey="h" href="index.html">Home</a>
96          </td>
97          <td width="40%" align="right" valign="top">��Placing Objects in an Entity Store</td>
98        </tr>
99      </table>
100    </div>
101  </body>
102</html>
103