diff options
author | Bernard Normier <bernard@zeroc.com> | 2006-08-10 18:36:30 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2006-08-10 18:36:30 +0000 |
commit | 667420c66b32e2200fd15c57e108a35d40499d48 (patch) | |
tree | 11c38ec276c28932ce631189954d25472031a2cc /cpp/demo/Database/Oracle/proc/Server.pc | |
parent | remove redundant batch labels (diff) | |
download | ice-667420c66b32e2200fd15c57e108a35d40499d48.tar.bz2 ice-667420c66b32e2200fd15c57e108a35d40499d48.tar.xz ice-667420c66b32e2200fd15c57e108a35d40499d48.zip |
Oracle Pro*C demo
Diffstat (limited to 'cpp/demo/Database/Oracle/proc/Server.pc')
-rw-r--r-- | cpp/demo/Database/Oracle/proc/Server.pc | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/cpp/demo/Database/Oracle/proc/Server.pc b/cpp/demo/Database/Oracle/proc/Server.pc new file mode 100644 index 00000000000..f3551bbcda4 --- /dev/null +++ b/cpp/demo/Database/Oracle/proc/Server.pc @@ -0,0 +1,109 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 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 <EmpI.h> +#include <DeptI.h> +#include <DeptFactoryI.h> +#include <Ice/Application.h> +#include <Ice/ServantLocator.h> +#include <sqlca.h> + +using namespace std; + +class HRServer : public Ice::Application +{ +public: + + HRServer(const CurrentSqlContext&); + + virtual int run(int, char*[]); + +private: + CurrentSqlContext _currentCtx; +}; + +class DefaultServantLocator : public Ice::ServantLocator +{ +public: + + DefaultServantLocator(const Ice::ObjectPtr& servant) : + _servant(servant) + { + } + + virtual Ice::ObjectPtr locate(const Ice::Current&, Ice::LocalObjectPtr&) + { + return _servant; + } + + virtual void finished(const Ice::Current& curr, + const Ice::ObjectPtr& servant, + const Ice::LocalObjectPtr& cookie) + { + } + + virtual void deactivate(const std::string&) + { + } + +private: + Ice::ObjectPtr _servant; +}; + + +int +main(int argc, char* argv[]) +{ + struct sqlca sqlca; + EXEC SQL CONTEXT USE DEFAULT; + EXEC SQL ENABLE THREADS; + + Ice::InitializationData initData; + initData.properties = Ice::createProperties(argc, argv); + initData.properties->load("config.server"); + + const string connectInfo = initData.properties + ->getPropertyWithDefault("Oracle.ConnectInfo", "scott/tiger"); + CurrentSqlContext currentCtx(connectInfo); + initData.threadHook = currentCtx.getHook(); + + HRServer app(currentCtx); + return app.main(argc, argv, initData); +} + +HRServer::HRServer(const CurrentSqlContext& currentCtx) : + _currentCtx(currentCtx) +{ +} + +int +HRServer::run(int argc, char* argv[]) +{ + Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("HR"); + + const string empCategory = "Emp"; + const string deptCategory = "Dept"; + + adapter->addServantLocator(new DefaultServantLocator( + new EmpI(_currentCtx, empCategory, deptCategory)), + empCategory); + + adapter->addServantLocator(new DefaultServantLocator( + new DeptI(_currentCtx, empCategory)), + deptCategory); + + adapter->add(new DeptFactoryI(_currentCtx, deptCategory), + communicator()->stringToIdentity("DeptFactory")); + + adapter->activate(); + communicator()->waitForShutdown(); + return EXIT_SUCCESS; +} + |