summaryrefslogtreecommitdiff
path: root/cpp/demo/Freeze/customEvictor/CurrentDatabase.cpp
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2007-03-20 17:29:05 +0000
committerBernard Normier <bernard@zeroc.com>2007-03-20 17:29:05 +0000
commitdf34cb828aa5be1945f4f51d99be5f33a9e4f65d (patch)
tree3dfd794e8398af65d28c10b6f60828ba41f2651d /cpp/demo/Freeze/customEvictor/CurrentDatabase.cpp
parentBug 2050. (diff)
downloadice-df34cb828aa5be1945f4f51d99be5f33a9e4f65d.tar.bz2
ice-df34cb828aa5be1945f4f51d99be5f33a9e4f65d.tar.xz
ice-df34cb828aa5be1945f4f51d99be5f33a9e4f65d.zip
New demo: IceUtil::Cache-based evictor
Diffstat (limited to 'cpp/demo/Freeze/customEvictor/CurrentDatabase.cpp')
-rw-r--r--cpp/demo/Freeze/customEvictor/CurrentDatabase.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/cpp/demo/Freeze/customEvictor/CurrentDatabase.cpp b/cpp/demo/Freeze/customEvictor/CurrentDatabase.cpp
new file mode 100644
index 00000000000..a2d928a30be
--- /dev/null
+++ b/cpp/demo/Freeze/customEvictor/CurrentDatabase.cpp
@@ -0,0 +1,65 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2007 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 <CurrentDatabase.h>
+#include <Freeze/Freeze.h>
+
+using namespace std;
+
+//
+// This implementation is very simple but not restartable, i.e.
+// you can only create and destroy one CurrentDatabase per process run.
+//
+
+#ifdef _MSC_VER
+ #define __thread __declspec(thread)
+#endif
+
+namespace
+{
+
+//
+// We keep a db on each thread
+//
+
+__thread Database* db = 0;
+
+}
+
+
+CurrentDatabase::CurrentDatabase(const Ice::CommunicatorPtr& communicator, const string& envName, const string& dbName)
+ : _communicator(communicator),
+ _envName(envName),
+ _dbName(dbName)
+{
+}
+
+CurrentDatabase::~CurrentDatabase()
+{
+ for(list<Database*>::iterator p = _dbList.begin(); p != _dbList.end(); ++p)
+ {
+ delete *p;
+ }
+}
+
+
+Database&
+CurrentDatabase::get()
+{
+ if(db == 0)
+ {
+ Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName);
+ db = new Database(connection, _dbName);
+ _dbList.push_back(db);
+ }
+ return *db;
+}
+
+
+