You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by mi...@apache.org on 2020/06/08 10:33:48 UTC

[incubator-streampipes-extensions] branch feature/jdbc_rewrite updated (e96f541 -> 0142fbf)

This is an automated email from the ASF dual-hosted git repository.

micklich pushed a change to branch feature/jdbc_rewrite
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes-extensions.git.


    from e96f541  added new resources
     new ad660a8  fix tableExists and added overwrite generatePreparedStatement
     new 2ed4ced  change PG double to numeric type
     new 930e9d0  add schema to generatePreparedStatement
     new 0142fbf  fixed wrong checkTable statement

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../databases/jvm/jdbcclient/SqlAttribute.java     |  2 +-
 .../jvm/postgresql/PostgresJdbcClient.java         | 57 ++++++++--------------
 2 files changed, 22 insertions(+), 37 deletions(-)


[incubator-streampipes-extensions] 02/04: change PG double to numeric type

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

micklich pushed a commit to branch feature/jdbc_rewrite
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes-extensions.git

commit 2ed4ced76ba11b6b50918526236b7b0fef801ddd
Author: micklich <fl...@disy.net>
AuthorDate: Sun Jun 7 16:27:12 2020 +0200

    change PG double to numeric type
---
 .../apache/streampipes/sinks/databases/jvm/jdbcclient/SqlAttribute.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/streampipes-sinks-databases-jvm/src/main/java/org/apache/streampipes/sinks/databases/jvm/jdbcclient/SqlAttribute.java b/streampipes-sinks-databases-jvm/src/main/java/org/apache/streampipes/sinks/databases/jvm/jdbcclient/SqlAttribute.java
