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:00 cwl Exp $
007: */
008:
009: package collections.ship.basic;
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.StoredMap;
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 StoredMap partMap;
026: private StoredMap supplierMap;
027: private StoredMap shipmentMap;
028:
029: /**
030: * Create the data bindings and collection views.
031: */
032: public SampleViews(SampleDatabase db) {
033:
034: // In this sample, the stored key and data entries are used directly
035: // rather than mapping them to separate objects. Therefore, no binding
036: // classes are defined here and the SerialBinding class is used.
037: //
038: ClassCatalog catalog = db.getClassCatalog();
039: EntryBinding partKeyBinding = new SerialBinding(catalog,
040: PartKey.class);
041: EntryBinding partDataBinding = new SerialBinding(catalog,
042: PartData.class);
043: EntryBinding supplierKeyBinding = new SerialBinding(catalog,
044: SupplierKey.class);
045: EntryBinding supplierDataBinding = new SerialBinding(catalog,
046: SupplierData.class);
047: EntryBinding shipmentKeyBinding = new SerialBinding(catalog,
048: ShipmentKey.class);
049: EntryBinding shipmentDataBinding = new SerialBinding(catalog,
050: ShipmentData.class);
051:
052: // Create map views for all stores and indices.
053: // StoredSortedMap is not used since the stores and indices are
054: // ordered by serialized key objects, which do not provide a very
055: // useful ordering.
056: //
057: partMap = new StoredMap(db.getPartDatabase(), partKeyBinding,
058: partDataBinding, true);
059: supplierMap = new StoredMap(db.getSupplierDatabase(),
060: supplierKeyBinding, supplierDataBinding, true);
061: shipmentMap = new StoredMap(db.getShipmentDatabase(),
062: shipmentKeyBinding, shipmentDataBinding, true);
063: }
064:
065: // The views returned below can be accessed using the java.util.Map or
066: // java.util.Set interfaces, or using the StoredMap and StoredEntrySet
067: // classes, which provide additional methods. The entry sets could be
068: // obtained directly from the Map.entrySet() method, but convenience
069: // methods are provided here to return them in order to avoid down-casting
070: // elsewhere.
071:
072: /**
073: * Return a map view of the part storage container.
074: */
075: public final StoredMap getPartMap() {
076:
077: return partMap;
078: }
079:
080: /**
081: * Return a map view of the supplier storage container.
082: */
083: public final StoredMap getSupplierMap() {
084:
085: return supplierMap;
086: }
087:
088: /**
089: * Return a map view of the shipment storage container.
090: */
091: public final StoredMap getShipmentMap() {
092:
093: return shipmentMap;
094: }
095:
096: /**
097: * Return an entry set view of the part storage container.
098: */
099: public final StoredEntrySet getPartEntrySet() {
100:
101: return (StoredEntrySet) partMap.entrySet();
102: }
103:
104: /**
105: * Return an entry set view of the supplier storage container.
106: */
107: public final StoredEntrySet getSupplierEntrySet() {
108:
109: return (StoredEntrySet) supplierMap.entrySet();
110: }
111:
112: /**
113: * Return an entry set view of the shipment storage container.
114: */
115: public final StoredEntrySet getShipmentEntrySet() {
116:
117: return (StoredEntrySet) shipmentMap.entrySet();
118: }
119: }
|