Skip to content

Commit 7ab6352

Browse files
author
Olha Virolainen
authored
Sprint22 master (#31)
* Issue 29 add config parameter (#30) * add configurationProperties * Improving mssql stored procedures (#28) * Adding RESULT_VALUE parameter processing. * Improving MSSQL stored procedures processing * Fixing exceptions processing. * Add log properties * Update README.md
1 parent 890f2dc commit 7ab6352

File tree

65 files changed

+542
-200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+542
-200
lines changed

.circleci/config.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: 2
2+
jobs:
3+
test:
4+
docker:
5+
- image: circleci/openjdk:8
6+
steps:
7+
- checkout
8+
- restore_cache:
9+
key: gradle-{{ checksum "build.gradle" }}
10+
11+
- run: ./gradlew downloadDependencies --daemon
12+
- save_cache:
13+
key: gradle-{{ checksum "build.gradle" }}
14+
paths:
15+
- ~/.gradle/caches
16+
- ~/.gradle/wrapper
17+
18+
- run:
19+
name: Run Unit Tests
20+
command: ./gradlew test --daemon
21+
- run:
22+
name: Run Integration Tests
23+
command: ./gradlew integrationTest --daemon
24+
workflows:
25+
version: 2
26+
build_and_test:
27+
jobs:
28+
- test

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
out/
88
tests.log
99
tests.properties
10-
tests.script
10+
tests.script
11+
.env

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## 2.2.0 (August 28, 2019)
2+
3+
* Add support `Configuration properties` for DB connection
4+
* Enable circleci
5+
6+
## 2.1.0 (July 30, 2019)
7+
8+
* Initial release which includes a bunch of previous unversioned releases

README.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# JDBC-component
2+
23
## Description
34
This is an open source component for working with object-relational database management systems on [elastic.io platform](http://www.elastic.io "elastic.io platform").
45

@@ -27,8 +28,9 @@ Following actions are inside:
2728

2829
### Requirements
2930
Before you can deploy any code into elastic.io **you must be a registered elastic.io platform user**. Please see our home page at [http://www.elastic.io](http://www.elastic.io) to learn how.
31+
3032
#### Environment variables
31-
For unit-testing is needed to specify following environment variables:
33+
For integration-testing is needed to specify following environment variables:
3234
1. Connection to MSSQL:
3335
- ``CONN_USER_MSSQL`` - user login
3436
- ``CONN_PASSWORD_MSSQL`` - user password
@@ -55,29 +57,31 @@ For unit-testing is needed to specify following environment variables:
5557
- ``CONN_PORT_POSTGRESQL`` - DataBase port
5658
#### Others
5759
## Credentials
58-
You may use following properties to configure a connection:
59-
![image](https://user-images.githubusercontent.com/40201204/43577550-ce99efe6-9654-11e8-87ed-f3e0839d618a.png)
60-
You can add the authorisation methods during the integration flow design or by going to your Settings > Security credentials > REST client and adding there.
60+
You need to use following properties to configure credentials:
61+
6162
### DB Engine
62-
You are able to choose one of existing database types:
63+
Choose one of existing database types:
6364
![image](https://user-images.githubusercontent.com/40201204/43577772-6f85bdea-9655-11e8-96e1-368493a36c9d.png)
6465

6566
### Connection URI
66-
In the Connection URI field please provide hostname of the server, e.g. ``acme.com``
67+
Provide hostname of the server, e.g. ``acme.com``
6768
### Connection port
68-
In the Connection port field please provide port of the server instance, as by default:
69+
Optional field. Provide port of the server instance, as by default:
6970
- ``3306`` - MySQL
7071
- ``5432`` - PostgreSQL
7172
- ``1521`` - Oracle
7273
- ``1433`` - MSSQL
7374
### Database Name
74-
In the Database Name field please provide name of database at the instance that you want to interact with.
75+
Provide name of database at the instance that you want to interact with.
7576
### User
76-
In the User field please provide a username that has permissions to interact with the Database.
77+
Provide a username that has permissions to interact with the Database.
7778
### Password
78-
In the Password field please provide a password of the user that has permissions to interact with the Database.
79+
Provide a password of the user that has permissions to interact with the Database.
80+
### Configuration properties
81+
Optional field. Provide a configuration properties for connections to the Database, e.g. ``useUnicode=true&serverTimezone=UTC``
82+
83+
**Limitation:** `Configuration properties` value may not be checked during Credentials Verifacation, so in case of using this field make sure that it contains correct input.
7984

80-
Validation will start right after click on a Save button. You will be able to continue working with component after validation if all provided credentials will be valid.
8185
## Triggers
8286
### Select trigger
8387
You are able to provide SELECT query with last execution timestamp as WHERE clause criteria.
@@ -113,7 +117,6 @@ The format of ``Start Polling From (optional)`` field should be like ``yyyy-mm-d
113117
### SELECT trigger (Deprecated)
114118
This action exists in JDBC component only for backward compatibility. New [**Select trigger**](#select-trigger) is recommended to use.
115119

116-
117120
## Actions
118121
### Select action
119122
![image](https://user-images.githubusercontent.com/40201204/43592439-39ec5738-967e-11e8-8632-3655b08982d3.png)
@@ -248,7 +251,8 @@ Component generates next metadata:
248251

249252

250253
### Create or update record action (Deprecated)
251-
This action exists in JDBC component only for backward compatibility. [**Upsert row by primary key**](#upsert-row-by-primary-key-action) Action is recommended to use.
254+
This action exists in JDBC component only for backward compatibility.
255+
Please use [**Upsert row by primary key**](#upsert-row-by-primary-key-action) instead.
252256

253257
## Current limitations
254258
1. Only tables with one [PRIMARY KEY](https://en.wikipedia.org/wiki/Primary_key "PRIMARY KEY") is supported. You will see the message ``Table has not Primary Key. Should be one Primary Key

build.gradle

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,48 @@
11
group = 'io.elastic'
2-
version = '2.1.0'
2+
version = '2.2.0'
33
apply plugin: 'java'
44
apply plugin: 'idea'
55
apply plugin: 'eclipse'
66
apply plugin: 'groovy'
77

8+
sourceSets {
9+
integrationTest {
10+
java.outputDir = file('build/classes/integrationtest')
11+
java { srcDir file('src/integration-test/java') }
12+
resources { srcDir file('src/integration-test/resources') }
13+
}
14+
main {
15+
java.outputDir = file('build/classes/main')
16+
}
17+
test {
18+
java.outputDir = file('build/classes/test')
19+
}
20+
}
21+
22+
test {
23+
exclude 'io/elastic/jdbc/integration/**'
24+
testLogging {
25+
showStandardStreams = true
26+
}
27+
maxParallelForks 4
28+
}
29+
30+
task integrationTest(type: Test) {
31+
testLogging {
32+
showStandardStreams = true
33+
}
34+
filter() {
35+
includeTestsMatching "io.elastic.jdbc.integration.*"
36+
}
37+
}
38+
39+
task downloadDependencies() {
40+
description 'Download all dependencies to the Gradle cache'
41+
doLast {
42+
configurations.findAll { it.canBeResolved }.files
43+
}
44+
}
45+
846
sourceCompatibility = 1.8
947
targetCompatibility = 1.8
1048

@@ -28,10 +66,12 @@ dependencies {
2866
compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.3'
2967
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.3'
3068

69+
testCompile group: 'io.github.cdimascio', name: 'java-dotenv', version: '5.1.0'
3170
testCompile "org.spockframework:spock-core:1.1-groovy-2.4"
3271
testCompile 'org.hsqldb:hsqldb:2.0.0'
3372
}
3473

35-
task wrapper(type: Wrapper) {
36-
gradleVersion = '4.9'
74+
75+
wrapper {
76+
gradleVersion = '5.4.1'
3777
}

circle.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

component.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
"label": "Password",
4646
"required": true,
4747
"placeholder": "Password"
48+
},
49+
"configurationProperties": {
50+
"viewClass": "TextFieldView",
51+
"label": "Configuration properties",
52+
"required": false,
53+
"placeholder": "useUnicode=true&serverTimezone=UTC"
4854
}
4955
}
5056
},
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon Aug 10 13:36:19 EEST 2015
1+
#Tue Aug 13 13:58:37 EEST 2019
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

src/main/java/io/elastic/jdbc/ProcedureParameter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,9 @@ public int getType() {
8080
public int getOrder() {
8181
return order;
8282
}
83+
84+
public ProcedureParameter setOrder(int order) {
85+
this.order = order;
86+
return this;
87+
}
8388
}

src/main/java/io/elastic/jdbc/QueryBuilders/MSSQL.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.sql.CallableStatement;
88
import java.sql.Connection;
99
import java.sql.PreparedStatement;
10+
import java.sql.ResultSet;
1011
import java.sql.SQLException;
1112
import java.util.ArrayList;
1213
import java.util.Map;
@@ -16,9 +17,13 @@
1617
import javax.json.JsonObject;
1718
import javax.json.JsonObjectBuilder;
1819
import javax.json.JsonValue;
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
1922

2023
public class MSSQL extends Query {
2124

25+
private static final Logger LOGGER = LoggerFactory.getLogger(MSSQL.class);
26+
2227
public ArrayList executePolling(Connection connection) throws SQLException {
2328
validateQuery();
2429
String sql = "WITH Results_CTE AS" +
@@ -119,6 +124,7 @@ public void executeUpdate(Connection connection, String tableName, String idColu
119124
protected CallableStatement prepareCallableStatement(Connection connection, String procedureName,
120125
Map<String, ProcedureParameter> procedureParams, JsonObject messageBody)
121126
throws SQLException {
127+
122128
CallableStatement stmt = connection.prepareCall(
123129
String.format("{call %s%s}", procedureName,
124130
generateStatementWildcardMask(procedureParams)));
@@ -128,14 +134,16 @@ protected CallableStatement prepareCallableStatement(Connection connection, Stri
128134
ProcedureParameter parameter = procedureParams.values()
129135
.stream()
130136
.filter(p -> p.getOrder() == order)
131-
.findFirst().orElseThrow(() -> new IllegalStateException("Can't find parameter by order"));
137+
.findFirst()
138+
.orElseThrow(() -> new IllegalStateException("Can't find parameter by order"));
132139

133140
if (parameter.getDirection() == Direction.IN || parameter.getDirection() == Direction.INOUT) {
134141
if (parameter.getDirection() == Direction.INOUT) {
135142
stmt.registerOutParameter(inc, parameter.getType());
136143
}
137144

138145
String type = Utils.cleanJsonType(Utils.detectColumnType(parameter.getType(), ""));
146+
LOGGER.info("Processing: " + parameter.getName());
139147
switch (type) {
140148
case ("number"):
141149
stmt.setObject(inc,
@@ -168,10 +176,21 @@ public JsonObject callProcedure(Connection connection, JsonObject body, JsonObje
168176
CallableStatement stmt = prepareCallableStatement(connection,
169177
configuration.getString("procedureName"), procedureParams, body);
170178

171-
stmt.execute();
179+
ResultSet functionResultSet = null;
180+
try {
181+
functionResultSet = stmt.executeQuery();
182+
} catch (SQLException e) {
183+
if (e.getErrorCode() != 0) { // Ensuring that procedure was executed, but functionResultSet is empty
184+
throw e;
185+
}
186+
}
172187

173188
JsonObjectBuilder resultBuilder = Json.createObjectBuilder();
174189

190+
if (functionResultSet != null) {
191+
addResultSetToJson(resultBuilder, functionResultSet, "@RETURN_VALUE");
192+
}
193+
175194
procedureParams.values().stream()
176195
.filter(param -> param.getDirection() == Direction.OUT
177196
|| param.getDirection() == Direction.INOUT)

0 commit comments

Comments
 (0)