Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# JDBC Component

## 2.4.0 (March 12, 2020)

* Add Firebird RDBMS support

## 2.3.2 (October 21, 2019)

* Add rebound mechanism in case of deadlocks for actions: Insert, UpsertByPK, DeleteByPK
Expand Down
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ For integration-testing is needed to specify following environment variables:
- ``CONN_DBNAME_POSTGRESQL`` - DataBase name
- ``CONN_HOST_POSTGRESQL`` - DataBase host
- ``CONN_PORT_POSTGRESQL`` - DataBase port
5. Connection to Firebird:
- ``CONN_USER_FIREBIRD`` - user login
- ``CONN_PASSWORD_FIREBIRD`` - user password
- ``CONN_DBNAME_FIREBIRD`` - DataBase name
- ``CONN_HOST_FIREBIRD`` - DataBase host
- ``CONN_PORT_FIREBIRD`` - DataBase port
- ``CONN_PORT_FIREBIRD`` - DataBase port
#### Others
## Credentials
You need to use following properties to configure credentials:
Expand All @@ -74,6 +81,7 @@ Optional field. Provide port of the server instance, as by default:
- ``5432`` - PostgreSQL
- ``1521`` - Oracle
- ``1433`` - MSSQL
- ``3050`` - Firebird
### Database Name
Provide name of database at the instance that you want to interact with.
### User
Expand Down Expand Up @@ -341,15 +349,17 @@ Please use [**Upsert row by primary key**](#upsert-row-by-primary-key-action) in
- ``PostgreSQL`` - compatible with PostgreSQL 8.2 and higher
- ``Oracle`` - compatible with Oracle Database 8.1.7 - 12.1.0.2
- ``MSSQL`` - compatible with Microsoft SQL Server 2008 R2 and higher
- ``Firebird`` - compatible with Firebird 2.0 and higher
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.
4. The current implementation of the action ``Execute stored procedure`` doesn't support ResultSet MSSQL output.
5. The current implementation of the action ``Execute stored procedure`` doesn't support any array types parameters.
(MySQL does not have schemas by definition)
6. Rebound mechanism only works for this SQL State:
- ``MySQL``: 40001, XA102
- ``Oracle``: 61000
- ``MSSQL``: 40001
- ``PostgreSQL``: 40P01
- ``MySQL``: 40001, XA102
- ``Oracle``: 61000
- ``MSSQL``: 40001
- ``PostgreSQL``: 40P01
- ``Firebird``: 10054, 10038

## License
Apache-2.0 © [elastic.io GmbH](https://www.elastic.io "elastic.io GmbH")
Expand Down
14 changes: 8 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = 'io.elastic'
version = '2.4.0'
version = '6.3'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from 2.4.0 to 6.3? Is it correct?

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
Expand Down Expand Up @@ -28,11 +28,12 @@ test {
}

task integrationTest(type: Test) {
maxParallelForks = 1
testLogging {
showStandardStreams = true
}
filter() {
includeTestsMatching "io.elastic.jdbc.integration.*"
includeTestsMatching 'io.elastic.jdbc.integration.*'
}
}

Expand All @@ -48,16 +49,17 @@ targetCompatibility = 1.8

repositories {
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
mavenCentral()
mavenLocal()
}

dependencies {
compile "io.elastic:sailor-jvm:2.1.0"
compile "mysql:mysql-connector-java:8.0.11"
compile 'io.elastic:sailor-jvm:2.1.3'
compile 'mysql:mysql-connector-java:8.0.11'
compile group: 'org.postgresql', name: 'postgresql', version: '42.2.4'
compile group: 'org.firebirdsql.jdbc', name: 'jaybird-jdk18', version: '3.0.8'
compile files("./lib/ojdbc6.jar")
compile files("./lib/sqljdbc4.jar")
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
Expand All @@ -67,7 +69,7 @@ dependencies {
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.3'

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

Expand Down
3 changes: 2 additions & 1 deletion component.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"mysql": "MySQL",
"postgresql": "PostgreSQL",
"oracle": "Oracle",
"mssql": "MSSQL"
"mssql": "MSSQL",
"firebirdsql": "Firebird"
},
"prompt": "Please Select Database Type"
},
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Aug 13 13:58:37 EEST 2019
#Thu Apr 02 13:29:34 EEST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
zipStoreBase=GRADLE_USER_HOME
80 changes: 44 additions & 36 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
warn () {
echo "$*"
}

die ( ) {
die () {
echo
echo "$*"
echo
Expand All @@ -30,6 +48,7 @@ die ( ) {
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
Expand All @@ -40,31 +59,11 @@ case "`uname`" in
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac

# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
Expand All @@ -90,7 +89,7 @@ location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
Expand All @@ -101,7 +100,7 @@ if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not queryOld maximum file descriptor limit: $MAX_FD_LIMIT"
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi

Expand All @@ -114,6 +113,7 @@ fi
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
Expand Down Expand Up @@ -154,11 +154,19 @@ if $cygwin ; then
esac
fi

# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
APP_ARGS=$(save "$@")

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
exec "$JAVACMD" "$@"
14 changes: 4 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

Expand Down Expand Up @@ -46,10 +46,9 @@ echo location of your Java installation.
goto fail

:init
@rem Get command-line arguments, handling Windowz variants
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args

:win9xME_args
@rem Slurp the command line arguments.
Expand All @@ -60,11 +59,6 @@ set _SKIP=2
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*
goto execute

:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$

:execute
@rem Setup the command line
Expand Down
27 changes: 5 additions & 22 deletions src/main/java/io/elastic/jdbc/actions/DeleteRowByPrimaryKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,11 @@ public void execute(ExecutionParameters parameters) {
StringBuilder primaryKey = new StringBuilder();
StringBuilder primaryValue = new StringBuilder();
Integer primaryKeysCount = 0;
String tableName = "";
String dbEngine = "";
Boolean nullableResult = false;

if (configuration.containsKey(PROPERTY_TABLE_NAME)
&& Utils.getNonNullString(configuration, PROPERTY_TABLE_NAME).length() != 0) {
tableName = configuration.getString(PROPERTY_TABLE_NAME);
} else if (snapshot.containsKey(PROPERTY_TABLE_NAME)
&& Utils.getNonNullString(snapshot, PROPERTY_TABLE_NAME).length() != 0) {
tableName = snapshot.getString(PROPERTY_TABLE_NAME);
} else {
throw new RuntimeException("Table name is required field");
}

if (Utils.getNonNullString(configuration, PROPERTY_DB_ENGINE).length() != 0) {
dbEngine = configuration.getString(PROPERTY_DB_ENGINE);
} else if (Utils.getNonNullString(snapshot, PROPERTY_DB_ENGINE).length() != 0) {
dbEngine = snapshot.getString(PROPERTY_DB_ENGINE);
} else {
throw new RuntimeException("DB Engine is required field");
}
final String dbEngine = Utils.getDbEngine(configuration);
final boolean isOracle = dbEngine.equals(Engines.ORACLE.name().toLowerCase());
final boolean isFirebird = dbEngine.equals(Engines.FIREBIRDSQL.name().toLowerCase());
final String tableName = Utils.getTableName(configuration, (isOracle || isFirebird));

if (Utils.getNonNullString(configuration, PROPERTY_NULLABLE_RESULT).equals("true")) {
nullableResult = true;
Expand All @@ -73,8 +57,7 @@ public void execute(ExecutionParameters parameters) {
if (primaryKeysCount == 1) {
try (Connection connection = Utils.getConnection(configuration)) {
LOGGER.info("Executing delete row by primary key action");
boolean isOracle = dbEngine.equals(Engines.ORACLE.name().toLowerCase());
Utils.columnTypes = Utils.getColumnTypes(connection, isOracle, tableName);
Utils.columnTypes = Utils.getColumnTypes(connection, tableName);
LOGGER.info("Detected column types: " + Utils.columnTypes);
try {
QueryFactory queryFactory = new QueryFactory();
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/elastic/jdbc/actions/InsertAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ public void execute(ExecutionParameters parameters) {
final JsonObject body = parameters.getMessage().getBody();
final String dbEngine = Utils.getDbEngine(configuration);
final boolean isOracle = dbEngine.equals(Engines.ORACLE.name().toLowerCase());
final String tableName = Utils.getTableName(configuration, isOracle);
final boolean isFirebird = dbEngine.equals(Engines.FIREBIRDSQL.name().toLowerCase());
final String tableName = Utils.getTableName(configuration, (isOracle || isFirebird));
LOGGER.info("Found dbEngine: '{}' and tableName: '{}'", dbEngine, tableName);
try (Connection connection = Utils.getConnection(configuration)) {
Utils.columnTypes = Utils.getColumnTypes(connection, isOracle, tableName);
Utils.columnTypes = Utils.getColumnTypes(connection, tableName);
LOGGER.info("Detected column types: " + Utils.columnTypes);
LOGGER.info("Inserting in table '{}' values '{}'", tableName, body);
QueryFactory queryFactory = new QueryFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public void execute(ExecutionParameters parameters) {
JsonObject snapshot = parameters.getSnapshot();
StringBuilder primaryKey = new StringBuilder();
StringBuilder primaryValue = new StringBuilder();
Integer primaryKeysCount = 0;
int primaryKeysCount = 0;
String tableName = "";
String dbEngine = "";
Boolean nullableResult = false;
boolean nullableResult = false;

if (configuration.containsKey(PROPERTY_TABLE_NAME)
&& Utils.getNonNullString(configuration, PROPERTY_TABLE_NAME).length() != 0) {
Expand All @@ -64,8 +64,6 @@ public void execute(ExecutionParameters parameters) {
nullableResult = true;
}

boolean isOracle = dbEngine.equals(Engines.ORACLE.name().toLowerCase());

for (Map.Entry<String, JsonValue> entry : body.entrySet()) {
LOGGER.info("{} = {}", entry.getKey(), entry.getValue());
primaryKey.append(entry.getKey());
Expand All @@ -77,7 +75,7 @@ public void execute(ExecutionParameters parameters) {

try (Connection connection = Utils.getConnection(configuration)) {
LOGGER.info("Executing lookup row by primary key action");
Utils.columnTypes = Utils.getColumnTypes(connection, isOracle, tableName);
Utils.columnTypes = Utils.getColumnTypes(connection, tableName);
LOGGER.info("Detected column types: " + Utils.columnTypes);
try {
QueryFactory queryFactory = new QueryFactory();
Expand Down
Loading