diff options
author | Matthew Newhook <matthew@zeroc.com> | 2002-03-08 13:47:12 +0000 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2002-03-08 13:47:12 +0000 |
commit | 2ee86c01bdce8ff4fb14120f9603e2d4382a32af (patch) | |
tree | 9ef026ad20f848bf3f4217eebd478804e3740f9f /cpp/src | |
parent | adding constructors to holder classes (diff) | |
download | ice-2ee86c01bdce8ff4fb14120f9603e2d4382a32af.tar.bz2 ice-2ee86c01bdce8ff4fb14120f9603e2d4382a32af.tar.xz ice-2ee86c01bdce8ff4fb14120f9603e2d4382a32af.zip |
updates for Freeze.
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Freeze/Application.cpp | 1 | ||||
-rw-r--r-- | cpp/src/Freeze/DBI.cpp | 109 | ||||
-rw-r--r-- | cpp/src/Freeze/DBI.h | 1 | ||||
-rw-r--r-- | cpp/src/Freeze/EvictorI.cpp | 19 |
4 files changed, 101 insertions, 29 deletions
diff --git a/cpp/src/Freeze/Application.cpp b/cpp/src/Freeze/Application.cpp index 06ca83de335..c3088794a2b 100644 --- a/cpp/src/Freeze/Application.cpp +++ b/cpp/src/Freeze/Application.cpp @@ -41,6 +41,7 @@ Freeze::Application::run(int argc, char* argv[]) cerr << appName() << ": " << ex << ": " << ex.message << endl; status = EXIT_FAILURE; } + // TODO: How does this compile? catch(const Exception& ex) { cerr << appName() << ": " << ex << endl; diff --git a/cpp/src/Freeze/DBI.cpp b/cpp/src/Freeze/DBI.cpp index 254291b451d..952195a6b59 100644 --- a/cpp/src/Freeze/DBI.cpp +++ b/cpp/src/Freeze/DBI.cpp @@ -40,7 +40,7 @@ Freeze::checkBerkeleyDBReturn(int ret, const string& prefix, const string& op) { case DB_LOCK_DEADLOCK: { - DBDeadlockException ex; + DBDeadlockException ex(__FILE__, __LINE__);; ex.message = s.str(); throw ex; } @@ -48,14 +48,14 @@ Freeze::checkBerkeleyDBReturn(int ret, const string& prefix, const string& op) case ENOENT: // The case that db->open was called with a non-existent database case DB_NOTFOUND: { - DBNotFoundException ex; + DBNotFoundException ex(__FILE__, __LINE__); ex.message = s.str(); throw ex; } default: { - DBException ex; + DBException ex(__FILE__, __LINE__); ex.message = s.str(); throw ex; } @@ -71,14 +71,14 @@ Freeze::DBEnvironmentI::DBEnvironmentI(const CommunicatorPtr& communicator, cons _errorPrefix = "Freeze::DBEnvironment(\"" + _name + "\"): "; _trace = atoi(_communicator->getProperties()->getProperty("Freeze.Trace.DB").c_str()); - checkBerkeleyDBReturn(db_env_create(&_dbEnv, 0), _errorPrefix, "db_env_create"); - if (_trace >= 1) { Trace out(_communicator->getLogger(), "DB"); out << "opening database environment \"" << _name << "\""; } + checkBerkeleyDBReturn(db_env_create(&_dbEnv, 0), _errorPrefix, "db_env_create"); + checkBerkeleyDBReturn(_dbEnv->open(_dbEnv, _name.c_str(), DB_CREATE | DB_INIT_LOCK | @@ -121,7 +121,7 @@ Freeze::DBEnvironmentI::openDB(const string& name, bool create) { ostringstream s; s << _errorPrefix << "\"" << _name << "\" has been closed"; - DBException ex; + DBException ex(__FILE__, __LINE__); ex.message = s.str(); throw ex; } @@ -268,7 +268,7 @@ Freeze::DBTransactionI::commit() { ostringstream s; s << _errorPrefix << "transaction has already been committed or aborted"; - DBException ex; + DBException ex(__FILE__, __LINE__); ex.message = s.str(); throw ex; } @@ -293,7 +293,7 @@ Freeze::DBTransactionI::abort() { ostringstream s; s << _errorPrefix << "transaction has already been committed or aborted"; - DBException ex; + DBException ex(__FILE__, __LINE__); ex.message = s.str(); throw ex; } @@ -350,7 +350,7 @@ DBCursorI::curr(Key& key, Value& value) { ostringstream s; s << _errorPrefix << "\"" << _name << "\" has been closed"; - DBException ex; + DBException ex(__FILE__, __LINE__); ex.message = s.str(); throw ex; } @@ -383,7 +383,7 @@ DBCursorI::set(const Value& value) { ostringstream s; s << _errorPrefix << "\"" << _name << "\" has been closed"; - DBException ex; + DBException ex(__FILE__, __LINE__); ex.message = s.str(); throw ex; } @@ -397,7 +397,7 @@ DBCursorI::set(const Value& value) if (_trace >= 1) { Trace out(_communicator->getLogger(), "DB"); - out << "reading current value from database \"" << _name << "\""; + out << "setting current value in database \"" << _name << "\""; } // @@ -415,7 +415,7 @@ DBCursorI::next() { ostringstream s; s << _errorPrefix << "\"" << _name << "\" has been closed"; - DBException ex; + DBException ex(__FILE__, __LINE__); ex.message = s.str(); throw ex; } @@ -456,7 +456,7 @@ DBCursorI::prev() { ostringstream s; s << _errorPrefix << "\"" << _name << "\" has been closed"; - DBException ex; + DBException ex(__FILE__, __LINE__); ex.message = s.str(); throw ex; } @@ -497,7 +497,7 @@ DBCursorI::del() { ostringstream s; s << _errorPrefix << "\"" << _name << "\" has been closed"; - DBException ex; + DBException ex(__FILE__, __LINE__); ex.message = s.str(); throw ex; } @@ -520,7 +520,7 @@ DBCursorI::clone() { ostringstream s; s << _errorPrefix << "\"" << _name << "\" has been closed"; - DBException ex; + DBException ex(__FILE__, __LINE__); ex.message = s.str(); throw ex; } @@ -606,7 +606,7 @@ Freeze::DBI::getNumberOfRecords() { ostringstream s; s << _errorPrefix << "\"" << _name << "\" has been closed"; - DBException ex; + DBException ex(__FILE__, __LINE__); ex.message = s.str(); throw ex; } @@ -630,7 +630,7 @@ Freeze::DBI::getCursor() { ostringstream s; s << _errorPrefix << "\"" << _name << "\" has been closed"; - DBException ex; + DBException ex(__FILE__, __LINE__); ex.message = s.str(); throw ex; } @@ -675,7 +675,7 @@ Freeze::DBI::getCursorAtKey(const Key& key) { ostringstream s; s << _errorPrefix << "\"" << _name << "\" has been closed"; - DBException ex; + DBException ex(__FILE__, __LINE__); ex.message = s.str(); throw ex; } @@ -726,7 +726,7 @@ Freeze::DBI::put(const Key& key, const Value& value) { ostringstream s; s << _errorPrefix << "\"" << _name << "\" has been closed"; - DBException ex; + DBException ex(__FILE__, __LINE__); ex.message = s.str(); throw ex; } @@ -748,6 +748,45 @@ Freeze::DBI::put(const Key& key, const Value& value) checkBerkeleyDBReturn(_db->put(_db, 0, &dbKey, &dbData, 0), _errorPrefix, "DB->put"); } +bool +Freeze::DBI::contains(const Key& key) +{ + IceUtil::Mutex::Lock sync(*this); + + if (!_db) + { + ostringstream s; + s << _errorPrefix << "\"" << _name << "\" has been closed"; + DBException ex(__FILE__, __LINE__); + ex.message = s.str(); + throw ex; + } + + DBT dbKey; + memset(&dbKey, 0, sizeof(dbKey)); + dbKey.data = const_cast<void*>(static_cast<const void*>(key.begin())); + dbKey.size = key.size(); + + DBT dbData; + memset(&dbData, 0, sizeof(dbData)); + dbData.flags = DB_DBT_PARTIAL; + + if (_trace >= 1) + { + Trace out(_communicator->getLogger(), "DB"); + out << "checking key in database \"" << _name << "\""; + } + + int rc = _db->get(_db, 0, &dbKey, &dbData, 0); + if (rc == DB_NOTFOUND) + { + return false; + } + + checkBerkeleyDBReturn(rc, _errorPrefix, "DB->get"); + return true; +} + Value Freeze::DBI::get(const Key& key) { @@ -757,7 +796,7 @@ Freeze::DBI::get(const Key& key) { ostringstream s; s << _errorPrefix << "\"" << _name << "\" has been closed"; - DBException ex; + DBException ex(__FILE__, __LINE__); ex.message = s.str(); throw ex; } @@ -788,7 +827,7 @@ Freeze::DBI::del(const Key& key) { ostringstream s; s << _errorPrefix << "\"" << _name << "\" has been closed"; - DBException ex; + DBException ex(__FILE__, __LINE__); ex.message = s.str(); throw ex; } @@ -816,7 +855,7 @@ Freeze::DBI::clear() { ostringstream s; s << _errorPrefix << "\"" << _name << "\" has been closed"; - DBException ex; + DBException ex(__FILE__, __LINE__); ex.message = s.str(); throw ex; } @@ -894,10 +933,34 @@ Freeze::DBI::createEvictor(EvictorPersistenceMode persistenceMode) { ostringstream s; s << _errorPrefix << "\"" << _name << "\" has been closed"; - DBException ex; + DBException ex(__FILE__, __LINE__); ex.message = s.str(); throw ex; } return new EvictorI(this, persistenceMode); } + +// +// Print for the various exception types. +// +void +Freeze::DBDeadlockException::ice_print(ostream& out) const +{ + Exception::ice_print(out); + out << ":\nunknown local exception"; +} + +void +Freeze::DBNotFoundException::ice_print(ostream& out) const +{ + Exception::ice_print(out); + out << ":\nunknown local exception"; +} + +void +Freeze::DBException::ice_print(ostream& out) const +{ + Exception::ice_print(out); + out << ":\nunknown local exception"; +} diff --git a/cpp/src/Freeze/DBI.h b/cpp/src/Freeze/DBI.h index 15ef795b618..448a7dfa680 100644 --- a/cpp/src/Freeze/DBI.h +++ b/cpp/src/Freeze/DBI.h @@ -129,6 +129,7 @@ public: virtual DBCursorPtr getCursorAtKey(const Key&); virtual void put(const Key&, const Value&); + virtual bool contains(const Key&); virtual Value get(const Key&); virtual void del(const Key&); diff --git a/cpp/src/Freeze/EvictorI.cpp b/cpp/src/Freeze/EvictorI.cpp index e278dd630cc..d5381c2539d 100644 --- a/cpp/src/Freeze/EvictorI.cpp +++ b/cpp/src/Freeze/EvictorI.cpp @@ -42,7 +42,7 @@ Freeze::EvictorI::getDB() if (_deactivated) { - throw EvictorDeactivatedException(); + throw EvictorDeactivatedException(__FILE__, __LINE__); } return _db; @@ -55,7 +55,7 @@ Freeze::EvictorI::setSize(Int evictorSize) if (_deactivated) { - throw EvictorDeactivatedException(); + throw EvictorDeactivatedException(__FILE__, __LINE__); } // @@ -84,7 +84,7 @@ Freeze::EvictorI::getSize() if (_deactivated) { - throw EvictorDeactivatedException(); + throw EvictorDeactivatedException(__FILE__, __LINE__); } return static_cast<Int>(_evictorSize); @@ -97,7 +97,7 @@ Freeze::EvictorI::createObject(const Identity& ident, const ObjectPtr& servant) if (_deactivated) { - throw EvictorDeactivatedException(); + throw EvictorDeactivatedException(__FILE__, __LINE__); } // @@ -125,7 +125,7 @@ Freeze::EvictorI::destroyObject(const Identity& ident) if (_deactivated) { - throw EvictorDeactivatedException(); + throw EvictorDeactivatedException(__FILE__, __LINE__); } // @@ -148,7 +148,7 @@ Freeze::EvictorI::installServantInitializer(const ServantInitializerPtr& initial if (_deactivated) { - throw EvictorDeactivatedException(); + throw EvictorDeactivatedException(__FILE__, __LINE__); } _initializer = initializer; @@ -416,3 +416,10 @@ Freeze::EvictorI::remove(const Identity& ident) _evictorMap.erase(p); } } + +void +Freeze::EvictorDeactivatedException::ice_print(ostream& out) const +{ + Exception::ice_print(out); + out << ":\nunknown local exception"; +} |