From d384e06186de83c49cf14fa70b13fb73d27829bd Mon Sep 17 00:00:00 2001 From: benoitgaudou Date: Sat, 13 Jun 2020 10:30:37 +0700 Subject: [PATCH] Database bug fix on the testConnection actions of agentDB species. Update of library model to test all connections --- .../extensions/database/species/AgentDB.java | 12 ++---- .../models/Database/Connection Test.gaml | 41 ++++++++++++++++++- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/irit.gaml.extensions.database/src/irit/gaml/extensions/database/species/AgentDB.java b/irit.gaml.extensions.database/src/irit/gaml/extensions/database/species/AgentDB.java index 9c4189732e..c803170ec7 100644 --- a/irit.gaml.extensions.database/src/irit/gaml/extensions/database/species/AgentDB.java +++ b/irit.gaml.extensions.database/src/irit/gaml/extensions/database/species/AgentDB.java @@ -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 ( @@ -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; // --------------------------------------------------------------------------------------- diff --git a/msi.gama.models/models/Data/Database Usage/models/Database/Connection Test.gaml b/msi.gama.models/models/Data/Database Usage/models/Database/Connection Test.gaml index b48bc10647..38d0fc67df 100644 --- a/msi.gama.models/models/Data/Database Usage/models/Database/Connection Test.gaml +++ b/msi.gama.models/models/Data/Database Usage/models/Database/Connection Test.gaml @@ -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; } } @@ -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 { -} \ No newline at end of file +experiment default_expr type: gui {} \ No newline at end of file