diff options
author | Bernard Normier <bernard@zeroc.com> | 2006-08-17 21:26:26 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2006-08-17 21:26:26 +0000 |
commit | 96ba1e0f0ceece084ec47e80665a0ac90e935493 (patch) | |
tree | 65e7d5173090cd1bf1e26d25145e4b63b478cd4b /cpp/demo/Database/Oracle/occi | |
parent | Remove debug return (diff) | |
download | ice-96ba1e0f0ceece084ec47e80665a0ac90e935493.tar.bz2 ice-96ba1e0f0ceece084ec47e80665a0ac90e935493.tar.xz ice-96ba1e0f0ceece084ec47e80665a0ac90e935493.zip |
First cut of OCCI demo
Diffstat (limited to 'cpp/demo/Database/Oracle/occi')
19 files changed, 2324 insertions, 0 deletions
diff --git a/cpp/demo/Database/Oracle/occi/Client.cpp b/cpp/demo/Database/Oracle/occi/Client.cpp new file mode 100644 index 00000000000..3ebdc9f32c6 --- /dev/null +++ b/cpp/demo/Database/Oracle/occi/Client.cpp @@ -0,0 +1,673 @@ +// ********************************************************************** +// +// 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 <Ice/Ice.h> +#include <HR.h> +#include <iostream> +#include <limits> + +using namespace std; +using namespace HR; + +class HRClient : public Ice::Application +{ +public: + HRClient(); + + virtual int run(int, char*[]); + + enum Menu {rootMenu, empMenu, deptMenu}; + +private: + + void help() const; + bool checkCin(const string& command) const; + void checkEof(const string& command) const; + void invalidCommand(const string& command) const; + + void doRootMenu(const string&) const; + void doDeptMenu(const string&) const; + void doEmpMenu(const string&) const; + + Menu _currentMenu; + DeptFactoryPrx _factory; + DeptPrx _currentDept; + EmpPrx _currentEmp; + + string _commonCommands; + string _rootCommands; + string _deptCommands; + string _empCommands; +}; + +int +main(int argc, char* argv[]) +{ + HRClient app; + return app.main(argc, argv, "config.client"); +} + +HRClient::HRClient() : + _currentMenu(rootMenu) +{ + _commonCommands = + "dept <identity>: set department <identity> as the current department\n" + "emp <identity>: set employee <identity> as the current employee\n" + "exit: exit client\n" + "help: print this list of commands\n" + "root: go back to the root menu\n"; + + _rootCommands = + "create: create a new department\n" + "find <name>: find the deparment(s) with the given name\n" + "list: list all departments\n"; + + + _deptCommands = + "create: create a new employee in this department\n" + "find <name>: find employee(s) named <name> in this department\n" + "list: list all employees in this department\n" + "remove: remove this department\n" + "show: describe this department\n" + "update: update this department\n"; + + _empCommands = + "remove: remove this employee\n" + "show: describe this employee\n" + "update: update this employee\n"; +} + +void +HRClient::checkEof(const string& command) const +{ + if(!cin.eof()) + { + string extra; + getline(cin, extra); + if(extra.size() > 0) + { + cout << "Warning: ignoring extra args '" << extra + << "' for '" << command << "'" << endl; + } + } +} + +bool +HRClient::checkCin(const string& command) const +{ + if(!cin) + { + cout << "Error: failed to read arguments for '" << command << "'" << endl; + cin.clear(); + cin.ignore(numeric_limits<streamsize>::max(), '\n'); + return false; + } + checkEof(command); + return true; +} + +void +HRClient::invalidCommand(const string& command) const +{ + cout << "Invalid command '" << command << "'. " + "Type 'help' for help." << endl; + cin.ignore(numeric_limits<streamsize>::max(), '\n'); +} + +void +HRClient::help() const +{ + cout << "Commands are:\n"; + cout << "--- Specific to this menu ---\n"; + + switch(_currentMenu) + { + case rootMenu: + { + cout << _rootCommands; + break; + } + case deptMenu: + { + cout << _deptCommands; + break; + } + case empMenu: + { + cout << _empCommands; + break; + } + } + cout << "--- Common to all menus ---\n"; + cout << _commonCommands << endl; +} + +int +HRClient::run(int argc, char* argv[]) +{ + Ice::PropertiesPtr properties = communicator()->getProperties(); + const string proxyProperty = "HR.DeptFactory"; + std::string proxy = properties->getProperty(proxyProperty); + if(proxy.empty()) + { + cerr << argv[0] << ": property `" << proxyProperty << "' not set" << endl; + return EXIT_FAILURE; + } + + Ice::ObjectPrx base = communicator()->stringToProxy(proxy); + _factory = DeptFactoryPrx::checkedCast(base); + if(_factory == 0) + { + cerr << argv[0] << ": invalid proxy" << endl; + return EXIT_FAILURE; + } + + Ice::EndpointSeq endpoints = _factory->ice_getEndpoints(); + + + // + // cin loop + // + + string command; + + do + { + cout << "==> "; + cin >> command; + + if(!cin) + { + break; + } + + // + // Common commands + // + if(command == "dept") + { + string identity; + cin >> identity; + if(checkCin(command)) + { + _currentMenu = deptMenu; + _currentDept = DeptPrx::uncheckedCast( + communicator()->stringToProxy(identity)->ice_endpoints(endpoints)); + } + } + else if(command == "emp") + { + string identity; + cin >> identity; + if(checkCin(command)) + { + _currentMenu = empMenu; + _currentEmp = EmpPrx::uncheckedCast( + communicator()->stringToProxy(identity)->ice_endpoints(endpoints)); + } + } + else if(command == "exit") + { + checkEof(command); + break; + } + else if(command == "help") + { + checkEof(command); + help(); + } + else if(command == "root") + { + checkEof(command); + _currentMenu = rootMenu; + } + else if(_currentMenu == rootMenu) + { + doRootMenu(command); + } + else if(_currentMenu == deptMenu) + { + doDeptMenu(command); + } + else if(_currentMenu == empMenu) + { + doEmpMenu(command); + } + else + { + assert(0); + } + } + while(cin.good()); + + return EXIT_SUCCESS; +} + +void +HRClient::doRootMenu(const string& command) const +{ + if(command == "create") + { + checkEof(command); + cout << "Please enter: deptno dname loc ==> "; + int deptno; + DeptDesc desc; + cin >> deptno >> desc.dname >> desc.loc; + if(checkCin("create parameters")) + { + try + { + _factory->createDept(deptno, desc); + cout << "Created new department number " << deptno << endl; + } + catch(const SqlException& e) + { + cout << "Caught a SqlException: " << e.reason << endl; + } + catch(const IceUtil::Exception& e) + { + cout << "Caught an Ice exception: " << e << endl; + } + catch(const std::exception& e) + { + cout << "Caught a std::exception: " << e.what() << endl; + } + catch(...) + { + cout << "Caught an unknown exception" << endl; + } + } + } + else if(command == "find") + { + string name; + cin >> name; + if(checkCin(command)) + { + DeptPrxSeq depts; + try + { + depts = _factory->findByName(name); + if(depts.size() == 0) + { + cout << "<None found>" << endl; + } + else + { + for(DeptPrxSeq::iterator p = depts.begin(); p != depts.end(); ++p) + { + cout << communicator()->identityToString((*p)->ice_getIdentity()) << endl; + } + } + + } + catch(const IceUtil::Exception& e) + { + cout << "Caught an Ice exception: " << e << endl; + } + catch(const std::exception& e) + { + cout << "Caught a std::exception: " << e.what() << endl; + } + catch(...) + { + cout << "Caught an unknown exception" << endl; + } + } + } + else if(command == "list") + { + checkEof(command); + DeptPrxSeq depts; + try + { + depts = _factory->findAll(); + if(depts.size() == 0) + { + cout << "<None found>" << endl; + } + else + { + for(DeptPrxSeq::iterator p = depts.begin(); p != depts.end(); ++p) + { + cout << communicator()->identityToString((*p)->ice_getIdentity()) << endl; + } + } + } + catch(const IceUtil::Exception& e) + { + cout << "Caught an Ice exception: " << e << endl; + } + catch(const std::exception& e) + { + cout << "Caught a std::exception: " << e.what() << endl; + } + catch(...) + { + cout << "Caught an unknown exception" << endl; + } + } + else + { + invalidCommand(command); + } +} + +void +HRClient::doDeptMenu(const string& command) const +{ + if(command == "create") + { + checkEof(command); + cout << "Please enter: empno ename job mgr hiredate sal comm ==> "; + int empno; + string mgrId; + EmpDesc desc; + cin >> empno >> desc.ename >> desc.job >> mgrId >> desc.hiredate >> desc.sal >> desc.comm; + if(mgrId != "<None>") + { + desc.mgr = EmpPrx::uncheckedCast(communicator() + ->stringToProxy(mgrId)->ice_endpoints( + _factory->ice_getEndpoints())); + } + desc.edept = _currentDept; + + if(checkCin("create parameters")) + { + try + { + _currentDept->createEmp(empno, desc); + cout << "Created new employee number " << empno << endl; + } + catch(const SqlException& e) + { + cout << "Caught a SqlException: " << e.reason << endl; + } + catch(const IceUtil::Exception& e) + { + cout << "Caught an Ice exception: " << e << endl; + } + catch(const std::exception& e) + { + cout << "Caught a std::exception: " << e.what() << endl; + } + catch(...) + { + cout << "Caught an unknown exception" << endl; + } + } + } + else if(command == "find") + { + string name; + cin >> name; + if(checkCin(command)) + { + EmpPrxSeq emps; + try + { + emps = _currentDept->findByName(name); + if(emps.size() == 0) + { + cout << "<None found>" << endl; + } + else + { + for(EmpPrxSeq::iterator p = emps.begin(); p != emps.end(); ++p) + { + cout << communicator()->identityToString((*p)->ice_getIdentity()) << endl; + } + } + + } + catch(const IceUtil::Exception& e) + { + cout << "Caught an Ice exception: " << e << endl; + } + catch(const std::exception& e) + { + cout << "Caught a std::exception: " << e.what() << endl; + } + catch(...) + { + cout << "Caught an unknown exception" << endl; + } + } + } + else if(command == "list") + { + checkEof(command); + EmpPrxSeq emps; + try + { + emps = _currentDept->findAll(); + if(emps.size() == 0) + { + cout << "<None found>" << endl; + } + else + { + for(EmpPrxSeq::iterator p = emps.begin(); p != emps.end(); ++p) + { + cout << communicator()->identityToString((*p)->ice_getIdentity()) << endl; + } + } + } + catch(const IceUtil::Exception& e) + { + cout << "Caught an Ice exception: " << e << endl; + } + catch(const std::exception& e) + { + cout << "Caught a std::exception: " << e.what() << endl; + } + catch(...) + { + cout << "Caught an unknown exception" << endl; + } + } + else if(command == "remove") + { + checkEof(command); + try + { + _currentDept->remove(); + } + catch(const SqlException& e) + { + cout << "Caught a SqlException: " << e.reason << endl; + } + catch(const IceUtil::Exception& e) + { + cout << "Caught an Ice exception: " << e << endl; + } + catch(const std::exception& e) + { + cout << "Caught a std::exception: " << e.what() << endl; + } + catch(...) + { + cout << "Caught an unknown exception" << endl; + } + } + else if(command == "show") + { + checkEof(command); + try + { + DeptDesc desc = _currentDept->getDesc(); + cout << "identity: " << communicator()->identityToString( + _currentDept->ice_getIdentity()) << endl; + cout << "dname: " << desc.dname << endl; + cout << "loc: " << desc.loc << endl; + } + catch(const IceUtil::Exception& e) + { + cout << "Caught an Ice exception: " << e << endl; + } + catch(const std::exception& e) + { + cout << "Caught a std::exception: " << e.what() << endl; + } + catch(...) + { + cout << "Caught an unknown exception" << endl; + } + } + else if(command == "update") + { + checkEof(command); + cout << "Please enter: dname loc ==> "; + DeptDesc desc; + cin >> desc.dname >> desc.loc; + if(checkCin("update parameters")) + { + try + { + _currentDept->updateDesc(desc); + cout << "Department updated" << endl; + } + catch(const SqlException& e) + { + cout << "Caught a SqlException: " << e.reason << endl; + } + catch(const IceUtil::Exception& e) + { + cout << "Caught an Ice exception: " << e << endl; + } + catch(const std::exception& e) + { + cout << "Caught a std::exception: " << e.what() << endl; + } + catch(...) + { + cout << "Caught an unknown exception" << endl; + } + } + } + else + { + invalidCommand(command); + } +} + +void +HRClient::doEmpMenu(const string& command) const +{ + if(command == "remove") + { + checkEof(command); + try + { + _currentEmp->remove(); + } + catch(const SqlException& e) + { + cout << "Caught a SqlException: " << e.reason << endl; + } + catch(const IceUtil::Exception& e) + { + cout << "Caught an Ice exception: " << e << endl; + } + catch(const std::exception& e) + { + cout << "Caught a std::exception: " << e.what() << endl; + } + catch(...) + { + cout << "Caught an unknown exception" << endl; + } + } + else if(command == "show") + { + checkEof(command); + try + { + EmpDesc desc = _currentEmp->getDesc(); + cout << "identity: " << communicator()->identityToString( + _currentEmp->ice_getIdentity()) << endl; + cout << "ename: " << desc.ename << endl; + cout << "job: " << desc.job << endl; + cout << "mgr: " << (desc.mgr == 0 ? "<None>" : + communicator()->identityToString( + desc.mgr->ice_getIdentity())) << endl; + cout << "hiredate: " << desc.hiredate << endl; + cout << "sal: " << desc.sal << endl; + cout << "comm: " << desc.comm << endl; + cout << "dept: " << (desc.edept == 0 ? "<None>" : + communicator()->identityToString( + desc.edept->ice_getIdentity())) << endl; + } + catch(const IceUtil::Exception& e) + { + cout << "Caught an Ice exception: " << e << endl; + } + catch(const std::exception& e) + { + cout << "Caught a std::exception: " << e.what() << endl; + } + catch(...) + { + cout << "Caught an unknown exception" << endl; + } + } + else if(command == "update") + { + checkEof(command); + cout << "Please enter: ename job mgr hiredate sal comm dept ==> "; + EmpDesc desc; + string mgrId; + string deptId; + cin >> desc.ename >> desc.job + >> mgrId >> desc.hiredate >> desc.sal >> desc.comm >> deptId; + + if(mgrId != "<None>") + { + desc.mgr = EmpPrx::uncheckedCast(communicator() + ->stringToProxy(mgrId)->ice_endpoints( + _factory->ice_getEndpoints())); + } + + if(deptId != "<None>") + { + desc.edept = DeptPrx::uncheckedCast(communicator() + ->stringToProxy(deptId)->ice_endpoints( + _factory->ice_getEndpoints())); + } + + if(checkCin("update parameters")) + { + try + { + _currentEmp->updateDesc(desc); + cout << "Employee updated" << endl; + } + catch(const SqlException& e) + { + cout << "Caught a SqlException: " << e.reason << endl; + } + catch(const IceUtil::Exception& e) + { + cout << "Caught an Ice exception: " << e << endl; + } + catch(const std::exception& e) + { + cout << "Caught a std::exception: " << e.what() << endl; + } + catch(...) + { + cout << "Caught an unknown exception" << endl; + } + } + } + else + { + invalidCommand(command); + } +} diff --git a/cpp/demo/Database/Oracle/occi/DbTypes.typ b/cpp/demo/Database/Oracle/occi/DbTypes.typ new file mode 100755 index 00000000000..bcaf9c7defc --- /dev/null +++ b/cpp/demo/Database/Oracle/occi/DbTypes.typ @@ -0,0 +1,16 @@ +# **********************************************************************
+#
+# 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.
+#
+# **********************************************************************
+#
+# Compile with:
+# ott userid=scott/tiger@orcl code=cpp hfile=DbTypes.h cppfile=DbTypes.cpp
+# mapfile=DbTypesMap.cpp intype=DbTypes.typ outtype=DbTypesOut.typ
+# attraccess=private
+#
+TYPE DEPT_T
+TYPE EMP_T
diff --git a/cpp/demo/Database/Oracle/occi/DeptFactoryI.cpp b/cpp/demo/Database/Oracle/occi/DeptFactoryI.cpp new file mode 100644 index 00000000000..1f0c1fbdb36 --- /dev/null +++ b/cpp/demo/Database/Oracle/occi/DeptFactoryI.cpp @@ -0,0 +1,108 @@ +// ********************************************************************** +// +// 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 <Ice/Ice.h> +#include <DeptFactoryI.h> +#include <Util.h> +#include <DbTypes.h> + +#ifdef _MSC_VER +// +// ott generates placement new without the corresponding delete +// +# pragma warning( 4 : 4291 ) +#endif + +using namespace std; +using namespace oracle::occi; + +DeptFactoryI::DeptFactoryI(StatelessConnectionPool* pool, + const string& deptCategory) : + _pool(pool), + _deptCategory(deptCategory) +{ +} + +HR::DeptPrx +DeptFactoryI::createDept(int deptno, const HR::DeptDesc& desc, const Ice::Current& current) +{ + ConnectionHolder conh(_pool); + + // + // Inserted into the OCCI cache + // + DEPT_T* dept = new(conh.connection(), "DEPT_VIEW")DEPT_T; + dept->setDeptno(deptno); + dept->setDname(desc.dname); + dept->setLoc(desc.loc); + conh.commit(); + + Ice::Identity deptId; + deptId.name = encodeName(deptno); + deptId.category = _deptCategory; + return HR::DeptPrx::uncheckedCast(current.adapter->createProxy(deptId)); +} + +HR::DeptPrxSeq +DeptFactoryI::findAll(const Ice::Current& current) +{ + HR::DeptPrxSeq result; + + ConnectionHolder conh(_pool); + { + StatementHolder stmth(conh); + + auto_ptr<ResultSet> rs = + stmth.statement()->executeQuery("SELECT DEPTNO FROM DEPT_VIEW"); + + while(rs->next() != ResultSet::END_OF_FETCH) + { + Ice::Identity deptId; + deptId.category = _deptCategory; + deptId.name = rs->getString(1); // first column as string + + result.push_back( + HR::DeptPrx::uncheckedCast( + current.adapter->createProxy(deptId))); + } + } + conh.commit(); + return result; +} + + +HR::DeptPrxSeq +DeptFactoryI::findByName(const string& name, const Ice::Current& current) +{ + HR::DeptPrxSeq result; + + ConnectionHolder conh(_pool); + { + StatementHolder stmth(conh); + stmth.statement()->setSQL("SELECT DEPTNO FROM DEPT_VIEW WHERE DNAME = :1"); + stmth.statement()->setString(1, name); + stmth.statement()->execute(); + + auto_ptr<ResultSet> rs = + stmth.statement()->getResultSet(); + + while(rs->next() != ResultSet::END_OF_FETCH) + { + Ice::Identity deptId; + deptId.category = _deptCategory; + deptId.name = rs->getString(1); // first column as string + + result.push_back( + HR::DeptPrx::uncheckedCast( + current.adapter->createProxy(deptId))); + } + } + conh.commit(); + return result; +} diff --git a/cpp/demo/Database/Oracle/occi/DeptFactoryI.h b/cpp/demo/Database/Oracle/occi/DeptFactoryI.h new file mode 100644 index 00000000000..e77e2bb377d --- /dev/null +++ b/cpp/demo/Database/Oracle/occi/DeptFactoryI.h @@ -0,0 +1,32 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +#ifndef DEPT_FACTORYI_H +#define DEPT_FACTORYI_H + +#include <HR.h> +#include <occi.h> + +class DeptFactoryI : public HR::DeptFactory +{ +public: + + DeptFactoryI(oracle::occi::StatelessConnectionPool*, const std::string&); + + virtual HR::DeptPrx createDept(int, const HR::DeptDesc&, const Ice::Current&); + + virtual HR::DeptPrxSeq findAll(const Ice::Current&); + virtual HR::DeptPrxSeq findByName(const std::string&, const Ice::Current&); + +private: + oracle::occi::StatelessConnectionPool* _pool; + const std::string _deptCategory; +}; + +#endif diff --git a/cpp/demo/Database/Oracle/occi/DeptI.cpp b/cpp/demo/Database/Oracle/occi/DeptI.cpp new file mode 100644 index 00000000000..bfa1a3e073a --- /dev/null +++ b/cpp/demo/Database/Oracle/occi/DeptI.cpp @@ -0,0 +1,218 @@ +// ********************************************************************** +// +// 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 <Ice/Ice.h> +#include <DeptI.h> +#include <Util.h> +#include <EmpI.h> + +#ifdef _MSC_VER +// +// ott generates placement new without the corresponding delete +// +# pragma warning( 4 : 4291 ) +#endif + +using namespace std; +using namespace oracle::occi; + +DeptI::DeptI(Environment* env, StatelessConnectionPool* pool, const string& empCategory) : + _env(env), + _pool(pool), + _empCategory(empCategory) +{ +} + +void +DeptI::ice_ping(const Ice::Current& current) const +{ + ConnectionHolder conh(_pool); + { + StatementHolder stmth(conh); + stmth.statement()->setSQL("BEGIN; SELECT COUNT(*) INTO :1 FROM DEPT_VIEW WHERE DEPTNO = :2; END"); + stmth.statement()->registerOutParam(1, OCCIINT); + stmth.statement()->setString(2, current.id.name); + stmth.statement()->execute(); + + if(stmth.statement()->getInt(1) == 0) + { + throw Ice::ObjectNotExistException(__FILE__, __LINE__); + } + } + conh.commit(); +} + +HR::EmpPrx +DeptI::createEmp(int empno, const HR::EmpDesc& desc, const Ice::Current& current) +{ + ConnectionHolder conh(_pool); + + Ref<DEPT_T> deptRef = getRef(conh.connection(), decodeName(current.id.name)); + if(deptRef.isNull()) + { + throw Ice::ObjectNotExistException(__FILE__, __LINE__); + } + + // + // Inserted into the OCCI cache + // + EMP_T* emp = new(conh.connection(), "EMP_VIEW")EMP_T; + + emp->setEmpno(empno); + emp->setEname(desc.ename); + emp->setJob(desc.job); + if(desc.mgr != 0) + { + Ref<EMP_T> mgrRef = + EmpI::getRef(conh.connection(), decodeName(desc.mgr->ice_getIdentity().name)); + + if(mgrRef.isNull()) + { + throw Ice::ObjectNotExistException(__FILE__, __LINE__); + } + emp->setMgrref(mgrRef); + } + + Date hiredate; + hiredate.fromText(desc.hiredate); + emp->setHiredate(hiredate); + + Number sal; + sal.fromText(_env, desc.sal, "9,999,999.99"); + emp->setSal(sal); + + Number comm; + comm.fromText(_env, desc.comm, "0.999"); + emp->setComm(comm); + + emp->setDeptref(deptRef); + conh.commit(); + + Ice::Identity empId; + empId.name = encodeName(empno); + empId.category = _empCategory; + return HR::EmpPrx::uncheckedCast(current.adapter->createProxy(empId)); +} + +HR::DeptDesc +DeptI::getDesc(const Ice::Current& current) +{ + ConnectionHolder conh(_pool); + + Ref<DEPT_T> deptRef = getRef(conh.connection(), decodeName(current.id.name)); + if(deptRef.isNull()) + { + throw Ice::ObjectNotExistException(__FILE__, __LINE__); + } + + HR::DeptDesc result = {deptRef->getDname(), deptRef->getLoc()}; + conh.commit(); + return result; +} + +void DeptI::updateDesc(const HR::DeptDesc& newDesc, const Ice::Current& current) +{ + ConnectionHolder conh(_pool); + + Ref<DEPT_T> deptRef = getRef(conh.connection(), decodeName(current.id.name)); + if(deptRef.isNull()) + { + throw Ice::ObjectNotExistException(__FILE__, __LINE__); + } + + deptRef->setDname(newDesc.dname); + deptRef->setLoc(newDesc.loc); + deptRef->markModified(); + conh.commit(); +} + +void DeptI::remove(const Ice::Current& current) +{ + ConnectionHolder conh(_pool); + + Ref<DEPT_T> deptRef = getRef(conh.connection(), decodeName(current.id.name)); + if(deptRef.isNull()) + { + throw Ice::ObjectNotExistException(__FILE__, __LINE__); + } + + deptRef->markDelete(); + conh.commit(); +} + +HR::EmpPrxSeq +DeptI::findAll(const Ice::Current& current) +{ + HR::EmpPrxSeq result; + + ConnectionHolder conh(_pool); + { + StatementHolder stmth(conh); + + auto_ptr<ResultSet> rs = + stmth.statement()->executeQuery("SELECT EMPNO FROM EMP_VIEW"); + + while(rs->next() != ResultSet::END_OF_FETCH) + { + Ice::Identity empId; + empId.category = _empCategory; + empId.name = rs->getString(1); // first column as string + + result.push_back( + HR::EmpPrx::uncheckedCast( + current.adapter->createProxy(empId))); + } + } + conh.commit(); + return result; +} + + +HR::EmpPrxSeq +DeptI::findByName(const string& name, const Ice::Current& current) +{ + HR::EmpPrxSeq result; + + ConnectionHolder conh(_pool); + { + StatementHolder stmth(conh); + stmth.statement()->setSQL("SELECT EMPNO FROM EMP_VIEW WHERE ENAME = :1"); + stmth.statement()->setString(1, name); + stmth.statement()->execute(); + + auto_ptr<ResultSet> rs = + stmth.statement()->getResultSet(); + + while(rs->next() != ResultSet::END_OF_FETCH) + { + Ice::Identity empId; + empId.category = _empCategory; + empId.name = rs->getString(1); // first column as string + + result.push_back( + HR::EmpPrx::uncheckedCast( + current.adapter->createProxy(empId))); + } + } + conh.commit(); + return result; +} + + +/*static*/ +Ref<DEPT_T> +DeptI::getRef(Connection* con, int deptno) +{ + StatementHolder stmth(con); + stmth.statement()->setSQL("BEGIN; SELECT REF(d) INTO :1 FROM DEPT_VIEW d WHERE DEPTNO = :2; END"); + stmth.statement()->registerOutParam(1, OCCIREF); + stmth.statement()->setInt(2, deptno); + stmth.statement()->execute(); + return stmth.statement()->getRef(1); +} diff --git a/cpp/demo/Database/Oracle/occi/DeptI.h b/cpp/demo/Database/Oracle/occi/DeptI.h new file mode 100644 index 00000000000..7482ba7eda6 --- /dev/null +++ b/cpp/demo/Database/Oracle/occi/DeptI.h @@ -0,0 +1,47 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +#ifndef DEPTI_H +#define DEPTI_H + +#include <HR.h> +#include <occi.h> +#include <DbTypes.h> + +class DeptI : public HR::Dept +{ +public: + + DeptI(oracle::occi::Environment* env, + oracle::occi::StatelessConnectionPool*, const std::string&); + + virtual void ice_ping(const Ice::Current&) const; + + virtual HR::EmpPrx createEmp(int, const HR::EmpDesc&, const Ice::Current&); + + virtual HR::DeptDesc getDesc(const Ice::Current&); + virtual void updateDesc(const HR::DeptDesc& newDesc, const Ice::Current&); + virtual void remove(const Ice::Current&); + + virtual HR::EmpPrxSeq findAll(const Ice::Current&); + virtual HR::EmpPrxSeq findByName(const std::string&, const Ice::Current&); + + // + // Returns a null ref when not found + // + static oracle::occi::Ref<DEPT_T> getRef(oracle::occi::Connection* con, int deptno); + +private: + + oracle::occi::Environment* _env; + oracle::occi::StatelessConnectionPool* _pool; + const std::string _empCategory; +}; + +#endif diff --git a/cpp/demo/Database/Oracle/occi/EmpI.cpp b/cpp/demo/Database/Oracle/occi/EmpI.cpp new file mode 100644 index 00000000000..d713b9f067f --- /dev/null +++ b/cpp/demo/Database/Oracle/occi/EmpI.cpp @@ -0,0 +1,179 @@ +// ********************************************************************** +// +// 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 <Ice/Ice.h> +#include <EmpI.h> +#include <Util.h> +#include <occi.h> + +using namespace std; +using namespace oracle::occi; + +EmpI::EmpI(Environment* env, StatelessConnectionPool* pool, + const string& empCategory, const string& deptCategory) : + _env(env), + _pool(pool), + _empCategory(empCategory), _deptCategory(deptCategory) +{ +} + +void +EmpI::ice_ping(const Ice::Current& current) const +{ + ConnectionHolder conh(_pool); + { + StatementHolder stmth(conh); + + stmth.statement()->setSQL("BEGIN; SELECT COUNT(*) INTO :1 FROM EMP_VIEW WHERE EMPNO = :2; END"); + stmth.statement()->registerOutParam(1, OCCIINT); + stmth.statement()->setString(2, current.id.name); + stmth.statement()->execute(); + + if(stmth.statement()->getInt(1) == 0) + { + throw Ice::ObjectNotExistException(__FILE__, __LINE__); + } + } + conh.commit(); +} + + +HR::EmpDesc +EmpI::getDesc(const Ice::Current& current) +{ + ConnectionHolder conh(_pool); + + Ref<EMP_T> empRef = getRef(conh.connection(), decodeName(current.id.name)); + if(empRef.isNull()) + { + throw Ice::ObjectNotExistException(__FILE__, __LINE__); + } + + HR::EmpDesc result; + result.ename = empRef->getEname(); + result.job = empRef->getJob(); + + Ref<EMP_T> mgrRef = empRef->getMgrref(); + if(!mgrRef.isNull()) + { + Ice::Identity mgrId; + mgrId.name = encodeName(mgrRef->getEmpno()); + mgrId.category = _empCategory; + result.mgr = + HR::EmpPrx::uncheckedCast(current.adapter->createProxy(mgrId)); + } + + if(!empRef->getSal().isNull()) + { + result.sal = empRef->getSal().toText(_env, "9,999,999.99"); + } + + if(!empRef->getComm().isNull()) + { + result.comm = empRef->getComm().toText(_env, "0.999"); + } + + Ref<DEPT_T> deptRef = empRef->getDeptref(); + if(!deptRef.isNull()) + { + Ice::Identity deptId; + deptId.name = encodeName(deptRef->getDeptno()); + deptId.category = _deptCategory; + result.edept = + HR::DeptPrx::uncheckedCast(current.adapter->createProxy(deptId)); + } + + conh.commit(); + return result; +} + +void EmpI::updateDesc(const HR::EmpDesc& newDesc, const Ice::Current& current) +{ + ConnectionHolder conh(_pool); + + Ref<EMP_T> empRef = getRef(conh.connection(), decodeName(current.id.name)); + if(empRef.isNull()) + { + throw Ice::ObjectNotExistException(__FILE__, __LINE__); + } + + empRef->setEname(newDesc.ename); + empRef->setJob(newDesc.job); + + if(newDesc.mgr == 0) + { + empRef->setMgrref(Ref<EMP_T>()); + } + else + { + Ref<EMP_T> mgrRef = getRef(conh.connection(), + decodeName(newDesc.mgr->ice_getIdentity().name)); + if(mgrRef.isNull()) + { + throw Ice::ObjectNotExistException(__FILE__, __LINE__); + } + empRef->setMgrref(mgrRef); + } + + Date hiredate; + hiredate.fromText(newDesc.hiredate); + empRef->setHiredate(hiredate); + + Number sal; + sal.fromText(_env, newDesc.sal, "9,999,999.99"); + empRef->setSal(sal); + + Number comm; + comm.fromText(_env, newDesc.comm, "0.999"); + empRef->setComm(comm); + + if(newDesc.edept == 0) + { + empRef->setDeptref(Ref<DEPT_T>()); + } + else + { + Ref<DEPT_T> deptRef = getRef(conh.connection(), + decodeName(newDesc.edept->ice_getIdentity().name)); + if(deptRef.isNull()) + { + throw Ice::ObjectNotExistException(__FILE__, __LINE__); + } + empRef->setDeptref(deptRef); + } + + empRef->markModified(); + conh.commit(); +} + +void EmpI::remove(const Ice::Current& current) +{ + ConnectionHolder conh(_pool); + + Ref<EMP_T> empRef = getRef(conh.connection(), decodeName(current.id.name)); + if(empRef.isNull()) + { + throw Ice::ObjectNotExistException(__FILE__, __LINE__); + } + + empRef->markDelete(); + conh.commit(); +} + +/*static*/ +Ref<EMP_T> +EmpI::getRef(Connection* con, int empno) +{ + StatementHolder stmth(con); + stmth.statement()->setSQL("BEGIN; SELECT REF(e) INTO :1 FROM EMP_VIEW e WHERE EMPNO = :2; END"); + stmth.statement()->registerOutParam(1, OCCIREF); + stmth.statement()->setInt(2, empno); + stmth.statement()->execute(); + return stmth.statement()->getRef(1); +} diff --git a/cpp/demo/Database/Oracle/occi/EmpI.h b/cpp/demo/Database/Oracle/occi/EmpI.h new file mode 100644 index 00000000000..ba7442d98a6 --- /dev/null +++ b/cpp/demo/Database/Oracle/occi/EmpI.h @@ -0,0 +1,42 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +#ifndef EMPI_H +#define EMPI_H + +#include <HR.h> +#include <occi.h> +#include <DbTypes.h> + +class EmpI : public HR::Emp +{ +public: + + EmpI(oracle::occi::Environment* env, + oracle::occi::StatelessConnectionPool*, const std::string&, const std::string&); + + virtual void ice_ping(const Ice::Current&) const; + + virtual HR::EmpDesc getDesc(const Ice::Current&); + virtual void updateDesc(const HR::EmpDesc& newDesc, const Ice::Current&); + virtual void remove(const Ice::Current&); + + // + // Returns a null ref when not found + // + static oracle::occi::Ref<EMP_T> getRef(oracle::occi::Connection* con, int empno); + +private: + oracle::occi::Environment* _env; + oracle::occi::StatelessConnectionPool* _pool; + const std::string _empCategory; + const std::string _deptCategory; +}; + +#endif diff --git a/cpp/demo/Database/Oracle/occi/HR.ice b/cpp/demo/Database/Oracle/occi/HR.ice new file mode 100644 index 00000000000..7053cb549a4 --- /dev/null +++ b/cpp/demo/Database/Oracle/occi/HR.ice @@ -0,0 +1,85 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +#ifndef HR_ICE +#define HR_ICE + +// +// Corresponds to the well-known Dept/Emp Oracle demo database. +// See rdbms/admin/utlsamp.sql +// + + +module HR +{ + +interface Dept; +sequence<Dept*> DeptPrxSeq; + +interface Emp; +sequence<Emp*> EmpPrxSeq; + +exception SqlException +{ + string reason; +}; + +// +// The data we maintain about each department +// +struct DeptDesc +{ + string dname; + string loc; +}; + +// +// The data we maintain about each Employee +// +struct EmpDesc +{ + string ename; + string job; + Emp* mgr; + string hiredate; + string sal; + string comm; + Dept* edept; +}; + +interface Emp +{ + idempotent EmpDesc getDesc(); + idempotent void updateDesc(EmpDesc newDesc) throws SqlException; + void remove(); +}; + +interface Dept +{ + Emp* createEmp(int empno, EmpDesc descx) throws SqlException; + + idempotent DeptDesc getDesc(); + idempotent void updateDesc(DeptDesc newDesc) throws SqlException; + void remove() throws SqlException; + + idempotent EmpPrxSeq findAll(); + idempotent EmpPrxSeq findByName(string ename); +}; + +interface DeptFactory +{ + Dept* createDept(int deptno, DeptDesc desc) throws SqlException; + + idempotent DeptPrxSeq findAll(); + idempotent DeptPrxSeq findByName(string dname); +}; + +}; + +#endif diff --git a/cpp/demo/Database/Oracle/occi/Makefile b/cpp/demo/Database/Oracle/occi/Makefile new file mode 100644 index 00000000000..1e53760bfbd --- /dev/null +++ b/cpp/demo/Database/Oracle/occi/Makefile @@ -0,0 +1,71 @@ +# ********************************************************************** +# +# 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. +# +# ********************************************************************** + +top_srcdir = ../../../.. + +CLIENT = client +SERVER = server + +TARGETS = $(CLIENT) $(SERVER) + +SLICE_SRCS = HR.ice + +PROC_SRCS = CurrentSqlContext.pc \ + Util.pc \ + EmpI.pc \ + DeptI.pc \ + DeptFactoryI.pc \ + Server.pc + +OBJS = HR.o + +COBJS = Client.o + +SOBJS = $(PROC_SRCS:.pc=.o) + +SRCS = $(OBJS:.o=.cpp) \ + $(COBJS:.o=.cpp) \ + $(SOBJS:.o=.cpp) + + + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I$(ORACLE_HOME)/precomp/public -DSQLCA_NONE $(CPPFLAGS) + +GENERATED_PROC_FILES = $(PROC_SRCS:.pc=.cpp) + +ifeq ($(LP64),yes) + ORACLE_LIBS = -L$(ORACLE_HOME)/lib -lclntsh +else + ORACLE_LIBS = -L$(ORACLE_HOME)/lib32 -lclntsh +endif + +.SUFFIXES: +.SUFFIXES: .pc .cpp .c .o + +# +# The rm -f tp* $*.lis is to work around a proc bug on Linux +# +.pc.cpp: + proc threads=yes parse=none lines=yes code=cpp cpp_suffix=cpp close_on_commit=yes $< + rm -f tp* $*.lis + +$(CLIENT): $(OBJS) $(COBJS) + rm -f $@ + $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(COBJS) $(LIBS) + +$(SERVER): $(OBJS) $(SOBJS) + rm -f $@ + $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(SOBJS) $(ORACLE_LIBS) $(LIBS) + +clean:: + rm -f $(GENERATED_PROC_FILES) + +include .depend diff --git a/cpp/demo/Database/Oracle/occi/README b/cpp/demo/Database/Oracle/occi/README new file mode 100644 index 00000000000..555cff270b7 --- /dev/null +++ b/cpp/demo/Database/Oracle/occi/README @@ -0,0 +1,39 @@ +Oracle Pro*C/C++ demo +===================== + +This demo shows how to implement an Ice server that uses Oracle +through its Embedded SQL (Pro*C/C++) API. + +It is a fairly simple demo that illustrates how to: + - map relational data to Ice objects, in particular convert + between Ice and Oracle Pro*C/C++ types. + - associate an Oracle Pro*C/C++ context and database connection + to each thread in the Ice server thread pool. + - use Ice default servants + +Building the demo +----------------- +On Linux or Unix, set ORACLE_HOME to point to your Oracle +installation home directory. Then build as usual. + +On Windows, you need to add the following directories to your +Visual C++ environment: + - Include files: <oracle-home>\precomp\public + - Library files: <oracle-home>\precomp\lib + - Executable files: <oracle-home>\bin +Then build as usual. + +Running the demo +---------------- +- Setup an Oracle database with the traditional EMP/DEPT schema. +With Oracle server 10.2, the corresponding SQL script is +$ORACLE_HOME/rdbms/admin/utilsamp.sql. + +- Review the Oracle.ConnectInfo property in the config.server file. +You may need to change it to connect to your Oracle instance. + +- Start the server: +$ server + +- Start the client in a separate terminal: +$ client diff --git a/cpp/demo/Database/Oracle/occi/Server.cpp b/cpp/demo/Database/Oracle/occi/Server.cpp new file mode 100644 index 00000000000..1207685e2db --- /dev/null +++ b/cpp/demo/Database/Oracle/occi/Server.cpp @@ -0,0 +1,130 @@ +// ********************************************************************** +// +// 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 <occi.h> + +using namespace std; +using namespace oracle::occi; + +class HRServer : public Ice::Application +{ +public: + + virtual int run(int, char*[]); +}; + +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[]) +{ + HRServer app; + return app.main(argc, argv, "config.server"); +} + +int +HRServer::run(int argc, char* argv[]) +{ + const string username = communicator()->getProperties() + ->getPropertyWithDefault("Oracle.Username", "scott"); + const string password = communicator()->getProperties() + ->getPropertyWithDefault("Oracle.Password", "password"); + const string connectString = communicator()->getProperties() + ->getProperty("Oracle.ConnectString"); + + const string empCategory = "Emp"; + const string deptCategory = "Dept"; + + Environment* env = 0; + StatelessConnectionPool* pool = 0; + + try + { + // + // Using an enum parameter for a bitmask is not such a good idea! + // + env = Environment::createEnvironment( + Environment::Mode(Environment::THREADED_MUTEXED | Environment::OBJECT)); + + pool = env->createStatelessConnectionPool( + username, password, connectString, 5, 2, 1, + StatelessConnectionPool::HOMOGENEOUS); + + Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("HR"); + + adapter->addServantLocator(new DefaultServantLocator( + new EmpI(env, pool, empCategory, deptCategory)), + empCategory); + + adapter->addServantLocator(new DefaultServantLocator( + new DeptI(env, pool, empCategory)), + deptCategory); + + adapter->add(new DeptFactoryI(pool, deptCategory), + communicator()->stringToIdentity("DeptFactory")); + + adapter->activate(); + communicator()->waitForShutdown(); + } + catch(...) + { + if(pool != 0) + { + env->terminateStatelessConnectionPool(pool); + } + if(env != 0) + { + Environment::terminateEnvironment(env); + } + throw; + } + + if(pool != 0) + { + env->terminateStatelessConnectionPool(pool); + } + if(env != 0) + { + Environment::terminateEnvironment(env); + } + return EXIT_SUCCESS; +} diff --git a/cpp/demo/Database/Oracle/occi/Util.cpp b/cpp/demo/Database/Oracle/occi/Util.cpp new file mode 100644 index 00000000000..dd7a0107c7d --- /dev/null +++ b/cpp/demo/Database/Oracle/occi/Util.cpp @@ -0,0 +1,126 @@ +// ********************************************************************** +// +// 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 <Ice/Ice.h> +#include <HR.h> +#include <Util.h> +#include <sstream> + +using namespace std; +using namespace oracle::occi; + +ConnectionHolder::ConnectionHolder(StatelessConnectionPool* pool) + : _con(pool->getAnyTaggedConnection()), + _pool(pool) +{ +} + +ConnectionHolder::~ConnectionHolder() +{ + if(_con != 0) + { + try + { + rollback(); + } + catch(...) + { + // ignored, to avoid a crash during + // stack unwinding + } + } +} + +void +ConnectionHolder::commit() +{ + assert(_con != 0); + try + { + _con->commit(); + } + catch(const SQLException& e) + { + release(); + throw HR::SqlException(e.what()); + } + catch(...) + { + release(); + throw; + } + release(); +} + +void +ConnectionHolder::rollback() +{ + assert(_con != 0); + try + { + _con->rollback(); + } + catch(const SQLException& e) + { + release(); + throw HR::SqlException(e.what()); + } + catch(...) + { + release(); + throw; + } + release(); +} + +void +ConnectionHolder::release() +{ + Connection* con = _con; + _con = 0; + _pool->releaseConnection(con); +} + +StatementHolder::StatementHolder(Connection* con) : + _stmt(con->createStatement()), + _con(con) +{ +} + +StatementHolder::StatementHolder(ConnectionHolder& conh) : + _stmt(conh.connection()->createStatement()), + _con(conh.connection()) +{ +} + +StatementHolder::~StatementHolder() +{ + _con->terminateStatement(_stmt); +} + +int decodeName(const string& name) +{ + int result = 0; + istringstream is(name); + is >> result; + if(!is || !is.eof()) + { + cerr << "Unable to decode " << name << endl; + throw Ice::ObjectNotExistException(__FILE__, __LINE__); + } + return result; +} + +string encodeName(int n) +{ + ostringstream os; + os << n; + return os.str(); +} + diff --git a/cpp/demo/Database/Oracle/occi/Util.h b/cpp/demo/Database/Oracle/occi/Util.h new file mode 100644 index 00000000000..af221566569 --- /dev/null +++ b/cpp/demo/Database/Oracle/occi/Util.h @@ -0,0 +1,69 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +#ifndef UTIL_H +#define UTIL_H + +#include <occi.h> +#include <string> + +// +// Grabs a connection from a connection pool and ensures +// it's properly released when ConnectionHolder goes out +// scope +// +class ConnectionHolder +{ +public: + + ConnectionHolder(oracle::occi::StatelessConnectionPool*); + ~ConnectionHolder(); + + oracle::occi::Connection* connection() const + { + return _con; + } + + void commit(); + void rollback(); + +private: + + void release(); + + oracle::occi::Connection* _con; + oracle::occi::StatelessConnectionPool* _pool; +}; + + +// +// Create a fresh exception-safe statement +// +class StatementHolder +{ +public: + StatementHolder(oracle::occi::Connection*); + StatementHolder(ConnectionHolder&); + ~StatementHolder(); + + oracle::occi::Statement* statement() const + { + return _stmt; + } + +private: + oracle::occi::Connection* _con; + oracle::occi::Statement* _stmt; +}; + + +int decodeName(const std::string&); +std::string encodeName(int); + +#endif diff --git a/cpp/demo/Database/Oracle/occi/config.client b/cpp/demo/Database/Oracle/occi/config.client new file mode 100644 index 00000000000..be8c63ec65c --- /dev/null +++ b/cpp/demo/Database/Oracle/occi/config.client @@ -0,0 +1 @@ +HR.DeptFactory=DeptFactory:tcp -p 10000 diff --git a/cpp/demo/Database/Oracle/occi/config.server b/cpp/demo/Database/Oracle/occi/config.server new file mode 100644 index 00000000000..0b627b50ba0 --- /dev/null +++ b/cpp/demo/Database/Oracle/occi/config.server @@ -0,0 +1,10 @@ +HR.Endpoints=tcp -p 10000 + +Ice.ThreadPool.Server.Size=5 + +Oracle.Username=scott +Oracle.Password=tiger +Oracle.ConnectString=orcl + + + diff --git a/cpp/demo/Database/Oracle/occi/createTypes.sql b/cpp/demo/Database/Oracle/occi/createTypes.sql new file mode 100755 index 00000000000..f85a82c8e43 --- /dev/null +++ b/cpp/demo/Database/Oracle/occi/createTypes.sql @@ -0,0 +1,55 @@ +Rem
+Rem Copyright (c) 2006 ZeroC, Inc. All rights reserved.
+Rem
+Rem This copy of Ice is licensed to you under the terms described in the
+Rem ICE_LICENSE file included in this distribution.
+
+Rem
+Rem Create object types and views for the DEPT and EMP tables
+Rem
+
+SET TERMOUT OFF
+SET ECHO
+
+CONNECT SCOTT/TIGER@ORCL
+
+DROP VIEW EMP_VIEW;
+DROP VIEW DEPT_VIEW;
+DROP TYPE EMP_T;
+DROP TYPE DEPT_T;
+
+CREATE TYPE DEPT_T AS OBJECT(
+ DEPTNO NUMBER(2),
+ DNAME VARCHAR2(14),
+ LOC VARCHAR2(13));
+/
+
+CREATE TYPE EMP_T;
+/
+CREATE TYPE EMP_T AS OBJECT(
+ EMPNO NUMBER(4),
+ ENAME VARCHAR2(10),
+ JOB VARCHAR2(9),
+ MGRREF REF EMP_T,
+ HIREDATE DATE,
+ SAL NUMBER(7,2),
+ COMM NUMBER(7,2),
+ DEPTREF REF DEPT_T);
+/
+
+CREATE VIEW DEPT_VIEW OF DEPT_T WITH OBJECT IDENTIFIER(DEPTNO)
+ AS SELECT DEPTNO, DNAME, LOC FROM DEPT;
+
+Rem
+Rem Need to create the view in two steps since it references itself
+Rem
+CREATE VIEW EMP_VIEW OF EMP_T WITH OBJECT IDENTIFIER(EMPNO)
+ AS SELECT EMPNO, ENAME, JOB, NULL, HIREDATE, SAL, COMM,
+ MAKE_REF(DEPT_VIEW, DEPTNO) FROM EMP;
+
+CREATE OR REPLACE VIEW EMP_VIEW OF EMP_T WITH OBJECT IDENTIFIER(EMPNO)
+ AS SELECT EMPNO, ENAME, JOB, MAKE_REF(EMP_VIEW, MGR), HIREDATE, SAL,
+ COMM, MAKE_REF(DEPT_VIEW, DEPTNO) FROM EMP;
+
+COMMIT;
+EXIT
diff --git a/cpp/demo/Database/Oracle/occi/occiC.dsp b/cpp/demo/Database/Oracle/occi/occiC.dsp new file mode 100644 index 00000000000..853f092ee6a --- /dev/null +++ b/cpp/demo/Database/Oracle/occi/occiC.dsp @@ -0,0 +1,157 @@ +# Microsoft Developer Studio Project File - Name="occiC" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=occiC - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "occiC.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "occiC.mak" CFG="occiC - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "occiC - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "occiC - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "occiC - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /WX /GR /GX /O2 /I "." /I "../../../../include" /I "../../../../include/stlport" /D "_CONSOLE" /D "NDEBUG" /D "WIN32_LEAN_AND_MEAN" /FD /c
+# SUBTRACT CPP /Fr /YX
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 Ice.lib IceUtil.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"client.exe" /libpath:"../../../../lib" /FIXED:no
+# SUBTRACT LINK32 /debug /nodefaultlib
+
+!ELSEIF "$(CFG)" == "occiC - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /WX /Gm /GR /GX /Zi /Od /I "." /I "../../../../include" /I "../../../../include/stlport" /D "_CONSOLE" /D "_DEBUG" /D "WIN32_LEAN_AND_MEAN" /FD /GZ /c
+# SUBTRACT CPP /Fr /YX
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 Iced.lib IceUtild.lib /nologo /subsystem:console /debug /machine:I386 /out:"client.exe" /pdbtype:sept /libpath:"../../../../lib" /FIXED:no
+# SUBTRACT LINK32 /pdb:none
+
+!ENDIF
+
+# Begin Target
+
+# Name "occiC - Win32 Release"
+# Name "occiC - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\Client.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\HR.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\HR.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# Begin Source File
+
+SOURCE=.\HR.ice
+
+!IF "$(CFG)" == "occiC - Win32 Release"
+
+USERDEP__HELLO="..\..\..\..\bin\slice2cpp.exe" "..\..\..\..\lib\slice.lib"
+# Begin Custom Build
+InputPath=.\HR.ice
+
+BuildCmds= \
+ ..\..\..\..\bin\slice2cpp.exe HR.ice
+
+"HR.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"HR.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "occiC - Win32 Debug"
+
+USERDEP__HELLO="..\..\..\..\bin\slice2cpp.exe" "..\..\..\..\lib\sliced.lib"
+# Begin Custom Build
+InputPath=.\HR.ice
+
+BuildCmds= \
+ ..\..\..\..\bin\slice2cpp.exe HR.ice
+
+"HR.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"HR.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+# End Custom Build
+
+!ENDIF
+
+# End Source File
+# End Group
+# Begin Source File
+
+SOURCE=.\README
+# End Source File
+# End Target
+# End Project
diff --git a/cpp/demo/Database/Oracle/occi/occiS.dsp b/cpp/demo/Database/Oracle/occi/occiS.dsp new file mode 100755 index 00000000000..be939a65344 --- /dev/null +++ b/cpp/demo/Database/Oracle/occi/occiS.dsp @@ -0,0 +1,266 @@ +# Microsoft Developer Studio Project File - Name="occiS" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=occiS - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "occiS.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "occiS.mak" CFG="occiS - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "occiS - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "occiS - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "occiS - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /WX /GR /GX /O2 /I "." /I "../../../../include" /I "../../../../include/stlport" /D "_CONSOLE" /D "NDEBUG" /D "WIN32_LEAN_AND_MEAN" /FD /c
+# SUBTRACT CPP /Fr /YX
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 Ice.lib IceUtil.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"server.exe" /libpath:"../../../../lib" /FIXED:no
+# SUBTRACT LINK32 /debug /nodefaultlib
+
+!ELSEIF "$(CFG)" == "occiS - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /WX /Gm /GR /GX /Zi /Od /I "." /I "../../../../include" /I "../../../../include/stlport" /D "_CONSOLE" /D "_DEBUG" /D "WIN32_LEAN_AND_MEAN" /FD /GZ /c
+# SUBTRACT CPP /Fr /YX
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 orasql10.lib Iced.lib IceUtild.lib /nologo /subsystem:console /debug /machine:I386 /out:"server.exe" /pdbtype:sept /libpath:"../../../../lib" /FIXED:no
+# SUBTRACT LINK32 /pdb:none
+
+!ENDIF
+
+# Begin Target
+
+# Name "occiS - Win32 Release"
+# Name "occiS - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\DbTypes.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\DbTypesMap.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\DeptFactoryI.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\DeptI.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\EmpI.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\HR.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\Server.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\Util.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\DbTypes.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\DbTypesMap.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\DeptFactoryI.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\DeptI.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\EmpI.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\HR.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Util.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# Begin Source File
+
+SOURCE=.\DbTypes.typ
+
+!IF "$(CFG)" == "occiS - Win32 Release"
+
+# Begin Custom Build
+InputPath=.\DbTypes.typ
+InputName=DbTypes
+
+BuildCmds= \
+ ott userid=scott/tiger@orcl code=cpp hfile=$(InputName).h cppfile=$(InputName).cpp mapfile=$(InputName)Map.cpp intype=$(InputPath) outtype=$(InputName)Out.typ attraccess=private
+
+"$(InputName).h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"$(InputName).cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"$(InputName)Map.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"$(InputName)Map.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"$(InputName)Out.typ" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "occiS - Win32 Debug"
+
+# Begin Custom Build
+InputPath=.\DbTypes.typ
+InputName=DbTypes
+
+BuildCmds= \
+ ott userid=scott/tiger@orcl code=cpp hfile=$(InputName).h cppfile=$(InputName).cpp mapfile=$(InputName)Map.cpp intype=$(InputPath) outtype=$(InputName)Out.typ attraccess=private
+
+"$(InputName).h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"$(InputName).cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"$(InputName)Map.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"$(InputName)Map.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"$(InputName)Out.typ" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+# End Custom Build
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=.\HR.ice
+
+!IF "$(CFG)" == "occiS - Win32 Release"
+
+# Begin Custom Build
+InputPath=.\HR.ice
+InputName=HR
+
+BuildCmds= \
+ ..\..\..\..\bin\slice2cpp.exe $(InputPath)
+
+"$(InputName).h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"$(InputName).cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "occiS - Win32 Debug"
+
+# Begin Custom Build
+InputPath=.\HR.ice
+InputName=HR
+
+BuildCmds= \
+ ..\..\..\..\bin\slice2cpp.exe $(InputPath)
+
+"$(InputName).h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"$(InputName).cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+# End Custom Build
+
+!ENDIF
+
+# End Source File
+# End Group
+# Begin Source File
+
+SOURCE=.\createTypes.sql
+# End Source File
+# Begin Source File
+
+SOURCE=.\README
+# End Source File
+# End Target
+# End Project
|