Skip to content

Commit

Permalink
Database bug fix on the testConnection actions of agentDB species.
Browse files Browse the repository at this point in the history
Update of library model to test all connections
  • Loading branch information
benoitgaudou committed Jun 13, 2020
1 parent e342f03 commit d384e06
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
Expand Up @@ -161,9 +161,9 @@ public Object connectDB(final IScope scope) throws GamaRuntimeException {
}

/*
* Make a connection to BDMS
* Test a connection to DBMS
*
* @syntax: do action: connectDB { arg params value:[ "dbtype":"SQLSERVER", "url":"host address", "port":
* @syntax: testConnection { arg params value:[ "dbtype":"SQLSERVER", "url":"host address", "port":
* "port number", "database":"database name", "user": "user name", "passwd": "password", ]; }
*/
@action (
Expand All @@ -178,12 +178,8 @@ public Object connectDB(final IScope scope) throws GamaRuntimeException {
returns = "Returns true if connection to the server was successfully established, otherwise, it returns false.")
)
public boolean testConnection(final IScope scope) throws GamaRuntimeException {
try {
SqlConnection sqlConn;
sqlConn = SqlUtils.createConnectionObject(scope);
try (final Connection conn = sqlConn.connectDB();) {}
} catch (final Exception e) {
throw GamaRuntimeException.create(e, scope);
try (final Connection conn = SqlUtils.createConnectionObject(scope).connectDB()) {} catch (final Exception e) {
return false;
}
return true;
// ---------------------------------------------------------------------------------------
Expand Down
Expand Up @@ -15,7 +15,16 @@ global {
init {
write "This model will work only if the corresponding database is installed and the database management server launched." color: #red;

write "TESTS CONNECTIONS WITH SQLSKILL";
create DB_connection_tester;

write "";
write "TESTS CONNECTIONS WITH AgentDB";
create AgentDB_SQLSERVER;
create AgentDB_MySQL;
create AgentDB_SQLITE;
create AgentDB_ORACLE;
create AgentDB_POSTGRESQL;
}

}
Expand All @@ -29,8 +38,36 @@ species DB_connection_tester skills: [SQLSKILL] {
write "Connection to ORACLE is " + testConnection(ORACLE);
write "Connection to POSTGRESQL is " + testConnection(POSTGRES);
}
}

species AgentDB_SQLSERVER parent: AgentDB {
init {
write "Connection to SQLSERVER with AgenDB is " + testConnection(SQLSERVER);
}
}

species AgentDB_MySQL parent: AgentDB {
init {
write "Connection to MySQL with AgenDB is " + testConnection(MySQL);
}
}

species AgentDB_SQLITE parent: AgentDB {
init {
write "Connection to SQLITE with AgenDB is " + testConnection(SQLITE);
}
}

species AgentDB_ORACLE parent: AgentDB {
init {
write "Connection to ORACLE with AgenDB is " + testConnection(ORACLE);
}
}

species AgentDB_POSTGRESQL parent: AgentDB {
init {
write "Connection to POSTGRESQL with AgenDB is " + testConnection(POSTGRES);
}
}

experiment default_expr type: gui {
}
experiment default_expr type: gui {}

0 comments on commit d384e06

Please sign in to comment.