@@ -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,
161180void 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,
179191Handle<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,
222227Handle<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,
265263Handle<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
0 commit comments