• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/ap/gpl/timemachine/db-4.7.25.NC/docs/collections/tutorial/
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		Using Transient Fields in an Entity Binding
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.��&#10;&#9;&#9;Using Serializable Entities&#10;&#9;" />
13    <link rel="previous" href="SerializableEntity.html" title="Chapter��6.��&#10;&#9;&#9;Using Serializable Entities&#10;&#9;" />
14    <link rel="next" href="removingredundantvalueclasses.html" title="&#10;&#9;&#9;Removing the Redundant Value Classes&#10;&#9;" />
15  </head>
16  <body>
17    <div class="navheader">
18      <table width="100%" summary="Navigation header">
19        <tr>
20          <th colspan="3" align="center">
21		Using Transient Fields in an Entity Binding
22	</th>
23        </tr>
24        <tr>
25          <td width="20%" align="left"><a accesskey="p" href="SerializableEntity.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="removingredundantvalueclasses.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="transientfieldsinbinding"></a>
39		Using Transient Fields in an Entity Binding
40	</h2>
41          </div>
42        </div>
43        <div></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 <tt class="methodname">entryToObject()</tt> 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 <tt class="methodname">objectToData()</tt> 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...
66public 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<b class="userinput"><tt>            Part part = (Part) dataInput;
80            part.setKey(number);
81            return part;</tt></b>
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<b class="userinput"><tt>            return object;</tt></b>
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<b class="userinput"><tt>            Supplier supplier = (Supplier) dataInput;
107            supplier.setKey(number);
108            return supplier;</tt></b>
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<b class="userinput"><tt>            return object;</tt></b>
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<b class="userinput"><tt>            Shipment shipment = (Shipment) dataInput;
135            shipment.setKey(partNumber, supplierNumber);
136            return shipment;</tt></b>
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<b class="userinput"><tt>            return object;</tt></b>
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>
178