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.14.2.2 2008/01/07 15:14:01 cwl Exp $
007: */
008:
009: package collections.ship.factory;
010:
011: import com.sleepycat.collections.StoredSortedMap;
012: import com.sleepycat.collections.StoredSortedValueSet;
013: import com.sleepycat.collections.TupleSerialFactory;
014:
015: /**
016: * SampleViews defines the data bindings and collection views for the sample
017: * database.
018: *
019: * @author Mark Hayes
020: */
021: public class SampleViews {
022:
023: private StoredSortedMap partMap;
024: private StoredSortedMap supplierMap;
025: private StoredSortedMap shipmentMap;
026: private StoredSortedMap shipmentByPartMap;
027: private StoredSortedMap shipmentBySupplierMap;
028: private StoredSortedMap supplierByCityMap;
029:
030: /**
031: * Create the data bindings and collection views.
032: */
033: public SampleViews(SampleDatabase db) {
034:
035: // Use the TupleSerialFactory for a Serial/Tuple-based database
036: // where marshalling interfaces are used.
037: //
038: TupleSerialFactory factory = db.getFactory();
039:
040: // Create map views for all stores and indices.
041: // StoredSortedMap is used since the stores and indices are ordered
042: // (they use the DB_BTREE access method).
043: //
044: partMap = factory.newSortedMap(db.getPartDatabase(),
045: PartKey.class, Part.class, true);
046: supplierMap = factory.newSortedMap(db.getSupplierDatabase(),
047: SupplierKey.class, Supplier.class, true);
048: shipmentMap = factory.newSortedMap(db.getShipmentDatabase(),
049: ShipmentKey.class, Shipment.class, true);
050: shipmentByPartMap = factory.newSortedMap(db
051: .getShipmentByPartDatabase(), PartKey.class,
052: Shipment.class, true);
053: shipmentBySupplierMap = factory.newSortedMap(db
054: .getShipmentBySupplierDatabase(), SupplierKey.class,
055: Shipment.class, true);
056: supplierByCityMap = factory.newSortedMap(db
057: .getSupplierByCityDatabase(), String.class,
058: Supplier.class, true);
059: }
060:
061: // The views returned below can be accessed using the java.util.Map or
062: // java.util.Set interfaces, or using the StoredMap and StoredValueSet
063: // classes, which provide additional methods. The entity sets could be
064: // obtained directly from the Map.values() method but convenience methods
065: // are provided here to return them in order to avoid down-casting
066: // elsewhere.
067:
068: /**
069: * Return a map view of the part storage container.
070: */
071: public StoredSortedMap getPartMap() {
072:
073: return partMap;
074: }
075:
076: /**
077: * Return a map view of the supplier storage container.
078: */
079: public StoredSortedMap getSupplierMap() {
080:
081: return supplierMap;
082: }
083:
084: /**
085: * Return a map view of the shipment storage container.
086: */
087: public StoredSortedMap getShipmentMap() {
088:
089: return shipmentMap;
090: }
091:
092: /**
093: * Return an entity set view of the part storage container.
094: */
095: public StoredSortedValueSet getPartSet() {
096:
097: return (StoredSortedValueSet) partMap.values();
098: }
099:
100: /**
101: * Return an entity set view of the supplier storage container.
102: */
103: public StoredSortedValueSet getSupplierSet() {
104:
105: return (StoredSortedValueSet) supplierMap.values();
106: }
107:
108: /**
109: * Return an entity set view of the shipment storage container.
110: */
111: public StoredSortedValueSet getShipmentSet() {
112:
113: return (StoredSortedValueSet) shipmentMap.values();
114: }
115:
116: /**
117: * Return a map view of the shipment-by-part index.
118: */
119: public StoredSortedMap getShipmentByPartMap() {
120:
121: return shipmentByPartMap;
122: }
123:
124: /**
125: * Return a map view of the shipment-by-supplier index.
126: */
127: public StoredSortedMap getShipmentBySupplierMap() {
128:
129: return shipmentBySupplierMap;
130: }
131:
132: /**
133: * Return a map view of the supplier-by-city index.
134: */
135: public StoredSortedMap getSupplierByCityMap() {
136:
137: return supplierByCityMap;
138: }
139: }
|