00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 package collections.ship.basic;
00011
00012 import java.io.File;
00013 import java.io.FileNotFoundException;
00014
00015 import com.sleepycat.bind.serial.StoredClassCatalog;
00016 import com.sleepycat.db.Database;
00017 import com.sleepycat.db.DatabaseConfig;
00018 import com.sleepycat.db.DatabaseException;
00019 import com.sleepycat.db.DatabaseType;
00020 import com.sleepycat.db.Environment;
00021 import com.sleepycat.db.EnvironmentConfig;
00022
00029 public class SampleDatabase {
00030
00031 private static final String CLASS_CATALOG = "java_class_catalog";
00032 private static final String SUPPLIER_STORE = "supplier_store";
00033 private static final String PART_STORE = "part_store";
00034 private static final String SHIPMENT_STORE = "shipment_store";
00035
00036 private Environment env;
00037 private Database partDb;
00038 private Database supplierDb;
00039 private Database shipmentDb;
00040 private StoredClassCatalog javaCatalog;
00041
00045 public SampleDatabase(String homeDirectory)
00046 throws DatabaseException, FileNotFoundException {
00047
00048
00049
00050 System.out.println("Opening environment in: " + homeDirectory);
00051 EnvironmentConfig envConfig = new EnvironmentConfig();
00052 envConfig.setTransactional(true);
00053 envConfig.setAllowCreate(true);
00054 envConfig.setInitializeCache(true);
00055 envConfig.setInitializeLocking(true);
00056 env = new Environment(new File(homeDirectory), envConfig);
00057
00058
00059
00060 DatabaseConfig dbConfig = new DatabaseConfig();
00061 dbConfig.setTransactional(true);
00062 dbConfig.setAllowCreate(true);
00063 dbConfig.setType(DatabaseType.BTREE);
00064
00065
00066
00067
00068 Database catalogDb = env.openDatabase(null, CLASS_CATALOG, null,
00069 dbConfig);
00070 javaCatalog = new StoredClassCatalog(catalogDb);
00071
00072
00073
00074
00075 partDb = env.openDatabase(null, PART_STORE, null, dbConfig);
00076
00077 supplierDb = env.openDatabase(null, SUPPLIER_STORE, null, dbConfig);
00078
00079 shipmentDb = env.openDatabase(null, SHIPMENT_STORE, null, dbConfig);
00080 }
00081
00085 public final Environment getEnvironment() {
00086
00087 return env;
00088 }
00089
00093 public final StoredClassCatalog getClassCatalog() {
00094
00095 return javaCatalog;
00096 }
00097
00101 public final Database getPartDatabase() {
00102
00103 return partDb;
00104 }
00105
00109 public final Database getSupplierDatabase() {
00110
00111 return supplierDb;
00112 }
00113
00117 public final Database getShipmentDatabase() {
00118
00119 return shipmentDb;
00120 }
00121
00125 public void close()
00126 throws DatabaseException {
00127
00128 partDb.close();
00129 supplierDb.close();
00130 shipmentDb.close();
00131
00132 javaCatalog.close();
00133 env.close();
00134 }
00135 }