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