index 6d62146..4e8c3b9 100644
--- a/streampipes-sinks-databases-jvm/src/main/java/org/apache/streampipes/sinks/databases/jvm/jdbcclient/SqlAttribute.java
+++ b/streampipes-sinks-databases-jvm/src/main/java/org/apache/streampipes/sinks/databases/jvm/jdbcclient/SqlAttribute.java
@@ -40,7 +40,7 @@ public enum SqlAttribute {
   //MYSQL
   MYSQL_DATETIME("DATETIME"),
   //POSTGRES / POSTGIS
-  PG_DOUBLE("DOUBLE PRECISION");
+  PG_DOUBLE("NUMERIC");
   private final String sqlName;
 
   SqlAttribute(String s) {


[incubator-streampipes-extensions] 04/04: fixed wrong checkTable statement

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

micklich pushed a commit to branch feature/jdbc_rewrite
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes-extensions.git

commit 0142fbf31aeeb68817f7eca2c34e4c6ef6ed20cf
Author: micklich <fl...@disy.net>
AuthorDate: Mon Jun 8 12:33:33 2020 +0200

    fixed wrong checkTable statement
---
 .../sinks/databases/jvm/postgresql/PostgresJdbcClient.java            | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/streampipes-sinks-databases-jvm/src/main/java/org/apache/streampipes/sinks/databases/jvm/postgresql/PostgresJdbcClient.java b/streampipes-sinks-databases-jvm/src/main/java/org/apache/streampipes/sinks/databases/jvm/postgresql/PostgresJdbcClient.java
index 6bc0c96..fcbcbe7 100644
--- a/streampipes-sinks-databases-jvm/src/main/java/org/apache/streampipes/sinks/databases/jvm/postgresql/PostgresJdbcClient.java
+++ b/streampipes-sinks-databases-jvm/src/main/java/org/apache/streampipes/sinks/databases/jvm/postgresql/PostgresJdbcClient.java
@@ -126,7 +126,7 @@ public class PostgresJdbcClient extends JdbcClient {
       // Database should exist by now so we can establish a connection
       c = DriverManager.getConnection(url + databaseName, user, password);
       st = c.createStatement();
-      ResultSet rs = c.getMetaData().getTables(null, null, schemaName, null);
+      ResultSet rs = c.getMetaData().getTables(null, null, tableName, null);
       while (rs.next()) {
         // same table names can exists in different schmemas
         if (rs.getString("TABLE_SCHEM").toLowerCase().equals(schemaName.toLowerCase())) {
@@ -138,7 +138,7 @@ public class PostgresJdbcClient extends JdbcClient {
           createTable();
         }
       }
-      super.tableExists = true;
+      tableExists = true;
       rs.close();
     } catch (SQLException e) {
       closeAll();


[incubator-streampipes-extensions] 01/04: fix tableExists and added overwrite generatePreparedStatement

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

micklich pushed a commit to branch feature/jdbc_rewrite
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes-extensions.git

commit ad660a83bb644477051b5b3a1cc235673ee0c3ad
Author: micklich <fl...@disy.net>
AuthorDate: Sun Jun 7 16:26:41 2020 +0200

    fix tableExists and added overwrite generatePreparedStatement
---
 .../jvm/postgresql/PostgresJdbcClient.java         | 59 ++++++++--------------
 1 file changed, 21 insertions(+), 38 deletions(-)

diff --git a/streampipes-sinks-databases-jvm/src/main/java/org/apache/streampipes/sinks/databases/jvm/postgresql/PostgresJdbcClient.java b/streampipes-sinks-databases-jvm/src/main/java/org/apache/streampipes/sinks/databases/jvm/postgresql/PostgresJdbcClient.java
index d45462b..9e0cd42 100644
--- a/streampipes-sinks-databases-jvm/src/main/java/org/apache/streampipes/sinks/databases/jvm/postgresql/PostgresJdbcClient.java
+++ b/streampipes-sinks-databases-jvm/src/main/java/org/apache/streampipes/sinks/databases/jvm/postgresql/PostgresJdbcClient.java
@@ -126,7 +126,7 @@ public class PostgresJdbcClient extends JdbcClient {
       // Database should exist by now so we can establish a connection
       c = DriverManager.getConnection(url + databaseName, user, password);
       st = c.createStatement();
-      ResultSet rs = c.getMetaData().getTables(null, null, tableName, null);
+      ResultSet rs = c.getMetaData().getTables(null, null, schemaName, null);
       while (rs.next()) {
         // same table names can exists in different schmemas
         if (rs.getString("TABLE_SCHEM").toLowerCase().equals(schemaName.toLowerCase())) {
@@ -138,7 +138,7 @@ public class PostgresJdbcClient extends JdbcClient {
           createTable();
         }
       }
-      tableExists = true;
+      super.tableExists = true;
       rs.close();
     } catch (SQLException e) {
       closeAll();
@@ -147,7 +147,6 @@ public class PostgresJdbcClient extends JdbcClient {
   }
 
 
-
   /**
    * Prepares a statement for the insertion of values or the
    *
@@ -252,42 +251,26 @@ public class PostgresJdbcClient extends JdbcClient {
     }
   }
 
+  @Override
+  protected void generatePreparedStatement(final Map<String, Object> event)
+      throws SQLException, SpRuntimeException {
+    // input: event
+    // wanted: INSERT INTO test4321 ( randomString, randomValue ) VALUES ( ?,? );
+    checkConnected();
+    parameters.clear();
+    StringBuilder statement1 = new StringBuilder("INSERT INTO ");
+    StringBuilder statement2 = new StringBuilder("VALUES ( ");
+    checkRegEx(tableName, "Tablename");
+    statement1.append(tableName).append(" ( ");
+
+    // Starts index at 1, since the parameterIndex in the PreparedStatement starts at 1 as well
+    extendPreparedStatement(event, statement1, statement2, 1);
 
-//  protected StringBuilder extractEventProperties(List<EventProperty> properties, String preProperty)
-//      throws SpRuntimeException {
-//    // output: "randomString VARCHAR(255), randomValue INT"
-//    StringBuilder s = new StringBuilder();
-//    String pre = "";
-//    for (EventProperty property : properties) {
-//      // Protection against SqlInjection
-//
-//      checkRegEx(property.getRuntimeName(), "Column name");
-//      if (property instanceof EventPropertyNested) {
-//        // if it is a nested property, recursively extract the needed properties
-//        StringBuilder tmp = extractEventProperties(((EventPropertyNested) property).getEventProperties(),
-//            preProperty + property.getRuntimeName() + "_");
-//        if (tmp.length() > 0) {
-//          s.append(pre).append(tmp);
-//        }
-//      } else {
-//        // Adding the name of the property (e.g. "randomString")
-//        // Or for properties in a nested structure: input1_randomValue
-//        // "pre" is there for the ", " part
-//        s.append(pre).append("\"").append(preProperty).append(property.getRuntimeName()).append("\" ");
-//
-//        // adding the type of the property (e.g. "VARCHAR(255)")
-//        if (property instanceof EventPropertyPrimitive) {
-//          s.append(SqlAttribute.getFromUri(((EventPropertyPrimitive) property).getRuntimeType()));
-//        } else {
-//          // Must be an EventPropertyList then
-//          s.append(SqlAttribute.getFromUri(XSD._string.toString()));
-//        }
-//      }
-//      pre = ", ";
-//    }
-//
-//    return s;
-//  }
+    statement1.append(" ) ");
+    statement2.append(" );");
+    String finalStatement = statement1.append(statement2).toString();
+    ps = c.prepareStatement(finalStatement);
+  }
 
   @Override
   protected StringBuilder extractEventProperties(List<EventProperty> properties, String preProperty)


[incubator-streampipes-extensions] 03/04: add schema to generatePreparedStatement

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

micklich pushed a commit to branch feature/jdbc_rewrite
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes-extensions.git

commit 930e9d0a6a53e5c236d21f1bb2ba7276ccb07884
Author: micklich <fl...@disy.net>
AuthorDate: Sun Jun 7 17:05:59 2020 +0200

    add schema to generatePreparedStatement
---
 .../streampipes/sinks/databases/jvm/postgresql/PostgresJdbcClient.java  | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/streampipes-sinks-databases-jvm/src/main/java/org/apache/streampipes/sinks/databases/jvm/postgresql/PostgresJdbcClient.java b/streampipes-sinks-databases-jvm/src/main/java/org/apache/streampipes/sinks/databases/jvm/postgresql/PostgresJdbcClient.java
index 9e0cd42..6bc0c96 100644
--- a/streampipes-sinks-databases-jvm/src/main/java/org/apache/streampipes/sinks/databases/jvm/postgresql/PostgresJdbcClient.java
+++ b/streampipes-sinks-databases-jvm/src/main/java/org/apache/streampipes/sinks/databases/jvm/postgresql/PostgresJdbcClient.java
@@ -261,6 +261,8 @@ public class PostgresJdbcClient extends JdbcClient {
     StringBuilder statement1 = new StringBuilder("INSERT INTO ");
     StringBuilder statement2 = new StringBuilder("VALUES ( ");
     checkRegEx(tableName, "Tablename");
+    checkRegEx(schemaName, "Tablename");
+    statement1.append(schemaName).append(".");
     statement1.append(tableName).append(" ( ");
 
     // Starts index at 1, since the parameterIndex in the PreparedStatement starts at 1 as well