KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > collections > ship > index > SampleViews


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: SampleViews.java,v 1.15 2006/10/30 21:13:59 bostic Exp $
7  */

8
9 package collections.ship.index;
10
11 import com.sleepycat.bind.EntryBinding;
12 import com.sleepycat.bind.serial.ClassCatalog;
13 import com.sleepycat.bind.serial.SerialBinding;
14 import com.sleepycat.collections.StoredEntrySet;
15 import com.sleepycat.collections.StoredSortedMap;
16
17 /**
18  * SampleViews defines the data bindings and collection views for the sample
19  * database.
20  *
21  * @author Mark Hayes
22  */

23 public class SampleViews {
24
25     private StoredSortedMap partMap;
26     private StoredSortedMap supplierMap;
27     private StoredSortedMap shipmentMap;
28     private StoredSortedMap shipmentByPartMap;
29     private StoredSortedMap shipmentBySupplierMap;
30     private StoredSortedMap supplierByCityMap;
31
32     /**
33      * Create the data bindings and collection views.
34      */

35     public SampleViews(SampleDatabase db) {
36
37         // Create the data bindings.
38
// In this sample, the stored key and data entries are used directly
39
// rather than mapping them to separate objects. Therefore, no binding
40
// classes are defined here and the SerialBinding class is used.
41
//
42
ClassCatalog catalog = db.getClassCatalog();
43         EntryBinding partKeyBinding =
44             new SerialBinding(catalog, PartKey.class);
45         EntryBinding partDataBinding =
46             new SerialBinding(catalog, PartData.class);
47         EntryBinding supplierKeyBinding =
48             new SerialBinding(catalog, SupplierKey.class);
49         EntryBinding supplierDataBinding =
50             new SerialBinding(catalog, SupplierData.class);
51         EntryBinding shipmentKeyBinding =
52             new SerialBinding(catalog, ShipmentKey.class);
53         EntryBinding shipmentDataBinding =
54             new SerialBinding(catalog, ShipmentData.class);
55         EntryBinding cityKeyBinding =
56             new SerialBinding(catalog, String JavaDoc.class);
57
58         // Create map views for all stores and indices.
59
// StoredSortedMap is not used since the stores and indices are
60
// ordered by serialized key objects, which do not provide a very
61
// useful ordering.
62
//
63
partMap =
64             new StoredSortedMap(db.getPartDatabase(),
65                                 partKeyBinding, partDataBinding, true);
66         supplierMap =
67             new StoredSortedMap(db.getSupplierDatabase(),
68                                 supplierKeyBinding, supplierDataBinding, true);
69         shipmentMap =
70             new StoredSortedMap(db.getShipmentDatabase(),
71                                 shipmentKeyBinding, shipmentDataBinding, true);
72         shipmentByPartMap =
73             new StoredSortedMap(db.getShipmentByPartDatabase(),
74                                 partKeyBinding, shipmentDataBinding, true);
75         shipmentBySupplierMap =
76             new StoredSortedMap(db.getShipmentBySupplierDatabase(),
77                                 supplierKeyBinding, shipmentDataBinding, true);
78         supplierByCityMap =
79             new StoredSortedMap(db.getSupplierByCityDatabase(),
80                                 cityKeyBinding, supplierDataBinding, true);
81     }
82
83     // The views returned below can be accessed using the java.util.Map or
84
// java.util.Set interfaces, or using the StoredSortedMap and
85
// StoredEntrySet classes, which provide additional methods. The entry
86
// sets could be obtained directly from the Map.entrySet() method, but
87
// convenience methods are provided here to return them in order to avoid
88
// down-casting elsewhere.
89

90     /**
91      * Return a map view of the part storage container.
92      */

93     public final StoredSortedMap getPartMap() {
94
95         return partMap;
96     }
97
98     /**
99      * Return a map view of the supplier storage container.
100      */

101     public final StoredSortedMap getSupplierMap() {
102
103         return supplierMap;
104     }
105
106     /**
107      * Return a map view of the shipment storage container.
108      */

109     public final StoredSortedMap getShipmentMap() {
110
111         return shipmentMap;
112     }
113
114     /**
115      * Return an entry set view of the part storage container.
116      */

117     public final StoredEntrySet getPartEntrySet() {
118
119         return (StoredEntrySet) partMap.entrySet();
120     }
121
122     /**
123      * Return an entry set view of the supplier storage container.
124      */

125     public final StoredEntrySet getSupplierEntrySet() {
126
127         return (StoredEntrySet) supplierMap.entrySet();
128     }
129
130     /**
131      * Return an entry set view of the shipment storage container.
132      */

133     public final StoredEntrySet getShipmentEntrySet() {
134
135         return (StoredEntrySet) shipmentMap.entrySet();
136     }
137
138     /**
139      * Return a map view of the shipment-by-part index.
140      */

141     public StoredSortedMap getShipmentByPartMap() {
142
143         return shipmentByPartMap;
144     }
145
146     /**
147      * Return a map view of the shipment-by-supplier index.
148      */

149     public StoredSortedMap getShipmentBySupplierMap() {
150
151         return shipmentBySupplierMap;
152     }
153
154     /**
155      * Return a map view of the supplier-by-city index.
156      */

157     public final StoredSortedMap getSupplierByCityMap() {
158
159         return supplierByCityMap;
160     }
161 }
162
Popular Tags