diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2009-09-28 11:05:44 -0230 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2009-09-28 11:05:44 -0230 |
commit | 7d20430028f05cc26c412465176a75ce4ea5af9e (patch) | |
tree | 593695acf366f7e3a7081d15af8f474683ce4af7 /cpp/src/IceGrid/DatabaseCache.cpp | |
parent | Removed unused __checkTwoway(const char*) from Proxy (diff) | |
download | ice-7d20430028f05cc26c412465176a75ce4ea5af9e.tar.bz2 ice-7d20430028f05cc26c412465176a75ce4ea5af9e.tar.xz ice-7d20430028f05cc26c412465176a75ce4ea5af9e.zip |
Bug 3231 - alternative storage for IceGrid and IceStorm
Diffstat (limited to 'cpp/src/IceGrid/DatabaseCache.cpp')
-rw-r--r-- | cpp/src/IceGrid/DatabaseCache.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/cpp/src/IceGrid/DatabaseCache.cpp b/cpp/src/IceGrid/DatabaseCache.cpp new file mode 100644 index 00000000000..12f544ded7a --- /dev/null +++ b/cpp/src/IceGrid/DatabaseCache.cpp @@ -0,0 +1,77 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <IceGrid/DatabaseCache.h> +#ifdef QTSQL +# include <Ice/Communicator.h> +#endif + +using namespace IceGrid; +using namespace std; + +#ifdef QTSQL + +DatabaseCache::DatabaseCache(const Ice::CommunicatorPtr& communicator, + const string&, + const string& instanceName, + const string& replicaName) : + IceSQL::DatabaseCache(communicator, + communicator->getProperties()->getProperty("IceGrid.SQL.DatabaseType"), + communicator->getProperties()->getProperty("IceGrid.SQL.DatabaseName"), + communicator->getProperties()->getProperty("IceGrid.SQL.HostName"), + communicator->getProperties()->getProperty("IceGrid.SQL.UserName"), + communicator->getProperties()->getProperty("IceGrid.SQL.Password"), + true) +{ + string tablePrefix = instanceName + "_" + replicaName; + replace(tablePrefix.begin(), tablePrefix.end(), '.', '_'); + replace(tablePrefix.begin(), tablePrefix.end(), '-', '_'); + replace(tablePrefix.begin(), tablePrefix.end(), ' ', '_'); + replace(tablePrefix.begin(), tablePrefix.end(), ';', '_'); + + IceSQL::DatabaseConnectionPtr connection = getConnection(); + IceSQL::TransactionHolder txn(connection); + + const_cast<SqlStringApplicationInfoDictPtr&>(applications) = + new SqlStringApplicationInfoDict(connection, tablePrefix + "_Applications", _communicator); + const_cast<SqlStringAdapterInfoDictPtr&>(adapters) = + new SqlStringAdapterInfoDict(connection, tablePrefix + "_Adapters", _communicator); + const_cast<SqlIdentityObjectInfoDictPtr&>(objects) = + new SqlIdentityObjectInfoDict(connection, tablePrefix + "_Objects", _communicator); + const_cast<SqlIdentityObjectInfoDictPtr&>(internalObjects) = + new SqlIdentityObjectInfoDict(connection, tablePrefix + "_InternalObjects", _communicator); + + txn.commit(); +} + +#else + +DatabaseCache::DatabaseCache(const Ice::CommunicatorPtr& communicator, + const string& envName, + const string&, + const string&) : + _communicator(communicator), + _envName(envName), + _connection(Freeze::createConnection(communicator, envName)) +{ +} + +DatabaseConnectionPtr +DatabaseCache::getConnection() +{ + return _connection; +} + +DatabaseConnectionPtr +DatabaseCache::newConnection() +{ + return Freeze::createConnection(_communicator, _envName); +} + +#endif |