src/main/java/org/embulk/output/jdbc/JdbcOutputConnection.java in embulk-output-jdbc-0.2.2 vs src/main/java/org/embulk/output/jdbc/JdbcOutputConnection.java in embulk-output-jdbc-0.2.3

- old
+ new

@@ -1,8 +1,7 @@ package org.embulk.output.jdbc; -import java.util.List; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -64,11 +63,11 @@ { try (ResultSet rs = connection.getMetaData().getTables(null, schemaName, tableName, null)) { return rs.next(); } } - + public void dropTableIfExists(String tableName) throws SQLException { Statement stmt = connection.createStatement(); try { dropTableIfExists(stmt, tableName); @@ -150,11 +149,11 @@ sb.append("CREATE TABLE "); quoteIdentifierString(sb, name); sb.append(buildColumnsOfCreateTableSql(schema)); return sb.toString(); } - + private String buildColumnsOfCreateTableSql(JdbcSchema schema) { StringBuilder sb = new StringBuilder(); sb.append(" ("); @@ -304,10 +303,17 @@ String insertSql = buildPrepareInsertSql(toTable, toTableSchema); logger.info("Prepared SQL: {}", insertSql); return connection.prepareStatement(insertSql); } + public PreparedStatement prepareUpsertSql(String toTable, JdbcSchema toTableSchema) throws SQLException + { + String upsertSql = buildPrepareUpsertSql(toTable, toTableSchema); + logger.info("Prepared SQL: {}", upsertSql); + return connection.prepareStatement(upsertSql); + } + protected String buildPrepareInsertSql(String toTable, JdbcSchema toTableSchema) throws SQLException { StringBuilder sb = new StringBuilder(); sb.append("INSERT INTO "); @@ -324,9 +330,14 @@ sb.append("?"); } sb.append(")"); return sb.toString(); + } + + protected String buildPrepareUpsertSql(String toTable, JdbcSchema toTableSchema) throws SQLException + { + throw new UnsupportedOperationException("not implemented yet"); } // TODO //protected void gatherInsertTables(List<String> fromTables, JdbcSchema fromTableSchema, String toTable, // boolean truncateDestinationFirst) throws SQLException