Skip to content

Commit 3c1a0ef

Browse files
authored
25 mysql display schemas (#37)
* Add placeholder for MySQL schema list * Add unit test for mysql storred procedures processing * Circle ci mysql (#38)
1 parent abfbc51 commit 3c1a0ef

File tree

15 files changed

+404
-123
lines changed

15 files changed

+404
-123
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# JDBC Component
22

3+
## 2.3.1 (September 30, 2019)
4+
5+
* Add placeholder to MySQL schemas list
6+
37
## 2.3.0 (September 25, 2019)
48

59
* Add new action `Insert`

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ Please use [**Upsert row by primary key**](#upsert-row-by-primary-key-action) in
293293
3. The current implementation of the action ``Upsert By Primary Key`` doesn't mark non-nullable fields as required fields at a dynamic metadata. In case of updating such fields with an empty value you will get SQL Exception ``Cannot insert the value NULL into...``. You should manually fill in all non-nullable fields with previous data, if you want to update part of columns in a row, even if data in that fields doesn't change.
294294
4. The current implementation of the action ``Execute stored procedure`` doesn't support ResultSet MSSQL output.
295295
5. The current implementation of the action ``Execute stored procedure`` doesn't support any array types parameters.
296-
6. The current implementation of the action ``Execute stored procedure`` doesn't support MySQL schemas dropdown list.
297296
(MySQL does not have schemas by definition)
298297

299298
## License

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group = 'io.elastic'
2-
version = '2.3.0'
2+
version = '2.3.1'
33
apply plugin: 'java'
44
apply plugin: 'idea'
55
apply plugin: 'eclipse'

src/main/java/io/elastic/jdbc/providers/SchemasProvider.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,21 @@ public class SchemasProvider implements SelectModelProvider {
2020
@Override
2121
public JsonObject getSelectModel(JsonObject configuration) {
2222
JsonObjectBuilder result = Json.createObjectBuilder();
23+
24+
LOGGER.info("Searching for %s db schemas...", configuration.getString("databaseName"));
2325
List<String> proceduresNames = getSchemasList(configuration);
26+
27+
LOGGER.info("Found %d db schemas", proceduresNames.size());
28+
LOGGER.debug("Schemas: " + proceduresNames.stream().reduce((s1, s2) -> s1 + ", " + s2).orElse(""));
29+
2430
proceduresNames.forEach(procedure -> result.add(procedure, procedure));
31+
32+
if (configuration.getString("dbEngine").equals("mysql")) {
33+
LOGGER.info("Adding placeholder to MySQL schemas list...");
34+
formatMySQLSchemasResponse(result, configuration.getString("databaseName"));
35+
}
36+
37+
LOGGER.info("Response building complete. Returning result...");
2538
return result.build();
2639
}
2740

@@ -41,4 +54,10 @@ public List<String> getSchemasList(JsonObject configuration) {
4154

4255
return result;
4356
}
57+
58+
private JsonObjectBuilder formatMySQLSchemasResponse(JsonObjectBuilder structure, String dbName) {
59+
structure.add(dbName, dbName);
60+
return structure;
61+
}
62+
4463
}

src/test/groovy/io/elastic/jdbc/integration/actions/delete_row_by_primary_key/DeleteActionMySQLSpec.groovy

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package io.elastic.jdbc.integration.actions.delete_row_by_primary_key
33
import io.elastic.api.EventEmitter
44
import io.elastic.api.ExecutionParameters
55
import io.elastic.api.Message
6+
import io.elastic.jdbc.TestUtils
67
import io.elastic.jdbc.actions.DeleteRowByPrimaryKey
78
import org.junit.Ignore
89
import spock.lang.Shared
@@ -14,23 +15,7 @@ import java.sql.Connection
1415
import java.sql.DriverManager
1516
import java.sql.ResultSet
1617

17-
@Ignore
1818
class DeleteActionMySQLSpec extends Specification {
19-
20-
@Shared
21-
def user = System.getenv("CONN_USER_MYSQL")
22-
@Shared
23-
def password = System.getenv("CONN_PASSWORD_MYSQL")
24-
@Shared
25-
def databaseName = System.getenv("CONN_DBNAME_MYSQL")
26-
@Shared
27-
def host = System.getenv("CONN_HOST_MYSQL")
28-
@Shared
29-
def port = System.getenv("CONN_PORT_MYSQL")
30-
@Shared
31-
def dbEngine = "mysql"
32-
@Shared
33-
def connectionString ="jdbc:" + dbEngine + "://" + host + ":" + port + "/" + databaseName + "?useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC"
3419
@Shared
3520
Connection connection
3621

@@ -50,7 +35,8 @@ class DeleteActionMySQLSpec extends Specification {
5035
DeleteRowByPrimaryKey action
5136

5237
def setupSpec() {
53-
connection = DriverManager.getConnection(connectionString, user, password)
38+
JsonObject config = getStarsConfig()
39+
connection = DriverManager.getConnection(config.getString("connectionString"), config.getString("user"), config.getString("password"))
5440
}
5541

5642
def setup() {
@@ -75,14 +61,8 @@ class DeleteActionMySQLSpec extends Specification {
7561
}
7662

7763
def getStarsConfig() {
78-
JsonObject config = Json.createObjectBuilder()
64+
JsonObject config = TestUtils.getMysqlConfigurationBuilder()
7965
.add("tableName", "stars")
80-
.add("user", user)
81-
.add("password", password)
82-
.add("dbEngine", "mysql")
83-
.add("host", host)
84-
.add("port", port)
85-
.add("databaseName", databaseName)
8666
.add("nullableResult", "true")
8767
.build();
8868
return config;

src/test/groovy/io/elastic/jdbc/integration/actions/execute_stored_procedure/ExecuteStoredProcedureMysqlSpec.groovy

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package io.elastic.jdbc.integration.actions.execute_stored_procedure
33
import io.elastic.api.EventEmitter
44
import io.elastic.api.ExecutionParameters
55
import io.elastic.api.Message
6+
import io.elastic.jdbc.TestUtils
67
import io.elastic.jdbc.actions.ExecuteStoredProcedure
78
import spock.lang.Ignore
89
import spock.lang.Shared
@@ -13,20 +14,7 @@ import javax.json.JsonObject
1314
import java.sql.Connection
1415
import java.sql.DriverManager
1516

16-
@Ignore
1717
class ExecuteStoredProcedureMysqlSpec extends Specification {
18-
@Shared
19-
def user = System.getenv("CONN_USER_MYSQL")
20-
@Shared
21-
def password = System.getenv("CONN_USER_MYSQL")
22-
@Shared
23-
def databaseName = System.getenv("CONN_USER_MYSQL")
24-
@Shared
25-
def host = System.getenv("CONN_USER_MYSQL")
26-
@Shared
27-
def port = System.getenv("CONN_USER_MYSQL")
28-
@Shared
29-
def connectionString = "jdbc:mysql://" + host + ":" + port + "/" + databaseName
3018

3119
@Shared
3220
Connection connection
@@ -47,7 +35,8 @@ class ExecuteStoredProcedureMysqlSpec extends Specification {
4735
ExecuteStoredProcedure action
4836

4937
def setupSpec() {
50-
connection = DriverManager.getConnection(connectionString, user, password)
38+
JsonObject config = getStarsConfig()
39+
connection = DriverManager.getConnection(config.getString("connectionString"), config.getString("user"), config.getString("password"))
5140
}
5241

5342
def setup() {
@@ -72,15 +61,9 @@ class ExecuteStoredProcedureMysqlSpec extends Specification {
7261
}
7362

7463
def getStarsConfig() {
75-
JsonObject config = Json.createObjectBuilder()
64+
JsonObject config = TestUtils.getMysqlConfigurationBuilder()
7665
.add("schemaName", "ELASTICIO")
7766
.add("procedureName", "GET_CUSTOMER_BY_ID_AND_NAME")
78-
.add("user", user)
79-
.add("password", password)
80-
.add("dbEngine", "mysql")
81-
.add("host", host)
82-
.add("port", port)
83-
.add("databaseName", databaseName)
8467
.build();
8568
return config;
8669
}

src/test/groovy/io/elastic/jdbc/integration/actions/select_action/SelectMySQLSpec.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import javax.json.JsonObject
1414
import java.sql.Connection
1515
import java.sql.DriverManager
1616

17-
@Ignore
1817
class SelectMySQLSpec extends Specification {
1918

2019
@Shared

src/test/groovy/io/elastic/jdbc/integration/actions/upsert_row_by_primary_key/UpsertRowByPrimaryKeyMySQLSpec.groovy

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package io.elastic.jdbc.integration.actions.upsert_row_by_primary_key
33
import io.elastic.api.EventEmitter
44
import io.elastic.api.ExecutionParameters
55
import io.elastic.api.Message
6+
import io.elastic.jdbc.TestUtils
67
import io.elastic.jdbc.actions.UpsertRowByPrimaryKey
78
import spock.lang.Ignore
89
import spock.lang.Shared
@@ -14,23 +15,8 @@ import java.sql.Connection
1415
import java.sql.DriverManager
1516
import java.sql.ResultSet
1617

17-
@Ignore
1818
class UpsertRowByPrimaryKeyMySQLSpec extends Specification {
1919

20-
@Shared
21-
def user = System.getenv("CONN_USER_MYSQL")
22-
@Shared
23-
def password = System.getenv("CONN_PASSWORD_MYSQL")
24-
@Shared
25-
def databaseName = System.getenv("CONN_DBNAME_MYSQL")
26-
@Shared
27-
def host = System.getenv("CONN_HOST_MYSQL")
28-
@Shared
29-
def port = System.getenv("CONN_PORT_MYSQL")
30-
@Shared
31-
def dbEngine = "mysql"
32-
@Shared
33-
def connectionString ="jdbc:" + dbEngine + "://" + host + ":" + port + "/" + databaseName + "?useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC"
3420
@Shared
3521
Connection connection
3622

@@ -50,7 +36,8 @@ class UpsertRowByPrimaryKeyMySQLSpec extends Specification {
5036
UpsertRowByPrimaryKey action
5137

5238
def setupSpec() {
53-
connection = DriverManager.getConnection(connectionString, user, password)
39+
JsonObject config = getStarsConfig();
40+
connection = DriverManager.getConnection(config.getString("connectionString"), config.getString("user"), config.getString("password"))
5441
}
5542

5643
def setup() {
@@ -75,14 +62,8 @@ class UpsertRowByPrimaryKeyMySQLSpec extends Specification {
7562
}
7663

7764
def getStarsConfig() {
78-
JsonObject config = Json.createObjectBuilder()
65+
JsonObject config = TestUtils.getMysqlConfigurationBuilder()
7966
.add("tableName", "stars")
80-
.add("user", user)
81-
.add("password", password)
82-
.add("dbEngine", dbEngine)
83-
.add("host", host)
84-
.add("port", port)
85-
.add("databaseName", databaseName)
8667
.build();
8768
return config;
8869
}
@@ -219,14 +200,8 @@ class UpsertRowByPrimaryKeyMySQLSpec extends Specification {
219200

220201

221202
def getPersonsConfig() {
222-
JsonObject config = Json.createObjectBuilder()
203+
JsonObject config = TestUtils.getMysqlConfigurationBuilder()
223204
.add("tableName", "persons")
224-
.add("user", user)
225-
.add("password", password)
226-
.add("dbEngine", dbEngine)
227-
.add("host", host)
228-
.add("port", port)
229-
.add("databaseName", databaseName)
230205
.build()
231206
return config
232207
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package io.elastic.jdbc.integration.providers.column_names_provider
2+
3+
import io.elastic.jdbc.TestUtils
4+
import io.elastic.jdbc.providers.ColumnNamesProvider
5+
import spock.lang.Shared
6+
import spock.lang.Specification
7+
8+
import javax.json.JsonObject
9+
import java.sql.Connection
10+
import java.sql.DriverManager
11+
12+
class ColumnNamesProviderMySQLSpec extends Specification {
13+
@Shared
14+
Connection connection
15+
@Shared
16+
JsonObject config
17+
18+
def setup() {
19+
config = TestUtils.getMysqlConfigurationBuilder()
20+
.add("tableName", "stars")
21+
.build()
22+
connection = DriverManager.getConnection(config.getString("connectionString"), config.getString("user"), config.getString("password"));
23+
String sql = "DROP TABLE IF EXISTS stars;"
24+
connection.createStatement().execute(sql)
25+
sql = "CREATE TABLE stars (ID int, name varchar(255) NOT NULL, radius int, destination float, createdat DATETIME)"
26+
connection.createStatement().execute(sql);
27+
}
28+
29+
def cleanupSpec() {
30+
String sql = " DROP TABLE IF EXISTS stars;"
31+
connection.createStatement().execute(sql)
32+
connection.close()
33+
}
34+
35+
def "get metadata model, given table name"() {
36+
37+
38+
ColumnNamesProvider provider = new ColumnNamesProvider()
39+
JsonObject meta = provider.getMetaModel(config)
40+
print meta
41+
expect:
42+
meta.toString() == "{\"out\":{\"type\":\"object\",\"properties\":{\"ID\":{\"required\":false,\"title\":\"ID\",\"type\":\"number\"},\"name\":{\"required\":true,\"title\":\"name\",\"type\":\"string\"},\"radius\":{\"required\":false,\"title\":\"radius\",\"type\":\"number\"},\"destination\":{\"required\":false,\"title\":\"destination\",\"type\":\"number\"},\"createdat\":{\"required\":false,\"title\":\"createdat\",\"type\":\"string\"}}},\"in\":{\"type\":\"object\",\"properties\":{\"ID\":{\"required\":false,\"title\":\"ID\",\"type\":\"number\"},\"name\":{\"required\":true,\"title\":\"name\",\"type\":\"string\"},\"radius\":{\"required\":false,\"title\":\"radius\",\"type\":\"number\"},\"destination\":{\"required\":false,\"title\":\"destination\",\"type\":\"number\"},\"createdat\":{\"required\":false,\"title\":\"createdat\",\"type\":\"string\"}}}}"
43+
}
44+
45+
}

src/test/groovy/io/elastic/jdbc/integration/providers/column_names_with_primary_key_provider/ColumnNamesWithPrimaryKeyProviderMySQLSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ColumnNamesWithPrimaryKeyProviderMySQLSpec extends Specification {
2121
config = TestUtils.getMysqlConfigurationBuilder()
2222
.add("tableName", "stars")
2323
.build()
24-
connection = DriverManager.getConnection(config.getString("connectionString"), config.getString("user"), config.getString("password"));
24+
connection = DriverManager.getConnection(config.getString("connectionString"), config.getString("user"), config.getString("password"))
2525
String sql = " DROP TABLE IF EXISTS stars;"
2626
connection.createStatement().execute(sql)
2727
sql = "CREATE TABLE stars (id int AUTO_INCREMENT, isDead boolean, name varchar(255) NOT NULL, radius int, destination float, createdat timestamp, PRIMARY KEY (id))"

0 commit comments

Comments
 (0)