001: /*-
002: * See the file LICENSE for redistribution information.
003: *
004: * Copyright (c) 2002,2008 Oracle. All rights reserved.
005: *
006: * $Id: SampleViews.java,v 1.15.2.2 2008/01/07 15:14:01 cwl Exp $
007: */
008:
009: package collections.ship.index;
010:
011: import com.sleepycat.bind.EntryBinding;
012: import com.sleepycat.bind.serial.ClassCatalog;
013: import com.sleepycat.bind.serial.SerialBinding;
014: import com.sleepycat.collections.StoredEntrySet;
015: import com.sleepycat.collections.StoredSortedMap;
016:
017: /**
018: * SampleViews defines the data bindings and collection views for the sample
019: * database.
020: *
021: * @author Mark Hayes
022: */
023: public class SampleViews {
024:
025: private StoredSortedMap partMap;
026: private StoredSortedMap supplierMap;
027: private StoredSortedMap shipmentMap;
028: private StoredSortedMap shipmentByPartMap;
029: private StoredSortedMap shipmentBySupplierMap;
030: private StoredSortedMap supplierByCityMap;
031:
032: /**
033: * Create the data bindings and collection views.
034: */
035: public SampleViews(SampleDatabase db) {
036:
037: // Create the data bindings.
038: // In this sample, the stored key and data entries are used directly
039: // rather than mapping them to separate objects. Therefore, no binding
040: // classes are defined here and the SerialBinding class is used.
041: //
042: ClassCatalog catalog = db.getClassCatalog();
043: EntryBinding partKeyBinding = new SerialBinding(catalog,
044: PartKey.class);
045: EntryBinding partDataBinding = new SerialBinding(catalog,
046: PartData.class);
047: EntryBinding supplierKeyBinding = new SerialBinding(catalog,
048: SupplierKey.class);
049: EntryBinding supplierDataBinding = new SerialBinding(catalog,
050: SupplierData.class);
051: EntryBinding shipmentKeyBinding = new SerialBinding(catalog,
052: ShipmentKey.class);
053: EntryBinding shipmentDataBinding = new SerialBinding(catalog,
054: ShipmentData.class);
055: EntryBinding cityKeyBinding = new SerialBinding(catalog,
056: String.class);
057:
058: // Create map views for all stores and indices.
059: // StoredSortedMap is not used since the stores and indices are
060: // ordered by serialized key objects, which do not provide a very
061: // useful ordering.
062: //
063: partMap = new StoredSortedMap(db.getPartDatabase(),
064: partKeyBinding, partDataBinding, true);
065: supplierMap = new StoredSortedMap(db.getSupplierDatabase(),
066: supplierKeyBinding, supplierDataBinding, true);
067: shipmentMap = new StoredSortedMap(db.getShipmentDatabase(),
068: shipmentKeyBinding, shipmentDataBinding, true);
069: shipmentByPartMap = new StoredSortedMap(db
070: .getShipmentByPartDatabase(), partKeyBinding,
071: shipmentDataBinding, true);
072: shipmentBySupplierMap = new StoredSortedMap(db
073: .getShipmentBySupplierDatabase(), supplierKeyBinding,
074: shipmentDataBinding, true);
075: supplierByCityMap = new StoredSortedMap(db
076: .getSupplierByCityDatabase(), cityKeyBinding,
077: supplierDataBinding, true);
078: }
079:
080: // The views returned below can be accessed using the java.util.Map or
081: // java.util.Set interfaces, or using the StoredSortedMap and
082: // StoredEntrySet classes, which provide additional methods. The entry
083: // sets could be obtained directly from the Map.entrySet() method, but
084: // convenience methods are provided here to return them in order to avoid
085: // down-casting elsewhere.
086:
087: /**
088: * Return a map view of the part storage container.
089: */
090: public final StoredSortedMap getPartMap() {
091:
092: return partMap;
093: }
094:
095: /**
096: * Return a map view of the supplier storage container.
097: */
098: public final StoredSortedMap getSupplierMap() {
099:
100: return supplierMap;
101: }
102:
103: /**
104: * Return a map view of the shipment storage container.
105: */
106: public final StoredSortedMap getShipmentMap() {
107:
108: return shipmentMap;
109: }
110:
111: /**
112: * Return an entry set view of the part storage container.
113: */
114: public final StoredEntrySet getPartEntrySet() {
115:
116: return (StoredEntrySet) partMap.entrySet();
117: }
118:
119: /**
120: * Return an entry set view of the supplier storage container.
121: */
122: public final StoredEntrySet getSupplierEntrySet() {
123:
124: return (StoredEntrySet) supplierMap.entrySet();
125: }
126:
127: /**
128: * Return an entry set view of the shipment storage container.
129: */
130: public final StoredEntrySet getShipmentEntrySet() {
131:
132: return (StoredEntrySet) shipmentMap.entrySet();
133: }
134:
135: /**
136: * Return a map view of the shipment-by-part index.
137: */
138: public StoredSortedMap getShipmentByPartMap() {
139:
140: return shipmentByPartMap;
141: }
142:
143: /**
144: * Return a map view of the shipment-by-supplier index.
145: */
146: public StoredSortedMap getShipmentBySupplierMap() {
147:
148: return shipmentBySupplierMap;
149: }
150:
151: /**
152: * Return a map view of the supplier-by-city index.
153: */
154: public final StoredSortedMap getSupplierByCityMap() {
155:
156: return supplierByCityMap;
157: }
158: }
|