Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
Merge branch 'cjlucas/terminate-connection'
Browse files Browse the repository at this point in the history
  • Loading branch information
cjlucas committed Aug 17, 2015
2 parents 3b7b5a0 + 5ef560f commit 37f3edf
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
11 changes: 11 additions & 0 deletions lib/src/connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,14 @@ void OracleConnection_changePassword(Dart_NativeArguments args){

Dart_ExitScope();
}

void OracleConnection_terminate(Dart_NativeArguments args) {
Dart_EnterScope();

auto conn = getThis<std::shared_ptr<Connection>>(args)->get();
try {
conn->terminate();
} CATCH_SQL_EXCEPTION

Dart_ExitScope();
}
14 changes: 13 additions & 1 deletion lib/src/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,29 @@ struct Connection {
occi::Connection *conn;
std::string username;
std::string connstr;
bool terminated;

Connection(std::shared_ptr<Environment> env,
std::string username,
std::string password,
std::string connStr) : env(env), username{username}, connstr{connStr} {
conn = env.get()->env->createConnection(username, password, connStr);
terminated = false;
}

void terminate() {
if (terminated) {
return;
}

terminated = true;
env.get()->env->terminateConnection(conn);
}

~Connection() {
//printf("in ~Connection\n");
env.get()->env->terminateConnection(conn);
//printf("Environment use count %ld\n", env.use_count());
terminate();
}
};

Expand All @@ -38,3 +49,4 @@ void OracleConnection_rollback(Dart_NativeArguments arguments);
void OracleConnection_getUsername(Dart_NativeArguments arguments);
void OracleConnection_getConnectionString(Dart_NativeArguments arguments);
void OracleConnection_changePassword(Dart_NativeArguments arguments);
void OracleConnection_terminate(Dart_NativeArguments arguments);
1 change: 1 addition & 0 deletions lib/src/occi_extension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ FunctionLookup function_list[] = {
{"OracleConnection_getUsername", OracleConnection_getUsername},
{"OracleConnection_getConnectionString", OracleConnection_getConnectionString},
{"OracleConnection_changePassword", OracleConnection_changePassword},
{"OracleConnection_terminate", OracleConnection_terminate},
{"OracleStatement_getSql", OracleStatement_getSql},
{"OracleStatement_setSql", OracleStatement_setSql},
{"OracleStatement_setPrefetchRowCount", OracleStatement_setPrefetchRowCount},
Expand Down
3 changes: 3 additions & 0 deletions lib/src/occi_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Environment {

Connection createConnection(String username, String password,
String connStr) native 'OracleEnvironment_createConnection';

void terminateConnection(Connection conn) => conn.terminate();
}

class Connection {
Expand Down Expand Up @@ -58,6 +60,7 @@ class Connection {
String getUsername() native 'OracleConnection_getUsername';
String getConnectionString() native 'OracleConnection_getConnectionString';
String changePassword(String oldpass, String newpass) native 'OracleConnection_changePassword';
void terminate() native 'OracleConnection_terminate';

void execute(String sql, [List<Object> args]) {
var stmt = createStatement(sql);
Expand Down
21 changes: 13 additions & 8 deletions test/complete_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,20 @@ main() {
con.commit();
});
test('change password', (){
con.changePassword(password, 'dig');
var newcon = env.createConnection(username, 'dig', connString);
var stmt = newcon.createStatement("SELECT * FROM test_table");
var results = stmt.executeQuery();
results.next(1);
expect(results.getNum(1), equals(34));
con.execute('CREATE USER foo IDENTIFIED BY "bar"');
con.execute('GRANT CREATE SESSION to foo');
var con2 = env.createConnection('foo', 'bar', connString);

expect(() => con2.changePassword('bar', 'bar2'), returnsNormally);
con2.terminate();

expect(() => con2 = env.createConnection('foo', 'bar2', connString),
returnsNormally);

con2.terminate();
con.execute('DROP USER foo');
});

newcon.changePassword('dig', password);
}, skip: 'it works, trust me');
test('get connection properties', (){
expect(con.getConnectionString(), equals(connString));
expect(con.getUsername(), equals(username));
Expand Down

0 comments on commit 37f3edf

Please sign in to comment.