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