1 8 9 package collections.ship.entity; 10 11 import com.sleepycat.bind.EntityBinding; 12 import com.sleepycat.bind.serial.ClassCatalog; 13 import com.sleepycat.bind.serial.SerialBinding; 14 import com.sleepycat.bind.serial.SerialSerialBinding; 15 import com.sleepycat.collections.StoredSortedMap; 16 import com.sleepycat.collections.StoredValueSet; 17 18 24 public class SampleViews { 25 26 private StoredSortedMap partMap; 27 private StoredSortedMap supplierMap; 28 private StoredSortedMap shipmentMap; 29 private StoredSortedMap shipmentByPartMap; 30 private StoredSortedMap shipmentBySupplierMap; 31 private StoredSortedMap supplierByCityMap; 32 33 36 public SampleViews(SampleDatabase db) { 37 38 ClassCatalog catalog = db.getClassCatalog(); 45 SerialBinding partKeyBinding = 46 new SerialBinding(catalog, PartKey.class); 47 EntityBinding partDataBinding = 48 new PartBinding(catalog, PartKey.class, PartData.class); 49 SerialBinding supplierKeyBinding = 50 new SerialBinding(catalog, SupplierKey.class); 51 EntityBinding supplierDataBinding = 52 new SupplierBinding(catalog, SupplierKey.class, 53 SupplierData.class); 54 SerialBinding shipmentKeyBinding = 55 new SerialBinding(catalog, ShipmentKey.class); 56 EntityBinding shipmentDataBinding = 57 new ShipmentBinding(catalog, ShipmentKey.class, 58 ShipmentData.class); 59 SerialBinding cityKeyBinding = 60 new SerialBinding(catalog, String .class); 61 62 partMap = 68 new StoredSortedMap(db.getPartDatabase(), 69 partKeyBinding, partDataBinding, true); 70 supplierMap = 71 new StoredSortedMap(db.getSupplierDatabase(), 72 supplierKeyBinding, supplierDataBinding, true); 73 shipmentMap = 74 new StoredSortedMap(db.getShipmentDatabase(), 75 shipmentKeyBinding, shipmentDataBinding, true); 76 shipmentByPartMap = 77 new StoredSortedMap(db.getShipmentByPartDatabase(), 78 partKeyBinding, shipmentDataBinding, true); 79 shipmentBySupplierMap = 80 new StoredSortedMap(db.getShipmentBySupplierDatabase(), 81 supplierKeyBinding, shipmentDataBinding, true); 82 supplierByCityMap = 83 new StoredSortedMap(db.getSupplierByCityDatabase(), 84 cityKeyBinding, supplierDataBinding, true); 85 } 86 87 94 97 public StoredSortedMap getPartMap() { 98 99 return partMap; 100 } 101 102 105 public StoredSortedMap getSupplierMap() { 106 107 return supplierMap; 108 } 109 110 113 public StoredSortedMap getShipmentMap() { 114 115 return shipmentMap; 116 } 117 118 121 public StoredValueSet getPartSet() { 122 123 return (StoredValueSet) partMap.values(); 124 } 125 126 129 public StoredValueSet getSupplierSet() { 130 131 return (StoredValueSet) supplierMap.values(); 132 } 133 134 137 public StoredValueSet getShipmentSet() { 138 139 return (StoredValueSet) shipmentMap.values(); 140 } 141 142 145 public StoredSortedMap getShipmentByPartMap() { 146 147 return shipmentByPartMap; 148 } 149 150 153 public StoredSortedMap getShipmentBySupplierMap() { 154 155 return shipmentBySupplierMap; 156 } 157 158 161 public final StoredSortedMap getSupplierByCityMap() { 162 163 return supplierByCityMap; 164 } 165 166 170 private static class PartBinding extends SerialSerialBinding { 171 172 175 private PartBinding(ClassCatalog classCatalog, 176 Class keyClass, 177 Class dataClass) { 178 179 super(classCatalog, keyClass, dataClass); 180 } 181 182 185 public Object entryToObject(Object keyInput, Object dataInput) { 186 187 PartKey key = (PartKey) keyInput; 188 PartData data = (PartData) dataInput; 189 return new Part(key.getNumber(), data.getName(), data.getColor(), 190 data.getWeight(), data.getCity()); 191 } 192 193 196 public Object objectToKey(Object object) { 197 198 Part part = (Part) object; 199 return new PartKey(part.getNumber()); 200 } 201 202 205 public Object objectToData(Object object) { 206 207 Part part = (Part) object; 208 return new PartData(part.getName(), part.getColor(), 209 part.getWeight(), part.getCity()); 210 } 211 } 212 213 217 private static class SupplierBinding extends SerialSerialBinding { 218 219 222 private SupplierBinding(ClassCatalog classCatalog, 223 Class keyClass, 224 Class dataClass) { 225 226 super(classCatalog, keyClass, dataClass); 227 } 228 229 232 public Object entryToObject(Object keyInput, Object dataInput) { 233 234 SupplierKey key = (SupplierKey) keyInput; 235 SupplierData data = (SupplierData) dataInput; 236 return new Supplier(key.getNumber(), data.getName(), 237 data.getStatus(), data.getCity()); 238 } 239 240 243 public Object objectToKey(Object object) { 244 245 Supplier supplier = (Supplier) object; 246 return new SupplierKey(supplier.getNumber()); 247 } 248 249 252 public Object objectToData(Object object) { 253 254 Supplier supplier = (Supplier) object; 255 return new SupplierData(supplier.getName(), supplier.getStatus(), 256 supplier.getCity()); 257 } 258 } 259 260 264 private static class ShipmentBinding extends SerialSerialBinding { 265 266 269 private ShipmentBinding(ClassCatalog classCatalog, 270 Class keyClass, 271 Class dataClass) { 272 273 super(classCatalog, keyClass, dataClass); 274 } 275 276 279 public Object entryToObject(Object keyInput, Object dataInput) { 280 281 ShipmentKey key = (ShipmentKey) keyInput; 282 ShipmentData data = (ShipmentData) dataInput; 283 return new Shipment(key.getPartNumber(), key.getSupplierNumber(), 284 data.getQuantity()); 285 } 286 287 290 public Object objectToKey(Object object) { 291 292 Shipment shipment = (Shipment) object; 293 return new ShipmentKey(shipment.getPartNumber(), 294 shipment.getSupplierNumber()); 295 } 296 297 300 public Object objectToData(Object object) { 301 302 Shipment shipment = (Shipment) object; 303 return new ShipmentData(shipment.getQuantity()); 304 } 305 } 306 } 307 | Popular Tags |