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>Saving a Retrieving Data</title>
7    <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
8    <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
9    <link rel="start" href="index.html" title="Getting Started with Berkeley DB" />
10    <link rel="up" href="persist_first.html" title="Chapter��3.��Direct Persistence Layer First Steps" />
11    <link rel="prev" href="persistobject.html" title="Persistent Objects" />
12    <link rel="next" href="persist_index.html" title="Chapter��4.��Working with Indices" />
13  </head>
14  <body>
15    <div class="navheader">
16      <table width="100%" summary="Navigation header">
17        <tr>
18          <th colspan="3" align="center">Saving a Retrieving Data</th>
19        </tr>
20        <tr>
21          <td width="20%" align="left"><a accesskey="p" href="persistobject.html">Prev</a>��</td>
22          <th width="60%" align="center">Chapter��3.��Direct Persistence Layer First Steps</th>
23          <td width="20%" align="right">��<a accesskey="n" href="persist_index.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="saveret"></a>Saving a Retrieving Data</h2>
33          </div>
34        </div>
35      </div>
36      <p>
37                  All data stored using the DPL has one primary index and
38                  zero or more secondary indices associated with it.
39                  (Sometimes these are referred to as the primary and
40                  secondary <span class="emphasis"><em>keys</em></span>.) So to store data under the DPL, you must:
41          </p>
42      <div class="orderedlist">
43        <ol type="1">
44          <li>
45            <p>
46                                  Declare a class to be an entity class.
47                          </p>
48          </li>
49          <li>
50            <p>
51                                  Identify the features on the class which
52                                  represent indexed material.
53                          </p>
54          </li>
55          <li>
56            <p>
57                                  Retrieve the store's primary index for a
58                                  given class using the
59                                  <code class="methodname">EntityStore.getPrimaryIndex()</code>
60                                  method.
61                          </p>
62          </li>
63          <li>
64            <p>
65                                  Put class objects to the store using the
66                                  <code class="methodname">PrimaryIndex.put()</code>
67                                  method.
68                          </p>
69          </li>
70        </ol>
71      </div>
72      <p>
73                  In order to retrieve an object from the store, you use
74                  the index that is most convenient for your purpose. This
75                  may be the primary index, or it may be some other
76                  secondary index that you declared on your entity class.
77          </p>
78      <p>
79                  You obtain a primary index in the same was as when you
80                  put the object to the store: using
81                  <code class="methodname">EntityStore.getPrimaryIndex()</code>.
82                  You can get a secondary index for the store using the
83                  <code class="methodname">EntityStore.getSecondaryIndex()</code>
84                  method. Note that
85                  <code class="methodname">getSecondaryIndex()</code> requires you
86                  to provide a <code class="classname">PrimaryIndex</code> class
87                  instance when you call it, so a class's primary index is
88                  always required when retrieving objects from an entity
89                  store.
90          </p>
91      <p>
92                  Usually all of the activity surrounding saving and
93                  retrieving data is organized within a class or classes
94                  specialized to that purpose. We describe the construction
95                  of these data accessor classes in <a class="xref" href="simpleda.html" title="SimpleDA.class">SimpleDA.class</a>. But before you perform
96                  any entity store activity, you need to understand
97                  indexes. We therefore describe them in the next chapter.
98          </p>
99    </div>
100    <div class="navfooter">
101      <hr />
102      <table width="100%" summary="Navigation footer">
103        <tr>
104          <td width="40%" align="left"><a accesskey="p" href="persistobject.html">Prev</a>��</td>
105          <td width="20%" align="center">
106            <a accesskey="u" href="persist_first.html">Up</a>
107          </td>
108          <td width="40%" align="right">��<a accesskey="n" href="persist_index.html">Next</a></td>
109        </tr>
110        <tr>
111          <td width="40%" align="left" valign="top">Persistent Objects��</td>
112          <td width="20%" align="center">
113            <a accesskey="h" href="index.html">Home</a>
114          </td>
115          <td width="40%" align="right" valign="top">��Chapter��4.��Working with Indices</td>
116        </tr>
117      </table>
118    </div>
119  </body>
120</html>
121