2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved.
9 package collections.ship.basic;
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.StoredMap;
18 * SampleViews defines the data bindings and collection views for the sample
23 public class SampleViews {
25 private StoredMap partMap;
26 private StoredMap supplierMap;
27 private StoredMap shipmentMap;
30 * Create the data bindings and collection views.
32 public SampleViews(SampleDatabase db) {
34 // In this sample, the stored key and data entries are used directly
35 // rather than mapping them to separate objects. Therefore, no binding
36 // classes are defined here and the SerialBinding class is used.
38 ClassCatalog catalog = db.getClassCatalog();
39 EntryBinding partKeyBinding =
40 new SerialBinding(catalog, PartKey.class);
41 EntryBinding partDataBinding =
42 new SerialBinding(catalog, PartData.class);
43 EntryBinding supplierKeyBinding =
44 new SerialBinding(catalog, SupplierKey.class);
45 EntryBinding supplierDataBinding =
46 new SerialBinding(catalog, SupplierData.class);
47 EntryBinding shipmentKeyBinding =
48 new SerialBinding(catalog, ShipmentKey.class);
49 EntryBinding shipmentDataBinding =
50 new SerialBinding(catalog, ShipmentData.class);
52 // Create map views for all stores and indices.
53 // StoredSortedMap is not used since the stores and indices are
54 // ordered by serialized key objects, which do not provide a very
58 new StoredMap(db.getPartDatabase(),
59 partKeyBinding, partDataBinding, true);
61 new StoredMap(db.getSupplierDatabase(),
62 supplierKeyBinding, supplierDataBinding, true);
64 new StoredMap(db.getShipmentDatabase(),
65 shipmentKeyBinding, shipmentDataBinding, true);
68 // The views returned below can be accessed using the java.util.Map or
69 // java.util.Set interfaces, or using the StoredMap and StoredEntrySet
70 // classes, which provide additional methods. The entry sets could be
71 // obtained directly from the Map.entrySet() method, but convenience
72 // methods are provided here to return them in order to avoid down-casting
76 * Return a map view of the part storage container.
78 public final StoredMap getPartMap() {
84 * Return a map view of the supplier storage container.
86 public final StoredMap getSupplierMap() {
92 * Return a map view of the shipment storage container.
94 public final StoredMap getShipmentMap() {
100 * Return an entry set view of the part storage container.
102 public final StoredEntrySet getPartEntrySet() {
104 return (StoredEntrySet) partMap.entrySet();
108 * Return an entry set view of the supplier storage container.
110 public final StoredEntrySet getSupplierEntrySet() {
112 return (StoredEntrySet) supplierMap.entrySet();
116 * Return an entry set view of the shipment storage container.
118 public final StoredEntrySet getShipmentEntrySet() {
120 return (StoredEntrySet) shipmentMap.entrySet();