1 8 9 package collections.ship.basic; 10 11 import java.io.File ; 12 import java.io.FileNotFoundException ; 13 14 import com.sleepycat.bind.serial.StoredClassCatalog; 15 import com.sleepycat.je.Database; 16 import com.sleepycat.je.DatabaseConfig; 17 import com.sleepycat.je.DatabaseException; 18 import com.sleepycat.je.Environment; 19 import com.sleepycat.je.EnvironmentConfig; 20 21 27 public class SampleDatabase { 28 29 private static final String CLASS_CATALOG = "java_class_catalog"; 30 private static final String SUPPLIER_STORE = "supplier_store"; 31 private static final String PART_STORE = "part_store"; 32 private static final String SHIPMENT_STORE = "shipment_store"; 33 34 private Environment env; 35 private Database partDb; 36 private Database supplierDb; 37 private Database shipmentDb; 38 private StoredClassCatalog javaCatalog; 39 40 43 public SampleDatabase(String homeDirectory) 44 throws DatabaseException, FileNotFoundException { 45 46 System.out.println("Opening environment in: " + homeDirectory); 49 EnvironmentConfig envConfig = new EnvironmentConfig(); 50 envConfig.setTransactional(true); 51 envConfig.setAllowCreate(true); 52 env = new Environment(new File (homeDirectory), envConfig); 53 54 DatabaseConfig dbConfig = new DatabaseConfig(); 57 dbConfig.setTransactional(true); 58 dbConfig.setAllowCreate(true); 59 60 Database catalogDb = env.openDatabase(null, CLASS_CATALOG, dbConfig); 64 javaCatalog = new StoredClassCatalog(catalogDb); 65 66 partDb = env.openDatabase(null, PART_STORE, dbConfig); 70 71 supplierDb = env.openDatabase(null, SUPPLIER_STORE, dbConfig); 72 73 shipmentDb = env.openDatabase(null, SHIPMENT_STORE, dbConfig); 74 } 75 76 79 public final Environment getEnvironment() { 80 81 return env; 82 } 83 84 87 public final StoredClassCatalog getClassCatalog() { 88 89 return javaCatalog; 90 } 91 92 95 public final Database getPartDatabase() { 96 97 return partDb; 98 } 99 100 103 public final Database getSupplierDatabase() { 104 105 return supplierDb; 106 } 107 108 111 public final Database getShipmentDatabase() { 112 113 return shipmentDb; 114 } 115 116 119 public void close() 120 throws DatabaseException { 121 122 partDb.close(); 123 supplierDb.close(); 124 shipmentDb.close(); 125 javaCatalog.close(); 127 env.close(); 128 } 129 } 130 | Popular Tags |