summaryrefslogtreecommitdiff
path: root/db-4.8.30/examples_java/src/collections/ship/basic/SampleDatabase.java
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2016-12-17 21:28:53 -0800
committerJesse Morgan <jesse@jesterpm.net>2016-12-17 21:28:53 -0800
commit54df2afaa61c6a03cbb4a33c9b90fa572b6d07b8 (patch)
tree18147b92b969d25ffbe61935fb63035cac820dd0 /db-4.8.30/examples_java/src/collections/ship/basic/SampleDatabase.java
Berkeley DB 4.8 with rust build script for linux.
Diffstat (limited to 'db-4.8.30/examples_java/src/collections/ship/basic/SampleDatabase.java')
-rw-r--r--db-4.8.30/examples_java/src/collections/ship/basic/SampleDatabase.java134
1 files changed, 134 insertions, 0 deletions
diff --git a/db-4.8.30/examples_java/src/collections/ship/basic/SampleDatabase.java b/db-4.8.30/examples_java/src/collections/ship/basic/SampleDatabase.java
new file mode 100644
index 0000000..47fff2c
--- /dev/null
+++ b/db-4.8.30/examples_java/src/collections/ship/basic/SampleDatabase.java
@@ -0,0 +1,134 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 2002-2009 Oracle. All rights reserved.
+ *
+ * $Id$
+ */
+
+package collections.ship.basic;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+
+import com.sleepycat.bind.serial.StoredClassCatalog;
+import com.sleepycat.db.Database;
+import com.sleepycat.db.DatabaseConfig;
+import com.sleepycat.db.DatabaseException;
+import com.sleepycat.db.DatabaseType;
+import com.sleepycat.db.Environment;
+import com.sleepycat.db.EnvironmentConfig;
+
+/**
+ * SampleDatabase defines the storage containers, indices and foreign keys
+ * for the sample database.
+ *
+ * @author Mark Hayes
+ */
+public class SampleDatabase {
+
+ private static final String CLASS_CATALOG = "java_class_catalog";
+ private static final String SUPPLIER_STORE = "supplier_store";
+ private static final String PART_STORE = "part_store";
+ private static final String SHIPMENT_STORE = "shipment_store";
+
+ private Environment env;
+ private Database partDb;
+ private Database supplierDb;
+ private Database shipmentDb;
+ private StoredClassCatalog javaCatalog;
+
+ /**
+ * Open all storage containers, indices, and catalogs.
+ */
+ public SampleDatabase(String homeDirectory)
+ throws DatabaseException, FileNotFoundException {
+
+ // Open the Berkeley DB environment in transactional mode.
+ //
+ System.out.println("Opening environment in: " + homeDirectory);
+ EnvironmentConfig envConfig = new EnvironmentConfig();
+ envConfig.setTransactional(true);
+ envConfig.setAllowCreate(true);
+ envConfig.setInitializeCache(true);
+ envConfig.setInitializeLocking(true);
+ env = new Environment(new File(homeDirectory), envConfig);
+
+ // Set the Berkeley DB config for opening all stores.
+ //
+ DatabaseConfig dbConfig = new DatabaseConfig();
+ dbConfig.setTransactional(true);
+ dbConfig.setAllowCreate(true);
+ dbConfig.setType(DatabaseType.BTREE);
+
+ // Create the Serial class catalog. This holds the serialized class
+ // format for all database records of serial format.
+ //
+ Database catalogDb = env.openDatabase(null, CLASS_CATALOG, null,
+ dbConfig);
+ javaCatalog = new StoredClassCatalog(catalogDb);
+
+ // Open the Berkeley DB database for the part, supplier and shipment
+ // stores. The stores are opened with no duplicate keys allowed.
+ //
+ partDb = env.openDatabase(null, PART_STORE, null, dbConfig);
+
+ supplierDb = env.openDatabase(null, SUPPLIER_STORE, null, dbConfig);
+
+ shipmentDb = env.openDatabase(null, SHIPMENT_STORE, null, dbConfig);
+ }
+
+ /**
+ * Return the storage environment for the database.
+ */
+ public final Environment getEnvironment() {
+
+ return env;
+ }
+
+ /**
+ * Return the class catalog.
+ */
+ public final StoredClassCatalog getClassCatalog() {
+
+ return javaCatalog;
+ }
+
+ /**
+ * Return the part storage container.
+ */
+ public final Database getPartDatabase() {
+
+ return partDb;
+ }
+
+ /**
+ * Return the supplier storage container.
+ */
+ public final Database getSupplierDatabase() {
+
+ return supplierDb;
+ }
+
+ /**
+ * Return the shipment storage container.
+ */
+ public final Database getShipmentDatabase() {
+
+ return shipmentDb;
+ }
+
+ /**
+ * Close all databases and the environment.
+ */
+ public void close()
+ throws DatabaseException {
+
+ partDb.close();
+ supplierDb.close();
+ shipmentDb.close();
+ // And don't forget to close the catalog and the environment.
+ javaCatalog.close();
+ env.close();
+ }
+}