1
1
2
2
#include " connection.h"
3
+ #include " executeBaton.h"
4
+ #include " commitBaton.h"
5
+ #include " rollbackBaton.h"
3
6
#include " outParam.h"
4
7
#include < vector>
5
8
@@ -15,6 +18,9 @@ void Connection::Init(Handle<Object> target) {
15
18
16
19
NODE_SET_PROTOTYPE_METHOD (constructorTemplate, " execute" , Execute);
17
20
NODE_SET_PROTOTYPE_METHOD (constructorTemplate, " close" , Close);
21
+ NODE_SET_PROTOTYPE_METHOD (constructorTemplate, " setAutoCommit" , SetAutoCommit);
22
+ NODE_SET_PROTOTYPE_METHOD (constructorTemplate, " commit" , Commit);
23
+ NODE_SET_PROTOTYPE_METHOD (constructorTemplate, " rollback" , Rollback);
18
24
19
25
target->Set (String::NewSymbol (" Connection" ), constructorTemplate->GetFunction ());
20
26
}
@@ -69,6 +75,61 @@ Handle<Value> Connection::Close(const Arguments& args) {
69
75
return Undefined ();
70
76
}
71
77
78
+ Handle<Value> Connection::Commit (const Arguments& args) {
79
+ Connection* connection = ObjectWrap::Unwrap<Connection>(args.This ());
80
+
81
+ REQ_FUN_ARG (0 , callback);
82
+
83
+ CommitBaton* baton;
84
+ try {
85
+ baton = new CommitBaton (connection, &callback);
86
+ } catch (NodeOracleException &ex) {
87
+ Handle<Value> argv[2 ];
88
+ argv[0 ] = Exception::Error (String::New (ex.getMessage ().c_str ()));
89
+ argv[1 ] = Undefined ();
90
+ callback->Call (Context::GetCurrent ()->Global (), 2 , argv);
91
+ return Undefined ();
92
+ }
93
+
94
+ eio_custom (EIO_Commit, EIO_PRI_DEFAULT, EIO_AfterCommit, baton);
95
+ ev_ref (EV_DEFAULT_UC);
96
+
97
+ connection->Ref ();
98
+
99
+ return Undefined ();
100
+ }
101
+
102
+ Handle<Value> Connection::Rollback (const Arguments& args) {
103
+ Connection* connection = ObjectWrap::Unwrap<Connection>(args.This ());
104
+
105
+ REQ_FUN_ARG (0 , callback);
106
+
107
+ RollbackBaton* baton;
108
+ try {
109
+ baton = new RollbackBaton (connection, &callback);
110
+ } catch (NodeOracleException &ex) {
111
+ Handle<Value> argv[2 ];
112
+ argv[0 ] = Exception::Error (String::New (ex.getMessage ().c_str ()));
113
+ argv[1 ] = Undefined ();
114
+ callback->Call (Context::GetCurrent ()->Global (), 2 , argv);
115
+ return Undefined ();
116
+ }
117
+
118
+ eio_custom (EIO_Rollback, EIO_PRI_DEFAULT, EIO_AfterRollback, baton);
119
+ ev_ref (EV_DEFAULT_UC);
120
+
121
+ connection->Ref ();
122
+
123
+ return Undefined ();
124
+ }
125
+
126
+ Handle<Value> Connection::SetAutoCommit (const Arguments& args) {
127
+ Connection* connection = ObjectWrap::Unwrap<Connection>(args.This ());
128
+ REQ_BOOL_ARG (0 , autoCommit);
129
+ connection->m_autoCommit = autoCommit;
130
+ return Undefined ();
131
+ }
132
+
72
133
void Connection::closeConnection () {
73
134
if (m_environment && m_connection) {
74
135
m_environment->terminateConnection (m_connection);
@@ -187,6 +248,44 @@ row_t* Connection::CreateRowFromCurrentResultSetRow(oracle::occi::ResultSet* rs,
187
248
return row;
188
249
}
189
250
251
+ void Connection::EIO_Commit (eio_req* req) {
252
+ CommitBaton* baton = static_cast <CommitBaton*>(req->data );
253
+
254
+ baton->connection ->m_connection ->commit ();
255
+ }
256
+
257
+ int Connection::EIO_AfterCommit (eio_req* req) {
258
+ CommitBaton* baton = static_cast <CommitBaton*>(req->data );
259
+ ev_unref (EV_DEFAULT_UC);
260
+ baton->connection ->Unref ();
261
+
262
+ Handle<Value> argv[2 ];
263
+ argv[0 ] = Undefined ();
264
+ baton->callback ->Call (Context::GetCurrent ()->Global (), 1 , argv);
265
+
266
+ delete baton;
267
+ return 0 ;
268
+ }
269
+
270
+ void Connection::EIO_Rollback (eio_req* req) {
271
+ RollbackBaton* baton = static_cast <RollbackBaton*>(req->data );
272
+
273
+ baton->connection ->m_connection ->rollback ();
274
+ }
275
+
276
+ int Connection::EIO_AfterRollback (eio_req* req) {
277
+ RollbackBaton* baton = static_cast <RollbackBaton*>(req->data );
278
+ ev_unref (EV_DEFAULT_UC);
279
+ baton->connection ->Unref ();
280
+
281
+ Handle<Value> argv[2 ];
282
+ argv[0 ] = Undefined ();
283
+ baton->callback ->Call (Context::GetCurrent ()->Global (), 1 , argv);
284
+
285
+ delete baton;
286
+ return 0 ;
287
+ }
288
+
190
289
void Connection::EIO_Execute (eio_req* req) {
191
290
ExecuteBaton* baton = static_cast <ExecuteBaton*>(req->data );
192
291
@@ -198,6 +297,7 @@ void Connection::EIO_Execute(eio_req* req) {
198
297
try {
199
298
// printf("%s\n", baton->sql.c_str());
200
299
stmt = baton->connection ->m_connection ->createStatement (baton->sql );
300
+ stmt->setAutoCommit (baton->connection ->m_autoCommit );
201
301
int outputParam = SetValuesOnStatement (stmt, baton->values );
202
302
203
303
int status = stmt->execute ();
@@ -303,13 +403,13 @@ Local<Object> Connection::CreateV8ObjectFromRow(ExecuteBaton* baton, row_t* curr
303
403
break ;
304
404
case VALUE_TYPE_CLOB:
305
405
{
306
- oracle::occi::Clob* v = (oracle::occi::Clob*)val;
406
+ // oracle::occi::Clob* v = (oracle::occi::Clob*)val;
307
407
obj->Set (String::New (col->name .c_str ()), Null ()); // TODO: handle clobs
308
408
}
309
409
break ;
310
410
case VALUE_TYPE_BLOB:
311
411
{
312
- oracle::occi::Blob* v = (oracle::occi::Blob*)val;
412
+ // oracle::occi::Blob* v = (oracle::occi::Blob*)val;
313
413
obj->Set (String::New (col->name .c_str ()), Null ()); // TODO: handle blobs
314
414
}
315
415
break ;
0 commit comments