summaryrefslogtreecommitdiff
path: root/cpp/demo/Database/Oracle/occi/EmpI.cpp
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2007-01-13 02:01:21 +0000
committerBernard Normier <bernard@zeroc.com>2007-01-13 02:01:21 +0000
commitac34961ea546eb517a21e3e8680cad64117bac95 (patch)
tree3404a26b3c99dddf3d803bffb72c444318cf2ebd /cpp/demo/Database/Oracle/occi/EmpI.cpp
parentvarious improvements (diff)
downloadice-ac34961ea546eb517a21e3e8680cad64117bac95.tar.bz2
ice-ac34961ea546eb517a21e3e8680cad64117bac95.tar.xz
ice-ac34961ea546eb517a21e3e8680cad64117bac95.zip
Major update
Diffstat (limited to 'cpp/demo/Database/Oracle/occi/EmpI.cpp')
-rw-r--r--cpp/demo/Database/Oracle/occi/EmpI.cpp266
1 files changed, 109 insertions, 157 deletions
diff --git a/cpp/demo/Database/Oracle/occi/EmpI.cpp b/cpp/demo/Database/Oracle/occi/EmpI.cpp
index 7e341688b8e..d8d45649042 100644
--- a/cpp/demo/Database/Oracle/occi/EmpI.cpp
+++ b/cpp/demo/Database/Oracle/occi/EmpI.cpp
@@ -7,215 +7,167 @@
//
// **********************************************************************
-#include <Ice/Ice.h>
#include <EmpI.h>
-#include <DeptI.h>
-#include <Util.h>
-#include <occi.h>
using namespace std;
using namespace oracle::occi;
-EmpI::EmpI(DeptFactoryIPtr factory, Environment* env, StatelessConnectionPool* pool,
- const string& empCategory, const string& deptCategory) :
- _factory(factory), _env(env), _pool(pool),
- _empCategory(empCategory), _deptCategory(deptCategory)
+EmpI::EmpI(const RefAny& ref, const ConnectionHolderPtr& conh, const DeptFactoryIPtr& factory)
+ : _ref(ref), _conh(conh), _factory(factory)
{
}
-void
-EmpI::ice_ping(const Ice::Current& current) const
-{
- ConnectionHolder conh(_pool);
- {
- Ref<EMP_T> ref = decodeRef(current.id.name, _env, conh.connection());
- try
- {
- //
- // Dereferences object to see if it existts
- //
- ref.ptr();
- }
- catch(const SQLException& sqle)
- {
- if(sqle.getErrorCode() == 21700)
- {
- throw Ice::ObjectNotExistException(__FILE__, __LINE__);
- }
- else
- {
- throw;
- }
- }
- }
- conh.commit();
-}
-
-
HR::EmpDesc
EmpI::getDesc(const Ice::Current& current)
{
- ConnectionHolder conh(_pool);
+ Environment* env = _factory->getEnv();
HR::EmpDesc result;
+
+ Ref<EMP_T> empRef = decodeRef(current.id.name, env, _conh->connection());
+
+ result.empno = empRef->getEmpno();
+ result.ename = empRef->getEname();
+ result.job = empRef->getJob();
+
+ Ref<EMP_T> mgrRef = empRef->getMgrref();
+ if(!mgrRef.isNull())
{
- Ref<EMP_T> empRef = decodeRef(current.id.name, _env, conh.connection());
+ Ice::Identity mgrId;
+ mgrId.name = encodeRef(mgrRef, env);
+ mgrId.category = _factory->getCategory();
+ result.mgr = HR::EmpPrx::uncheckedCast(current.adapter->createProxy(mgrId));
+ }
- result.empno = empRef->getEmpno();
- result.ename = empRef->getEname();
- result.job = empRef->getJob();
-
- Ref<EMP_T> mgrRef = empRef->getMgrref();
- if(!mgrRef.isNull())
- {
- Ice::Identity mgrId;
- mgrId.name = encodeRef(mgrRef, _env);
- mgrId.category = _empCategory;
- result.mgr = HR::EmpPrx::uncheckedCast(current.adapter->createProxy(mgrId));
- }
-
- result.hiredate = empRef->getHiredate().toText();
-
- if(!empRef->getSal().isNull())
- {
- result.sal = empRef->getSal().toText(_env, "99999.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 = encodeRef(deptRef, _env);
- deptId.category = _deptCategory;
- result.edept = HR::DeptPrx::uncheckedCast(current.adapter->createProxy(deptId));
- }
+ result.hiredate = empRef->getHiredate().toText();
+
+ if(!empRef->getSal().isNull())
+ {
+ result.sal = empRef->getSal().toText(env, "99999.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 = encodeRef(deptRef, env);
+ deptId.category = _factory->getCategory();
+ result.edept = HR::DeptPrx::uncheckedCast(current.adapter->createProxy(deptId));
}
- conh.commit();
+ _conh->commit();
return result;
}
void EmpI::updateField(const string& field, const string& newValue, const Ice::Current& current)
{
- ConnectionHolder conh(_pool);
+ Ref<EMP_T> empRef = decodeRef(current.id.name, _factory->getEnv(), _conh->connection());
+
+ if(field == "ename")
+ {
+ empRef->setEname(newValue);
+ }
+ else if(field == "job")
+ {
+ empRef->setJob(newValue);
+ }
+ else if(field == "hiredate")
{
- Ref<EMP_T> empRef = decodeRef(current.id.name, _env, conh.connection());
-
- if(field == "ename")
+ if(newValue == "")
{
- empRef->setEname(newValue);
+ empRef->setHiredate(Date());
}
- else if(field == "job")
+ else
{
- empRef->setJob(newValue);
+ Date hiredate(_factory->getEnv());
+ hiredate.fromText(newValue);
+ empRef->setHiredate(hiredate);
}
- else if(field == "hiredate")
+ }
+ else if(field == "sal")
+ {
+ if(newValue == "")
{
- if(newValue == "")
- {
- empRef->setHiredate(Date());
- }
- else
- {
- Date hiredate(_env);
- hiredate.fromText(newValue);
- empRef->setHiredate(hiredate);
- }
+ empRef->setSal(Number());
}
- else if(field == "sal")
+ else
{
- if(newValue == "")
- {
- empRef->setSal(Number());
- }
- else
- {
- Number sal(0);
- sal.fromText(_env, newValue, "99999.99");
- empRef->setSal(sal);
- }
+ Number sal(0);
+ sal.fromText(_factory->getEnv(), newValue, "99999.99");
+ empRef->setSal(sal);
}
- else if(field == "comm")
+ }
+ else if(field == "comm")
+ {
+ if(newValue == "")
{
- if(newValue == "")
- {
- empRef->setComm(Number());
- }
- else
- {
- Number comm(0);
- comm.fromText(_env, newValue, "0.999");
- empRef->setComm(comm);
- }
+ empRef->setComm(Number());
}
else
{
- throw HR::SqlException("There is no field " + field + " in type EMP_T");
- }
- empRef->markModified();
+ Number comm(0);
+ comm.fromText(_factory->getEnv(), newValue, "0.999");
+ empRef->setComm(comm);
+ }
}
- conh.commit();
+ else
+ {
+ throw HR::SqlException("There is no field " + field + " in type EMP_T");
+ }
+ empRef->markModified();
+ _conh->commit();
}
void EmpI::updateMgr(int newMgr, const Ice::Current& current)
{
- ConnectionHolder conh(_pool);
+ Ref<EMP_T> empRef = decodeRef(current.id.name, _factory->getEnv(), _conh->connection());
+
+ if(newMgr == 0)
{
- Ref<EMP_T> empRef = decodeRef(current.id.name, _env, conh.connection());
-
- if(newMgr == 0)
- {
- empRef->setMgrref(Ref<EMP_T>());
- }
- else
+ empRef->setMgrref(Ref<EMP_T>());
+ }
+ else
+ {
+ Ref<EMP_T> mgrRef = _factory->findEmpRefByNo(newMgr, _conh->connection());
+
+ if(mgrRef.isNull())
{
- Ref<EMP_T> mgrRef = _factory->findEmpRefByNo(newMgr, conh.connection());
-
- if(mgrRef.isNull())
- {
- throw HR::SqlException("There is no employee with this empno");
- }
- empRef->setMgrref(mgrRef);
+ throw HR::SqlException("There is no employee with this empno");
}
- empRef->markModified();
+ empRef->setMgrref(mgrRef);
}
- conh.commit();
+ empRef->markModified();
+ _conh->commit();
}
void EmpI::updateDept(int newDept, const Ice::Current& current)
{
- ConnectionHolder conh(_pool);
+ Ref<EMP_T> empRef = decodeRef(current.id.name, _factory->getEnv(), _conh->connection());
+
+ if(newDept == 0)
{
- Ref<EMP_T> empRef = decodeRef(current.id.name, _env, conh.connection());
-
- if(newDept == 0)
- {
- empRef->setDeptref(Ref<DEPT_T>());
- }
- else
+ empRef->setDeptref(Ref<DEPT_T>());
+ }
+ else
+ {
+ Ref<DEPT_T> deptRef = _factory->findDeptRefByNo(newDept, _conh->connection());
+
+ if(deptRef.isNull())
{
- Ref<DEPT_T> deptRef = _factory->findDeptRefByNo(newDept, conh.connection());
-
- if(deptRef.isNull())
- {
- throw HR::SqlException("There is no department with this deptno");
- }
- empRef->setDeptref(deptRef);
+ throw HR::SqlException("There is no department with this deptno");
}
- empRef->markModified();
+ empRef->setDeptref(deptRef);
}
- conh.commit();
+ empRef->markModified();
+ _conh->commit();
}
void EmpI::remove(const Ice::Current& current)
{
- ConnectionHolder conh(_pool);
- {
- Ref<EMP_T> empRef = decodeRef(current.id.name, _env, conh.connection());
- empRef->markDelete();
- }
- conh.commit();
+ Ref<EMP_T> empRef = decodeRef(current.id.name, _factory->getEnv(), _conh->connection());
+ empRef->markDelete();
+ _conh->commit();
}