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">
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" />
15 <div xmlns="" class="navheader">
17 <p>Library Version 11.2.5.3</p>
19 <table width="100%" summary="Navigation header">
21 <th colspan="3" align="center">
22 Creating Collections with Entity Bindings
26 <td width="20%" align="left"><a accesskey="p" href="creatingentitybindings.html">Prev</a> </td>
27 <th width="60%" align="center">Chapter 4.
30 <td width="20%" align="right"> <a accesskey="n" href="entitieswithcollections.html">Next</a></td>
35 <div class="sect1" lang="en" xml:lang="en">
36 <div class="titlepage">
39 <h2 class="title" style="clear: both"><a id="collectionswithentities"></a>
40 Creating Collections with Entity Bindings
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>).
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.
60 <a id="entity_sampleviews2"></a>
61 <pre class="programlisting">public class SampleViews
64 public SampleViews(SampleDatabase db)
68 new StoredMap(db.getPartDatabase(),
69 partKeyBinding, partValueBinding, true);
71 new StoredMap(db.getSupplierDatabase(),
72 supplierKeyBinding, supplierValueBinding, true);
74 new StoredMap(db.getShipmentDatabase(),
75 shipmentKeyBinding, shipmentValueBinding, true);
80 <a class="ulink" href="../../java/com/sleepycat/bind/EntityBinding.html" target="_top">EntityBinding</a>
82 will select a different
83 <a class="ulink" href="../../java/com/sleepycat/collections/StoredMap.html" target="_top">StoredMap</a>
85 constructor, but the syntax is the same. In general, an entity
86 binding may be used anywhere that a value binding is used.
89 The following getter methods are defined for use by other
90 classes in the example program. Instead of returning the map's
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>),
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.
100 <a id="entity_sampleviews3"></a>
101 <pre class="programlisting"><strong class="userinput"><code>import com.sleepycat.collections.StoredValueSet;</code></strong>
103 public class SampleViews
106 <strong class="userinput"><code> public StoredValueSet getPartSet()
108 return (StoredValueSet) partMap.values();
111 public StoredValueSet getSupplierSet()
113 return (StoredValueSet) supplierMap.values();
116 public StoredValueSet getShipmentSet()
118 return (StoredValueSet) shipmentMap.values();
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>
127 <a class="ulink" href="../../java/com/sleepycat/collections/StoredValueSet.html" target="_top">StoredValueSet</a>
130 <a class="ulink" href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/Collection.html" target="_top">Collection</a>
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>
135 interface. As long as duplicate keys are not allowed, this
136 collection will behave as a true set and will disallow the addition
140 <div class="navfooter">
142 <table width="100%" summary="Navigation footer">
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>
148 <td width="40%" align="right"> <a accesskey="n" href="entitieswithcollections.html">Next</a></td>
151 <td width="40%" align="left" valign="top">
152 Creating Entity Bindings
154 <td width="20%" align="center">
155 <a accesskey="h" href="index.html">Home</a>
157 <td width="40%" align="right" valign="top">
158 Using Entities with Collections