Debian Codegraph @

docs/collections/tutorial/transientfieldsinbinding.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>Using Transient Fields in an Entity Binding</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="SerializableEntity.html" title="Chapter 6.  Using Serializable Entities" />
12 <link rel="next" href="removingredundantvalueclasses.html" title="Removing the Redundant Value Classes" />
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 Using Transient Fields in an Entity Binding
23 </th>
24 </tr>
25 <tr>
26 <td width="20%" align="left"><a accesskey="p" href="SerializableEntity.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="removingredundantvalueclasses.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="transientfieldsinbinding"></a>
40 Using Transient Fields in an Entity Binding
41 </h2>
42 </div>
43 </div>
44 </div>
45 <p>
46 The entity bindings from the prior example have been changed in
47 this example to use the entity object both as a value object and an
48 entity object.
49 </p>
50 <p>
51 Before, the <code class="methodname">entryToObject()</code> method combined the
52 deserialized value object with the key fields to create a new
53 entity object. Now, this method uses the deserialized object
54 directly as an entity, and initializes its key using the fields
55 read from the key tuple.
56 </p>
57 <p>
58 Before, the <code class="methodname">objectToData()</code> method constructed a new value
59 object using information in the entity. Now it simply returns the
60 entity. Nothing needs to be changed in the entity, since the
61 transient key fields won't be serialized.
62 </p>
63 <a id="sentity_partbinding"></a>
64 <pre class="programlisting">import com.sleepycat.bind.serial.ClassCatalog;
65 ...
66 public class SampleViews
67 {
68 ...
69 private static class PartBinding extends TupleSerialBinding
70 {
71 private PartBinding(ClassCatalog classCatalog, Class dataClass)
72 {
73 super(classCatalog, dataClass);
74 }
75
76 public Object entryToObject(TupleInput keyInput, Object dataInput)
77 {
78 String number = keyInput.readString();
79 <strong class="userinput"><code> Part part = (Part) dataInput;
80 part.setKey(number);
81 return part;</code></strong>
82 }
83
84 public void objectToKey(Object object, TupleOutput output)
85 {
86 Part part = (Part) object;
87 output.writeString(part.getNumber());
88 }
89
90 public Object objectToData(Object object)
91 {
92 <strong class="userinput"><code> return object;</code></strong>
93 }
94 }
95
96 private static class SupplierBinding extends TupleSerialBinding
97 {
98 private SupplierBinding(ClassCatalog classCatalog, Class dataClass)
99 {
100 super(classCatalog, dataClass);
101 }
102
103 public Object entryToObject(TupleInput keyInput, Object dataInput)
104 {
105 String number = keyInput.readString();
106 <strong class="userinput"><code> Supplier supplier = (Supplier) dataInput;
107 supplier.setKey(number);
108 return supplier;</code></strong>
109 }
110
111 public void objectToKey(Object object, TupleOutput output)
112 {
113 Supplier supplier = (Supplier) object;
114 output.writeString(supplier.getNumber());
115 }
116
117 public Object objectToData(Object object)
118 {
119 <strong class="userinput"><code> return object;</code></strong>
120 }
121 }
122
123 private static class ShipmentBinding extends TupleSerialBinding
124 {
125 private ShipmentBinding(ClassCatalog classCatalog, Class dataClass)
126 {
127 super(classCatalog, dataClass);
128 }
129
130 public Object entryToObject(TupleInput keyInput, Object dataInput)
131 {
132 String partNumber = keyInput.readString();
133 String supplierNumber = keyInput.readString();
134 <strong class="userinput"><code> Shipment shipment = (Shipment) dataInput;
135 shipment.setKey(partNumber, supplierNumber);
136 return shipment;</code></strong>
137 }
138
139 public void objectToKey(Object object, TupleOutput output)
140 {
141 Shipment shipment = (Shipment) object;
142 output.writeString(shipment.getPartNumber());
143 output.writeString(shipment.getSupplierNumber());
144 }
145
146 public Object objectToData(Object object)
147 {
148 <strong class="userinput"><code> return object;</code></strong>
149 }
150 }
151 } </pre>
152 </div>
153 <div class="navfooter">
154 <hr />
155 <table width="100%" summary="Navigation footer">
156 <tr>
157 <td width="40%" align="left"><a accesskey="p" href="SerializableEntity.html">Prev</a> </td>
158 <td width="20%" align="center">
159 <a accesskey="u" href="SerializableEntity.html">Up</a>
160 </td>
161 <td width="40%" align="right"> <a accesskey="n" href="removingredundantvalueclasses.html">Next</a></td>
162 </tr>
163 <tr>
164 <td width="40%" align="left" valign="top">Chapter 6. 
165 Using Serializable Entities
166  </td>
167 <td width="20%" align="center">
168 <a accesskey="h" href="index.html">Home</a>
169 </td>
170 <td width="40%" align="right" valign="top"> 
171 Removing the Redundant Value Classes
172 </td>
173 </tr>
174 </table>
175 </div>
176 </body>
177 </html>