summaryrefslogtreecommitdiff
path: root/java/src/Freeze/SharedDb.java
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2004-09-30 20:02:15 +0000
committerBernard Normier <bernard@zeroc.com>2004-09-30 20:02:15 +0000
commit61d07845e7640e3c5fbdc8599190dade12129d33 (patch)
treef118ec0fb9450aa0d4b90cbd2f8f2d562ee72e97 /java/src/Freeze/SharedDb.java
parentMap index support (diff)
downloadice-61d07845e7640e3c5fbdc8599190dade12129d33.tar.bz2
ice-61d07845e7640e3c5fbdc8599190dade12129d33.tar.xz
ice-61d07845e7640e3c5fbdc8599190dade12129d33.zip
Added index support to Freeze dictionaries
Diffstat (limited to 'java/src/Freeze/SharedDb.java')
-rwxr-xr-xjava/src/Freeze/SharedDb.java76
1 files changed, 71 insertions, 5 deletions
diff --git a/java/src/Freeze/SharedDb.java b/java/src/Freeze/SharedDb.java
index 60610d0859f..abe5fe25bd4 100755
--- a/java/src/Freeze/SharedDb.java
+++ b/java/src/Freeze/SharedDb.java
@@ -12,7 +12,7 @@ package Freeze;
class SharedDb extends com.sleepycat.db.Db
{
public static SharedDb
- get(ConnectionI connection, String dbName, boolean createDb)
+ get(ConnectionI connection, String dbName, Map.Index[] indices, boolean createDb)
{
MapKey key = new MapKey(connection.envName(), connection.communicator(), dbName);
@@ -23,7 +23,7 @@ class SharedDb extends com.sleepycat.db.Db
{
try
{
- result = new SharedDb(key, connection, createDb);
+ result = new SharedDb(key, connection, indices, createDb);
}
catch(com.sleepycat.db.DbException dx)
{
@@ -38,6 +38,7 @@ class SharedDb extends com.sleepycat.db.Db
}
else
{
+ result.connectIndices(indices);
result._refCount++;
}
return result;
@@ -74,6 +75,8 @@ class SharedDb extends com.sleepycat.db.Db
//
try
{
+ cleanupIndices();
+
super.close(0);
}
catch(com.sleepycat.db.DbException dx)
@@ -93,22 +96,40 @@ class SharedDb extends com.sleepycat.db.Db
assert(_refCount == 0);
}
- private SharedDb(MapKey key, ConnectionI connection, boolean createDb) throws com.sleepycat.db.DbException
+ private SharedDb(MapKey key, ConnectionI connection, Map.Index[] indices,
+ boolean createDb) throws com.sleepycat.db.DbException
{
super(connection.dbEnv(), 0);
_key = key;
+ _indices = indices;
_trace = connection.trace();
+ com.sleepycat.db.DbTxn txn = null;
+
try
{
- int flags = com.sleepycat.db.Db.DB_AUTO_COMMIT;
+ txn = connection.dbEnv().txnBegin(null, 0);
+
+ int flags = 0;
if(createDb)
{
flags |= com.sleepycat.db.Db.DB_CREATE;
}
- open(null, key.dbName, null, com.sleepycat.db.Db.DB_BTREE, flags, 0);
+ open(txn, key.dbName, null, com.sleepycat.db.Db.DB_BTREE, flags, 0);
+
+ if(_indices != null)
+ {
+ for(int i = 0; i < _indices.length; ++i)
+ {
+ _indices[i].associate(key.dbName, this, txn, createDb);
+ }
+ }
+
+ com.sleepycat.db.DbTxn toCommit = txn;
+ txn = null;
+ toCommit.commit(0);
//
// TODO: FREEZE_DB_MODE
@@ -116,6 +137,7 @@ class SharedDb extends com.sleepycat.db.Db
}
catch(java.io.FileNotFoundException dx)
{
+ cleanupIndices();
NotFoundException ex = new NotFoundException();
ex.initCause(dx);
ex.message = errorPrefix(_key) + "Db.open: " + dx.getMessage();
@@ -123,14 +145,57 @@ class SharedDb extends com.sleepycat.db.Db
}
catch(com.sleepycat.db.DbException dx)
{
+ cleanupIndices();
DatabaseException ex = new DatabaseException();
ex.initCause(dx);
ex.message = errorPrefix(_key) + "Db.open: " + dx.getMessage();
throw ex;
}
+ finally
+ {
+ if(txn != null)
+ {
+ try
+ {
+ txn.abort();
+ }
+ catch(com.sleepycat.db.DbException dx)
+ {
+ }
+ }
+ }
+
_refCount = 1;
}
+ private void
+ connectIndices(Map.Index[] indices)
+ {
+ if(indices != null)
+ {
+ assert(_indices != null && indices.length == _indices.length);
+
+ for(int i = 0; i < indices.length; ++i)
+ {
+ indices[i].init(_indices[i]);
+ }
+ }
+ }
+
+ private void
+ cleanupIndices()
+ {
+ if(_indices != null)
+ {
+ for(int i = 0; i < _indices.length; ++i)
+ {
+ _indices[i].close();
+ }
+ _indices = null;
+ }
+ }
+
+
private static String
errorPrefix(MapKey k)
{
@@ -174,6 +239,7 @@ class SharedDb extends com.sleepycat.db.Db
private MapKey _key;
private int _refCount = 0;
private int _trace;
+ private Map.Index[] _indices;
//
// Hash map of (MapKey, SharedDb)