Skip to content

Commit

Permalink
Improvements for the MySQL/MariaDB component: It works now also with the
Browse files Browse the repository at this point in the history
latest JDBC driver and the option to enable streaming is now more
generic and works also with other pools like C3PO and not only the
Apache DBCP2.
  • Loading branch information
jlolling committed Sep 29, 2021
1 parent d3b376a commit 8f61fa9
Show file tree
Hide file tree
Showing 21 changed files with 58 additions and 68 deletions.
3 changes: 2 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
Expand Down
9 changes: 6 additions & 3 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
17 changes: 3 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.jlo.talendcomp</groupId>
<artifactId>jlo-talendcomp-tabletransfer</artifactId>
<version>9.5</version>
<name>Talend Table Transfer Components</name>
<organization>
<name>Jan Lolling</name>
Expand All @@ -12,6 +13,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand All @@ -24,7 +26,7 @@
<configuration>
<copyFromSourceBaseDir>${project.basedir}/talend_component</copyFromSourceBaseDir>
<componentBaseDir>${project.basedir}/talend_component</componentBaseDir>
<studioUserComponentFolder>/Data/Talend/Studio/talend_user_components</studioUserComponentFolder>
<studioUserComponentFolder>${custom_component_folder}</studioUserComponentFolder>
</configuration>
<executions>
<execution>
Expand Down Expand Up @@ -88,18 +90,5 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1212.jre7</version>
<scope>provided</scope>
</dependency>
</dependencies>
<version>9.4</version>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ public SQLStatement buildPSInsertSQLStatement(SQLTable table, boolean fullName,
sqlPs.setPrepared(true);
int paramIndex = 0;
final StringBuilder sb = new StringBuilder();
sb.append("insert into ");
if (onConflictIgnore) {
sb.append("insert ignore into ");
} else {
sb.append("insert into ");
}
if (fullName) {
sb.append(getEncapsulatedName(table.getAbsoluteName()));
} else {
Expand Down Expand Up @@ -47,14 +51,7 @@ public SQLStatement buildPSInsertSQLStatement(SQLTable table, boolean fullName,
sqlPs.addParam(psParam);
}
sb.append(")");
if (onConflictIgnore || (hasNonePrimaryKeyFields == false)) {
sb.append("\n on duplicate key update ");
// build dummy assignment col=col
field = table.getFieldAt(0);
sb.append(field.getName());
sb.append("=");
sb.append(field.getName());
} else if (onConflictUpdate && hasNonePrimaryKeyFields) {
if (onConflictUpdate && hasNonePrimaryKeyFields) {
sb.append("\n on duplicate key update ");
// build assignment for the none-key fields
boolean firstLoop = true;
Expand Down
38 changes: 19 additions & 19 deletions src/main/java/de/jlo/talendcomp/tabletransfer/MySQLHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ public class MySQLHelper extends DBHelper {
private void enableStreaming(java.sql.Statement stmt) throws Exception {
if (stmt != null) {
Class<?> stmtClass = stmt.getClass();
if (stmt instanceof com.mysql.jdbc.Statement) {
((com.mysql.jdbc.Statement) stmt).enableStreamingResults();
} else if (stmtClass.getName().equals("org.apache.commons.dbcp2.DelegatingPreparedStatement")) {
Method method = stmtClass.getMethod("getDelegate", (Class<?>[]) null);
Object result = method.invoke(stmt, (Object[]) null);
if (result instanceof java.sql.Statement) {
enableStreaming((java.sql.Statement) result);
} else {
System.err.println("Got no statement object. Instead we got: " + result);
}
} else if (stmtClass.getName().equals("org.apache.commons.dbcp2.DelegatingStatement")) {
Method method = stmtClass.getMethod("getDelegate", (Class<?>[]) null);
Object result = method.invoke(stmt, (Object[]) null);
if (result instanceof java.sql.Statement) {
enableStreaming((java.sql.Statement) result);
} else {
System.err.println("Got no statement object. Instead we got: " + result);
boolean enablingSucceeded = false;
try {
Method method = stmtClass.getMethod("enableStreamingResults", (Class<?>[]) null);
method.invoke(stmt, (Object[]) null);
enablingSucceeded = true;
} catch (NoSuchMethodException nsme) {
// ignore intentionally
}
if (enablingSucceeded == false) {
// because it is a wrapper class from pools e.g.
try {
// most likely we will get the actual statement by fetching the delegate
Method method = stmtClass.getMethod("getDelegate", (Class<?>[]) null);
Object result = method.invoke(stmt, (Object[]) null);
if (result instanceof java.sql.Statement) {
enableStreaming((java.sql.Statement) result);
}
} catch (NoSuchMethodException nsme) {
// ignore intentionally
}
} else {
System.err.println("Incompatible statement class found: " + stmt.getClass().getName());
}
}
}
Expand Down
Binary file not shown.
Binary file not shown.
8 changes: 4 additions & 4 deletions talend_component/tDB2TableTransfer/tDB2TableTransfer_java.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<COMPONENT>
<HEADER PLATEFORM="ALL" SERIAL="" VERSION="9.4" STATUS="ALPHA" COMPATIBILITY="ALL" AUTHOR="Jan Lolling" RELEASE_DATE="20200804" STARTABLE="true" HAS_CONDITIONAL_OUTPUTS="false">
<HEADER PLATEFORM="ALL" SERIAL="" VERSION="9.5" STATUS="ALPHA" COMPATIBILITY="ALL" AUTHOR="Jan Lolling" RELEASE_DATE="20210929" STARTABLE="true" HAS_CONDITIONAL_OUTPUTS="false">
<SIGNATURE/>
</HEADER>
<FAMILIES>
Expand Down Expand Up @@ -148,13 +148,13 @@
<PARAMETER NAME="ALTERNATIVE_MODEL_KEY" FIELD="TEXT" NUM_ROW="80" SHOW_IF="REUSE_DATA_MODEL == 'true'">
<DEFAULT/>
</PARAMETER>
<PARAMETER NAME="RELEASE_LABEL_20200804" FIELD="LABEL" COLOR="0;0;0" NUM_ROW="900">
<DEFAULT>Release: 9.4 build at: 20200804</DEFAULT>
<PARAMETER NAME="RELEASE_LABEL_20210929" FIELD="LABEL" COLOR="0;0;0" NUM_ROW="900">
<DEFAULT>Release: 9.5 build at: 20210929</DEFAULT>
</PARAMETER>
</ADVANCED_PARAMETERS>
<CODEGENERATION>
<IMPORTS>
<IMPORT NAME="jlo-talendcomp-tabletransfer" MODULE="jlo-talendcomp-tabletransfer-9.4.jar" MVN="mvn:org.talend.libraries/jlo-talendcomp-tabletransfer-9.4/6.0.0-SNAPSHOT" REQUIRED="true"/>
<IMPORT NAME="jlo-talendcomp-tabletransfer" MODULE="jlo-talendcomp-tabletransfer-9.5.jar" MVN="mvn:org.talend.libraries/jlo-talendcomp-tabletransfer-9.5/6.0.0-SNAPSHOT" REQUIRED="true"/>
<IMPORT NAME="slf4j-api" MODULE="slf4j-api-1.7.30.jar" MVN="mvn:org.talend.libraries/slf4j-api-1.7.30/6.0.0-SNAPSHOT" REQUIRED="true"/>
</IMPORTS>
</CODEGENERATION>
Expand Down
Binary file not shown.
Binary file not shown.
8 changes: 4 additions & 4 deletions talend_component/tEXATableTransfer/tEXATableTransfer_java.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<COMPONENT>
<HEADER PLATEFORM="ALL" SERIAL="" VERSION="9.4" STATUS="ALPHA" COMPATIBILITY="ALL" AUTHOR="Jan Lolling" RELEASE_DATE="20200804" STARTABLE="true" HAS_CONDITIONAL_OUTPUTS="false">
<HEADER PLATEFORM="ALL" SERIAL="" VERSION="9.5" STATUS="ALPHA" COMPATIBILITY="ALL" AUTHOR="Jan Lolling" RELEASE_DATE="20210929" STARTABLE="true" HAS_CONDITIONAL_OUTPUTS="false">
<SIGNATURE/>
</HEADER>
<FAMILIES>
Expand Down Expand Up @@ -148,13 +148,13 @@
<PARAMETER NAME="ALTERNATIVE_MODEL_KEY" FIELD="TEXT" NUM_ROW="80" SHOW_IF="REUSE_DATA_MODEL == 'true'">
<DEFAULT/>
</PARAMETER>
<PARAMETER NAME="RELEASE_LABEL_20200804" FIELD="LABEL" COLOR="0;0;0" NUM_ROW="900">
<DEFAULT>Release: 9.4 build at: 20200804</DEFAULT>
<PARAMETER NAME="RELEASE_LABEL_20210929" FIELD="LABEL" COLOR="0;0;0" NUM_ROW="900">
<DEFAULT>Release: 9.5 build at: 20210929</DEFAULT>
</PARAMETER>
</ADVANCED_PARAMETERS>
<CODEGENERATION>
<IMPORTS>
<IMPORT NAME="jlo-talendcomp-tabletransfer" MODULE="jlo-talendcomp-tabletransfer-9.4.jar" MVN="mvn:org.talend.libraries/jlo-talendcomp-tabletransfer-9.4/6.0.0-SNAPSHOT" REQUIRED="true"/>
<IMPORT NAME="jlo-talendcomp-tabletransfer" MODULE="jlo-talendcomp-tabletransfer-9.5.jar" MVN="mvn:org.talend.libraries/jlo-talendcomp-tabletransfer-9.5/6.0.0-SNAPSHOT" REQUIRED="true"/>
<IMPORT NAME="slf4j-api" MODULE="slf4j-api-1.7.30.jar" MVN="mvn:org.talend.libraries/slf4j-api-1.7.30/6.0.0-SNAPSHOT" REQUIRED="true"/>
</IMPORTS>
</CODEGENERATION>
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@
System.out.println("Source query statement:" + <%=cid%>.getSourceQuery());
<% } %>
<% if (outputToTable && "true".equalsIgnoreCase(logoutInsert)) { %>
// log target statement
// log target statement
System.out.println("Target insert statement:" + <%=cid%>.getTargetInsertStatement());
<% } %>
<% if (outputToTable && "true".equalsIgnoreCase(truncateTarget)) { %>
System.out.println("truncate target table...");
System.out.println("truncate target table...");
<%=cid%>.executeSQLOnTarget("truncate table " + <%=cid%>.getTargetTable());
<% } %>
<% if (outputToTable && "true".equalsIgnoreCase(disableKeys)) { %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<COMPONENT>
<HEADER PLATEFORM="ALL" SERIAL="" VERSION="9.4" STATUS="ALPHA" COMPATIBILITY="ALL" AUTHOR="Jan Lolling" RELEASE_DATE="20200804" STARTABLE="true" HAS_CONDITIONAL_OUTPUTS="false">
<HEADER PLATEFORM="ALL" SERIAL="" VERSION="9.5" STATUS="ALPHA" COMPATIBILITY="ALL" AUTHOR="Jan Lolling" RELEASE_DATE="20210929" STARTABLE="true" HAS_CONDITIONAL_OUTPUTS="false">
<SIGNATURE/>
</HEADER>
<FAMILIES>
Expand Down Expand Up @@ -158,13 +158,13 @@
<PARAMETER NAME="ALTERNATIVE_MODEL_KEY" FIELD="TEXT" NUM_ROW="80" SHOW_IF="REUSE_DATA_MODEL == 'true'">
<DEFAULT/>
</PARAMETER>
<PARAMETER NAME="RELEASE_LABEL_20200804" FIELD="LABEL" COLOR="0;0;0" NUM_ROW="900">
<DEFAULT>Release: 9.4 build at: 20200804</DEFAULT>
<PARAMETER NAME="RELEASE_LABEL_20210929" FIELD="LABEL" COLOR="0;0;0" NUM_ROW="900">
<DEFAULT>Release: 9.5 build at: 20210929</DEFAULT>
</PARAMETER>
</ADVANCED_PARAMETERS>
<CODEGENERATION>
<IMPORTS>
<IMPORT NAME="jlo-talendcomp-tabletransfer" MODULE="jlo-talendcomp-tabletransfer-9.4.jar" MVN="mvn:org.talend.libraries/jlo-talendcomp-tabletransfer-9.4/6.0.0-SNAPSHOT" REQUIRED="true"/>
<IMPORT NAME="jlo-talendcomp-tabletransfer" MODULE="jlo-talendcomp-tabletransfer-9.5.jar" MVN="mvn:org.talend.libraries/jlo-talendcomp-tabletransfer-9.5/6.0.0-SNAPSHOT" REQUIRED="true"/>
<IMPORT NAME="slf4j-api" MODULE="slf4j-api-1.7.30.jar" MVN="mvn:org.talend.libraries/slf4j-api-1.7.30/6.0.0-SNAPSHOT" REQUIRED="true"/>
</IMPORTS>
</CODEGENERATION>
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<COMPONENT>
<HEADER PLATEFORM="ALL" SERIAL="" VERSION="9.4" STATUS="ALPHA" COMPATIBILITY="ALL" AUTHOR="Jan Lolling" RELEASE_DATE="20200804" STARTABLE="true" HAS_CONDITIONAL_OUTPUTS="false">
<HEADER PLATEFORM="ALL" SERIAL="" VERSION="9.5" STATUS="ALPHA" COMPATIBILITY="ALL" AUTHOR="Jan Lolling" RELEASE_DATE="20210929" STARTABLE="true" HAS_CONDITIONAL_OUTPUTS="false">
<SIGNATURE/>
</HEADER>
<FAMILIES>
Expand Down Expand Up @@ -148,13 +148,13 @@
<PARAMETER NAME="ALTERNATIVE_MODEL_KEY" FIELD="TEXT" NUM_ROW="80" SHOW_IF="REUSE_DATA_MODEL == 'true'">
<DEFAULT/>
</PARAMETER>
<PARAMETER NAME="RELEASE_LABEL_20200804" FIELD="LABEL" COLOR="0;0;0" NUM_ROW="900">
<DEFAULT>Release: 9.4 build at: 20200804</DEFAULT>
<PARAMETER NAME="RELEASE_LABEL_20210929" FIELD="LABEL" COLOR="0;0;0" NUM_ROW="900">
<DEFAULT>Release: 9.5 build at: 20210929</DEFAULT>
</PARAMETER>
</ADVANCED_PARAMETERS>
<CODEGENERATION>
<IMPORTS>
<IMPORT NAME="jlo-talendcomp-tabletransfer" MODULE="jlo-talendcomp-tabletransfer-9.4.jar" MVN="mvn:org.talend.libraries/jlo-talendcomp-tabletransfer-9.4/6.0.0-SNAPSHOT" REQUIRED="true"/>
<IMPORT NAME="jlo-talendcomp-tabletransfer" MODULE="jlo-talendcomp-tabletransfer-9.5.jar" MVN="mvn:org.talend.libraries/jlo-talendcomp-tabletransfer-9.5/6.0.0-SNAPSHOT" REQUIRED="true"/>
<IMPORT NAME="slf4j-api" MODULE="slf4j-api-1.7.30.jar" MVN="mvn:org.talend.libraries/slf4j-api-1.7.30/6.0.0-SNAPSHOT" REQUIRED="true"/>
</IMPORTS>
</CODEGENERATION>
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<COMPONENT>
<HEADER PLATEFORM="ALL" SERIAL="" VERSION="9.4" STATUS="ALPHA" COMPATIBILITY="ALL" AUTHOR="Jan Lolling" RELEASE_DATE="20200804" STARTABLE="true" HAS_CONDITIONAL_OUTPUTS="false">
<HEADER PLATEFORM="ALL" SERIAL="" VERSION="9.5" STATUS="ALPHA" COMPATIBILITY="ALL" AUTHOR="Jan Lolling" RELEASE_DATE="20210929" STARTABLE="true" HAS_CONDITIONAL_OUTPUTS="false">
<SIGNATURE/>
</HEADER>
<FAMILIES>
Expand Down Expand Up @@ -155,13 +155,13 @@
<PARAMETER NAME="ALTERNATIVE_MODEL_KEY" FIELD="TEXT" NUM_ROW="80" SHOW_IF="REUSE_DATA_MODEL == 'true'">
<DEFAULT/>
</PARAMETER>
<PARAMETER NAME="RELEASE_LABEL_20200804" FIELD="LABEL" COLOR="0;0;0" NUM_ROW="900">
<DEFAULT>Release: 9.4 build at: 20200804</DEFAULT>
<PARAMETER NAME="RELEASE_LABEL_20210929" FIELD="LABEL" COLOR="0;0;0" NUM_ROW="900">
<DEFAULT>Release: 9.5 build at: 20210929</DEFAULT>
</PARAMETER>
</ADVANCED_PARAMETERS>
<CODEGENERATION>
<IMPORTS>
<IMPORT NAME="jlo-talendcomp-tabletransfer" MODULE="jlo-talendcomp-tabletransfer-9.4.jar" MVN="mvn:org.talend.libraries/jlo-talendcomp-tabletransfer-9.4/6.0.0-SNAPSHOT" REQUIRED="true"/>
<IMPORT NAME="jlo-talendcomp-tabletransfer" MODULE="jlo-talendcomp-tabletransfer-9.5.jar" MVN="mvn:org.talend.libraries/jlo-talendcomp-tabletransfer-9.5/6.0.0-SNAPSHOT" REQUIRED="true"/>
<IMPORT NAME="slf4j-api" MODULE="slf4j-api-1.7.30.jar" MVN="mvn:org.talend.libraries/slf4j-api-1.7.30/6.0.0-SNAPSHOT" REQUIRED="true"/>
</IMPORTS>
</CODEGENERATION>
Expand Down

0 comments on commit 8f61fa9

Please sign in to comment.