embulk-output-mysql 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6b67a848e2202ebc31901130301005107ca6897
4
- data.tar.gz: f7cb4f67515ea512dbb6135da0ad2a89c498500f
3
+ metadata.gz: c26cb004402026d14a78720765e9c43fbf51837b
4
+ data.tar.gz: 971f0061e593d174aa77b55bc2a9526b7baeb754
5
5
  SHA512:
6
- metadata.gz: 963d894c295cbe6c0d242784dfbac06b062a6c1611b487adc8020c69ccce26f7d296060dff11acee1ed1db3c84f7c8d0c4dd74fae9e92945999c65f26b6afd42
7
- data.tar.gz: ada63428a1351d41140ace617b9fe7a37317e1e696b50104bedc4bd00c0e03f7b1d9c8cee29c07fa8d2a248adfd1f6d2c373aa091a20494a034f04c917fc6dc4
6
+ metadata.gz: 5e360066024cc173d4237fc9469acba6dd6feaa5d54f6e5f2faf868e688b180ff8e345bc9136cfd34497de0840085efa8fe4f27916c032f5b1b07cc624d90adb
7
+ data.tar.gz: 3fb0cc71310ce53577b20aafe9d18e07d23f38072e9110da53d67afe4cd22d836190a8231cac54150420387d99d109e5ad2589c86570a927c915752c1453d2ad
@@ -3,14 +3,12 @@ package org.embulk.output;
3
3
  import java.util.Properties;
4
4
  import java.io.IOException;
5
5
  import java.sql.SQLException;
6
- import java.sql.Connection;
7
- import org.embulk.spi.Exec;
6
+
7
+ import org.embulk.output.mysql.MySQLBatchUpsert;
8
8
  import org.embulk.config.Config;
9
9
  import org.embulk.config.ConfigDefault;
10
10
  import org.embulk.output.jdbc.AbstractJdbcOutputPlugin;
11
- import org.embulk.output.jdbc.JdbcOutputConnection;
12
11
  import org.embulk.output.jdbc.BatchInsert;
13
- import org.embulk.output.jdbc.JdbcOutputConnector;
14
12
  import org.embulk.output.mysql.MySQLOutputConnector;
15
13
  import org.embulk.output.mysql.MySQLBatchInsert;
16
14
 
@@ -96,6 +94,7 @@ public class MySQLOutputPlugin
96
94
  @Override
97
95
  protected BatchInsert newBatchInsert(PluginTask task) throws IOException, SQLException
98
96
  {
99
- return new MySQLBatchInsert(getConnector(task, true));
97
+ MySQLOutputConnector connector = getConnector(task, true);
98
+ return task.getMode().isMerge() ? new MySQLBatchUpsert(connector) : new MySQLBatchInsert(connector);
100
99
  }
101
100
  }
@@ -0,0 +1,22 @@
1
+ package org.embulk.output.mysql;
2
+
3
+ import org.embulk.output.jdbc.JdbcOutputConnection;
4
+ import org.embulk.output.jdbc.JdbcSchema;
5
+ import java.io.IOException;
6
+ import java.sql.PreparedStatement;
7
+ import java.sql.SQLException;
8
+
9
+ public class MySQLBatchUpsert extends MySQLBatchInsert {
10
+
11
+ public MySQLBatchUpsert(MySQLOutputConnector connector) throws IOException, SQLException {
12
+ super(connector);
13
+ }
14
+
15
+ @Override
16
+ protected PreparedStatement newPreparedStatement(JdbcOutputConnection connection,
17
+ String loadTable, JdbcSchema insertSchema) throws SQLException
18
+ {
19
+ return connection.prepareUpsertSql(loadTable, insertSchema);
20
+ }
21
+
22
+ }
@@ -2,10 +2,9 @@ package org.embulk.output.mysql;
2
2
 
3
3
  import java.sql.Connection;
4
4
  import java.sql.SQLException;
5
- import org.embulk.spi.Exec;
6
- import org.embulk.output.jdbc.BatchInsert;
5
+
6
+ import org.embulk.output.jdbc.JdbcSchema;
7
7
  import org.embulk.output.jdbc.JdbcOutputConnection;
8
- import org.embulk.output.jdbc.JdbcColumn;
9
8
 
10
9
  public class MySQLOutputConnection
11
10
  extends JdbcOutputConnection
@@ -17,6 +16,36 @@ public class MySQLOutputConnection
17
16
  connection.setAutoCommit(autoCommit);
18
17
  }
19
18
 
19
+ @Override
20
+ protected String buildPrepareUpsertSql(String toTable, JdbcSchema toTableSchema) throws SQLException
21
+ {
22
+ StringBuilder sb = new StringBuilder();
23
+
24
+ sb.append("INSERT INTO ");
25
+ quoteIdentifierString(sb, toTable);
26
+
27
+ sb.append(" (");
28
+ for (int i=0; i < toTableSchema.getCount(); i++) {
29
+ if(i != 0) { sb.append(", "); }
30
+ quoteIdentifierString(sb, toTableSchema.getColumnName(i));
31
+ }
32
+ sb.append(") VALUES (");
33
+ for(int i=0; i < toTableSchema.getCount(); i++) {
34
+ if(i != 0) { sb.append(", "); }
35
+ sb.append("?");
36
+ }
37
+ sb.append(")");
38
+
39
+ sb.append(" ON DUPLICATE KEY UPDATE ");
40
+ for (int i=0; i < toTableSchema.getCount(); i++) {
41
+ if(i != 0) { sb.append(", "); }
42
+ final String columnName = quoteIdentifierString(toTableSchema.getColumnName(i));
43
+ sb.append(columnName).append(" = VALUES(").append(columnName).append(")");
44
+ }
45
+
46
+ return sb.toString();
47
+ }
48
+
20
49
  @Override
21
50
  protected String convertTypeName(String typeName)
22
51
  {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-output-mysql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-07 00:00:00.000000000 Z
11
+ date: 2015-04-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Inserts or updates records to a table.
14
14
  email:
@@ -22,10 +22,11 @@ files:
22
22
  - lib/embulk/output/mysql.rb
23
23
  - src/main/java/org/embulk/output/MySQLOutputPlugin.java
24
24
  - src/main/java/org/embulk/output/mysql/MySQLBatchInsert.java
25
+ - src/main/java/org/embulk/output/mysql/MySQLBatchUpsert.java
25
26
  - src/main/java/org/embulk/output/mysql/MySQLOutputConnection.java
26
27
  - src/main/java/org/embulk/output/mysql/MySQLOutputConnector.java
27
- - classpath/embulk-output-jdbc-0.2.2.jar
28
- - classpath/embulk-output-mysql-0.2.2.jar
28
+ - classpath/embulk-output-jdbc-0.2.3.jar
29
+ - classpath/embulk-output-mysql-0.2.3.jar
29
30
  - classpath/mysql-connector-java-5.1.34.jar
30
31
  homepage: https://github.com/embulk/embulk-output-jdbc
31
32
  licenses: