-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOracleConnection.cxx
72 lines (66 loc) · 2.11 KB
/
OracleConnection.cxx
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
#include "OracleConnection.h"
#include "DBException.h"
//-------------------------------------------------------------------
// Constructor
OracleConnection::OracleConnection(const string& userid, const string& password, const string& connectString)
: m_environment(NULL), m_connection(NULL)
{
getConnection(userid, password, connectString);
}
//-------------------------------------------------------------------
// Destructor
OracleConnection::~OracleConnection()
{
releaseConnection();
}
//-------------------------------------------------------------------
// Gets the underlying oracle connection (occi connection)
Connection* OracleConnection::getConnection()
{
// return our database connection - the connection is obtained when
// this object is constructed
#ifndef __NO_DB__
return m_connection;
#else
return NULL;
#endif
}
//-------------------------------------------------------------------
// Gets a new connection to the database
void OracleConnection::getConnection(const string& userid, const string& password, const string& connectString)
{
#ifndef __NO_DB__
// initialize our environment
m_environment = Environment::createEnvironment (Environment::DEFAULT);
try
{
// get a new connection from the oracle environment
m_connection = m_environment->createConnection(userid, password, connectString);
}
catch (SQLException ex)
{
throw DBException((string)ex.getMessage().c_str());
}
catch (...)
{
throw DBException("An unexpected error occurred trying to get a connection to the database!");
}
#endif
}
//-------------------------------------------------------------------
// Releases the resources associated with the connection
void OracleConnection::releaseConnection()
{
#ifndef __NO_DB__
try
{
// need to move to explictit cleanup
m_environment->terminateConnection(m_connection);
Environment::terminateEnvironment(m_environment);
}
catch (SQLException sqlex)
{
throw DBException((string)sqlex.getMessage().c_str());
}
#endif
}