blob: 1f0c1fbdb36e2cf39892dbe4ab9bdfeb1bf05da3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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;
}
|