Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

SampleViews.java

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 2002-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: SampleViews.java,v 12.2 2005/06/16 20:22:32 bostic Exp $
00008  */
00009 
00010 package collections.ship.factory;
00011 
00012 import com.sleepycat.collections.StoredSortedMap;
00013 import com.sleepycat.collections.StoredSortedValueSet;
00014 import com.sleepycat.collections.TupleSerialFactory;
00015 
00022 public class SampleViews {
00023 
00024     private StoredSortedMap partMap;
00025     private StoredSortedMap supplierMap;
00026     private StoredSortedMap shipmentMap;
00027     private StoredSortedMap shipmentByPartMap;
00028     private StoredSortedMap shipmentBySupplierMap;
00029     private StoredSortedMap supplierByCityMap;
00030 
00034     public SampleViews(SampleDatabase db) {
00035 
00036         // Use the TupleSerialFactory for a Serial/Tuple-based database
00037         // where marshalling interfaces are used.
00038         //
00039         TupleSerialFactory factory = db.getFactory();
00040 
00041         // Create map views for all stores and indices.
00042         // StoredSortedMap is used since the stores and indices are ordered
00043         // (they use the DB_BTREE access method).
00044         //
00045         partMap =
00046             factory.newSortedMap(db.getPartDatabase(),
00047                                  PartKey.class, Part.class, true);
00048         supplierMap =
00049             factory.newSortedMap(db.getSupplierDatabase(),
00050                                  SupplierKey.class, Supplier.class, true);
00051         shipmentMap =
00052             factory.newSortedMap(db.getShipmentDatabase(),
00053                                  ShipmentKey.class, Shipment.class, true);
00054         shipmentByPartMap =
00055             factory.newSortedMap(db.getShipmentByPartDatabase(),
00056                                  PartKey.class, Shipment.class, true);
00057         shipmentBySupplierMap =
00058             factory.newSortedMap(db.getShipmentBySupplierDatabase(),
00059                                  SupplierKey.class, Shipment.class, true);
00060         supplierByCityMap =
00061             factory.newSortedMap(db.getSupplierByCityDatabase(),
00062                                  String.class, Supplier.class, true);
00063     }
00064 
00065     // The views returned below can be accessed using the java.util.Map or
00066     // java.util.Set interfaces, or using the StoredMap and StoredValueSet
00067     // classes, which provide additional methods.  The entity sets could be
00068     // obtained directly from the Map.values() method but convenience methods
00069     // are provided here to return them in order to avoid down-casting
00070     // elsewhere.
00071 
00075     public StoredSortedMap getPartMap() {
00076 
00077         return partMap;
00078     }
00079 
00083     public StoredSortedMap getSupplierMap() {
00084 
00085         return supplierMap;
00086     }
00087 
00091     public StoredSortedMap getShipmentMap() {
00092 
00093         return shipmentMap;
00094     }
00095 
00099     public StoredSortedValueSet getPartSet() {
00100 
00101         return (StoredSortedValueSet) partMap.values();
00102     }
00103 
00107     public StoredSortedValueSet getSupplierSet() {
00108 
00109         return (StoredSortedValueSet) supplierMap.values();
00110     }
00111 
00115     public StoredSortedValueSet getShipmentSet() {
00116 
00117         return (StoredSortedValueSet) shipmentMap.values();
00118     }
00119 
00123     public StoredSortedMap getShipmentByPartMap() {
00124 
00125         return shipmentByPartMap;
00126     }
00127 
00131     public StoredSortedMap getShipmentBySupplierMap() {
00132 
00133         return shipmentBySupplierMap;
00134     }
00135 
00139     public StoredSortedMap getSupplierByCityMap() {
00140 
00141         return supplierByCityMap;
00142     }
00143 }

Generated on Sun Dec 25 12:14:27 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2