Skip to content

Commit 09dbfea

Browse files
committed
Code tidy-up incorporating PR #28 (@krishnanm86)
1 parent eeda2f7 commit 09dbfea

File tree

6 files changed

+116
-183
lines changed

6 files changed

+116
-183
lines changed

src/dpi/src/dpiUtils.cpp

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,44 @@
3939
#endif
4040

4141

42+
static void ociCallCommon(sword rc, void *handle, ub4 errType);
43+
44+
/*****************************************************************************/
45+
/*
46+
DESCRIPTION
47+
Wrapper for ociCall and ociCallEnv.
48+
Abstraction for the redundant common functionality.
49+
50+
PARAMETERS:
51+
rc - OCI return code
52+
errh - OCI error hanlde
53+
errType - error type
54+
55+
RETURNS:
56+
nothing
57+
58+
NOTES:
59+
*/
60+
61+
void ociCallCommon(sword rc, void *handle, ub4 errType)
62+
{
63+
if (!rc)
64+
return;
65+
66+
OraText ociErrorMsg[OCI_ERROR_MAXMSG_SIZE];
67+
sb4 ociErrorNo = 0;
68+
memset(ociErrorMsg, 0, OCI_ERROR_MAXMSG_SIZE);
69+
70+
rc = OCIErrorGet(handle, 1, NULL, &ociErrorNo, ociErrorMsg,
71+
OCI_ERROR_MAXMSG_SIZE-1, errType);
72+
if (rc)
73+
throw ExceptionImpl(DpiErrUnkOciError);
74+
else
75+
{
76+
ociErrorMsg[strlen((char*)ociErrorMsg)-1]=0; //strip off newline
77+
throw ExceptionImpl("ORA", ociErrorNo, (const char *)ociErrorMsg);
78+
}
79+
}
4280

4381
/*---------------------------------------------------------------------------
4482
PUBLIC FUNCTIONS
@@ -63,22 +101,7 @@
63101

64102
void ociCall(sword rc, OCIError *errh)
65103
{
66-
if (!rc)
67-
return;
68-
69-
OraText ociErrorMsg[OCI_ERROR_MAXMSG_SIZE];
70-
sb4 ociErrorNo = 0;
71-
memset(ociErrorMsg, 0, OCI_ERROR_MAXMSG_SIZE);
72-
73-
rc = OCIErrorGet(errh, 1, NULL, &ociErrorNo, ociErrorMsg,
74-
OCI_ERROR_MAXMSG_SIZE-1, OCI_HTYPE_ERROR);
75-
if (rc)
76-
throw ExceptionImpl(DpiErrUnkOciError);
77-
else
78-
{
79-
ociErrorMsg[strlen((char*)ociErrorMsg)-1]=0; //strip off newline
80-
throw ExceptionImpl("ORA", ociErrorNo, (const char *)ociErrorMsg);
81-
}
104+
ociCallCommon(rc, errh, OCI_HTYPE_ERROR);
82105
}
83106

84107

@@ -103,22 +126,7 @@ void ociCall(sword rc, OCIError *errh)
103126

104127
void ociCallEnv(sword rc, OCIEnv *envh)
105128
{
106-
if (!rc)
107-
return;
108-
109-
OraText ociErrorMsg[OCI_ERROR_MAXMSG_SIZE];
110-
sb4 ociErrorNo = 0;
111-
memset(ociErrorMsg, 0, OCI_ERROR_MAXMSG_SIZE);
112-
113-
rc = OCIErrorGet(envh, 1, NULL, &ociErrorNo, ociErrorMsg,
114-
OCI_ERROR_MAXMSG_SIZE-1, OCI_HTYPE_ENV);
115-
if (rc)
116-
throw ExceptionImpl(DpiErrUnkOciError);
117-
else
118-
{
119-
ociErrorMsg[strlen((char*)ociErrorMsg)-1]=0; //strip off newline
120-
throw ExceptionImpl("ORA", ociErrorNo, (const char *)ociErrorMsg);
121-
}
129+
ociCallCommon(rc, envh, OCI_HTYPE_ENV);
122130
}
123131

124132

src/dpi/src/dpiUtils.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
---------------------------------------------------------------------------*/
3939

4040

41-
4241
/*---------------------------------------------------------------------------
4342
PUBLIC TYPES
4443
---------------------------------------------------------------------------*/
@@ -47,7 +46,6 @@
4746
/*---------------------------------------------------------------------------
4847
PUBLIC FUNCTIONS
4948
---------------------------------------------------------------------------*/
50-
5149
void ociCall(sword rc, OCIError *errh);
5250

5351
void ociCallEnv(sword rc, OCIEnv *envh);

src/njs/src/njsConnection.cpp

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,25 @@ Handle<Value> Connection::New(const Arguments& args)
124124
return args.This();
125125
}
126126

