1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2002,2008 Oracle. All rights reserved. 5 * 6 * $Id: SampleViews.java,v 12.7 2008/01/08 20:58:29 bostic Exp $ 7 */ 8 9package collections.ship.factory; 10 11import com.sleepycat.collections.StoredSortedMap; 12import com.sleepycat.collections.StoredSortedValueSet; 13import com.sleepycat.collections.TupleSerialFactory; 14 15/** 16 * SampleViews defines the data bindings and collection views for the sample 17 * database. 18 * 19 * @author Mark Hayes 20 */ 21public class SampleViews { 22 23 private StoredSortedMap partMap; 24 private StoredSortedMap supplierMap; 25 private StoredSortedMap shipmentMap; 26 private StoredSortedMap shipmentByPartMap; 27 private StoredSortedMap shipmentBySupplierMap; 28 private StoredSortedMap supplierByCityMap; 29 30 /** 31 * Create the data bindings and collection views. 32 */ 33 public SampleViews(SampleDatabase db) { 34 35 // Use the TupleSerialFactory for a Serial/Tuple-based database 36 // where marshalling interfaces are used. 37 // 38 TupleSerialFactory factory = db.getFactory(); 39 40 // Create map views for all stores and indices. 41 // StoredSortedMap is used since the stores and indices are ordered 42 // (they use the DB_BTREE access method). 43 // 44 partMap = 45 factory.newSortedMap(db.getPartDatabase(), 46 PartKey.class, Part.class, true); 47 supplierMap = 48 factory.newSortedMap(db.getSupplierDatabase(), 49 SupplierKey.class, Supplier.class, true); 50 shipmentMap = 51 factory.newSortedMap(db.getShipmentDatabase(), 52 ShipmentKey.class, Shipment.class, true); 53 shipmentByPartMap = 54 factory.newSortedMap(db.getShipmentByPartDatabase(), 55 PartKey.class, Shipment.class, true); 56 shipmentBySupplierMap = 57 factory.newSortedMap(db.getShipmentBySupplierDatabase(), 58 SupplierKey.class, Shipment.class, true); 59 supplierByCityMap = 60 factory.newSortedMap(db.getSupplierByCityDatabase(), 61 String.class, Supplier.class, true); 62 } 63 64 // The views returned below can be accessed using the java.util.Map or 65 // java.util.Set interfaces, or using the StoredMap and StoredValueSet 66 // classes, which provide additional methods. The entity sets could be 67 // obtained directly from the Map.values() method but convenience methods 68 // are provided here to return them in order to avoid down-casting 69 // elsewhere. 70 71 /** 72 * Return a map view of the part storage container. 73 */ 74 public StoredSortedMap getPartMap() { 75 76 return partMap; 77 } 78 79 /** 80 * Return a map view of the supplier storage container. 81 */ 82 public StoredSortedMap getSupplierMap() { 83 84 return supplierMap; 85 } 86 87 /** 88 * Return a map view of the shipment storage container. 89 */ 90 public StoredSortedMap getShipmentMap() { 91 92 return shipmentMap; 93 } 94 95 /** 96 * Return an entity set view of the part storage container. 97 */ 98 public StoredSortedValueSet getPartSet() { 99 100 return (StoredSortedValueSet) partMap.values(); 101 } 102 103 /** 104 * Return an entity set view of the supplier storage container. 105 */ 106 public StoredSortedValueSet getSupplierSet() { 107 108 return (StoredSortedValueSet) supplierMap.values(); 109 } 110 111 /** 112 * Return an entity set view of the shipment storage container. 113 */ 114 public StoredSortedValueSet getShipmentSet() { 115 116 return (StoredSortedValueSet) shipmentMap.values(); 117 } 118 119 /** 120 * Return a map view of the shipment-by-part index. 121 */ 122 public StoredSortedMap getShipmentByPartMap() { 123 124 return shipmentByPartMap; 125 } 126 127 /** 128 * Return a map view of the shipment-by-supplier index. 129 */ 130 public StoredSortedMap getShipmentBySupplierMap() { 131 132 return shipmentBySupplierMap; 133 } 134 135 /** 136 * Return a map view of the supplier-by-city index. 137 */ 138 public StoredSortedMap getSupplierByCityMap() { 139 140 return supplierByCityMap; 141 } 142} 143