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.73.2" /> 9 <link rel="start" 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="prev" 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> 36 <p> 37 As mentioned above, we organize our primary and 38 secondary indexes using a specialize data 39 accessor class. The main reason for this class 40 to exist is to provide convenient access to all 41 the indexes in use for our entity class (see 42 the previous section, <a class="xref" href="persist_access.html#simpleentity" title="A Simple Entity Class">A Simple Entity Class</a>, for that 43 implementation). 44 </p> 45 <p> 46 For a description on retrieving primary and 47 secondary indexes under the DPL, see 48 <a class="xref" href="persist_index.html" title="Chapter��4.��Working with Indices">Working with Indices</a> 49 </p> 50 <pre class="programlisting">package persist.gettingStarted; 51 52import java.io.File; 53 54import com.sleepycat.db.DatabaseException; 55import com.sleepycat.persist.EntityStore; 56import com.sleepycat.persist.PrimaryIndex; 57import com.sleepycat.persist.SecondaryIndex; 58 59public class SimpleDA { 60 // Open the indices 61 public SimpleDA(EntityStore store) 62 throws DatabaseException { 63 64 // Primary key for SimpleEntityClass classes 65 pIdx = store.getPrimaryIndex( 66 String.class, SimpleEntityClass.class); 67 68 // Secondary key for SimpleEntityClass classes 69 // Last field in the getSecondaryIndex() method must be 70 // the name of a class member; in this case, an 71 // SimpleEntityClass.class data member. 72 sIdx = store.getSecondaryIndex( 73 pIdx, String.class, "sKey"); 74 } 75 76 // Index Accessors 77 PrimaryIndex<String,SimpleEntityClass> pIdx; 78 SecondaryIndex<String,String,SimpleEntityClass> sIdx; 79} </pre> 80 </div> 81 <div class="navfooter"> 82 <hr /> 83 <table width="100%" summary="Navigation footer"> 84 <tr> 85 <td width="40%" align="left"><a accesskey="p" href="persist_access.html">Prev</a>��</td> 86 <td width="20%" align="center"> 87 <a accesskey="u" href="persist_access.html">Up</a> 88 </td> 89 <td width="40%" align="right">��<a accesskey="n" href="simpleput.html">Next</a></td> 90 </tr> 91 <tr> 92 <td width="40%" align="left" valign="top">Chapter��5.��Saving and Retrieving Objects��</td> 93 <td width="20%" align="center"> 94 <a accesskey="h" href="index.html">Home</a> 95 </td> 96 <td width="40%" align="right" valign="top">��Placing Objects in an Entity Store</td> 97 </tr> 98 </table> 99 </div> 100 </body> 101</html> 102