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>Using Sorted Collections</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="Tuple.html" title="Chapter 5. Using Tuples" />
11 <link rel="prev" href="tuple-serialentitybindings.html" title="Creating Tuple-Serial Entity Bindings" />
12 <link rel="next" href="SerializableEntity.html" title="Chapter 6. Using Serializable Entities" />
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 Using Sorted Collections
26 <td width="20%" align="left"><a accesskey="p" href="tuple-serialentitybindings.html">Prev</a> </td>
27 <th width="60%" align="center">Chapter 5.
30 <td width="20%" align="right"> <a accesskey="n" href="SerializableEntity.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="sortedcollections"></a>
40 Using Sorted Collections
46 In general, no changes to the prior example are necessary to use
47 collections having tuple keys. Iteration of elements in a stored
48 collection will be ordered by the sort order of the tuples.
51 In addition to using the tuple format, the
52 <a class="ulink" href="../../java/com/sleepycat/db/DatabaseType.html#BTREE" target="_top">DatabaseType.BTREE</a>
54 access method must be used when creating the database.
55 <a class="ulink" href="../../java/com/sleepycat/db/DatabaseType.html#BTREE" target="_top">DatabaseType.BTREE</a>
57 is used for the databases in all examples. The
58 <a class="ulink" href="../../java/com/sleepycat/db/DatabaseType.html#HASH" target="_top">DatabaseType.HASH</a>
60 access method does not support sorted keys.
63 Although not shown in the example, all methods of the
64 <a class="ulink" href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/SortedMap.html" target="_top">SortedMap</a>
67 <a class="ulink" href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/SortedSet.html" target="_top">SortedSet</a>
69 interfaces may be used with sorted collections. For example,
70 submaps and subsets may be created.
73 The output of the example program shows that records are sorted
76 <pre class="programlisting">Adding Suppliers
81 Part: number=P1 name=Nut color=Red weight=[12.0 grams] city=London
82 Part: number=P2 name=Bolt color=Green weight=[17.0 grams] city=Paris
83 Part: number=P3 name=Screw color=Blue weight=[17.0 grams] city=Rome
84 Part: number=P4 name=Screw color=Red weight=[14.0 grams] city=London
85 Part: number=P5 name=Cam color=Blue weight=[12.0 grams] city=Paris
86 Part: number=P6 name=Cog color=Red weight=[19.0 grams] city=London
89 Supplier: number=S1 name=Smith status=20 city=London
90 Supplier: number=S2 name=Jones status=10 city=Paris
91 Supplier: number=S3 name=Blake status=30 city=Paris
92 Supplier: number=S4 name=Clark status=20 city=London
93 Supplier: number=S5 name=Adams status=30 city=Athens
95 --- Suppliers for City Paris ---
96 Supplier: number=S2 name=Jones status=10 city=Paris
97 Supplier: number=S3 name=Blake status=30 city=Paris
100 Shipment: part=P1 supplier=S1 quantity=300
101 Shipment: part=P1 supplier=S2 quantity=300
102 Shipment: part=P2 supplier=S1 quantity=200
103 Shipment: part=P2 supplier=S2 quantity=400
104 Shipment: part=P2 supplier=S3 quantity=200
105 Shipment: part=P2 supplier=S4 quantity=200
106 Shipment: part=P3 supplier=S1 quantity=400
107 Shipment: part=P4 supplier=S1 quantity=200
108 Shipment: part=P4 supplier=S4 quantity=300
109 Shipment: part=P5 supplier=S1 quantity=100
110 Shipment: part=P5 supplier=S4 quantity=400
111 Shipment: part=P6 supplier=S1 quantity=100
113 --- Shipments for Part P1 ---
114 Shipment: part=P1 supplier=S1 quantity=300
115 Shipment: part=P1 supplier=S2 quantity=300
117 --- Shipments for Supplier S1 ---
118 Shipment: part=P1 supplier=S1 quantity=300
119 Shipment: part=P2 supplier=S1 quantity=200
120 Shipment: part=P3 supplier=S1 quantity=400
121 Shipment: part=P4 supplier=S1 quantity=200
122 Shipment: part=P5 supplier=S1 quantity=100
123 Shipment: part=P6 supplier=S1 quantity=100 </pre>
125 <div class="navfooter">
127 <table width="100%" summary="Navigation footer">
129 <td width="40%" align="left"><a accesskey="p" href="tuple-serialentitybindings.html">Prev</a> </td>
130 <td width="20%" align="center">
131 <a accesskey="u" href="Tuple.html">Up</a>
133 <td width="40%" align="right"> <a accesskey="n" href="SerializableEntity.html">Next</a></td>
136 <td width="40%" align="left" valign="top">
137 Creating Tuple-Serial Entity Bindings
139 <td width="20%" align="center">
140 <a accesskey="h" href="index.html">Home</a>
142 <td width="40%" align="right" valign="top"> Chapter 6.
143 Using Serializable Entities