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:35 bostic Exp $
00008  */
00009 
00010 package collections.ship.index;
00011 
00012 import com.sleepycat.bind.EntryBinding;
00013 import com.sleepycat.bind.serial.ClassCatalog;
00014 import com.sleepycat.bind.serial.SerialBinding;
00015 import com.sleepycat.collections.StoredEntrySet;
00016 import com.sleepycat.collections.StoredSortedMap;
00017 
00024 public class SampleViews {
00025 
00026     private StoredSortedMap partMap;
00027     private StoredSortedMap supplierMap;
00028     private StoredSortedMap shipmentMap;
00029     private StoredSortedMap shipmentByPartMap;
00030     private StoredSortedMap shipmentBySupplierMap;
00031     private StoredSortedMap supplierByCityMap;
00032 
00036     public SampleViews(SampleDatabase db) {
00037 
00038         // Create the data bindings.
00039         // In this sample, the stored key and data entries are used directly
00040         // rather than mapping them to separate objects. Therefore, no binding
00041         // classes are defined here and the SerialBinding class is used.
00042         //
00043         ClassCatalog catalog = db.getClassCatalog();
00044         EntryBinding partKeyBinding =
00045             new SerialBinding(catalog, PartKey.class);
00046         EntryBinding partDataBinding =
00047             new SerialBinding(catalog, PartData.class);
00048         EntryBinding supplierKeyBinding =
00049             new SerialBinding(catalog, SupplierKey.class);
00050         EntryBinding supplierDataBinding =
00051             new SerialBinding(catalog, SupplierData.class);
00052         EntryBinding shipmentKeyBinding =
00053             new SerialBinding(catalog, ShipmentKey.class);
00054         EntryBinding shipmentDataBinding =
00055             new SerialBinding(catalog, ShipmentData.class);
00056         EntryBinding cityKeyBinding =
00057             new SerialBinding(catalog, String.class);
00058 
00059         // Create map views for all stores and indices.
00060         // StoredSortedMap is not used since the stores and indices are
00061         // ordered by serialized key objects, which do not provide a very
00062         // useful ordering.
00063         //
00064         partMap =
00065             new StoredSortedMap(db.getPartDatabase(),
00066                                 partKeyBinding, partDataBinding, true);
00067         supplierMap =
00068             new StoredSortedMap(db.getSupplierDatabase(),
00069                                 supplierKeyBinding, supplierDataBinding, true);
00070         shipmentMap =
00071             new StoredSortedMap(db.getShipmentDatabase(),
00072                                 shipmentKeyBinding, shipmentDataBinding, true);
00073         shipmentByPartMap =
00074             new StoredSortedMap(db.getShipmentByPartDatabase(),
00075                                 partKeyBinding, shipmentDataBinding, true);
00076         shipmentBySupplierMap =
00077             new StoredSortedMap(db.getShipmentBySupplierDatabase(),
00078                                 supplierKeyBinding, shipmentDataBinding, true);
00079         supplierByCityMap =
00080             new StoredSortedMap(db.getSupplierByCityDatabase(),
00081                                 cityKeyBinding, supplierDataBinding, true);
00082     }
00083 
00084     // The views returned below can be accessed using the java.util.Map or
00085     // java.util.Set interfaces, or using the StoredSortedMap and
00086     // StoredEntrySet classes, which provide additional methods.  The entry
00087     // sets could be obtained directly from the Map.entrySet() method, but
00088     // convenience methods are provided here to return them in order to avoid
00089     // down-casting elsewhere.
00090 
00094     public final StoredSortedMap getPartMap() {
00095 
00096         return partMap;
00097     }
00098 
00102     public final StoredSortedMap getSupplierMap() {
00103 
00104         return supplierMap;
00105     }
00106 
00110     public final StoredSortedMap getShipmentMap() {
00111 
00112         return shipmentMap;
00113     }
00114 
00118     public final StoredEntrySet getPartEntrySet() {
00119 
00120         return (StoredEntrySet) partMap.entrySet();
00121     }
00122 
00126     public final StoredEntrySet getSupplierEntrySet() {
00127 
00128         return (StoredEntrySet) supplierMap.entrySet();
00129     }
00130 
00134     public final StoredEntrySet getShipmentEntrySet() {
00135 
00136         return (StoredEntrySet) shipmentMap.entrySet();
00137     }
00138 
00142     public StoredSortedMap getShipmentByPartMap() {
00143 
00144         return shipmentByPartMap;
00145     }
00146 
00150     public StoredSortedMap getShipmentBySupplierMap() {
00151 
00152         return shipmentBySupplierMap;
00153     }
00154 
00158     public final StoredSortedMap getSupplierByCityMap() {
00159 
00160         return supplierByCityMap;
00161     }
00162 }

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