Debian Codegraph @

docs/collections/tutorial/collectionswithentities.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>Creating Collections with Entity Bindings</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="Entity.html" title="Chapter 4.  Using Entity Classes" />
11 <link rel="prev" href="creatingentitybindings.html" title="Creating Entity Bindings" />
12 <link rel="next" href="entitieswithcollections.html" title="Using Entities with Collections" />
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 Creating Collections with Entity Bindings
23 </th>
24 </tr>
25 <tr>
26 <td width="20%" align="left"><a accesskey="p" href="creatingentitybindings.html">Prev</a> </td>
27 <th width="60%" align="center">Chapter 4. 
28 Using Entity Classes
29 </th>
30 <td width="20%" align="right"> <a accesskey="n" href="entitieswithcollections.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="collectionswithentities"></a>
40 Creating Collections with Entity Bindings
41 </h2>
42 </div>
43 </div>
44 </div>
45 <p>
46 Stored map objects are created in this example in the same way
47 as in prior examples, but using entity bindings in place of value
48 bindings. All value objects passed and returned to the Java
49 collections API are then actually entity objects (<code class="classname">Part</code>,
50 <code class="classname">Supplier</code> and <code class="classname">Shipment</code>). The application no longer
51 deals directly with plain value objects (<code class="classname">PartData</code>,
52 <code class="classname">SupplierData</code> and <code class="classname">ShipmentData</code>).
53 </p>
54 <p>
55 Since the <code class="literal">partValueBinding</code>, <code class="literal">supplierValueBinding</code>
56 and <code class="literal">shipmentValueBinding</code> were defined as entity bindings in
57 the prior section, there are no source code changes necessary for
58 creating the stored map objects.
59 </p>
60 <a id="entity_sampleviews2"></a>
61 <pre class="programlisting">public class SampleViews
62 {
63 ...
64 public SampleViews(SampleDatabase db)
65 {
66 ...
67 partMap =
68 new StoredMap(db.getPartDatabase(),
69 partKeyBinding, partValueBinding, true);
70 supplierMap =
71 new StoredMap(db.getSupplierDatabase(),
72 supplierKeyBinding, supplierValueBinding, true);
73 shipmentMap =
74 new StoredMap(db.getShipmentDatabase(),
75 shipmentKeyBinding, shipmentValueBinding, true);
76 ...
77 } </pre>
78 <p>
79 Specifying an
80 <a class="ulink" href="../../java/com/sleepycat/bind/EntityBinding.html" target="_top">EntityBinding</a>
81
82 will select a different
83 <a class="ulink" href="../../java/com/sleepycat/collections/StoredMap.html" target="_top">StoredMap</a>
84
85 constructor, but the syntax is the same. In general, an entity
86 binding may be used anywhere that a value binding is used.
87 </p>
88 <p>
89 The following getter methods are defined for use by other
90 classes in the example program. Instead of returning the map's
91 entry set
92 (<a class="ulink" href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/Map.html#entrySet()" target="_top">Map.entrySet</a>),
93 the map's value set
94 (<a class="ulink" href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/Map.html#values()" target="_top">Map.values</a>)
95 is returned. The entry set was convenient in prior examples because
96 it allowed enumerating all key/value pairs in the collection. Since
97 an entity contains the key and the value, enumerating the value set
98 can now be used more conveniently for the same purpose.
99 </p>
100 <a id="entity_sampleviews3"></a>
101 <pre class="programlisting"><strong class="userinput"><code>import com.sleepycat.collections.StoredValueSet;</code></strong>
102 ...
103 public class SampleViews
104 {
105 ...
106 <strong class="userinput"><code> public StoredValueSet getPartSet()
107 {
108 return (StoredValueSet) partMap.values();
109 }
110
111 public StoredValueSet getSupplierSet()
112 {
113 return (StoredValueSet) supplierMap.values();
114 }
115
116 public StoredValueSet getShipmentSet()
117 {
118 return (StoredValueSet) shipmentMap.values();
119 }</code></strong>
120 ...
121 } </pre>
122 <p>
123 Notice that the collection returned by the
124 <a class="ulink" href="../../java/com/sleepycat/collections/StoredMap.html#values()" target="_top">StoredMap.values</a>
125
126 method is actually a
127 <a class="ulink" href="../../java/com/sleepycat/collections/StoredValueSet.html" target="_top">StoredValueSet</a>
128
129 and not just a
130 <a class="ulink" href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/Collection.html" target="_top">Collection</a>
131
132 as defined by the
133 <a class="ulink" href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/Map.html#values()" target="_top">Map.values</a>
134
135 interface. As long as duplicate keys are not allowed, this
136 collection will behave as a true set and will disallow the addition
137 of duplicates, etc.
138 </p>
139 </div>
140 <div class="navfooter">
141 <hr />
142 <table width="100%" summary="Navigation footer">
143 <tr>
144 <td width="40%" align="left"><a accesskey="p" href="creatingentitybindings.html">Prev</a> </td>
145 <td width="20%" align="center">
146 <a accesskey="u" href="Entity.html">Up</a>
147 </td>
148 <td width="40%" align="right"> <a accesskey="n" href="entitieswithcollections.html">Next</a></td>
149 </tr>
150 <tr>
151 <td width="40%" align="left" valign="top">
152 Creating Entity Bindings
153  </td>
154 <td width="20%" align="center">
155 <a accesskey="h" href="index.html">Home</a>
156 </td>
157 <td width="40%" align="right" valign="top"> 
158 Using Entities with Collections
159 </td>
160 </tr>
161 </table>
162 </div>
163 </body>
164 </html>