Imported Upstream version 5.3.21
[platform/upstream/libdb.git] / docs / collections / tutorial / sortedcollections.html
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 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" />
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 Sorted Collections
23         </th>
24         </tr>
25         <tr>
26           <td width="20%" align="left"><a accesskey="p" href="tuple-serialentitybindings.html">Prev</a> </td>
27           <th width="60%" align="center">Chapter 5. 
28                 Using Tuples
29         </th>
30           <td width="20%" align="right"> <a accesskey="n" href="SerializableEntity.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="sortedcollections"></a>
40                 Using Sorted Collections
41         </h2>
42           </div>
43         </div>
44       </div>
45       <p>
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.
49 </p>
50       <p>
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>
53         
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>
56         
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>
59         
60     access method does not support sorted keys.
61 </p>
62       <p>
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>
65     
66         and 
67     <a class="ulink" href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/SortedSet.html" target="_top">SortedSet</a>
68     
69         interfaces may be used with sorted collections. For example,
70         submaps and subsets may be created.
71 </p>
72       <p>
73     The output of the example program shows that records are sorted
74         by key value.
75 </p>
76       <pre class="programlisting">Adding Suppliers
77 Adding Parts
78 Adding Shipments
79
80 --- Parts ---
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
87
88 --- Suppliers ---
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
94
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
98
99 --- Shipments ---
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
112
113 --- Shipments for Part P1 ---
114 Shipment: part=P1 supplier=S1 quantity=300
115 Shipment: part=P1 supplier=S2 quantity=300
116
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>
124     </div>
125     <div class="navfooter">
126       <hr />
127       <table width="100%" summary="Navigation footer">
128         <tr>
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>
132           </td>
133           <td width="40%" align="right"> <a accesskey="n" href="SerializableEntity.html">Next</a></td>
134         </tr>
135         <tr>
136           <td width="40%" align="left" valign="top">
137 Creating Tuple-Serial Entity Bindings
138  </td>
139           <td width="20%" align="center">
140             <a accesskey="h" href="index.html">Home</a>
141           </td>
142           <td width="40%" align="right" valign="top"> Chapter 6. 
143                 Using Serializable Entities
144         </td>
145         </tr>
146       </table>
147     </div>
148   </body>
149 </html>