From 43c536a71cf108c225fe9e94d554c3d8c240b4e0 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Mon, 21 Apr 2008 23:45:09 +0000 Subject: Support database name remapping. --- .../amazon/carbonado/repo/sleepycat/BDBRepository.java | 16 +++++++++++++--- .../carbonado/repo/sleepycat/BDBRepositoryBuilder.java | 6 ++++++ 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'src/main/java/com/amazon/carbonado/repo') 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 243fffc..a56a91d 100644 --- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java @@ -365,7 +365,11 @@ abstract class BDBRepository extends AbstractRepository String dbFileName = dbName; - if (singleFileName != null) { + if (singleFileName == null) { + if (mDatabaseHook != null) { + dbFileName = mDatabaseHook.databaseName(dbName); + } + } else { dbFileName = singleFileName; } @@ -379,7 +383,7 @@ abstract class BDBRepository extends AbstractRepository /** * Returns null if name should not be used. */ - String getDatabaseName(final String dbName) { + String getDatabaseName(String dbName) { if (mFileNameMap == null) { return null; } @@ -387,7 +391,13 @@ abstract class BDBRepository extends AbstractRepository if (name == null && dbName != null) { name = mFileNameMap.get(null); } - return name == null ? null : dbName; + if (name == null) { + return null; + } + if (mDatabaseHook != null) { + dbName = mDatabaseHook.databaseName(dbName); + } + return 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 1def43e..995fada 100644 --- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepositoryBuilder.java +++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepositoryBuilder.java @@ -795,6 +795,12 @@ public class BDBRepositoryBuilder extends AbstractRepositoryBuilder { } public static interface DatabaseHook { + /** + * Returns an appropriate database name for the given type. Simply + * return the type name as-is to support default behavior. + */ + String databaseName(String typeName); + /** * Called right before database is opened. * -- cgit v1.2.3