summaryrefslogtreecommitdiff
path: root/java/src/Freeze/ObjectStore.java
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2004-12-02 23:18:51 +0000
committerBernard Normier <bernard@zeroc.com>2004-12-02 23:18:51 +0000
commit7e5b25f64e832a9659dc054eef2935284c795a5a (patch)
tree4f9f3ce6eb8ec88d3455b8a07998ed4ab575ce9e /java/src/Freeze/ObjectStore.java
parentbzip2 fix (diff)
downloadice-7e5b25f64e832a9659dc054eef2935284c795a5a.tar.bz2
ice-7e5b25f64e832a9659dc054eef2935284c795a5a.tar.xz
ice-7e5b25f64e832a9659dc054eef2935284c795a5a.zip
Freeze catalogs
Diffstat (limited to 'java/src/Freeze/ObjectStore.java')
-rw-r--r--java/src/Freeze/ObjectStore.java135
1 files changed, 63 insertions, 72 deletions
diff --git a/java/src/Freeze/ObjectStore.java b/java/src/Freeze/ObjectStore.java
index 28118d62e26..9691d0d6bff 100644
--- a/java/src/Freeze/ObjectStore.java
+++ b/java/src/Freeze/ObjectStore.java
@@ -31,98 +31,89 @@ class ObjectStore implements IceUtil.Store
_dbName = facet;
}
- com.sleepycat.db.DbTxn txn = null;
- com.sleepycat.db.DbEnv dbEnv = evictor.dbEnv();
-
- String txnId = null;
+ Connection connection = Util.createConnection(_communicator, evictor.dbEnv().getEnvName());
try
- {
- _db = new com.sleepycat.db.Db(dbEnv, 0);
+ {
+ Catalog catalog = new Catalog(connection, Util.catalogName(), true);
+ CatalogData catalogData = (CatalogData)catalog.get(evictor.filename());
- txn = dbEnv.txnBegin(null, 0);
-
- if(evictor.txTrace() >= 1)
+ if(catalogData != null && catalogData.evictor == false)
{
- txnId = Long.toHexString((txn.id() & 0x7FFFFFFF) + 0x80000000L);
-
- evictor.communicator().getLogger().trace
- ("Freeze.Evictor", _evictor.errorPrefix() + "started transaction " +
- txnId + " to open Db");
+ DatabaseException ex = new DatabaseException();
+ ex.message = _evictor.errorPrefix() + evictor.filename() + " is not an evictor database";
+ throw ex;
}
+ com.sleepycat.db.DbEnv dbEnv = evictor.dbEnv().getEnv();
- //
- // TODO: FREEZE_DB_MODE
- //
- int flags = 0;
- if(createDb)
- {
- flags |= com.sleepycat.db.Db.DB_CREATE;
- }
- _db.open(txn, evictor.filename(), _dbName, com.sleepycat.db.Db.DB_BTREE, flags, 0);
+ try
+ {
+ _db = new com.sleepycat.db.Db(dbEnv, 0);
+
+ Transaction tx = connection.beginTransaction();
+ com.sleepycat.db.DbTxn txn = Util.getTxn(tx);
-
- java.util.Iterator p = _indices.iterator();
- while(p.hasNext())
+ //
+ // TODO: FREEZE_DB_MODE
+ //
+ int flags = 0;
+ if(createDb)
+ {
+ flags |= com.sleepycat.db.Db.DB_CREATE;
+ }
+ _db.open(txn, evictor.filename(), _dbName, com.sleepycat.db.Db.DB_BTREE, flags, 0);
+
+
+ java.util.Iterator p = _indices.iterator();
+ while(p.hasNext())
+ {
+ Index index = (Index) p.next();
+ index.associate(this, txn, createDb, populateEmptyIndices);
+ }
+
+ if(catalogData == null)
+ {
+ catalogData = new CatalogData();
+ catalogData.evictor = true;
+ catalog.put(evictor.filename(), catalogData);
+ }
+
+ tx.commit();
+ }
+ catch(java.io.FileNotFoundException dx)
{
- Index index = (Index) p.next();
- index.associate(this, txn, createDb, populateEmptyIndices);
+ NotFoundException ex = new NotFoundException();
+ ex.initCause(dx);
+ ex.message = _evictor.errorPrefix() + "Db.open: " + dx.getMessage();
+ throw ex;
}
-
- com.sleepycat.db.DbTxn toCommit = txn;
- txn = null;
- toCommit.commit(0);
-
- if(evictor.txTrace() >= 1)
+ catch(com.sleepycat.db.DbException dx)
{
- evictor.communicator().getLogger().trace
- ("Freeze.Evictor", _evictor.errorPrefix() + "committed transaction " +
- txnId);
+ DatabaseException ex = new DatabaseException();
+ ex.initCause(dx);
+ ex.message = _evictor.errorPrefix() + "Db.open: " + dx.getMessage();
+ throw ex;
}
-
- }
- catch(java.io.FileNotFoundException dx)
- {
- NotFoundException ex = new NotFoundException();
- ex.initCause(dx);
- ex.message = _evictor.errorPrefix() + "Db.open: " + dx.getMessage();
- throw ex;
- }
- catch(com.sleepycat.db.DbException dx)
- {
- DatabaseException ex = new DatabaseException();
- ex.initCause(dx);
- ex.message = _evictor.errorPrefix() + "Db.open: " + dx.getMessage();
- throw ex;
- }
- finally
- {
- if(txn != null)
+ finally
{
- try
- {
- txn.abort();
-
- if(evictor.txTrace() >= 1)
+ Transaction tx = connection.currentTransaction();
+ if(tx != null)
+ {
+ try
{
- evictor.communicator().getLogger().trace
- ("Freeze.Evictor", _evictor.errorPrefix() + "rolled back transaction " +
- txnId);
+ tx.rollback();
}
- }
- catch(com.sleepycat.db.DbException dx)
- {
- if(evictor.txTrace() >= 1)
+ catch(DatabaseException de)
{
- evictor.communicator().getLogger().trace
- ("Freeze.Evictor", _evictor.errorPrefix() + "failed to rollback transaction " +
- txnId + ": " + dx.getMessage());
}
-
}
}
}
+ finally
+ {
+ connection.close();
+ }
}
protected void