diff options
author | Mark Spruiell <mes@zeroc.com> | 2006-12-05 01:10:47 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2006-12-05 01:10:47 +0000 |
commit | a20c5e42adb986c4ef3d715a6350479ca8e94b08 (patch) | |
tree | f9bfa54df8dd9d3ea41814981318296143087107 /cpp/src/FreezeScript/Util.cpp | |
parent | More cleanup (diff) | |
download | ice-a20c5e42adb986c4ef3d715a6350479ca8e94b08.tar.bz2 ice-a20c5e42adb986c4ef3d715a6350479ca8e94b08.tar.xz ice-a20c5e42adb986c4ef3d715a6350479ca8e94b08.zip |
bug 1517: use catalog in FreezeScript tools
Diffstat (limited to 'cpp/src/FreezeScript/Util.cpp')
-rw-r--r-- | cpp/src/FreezeScript/Util.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/cpp/src/FreezeScript/Util.cpp b/cpp/src/FreezeScript/Util.cpp index 465dfb69ea4..431c2a8f081 100644 --- a/cpp/src/FreezeScript/Util.cpp +++ b/cpp/src/FreezeScript/Util.cpp @@ -9,7 +9,12 @@ #include <FreezeScript/Util.h> #include <FreezeScript/Exception.h> +#include <Freeze/Catalog.h> +#include <Freeze/Connection.h> +#include <Freeze/Initialize.h> #include <Slice/Preprocessor.h> +#include <db_cxx.h> +#include <sys/stat.h> using namespace std; using namespace Slice; @@ -198,3 +203,54 @@ FreezeScript::parseSlice(const string& n, const Slice::UnitPtr& u, const vector< return true; } + +FreezeScript::CatalogDataMap +FreezeScript::readCatalog(const Ice::CommunicatorPtr& communicator, const string& dbEnvName) +{ + CatalogDataMap result; + + DbEnv dbEnv(0); +#ifdef _WIN32 + int mode = 0; +#else + int mode = S_IRUSR | S_IWUSR; +#endif + try + { +#ifdef _WIN32 + // + // Berkeley DB may use a different C++ runtime. + // + dbEnv.set_alloc(::malloc, ::realloc, ::free); +#endif + + // + // Open the database environment. + // + { + u_int32_t flags = DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_CREATE | DB_THREAD | DB_RECOVER; + dbEnv.open(dbEnvName.c_str(), flags, mode); + } + + Freeze::ConnectionPtr connection = Freeze::createConnection(communicator, dbEnvName, dbEnv); + Freeze::Catalog catalog(connection, Freeze::catalogName()); + for(Freeze::Catalog::const_iterator p = catalog.begin(); p != catalog.end(); ++p) + { + result.insert(make_pair(p->first, p->second)); + } + } + catch(const DbException& ex) + { + dbEnv.close(0); + throw FailureException(__FILE__, __LINE__, string("database error: ") + ex.what()); + } + catch(...) + { + dbEnv.close(0); + throw FailureException(__FILE__, __LINE__, "unknown exception"); + } + + dbEnv.close(0); + + return result; +} |