summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2008-03-27 00:26:33 +0000
committerBrian S. O'Neill <bronee@gmail.com>2008-03-27 00:26:33 +0000
commite8847361b00c991c7d2183ed913b75408f27e064 (patch)
tree5ff0346f8e2d24967ee32181e31591577ee905f2 /src
parentc086d448ab308a64347de4487e1c34b076df9af4 (diff)
Support multiple databases in one file.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java36
-rw-r--r--src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepositoryBuilder.java31
2 files changed, 61 insertions, 6 deletions
diff --git a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java
index f12a58e..bbd4ea3 100644
--- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java
+++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java
@@ -112,6 +112,7 @@ abstract class BDBRepository<Txn> extends AbstractRepository<Txn>
final File mDataHome;
final File mEnvHome;
final String mSingleFileName;
+ final Map<Class<?>, String> mFileNameMap;
private LayoutFactory mLayoutFactory;
@@ -156,6 +157,7 @@ abstract class BDBRepository<Txn> extends AbstractRepository<Txn>
mDataHome = builder.getDataHomeFile();
mEnvHome = builder.getEnvironmentHomeFile();
mSingleFileName = builder.getSingleFileName();
+ mFileNameMap = builder.getFileNameMap();
}
@SuppressWarnings("unchecked")
@@ -352,16 +354,40 @@ abstract class BDBRepository<Txn> extends AbstractRepository<Txn>
return mIsMaster;
}
- String getDatabaseFileName(String dbName) {
- if (mSingleFileName != null) {
- dbName = mSingleFileName;
+ String getDatabaseFileName(final String dbName) {
+ String singleFileName = mSingleFileName;
+ if (singleFileName == null && mFileNameMap != null) {
+ singleFileName = mFileNameMap.get(dbName);
+ if (singleFileName == null && dbName != null) {
+ singleFileName = mFileNameMap.get(null);
+ }
+ }
+
+ String dbFileName = dbName;
+
+ if (singleFileName != null) {
+ dbFileName = singleFileName;
}
if (mDataHome != null && !mDataHome.equals(mEnvHome)) {
- dbName = new File(mDataHome, dbName).getPath();
+ dbFileName = new File(mDataHome, dbFileName).getPath();
}
- return dbName;
+ return dbFileName;
+ }
+
+ /**
+ * Returns null if name should not be used.
+ */
+ String getDatabaseName(final String dbName) {
+ if (mFileNameMap == null) {
+ return null;
+ }
+ String name = mFileNameMap.get(dbName);
+ if (name == null && dbName != null) {
+ name = mFileNameMap.get(null);
+ }
+ return name == null ? null : dbName;
}
StorableCodecFactory getStorableCodecFactory() {
diff --git a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepositoryBuilder.java b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepositoryBuilder.java
index fa24624..c965eff 100644
--- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepositoryBuilder.java
+++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepositoryBuilder.java
@@ -85,6 +85,7 @@ public class BDBRepositoryBuilder extends AbstractRepositoryBuilder {
private File mEnvHome;
private File mDataHome;
private String mSingleFileName;
+ private Map<Class<?>, String> mFileNames;
private boolean mIndexSupport = true;
private boolean mIndexRepairEnabled = true;
private double mIndexThrottle = 1.0;
@@ -290,10 +291,13 @@ public class BDBRepositoryBuilder extends AbstractRepositoryBuilder {
*
* <p>Note: When setting this option, the storable codec factory must also
* be changed, since the default storable codec factory is unable to
- * distinguish storable types that reside in a single database file.
+ * distinguish storable types that reside in a single database file. Call
+ * setFileName instead to use built-in BDB feature for supporting multiple
+ * databases in one file.
*/
public void setSingleFileName(String filename) {
mSingleFileName = filename;
+ mFileNames = null;
}
/**
@@ -304,6 +308,31 @@ public class BDBRepositoryBuilder extends AbstractRepositoryBuilder {
}
/**
+ * Specify the file that a BDB database should reside in, except for log
+ * files and caches. The filename is relative to the environment home,
+ * unless data directories have been specified. For BDBRepositories that
+ * are log files only, this configuration is ignored.
+ *
+ * @param filename BDB database filename
+ * @param type type to store in file; if null, the file is used by default
+ * for all types
+ */
+ public void setFileName(String filename, Class<? extends Storable> type) {
+ mSingleFileName = null;
+ if (mFileNames == null) {
+ mFileNames = new HashMap<Class<?>, String>();
+ }
+ mFileNames.put(type, filename);
+ }
+
+ Map<Class<?>, String> getFileNameMap() {
+ if (mFileNames == null) {
+ return null;
+ }
+ return new HashMap<Class<?>, String>(mFileNames);
+ }
+
+ /**
* By default, user specified indexes are supported. Pass false to disable
* this, and no indexes will be built. Another consequence of this option
* is that no unique constraint checks will be applied to alternate keys.