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:23 bostic Exp $
00008  */
00009 
00010 package collections.ship.basic;
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.StoredMap;
00017 
00024 public class SampleViews {
00025 
00026     private StoredMap partMap;
00027     private StoredMap supplierMap;
00028     private StoredMap shipmentMap;
00029 
00033     public SampleViews(SampleDatabase db) {
00034 
00035         // In this sample, the stored key and data entries are used directly
00036         // rather than mapping them to separate objects. Therefore, no binding
00037         // classes are defined here and the SerialBinding class is used.
00038         //
00039         ClassCatalog catalog = db.getClassCatalog();
00040         EntryBinding partKeyBinding =
00041             new SerialBinding(catalog, PartKey.class);
00042         EntryBinding partDataBinding =
00043             new SerialBinding(catalog, PartData.class);
00044         EntryBinding supplierKeyBinding =
00045             new SerialBinding(catalog, SupplierKey.class);
00046         EntryBinding supplierDataBinding =
00047             new SerialBinding(catalog, SupplierData.class);
00048         EntryBinding shipmentKeyBinding =
00049             new SerialBinding(catalog, ShipmentKey.class);
00050         EntryBinding shipmentDataBinding =
00051             new SerialBinding(catalog, ShipmentData.class);
00052 
00053         // Create map views for all stores and indices.
00054         // StoredSortedMap is not used since the stores and indices are
00055         // ordered by serialized key objects, which do not provide a very
00056         // useful ordering.
00057         //
00058         partMap =
00059             new StoredMap(db.getPartDatabase(),
00060                           partKeyBinding, partDataBinding, true);
00061         supplierMap =
00062             new StoredMap(db.getSupplierDatabase(),
00063                           supplierKeyBinding, supplierDataBinding, true);
00064         shipmentMap =
00065             new StoredMap(db.getShipmentDatabase(),
00066                           shipmentKeyBinding, shipmentDataBinding, true);
00067     }
00068 
00069     // The views returned below can be accessed using the java.util.Map or
00070     // java.util.Set interfaces, or using the StoredMap and StoredEntrySet
00071     // classes, which provide additional methods.  The entry sets could be
00072     // obtained directly from the Map.entrySet() method, but convenience
00073     // methods are provided here to return them in order to avoid down-casting
00074     // elsewhere.
00075 
00079     public final StoredMap getPartMap() {
00080 
00081         return partMap;
00082     }
00083 
00087     public final StoredMap getSupplierMap() {
00088 
00089         return supplierMap;
00090     }
00091 
00095     public final StoredMap getShipmentMap() {
00096 
00097         return shipmentMap;
00098     }
00099 
00103     public final StoredEntrySet getPartEntrySet() {
00104 
00105         return (StoredEntrySet) partMap.entrySet();
00106     }
00107 
00111     public final StoredEntrySet getSupplierEntrySet() {
00112 
00113         return (StoredEntrySet) supplierMap.entrySet();
00114     }
00115 
00119     public final StoredEntrySet getShipmentEntrySet() {
00120 
00121         return (StoredEntrySet) shipmentMap.entrySet();
00122     }
00123 }

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