Debian Codegraph @

docs/collections/tutorial/removingredundantvalueclasses.html

raw
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>Removing the Redundant Value Classes</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="Berkeley DB Collections Tutorial" />
10 <link rel="up" href="SerializableEntity.html" title="Chapter 6.  Using Serializable Entities" />
11 <link rel="prev" href="transientfieldsinbinding.html" title="Using Transient Fields in an Entity Binding" />
12 <link rel="next" href="Summary.html" title="Chapter 7.  Summary" />
13 </head>
14 <body>
15 <div xmlns="" class="navheader">
16 <div class="libver">
17 <p>Library Version 11.2.5.3</p>
18 </div>
19 <table width="100%" summary="Navigation header">
20 <tr>
21 <th colspan="3" align="center">
22 Removing the Redundant Value Classes
23 </th>
24 </tr>
25 <tr>
26 <td width="20%" align="left"><a accesskey="p" href="transientfieldsinbinding.html">Prev</a> </td>
27 <th width="60%" align="center">Chapter 6. 
28 Using Serializable Entities
29 </th>
30 <td width="20%" align="right"> <a accesskey="n" href="Summary.html">Next</a></td>
31 </tr>
32 </table>
33 <hr />
34 </div>
35 <div class="sect1" lang="en" xml:lang="en">
36 <div class="titlepage">
37 <div>
38 <div>
39 <h2 class="title" style="clear: both"><a id="removingredundantvalueclasses"></a>
40 Removing the Redundant Value Classes
41 </h2>
42 </div>
43 </div>
44 </div>
45 <p>
46 The <code class="classname">PartData</code>, <code class="classname">SupplierData</code> and <code class="classname">ShipmentData</code>
47 classes have been removed in this example, and the <code class="classname">Part</code>,
48 <code class="classname">Supplier</code> and <code class="classname">Shipment</code> entity classes are used in
49 their place.
50 </p>
51 <p>
52 The serial formats are created with the entity classes.
53 </p>
54 <a id="sentity_sampledatabase"></a>
55 <pre class="programlisting">public class SampleDatabase
56 {
57 ...
58 public SampleDatabase(String homeDirectory)
59 throws DatabaseException, FileNotFoundException
60 {
61 ...
62 secConfig.setKeyCreator(new SupplierByCityKeyCreator(javaCatalog,
63 <strong class="userinput"><code>Supplier</code></strong>.class));
64 ...
65 secConfig.setKeyCreator(new ShipmentByPartKeyCreator(javaCatalog,
66 <strong class="userinput"><code>Shipment</code></strong>.class));
67 ...
68 secConfig.setKeyCreator(new
69 ShipmentBySupplierKeyCreator(javaCatalog,
70 <strong class="userinput"><code>Shipment</code></strong>.class));
71 ...
72 }
73 } </pre>
74 <p>
75 The index key creator uses the entity class as well.
76 </p>
77 <a id="sentity_supplierbycitykeycreator"></a>
78 <pre class="programlisting">public class SampleDatabase
79 {
80 ...
81
82 private static class SupplierByCityKeyCreator
83 extends TupleSerialKeyCreator
84 {
85 private SupplierByCityKeyCreator(ClassCatalog catalog,
86 Class valueClass)
87 {
88 super(catalog, valueClass);
89 }
90
91 public boolean createSecondaryKey(TupleInput primaryKeyInput,
92 Object valueInput,
93 TupleOutput indexKeyOutput)
94 {
95 <strong class="userinput"><code>Supplier</code></strong> supplier = (<strong class="userinput"><code>Supplier</code></strong>) valueInput;
96 String city = supplier.getCity();
97 if (city != null) {
98 indexKeyOutput.writeString(supplier.getCity());
99 return true;
100 } else {
101 return false;
102 }
103 }
104 }
105 } </pre>
106 </div>
107 <div class="navfooter">
108 <hr />
109 <table width="100%" summary="Navigation footer">
110 <tr>
111 <td width="40%" align="left"><a accesskey="p" href="transientfieldsinbinding.html">Prev</a> </td>
112 <td width="20%" align="center">
113 <a accesskey="u" href="SerializableEntity.html">Up</a>
114 </td>
115 <td width="40%" align="right"> <a accesskey="n" href="Summary.html">Next</a></td>
116 </tr>
117 <tr>
118 <td width="40%" align="left" valign="top">
119 Using Transient Fields in an Entity Binding
120  </td>
121 <td width="20%" align="center">
122 <a accesskey="h" href="index.html">Home</a>
123 </td>
124 <td width="40%" align="right" valign="top"> Chapter 7. 
125 Summary
126 </td>
127 </tr>
128 </table>
129 </div>
130 </body>
131 </html>