127+
/*****************************************************************************/
128+
/*
129+
DESCRIPTION
130+
Abstraction for exception on accessing connection properties
131+
*/
132+
void Connection::connectionPropertyException(const AccessorInfo& info,
133+
NJSErrorType errType,
134+
string property)
135+
{
136+
HandleScope scope;
137+
Connection* njsConn = ObjectWrap::Unwrap<Connection>(info.Holder());
138+
string msg;
139+
if(!njsConn->isValid_)
140+
msg = NJSMessages::getErrorMsg(errInvalidConnection);
141+
else
142+
msg = NJSMessages::getErrorMsg(errType, property.c_str());
143+
NJS_SET_EXCEPTION(msg.c_str(), (int) msg.length());
144+
}
145+
127146
/*****************************************************************************/
128147
/*
129148
DESCRIPTION
@@ -136,7 +155,7 @@ Handle<Value> Connection::GetStmtCacheSize (Local<String> property,
136155
Connection* njsConn = ObjectWrap::Unwrap<Connection>(info.Holder());
137156
if(!njsConn->isValid_)
138157
{
139-
string error = NJSMessages::getErrorMsg ( errInvalidPool );
158+
string error = NJSMessages::getErrorMsg ( errInvalidConnection );
140159
NJS_SET_EXCEPTION(error.c_str(), error.length());
141160
return scope.Close(Undefined());
142161
}
@@ -161,14 +180,7 @@ Handle<Value> Connection::GetStmtCacheSize (Local<String> property,
161180
void Connection::SetStmtCacheSize(Local<String> property, Local<Value> value,
162181
const AccessorInfo& info)
163182
{
164-
HandleScope scope;
165-
Connection* njsConn = ObjectWrap::Unwrap<Connection>(info.Holder());
166-
string msg;
167-
if(!njsConn->isValid_)
168-
msg = NJSMessages::getErrorMsg(errInvalidConnection);
169-
else
170-
msg = NJSMessages::getErrorMsg(errReadOnly, "stmtCacheSize");
171-
NJS_SET_EXCEPTION(msg.c_str(), (int) msg.length());
183+
connectionPropertyException(info, errReadOnly, "stmtCacheSize");
172184
}
173185

174186
/*****************************************************************************/
@@ -179,14 +191,7 @@ void Connection::SetStmtCacheSize(Local<String> property, Local<Value> value,
179191
Handle<Value> Connection::GetClientId(Local<String> property,
180192
const AccessorInfo& info)
181193
{
182-
HandleScope scope;
183-
Connection* njsConn = ObjectWrap::Unwrap<Connection>(info.Holder());
184-
string msg;
185-
if(!njsConn->isValid_)
186-
msg = NJSMessages::getErrorMsg(errInvalidConnection);
187-
else
188-
msg = NJSMessages::getErrorMsg(errWriteOnly, "clientId");
189-
NJS_SET_EXCEPTION(msg.c_str(), (int) msg.length());
194+
connectionPropertyException(info, errWriteOnly, "clientId");
190195
return Undefined();
191196
}
192197

@@ -222,14 +227,7 @@ void Connection::SetClientId(Local<String> property, Local<Value> value,
222227
Handle<Value> Connection::GetModule (Local<String> property,
223228
const AccessorInfo& info)
224229
{
225-
HandleScope scope;
226-
Connection* njsConn = ObjectWrap::Unwrap<Connection>(info.Holder());
227-
string msg;
228-
if(!njsConn->isValid_)
229-
msg = NJSMessages::getErrorMsg(errInvalidConnection);
230-
else
231-
msg = NJSMessages::getErrorMsg(errWriteOnly, "module");
232-
NJS_SET_EXCEPTION(msg.c_str(), (int) msg.length());
230+
connectionPropertyException(info, errWriteOnly, "module");
233231
return Undefined();
234232
}
235233

@@ -265,14 +263,7 @@ void Connection::SetModule (Local<String> property, Local<Value> value,
265263
Handle<Value> Connection::GetAction (Local<String> property,
266264
const AccessorInfo& info)
267265
{
268-
HandleScope scope;
269-
Connection* njsConn = ObjectWrap::Unwrap<Connection>(info.Holder());
270-
string msg;
271-
if(!njsConn->isValid_)
272-
msg = NJSMessages::getErrorMsg(errInvalidConnection);
273-
else
274-
msg = NJSMessages::getErrorMsg(errWriteOnly, "action");
275-
NJS_SET_EXCEPTION(msg.c_str(), (int) msg.length());
266+
connectionPropertyException(info, errWriteOnly, "action");
276267
return Undefined();
277268
}
278269

src/njs/src/njsConnection.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ class Connection: public ObjectWrap
198198
const AccessorInfo& info);
199199
static void SetAction (Local<String> property,Local<Value> value,
200200
const AccessorInfo& info);
201+
202+
static void connectionPropertyException(const AccessorInfo& info,
203+
NJSErrorType errType,
204+
string property);
201205

202206
Connection ();
203207
~Connection ();

0 commit comments

Comments
 (0)