@@ -124,6 +124,25 @@ Handle<Value> Connection::New(const Arguments& args)
124
124
return args.This ();
125
125
}
126
126
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
+
127
146
/* ****************************************************************************/
128
147
/*
129
148
DESCRIPTION
@@ -136,7 +155,7 @@ Handle<Value> Connection::GetStmtCacheSize (Local<String> property,
136
155
Connection* njsConn = ObjectWrap::Unwrap<Connection>(info.Holder ());
137
156
if (!njsConn->isValid_ )
138
157
{
139
- string error = NJSMessages::getErrorMsg ( errInvalidPool );
158
+ string error = NJSMessages::getErrorMsg ( errInvalidConnection );
140
159
NJS_SET_EXCEPTION (error.c_str (), error.length ());
141
160
return scope.Close (Undefined ());
142
161
}
@@ -161,14 +180,7 @@ Handle<Value> Connection::GetStmtCacheSize (Local<String> property,
161
180
void Connection::SetStmtCacheSize (Local<String> property, Local<Value> value,
162
181
const AccessorInfo& info)
163
182
{
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" );
172
184
}
173
185
174
186
/* ****************************************************************************/
@@ -179,14 +191,7 @@ void Connection::SetStmtCacheSize(Local<String> property, Local<Value> value,
179
191
Handle<Value> Connection::GetClientId (Local<String> property,
180
192
const AccessorInfo& info)
181
193
{
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" );
190
195
return Undefined ();
191
196
}
192
197
@@ -222,14 +227,7 @@ void Connection::SetClientId(Local<String> property, Local<Value> value,
222
227
Handle<Value> Connection::GetModule (Local<String> property,
223
228
const AccessorInfo& info)
224
229
{
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" );
233
231
return Undefined ();
234
232
}
235
233
@@ -265,14 +263,7 @@ void Connection::SetModule (Local<String> property, Local<Value> value,
265
263
Handle<Value> Connection::GetAction (Local<String> property,
266
264
const AccessorInfo& info)
267
265
{
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" );
276
267
return Undefined ();
277
268
}
278
269
0 commit comments