summaryrefslogtreecommitdiff
path: root/cpp/src/Freeze/ObjectStore.cpp
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 /cpp/src/Freeze/ObjectStore.cpp
parentbzip2 fix (diff)
downloadice-7e5b25f64e832a9659dc054eef2935284c795a5a.tar.bz2
ice-7e5b25f64e832a9659dc054eef2935284c795a5a.tar.xz
ice-7e5b25f64e832a9659dc054eef2935284c795a5a.zip
Freeze catalogs
Diffstat (limited to 'cpp/src/Freeze/ObjectStore.cpp')
-rw-r--r--cpp/src/Freeze/ObjectStore.cpp54
1 files changed, 46 insertions, 8 deletions
diff --git a/cpp/src/Freeze/ObjectStore.cpp b/cpp/src/Freeze/ObjectStore.cpp
index 05b994a5ec0..9c5fc069ef6 100644
--- a/cpp/src/Freeze/ObjectStore.cpp
+++ b/cpp/src/Freeze/ObjectStore.cpp
@@ -11,6 +11,8 @@
#include <Freeze/EvictorI.h>
#include <Freeze/Util.h>
#include <Freeze/IndexI.h>
+#include <Freeze/Catalog.h>
+#include <Freeze/TransactionI.h>
using namespace std;
using namespace Ice;
@@ -35,14 +37,28 @@ Freeze::ObjectStore::ObjectStore(const string& facet,
_dbName = facet;
}
- DbTxn* txn = 0;
- DbEnv* dbEnv = evictor->dbEnv();
+ ConnectionPtr catalogConnection = createConnection(_communicator, evictor->dbEnv()->getEnvName());
+ Catalog catalog(catalogConnection, catalogName());
+
+ Catalog::iterator p = catalog.find(evictor->filename());
+ if(p != catalog.end())
+ {
+ if(p->second.evictor == false)
+ {
+ DatabaseException ex(__FILE__, __LINE__);
+ ex.message = evictor->filename() + " is an evictor database";
+ throw ex;
+ }
+ }
+
+ DbEnv* dbEnv = evictor->dbEnv()->getEnv();
try
{
_db.reset(new Db(dbEnv, 0));
- dbEnv->txn_begin(0, &txn, 0);
+ TransactionPtr tx = catalogConnection->beginTransaction();
+ DbTxn* txn = getTxn(tx);
u_int32_t flags = DB_THREAD;
if(createDb)
@@ -55,17 +71,24 @@ Freeze::ObjectStore::ObjectStore(const string& facet,
{
_indices[i]->_impl->associate(this, txn, createDb, populateEmptyIndices);
}
- DbTxn* toCommit = txn;
- txn = 0;
- toCommit->commit(0);
+
+ if(p == catalog.end())
+ {
+ CatalogData catalogData;
+ catalogData.evictor = true;
+ catalog.put(Catalog::value_type(evictor->filename(), catalogData));
+ }
+
+ tx->commit();
}
catch(const DbException& dx)
{
- if(txn != 0)
+ TransactionPtr tx = catalogConnection->currentTransaction();
+ if(tx != 0)
{
try
{
- txn->abort();
+ tx->rollback();
}
catch(...)
{
@@ -85,6 +108,21 @@ Freeze::ObjectStore::ObjectStore(const string& facet,
throw ex;
}
}
+ catch(...)
+ {
+ TransactionPtr tx = catalogConnection->currentTransaction();
+ if(tx != 0)
+ {
+ try
+ {
+ tx->rollback();
+ }
+ catch(...)
+ {
+ }
+ }
+ throw;
+ }
}
Freeze::ObjectStore::~ObjectStore()