embulk-output-jdbc 0.2.4 → 0.3.0

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/build.gradle +2 -2
  3. data/classpath/embulk-output-jdbc-0.3.0.jar +0 -0
  4. data/lib/embulk/output/jdbc.rb +3 -3
  5. data/src/main/java/org/embulk/output/JdbcOutputPlugin.java +138 -120
  6. data/src/main/java/org/embulk/output/jdbc/AbstractJdbcOutputPlugin.java +964 -755
  7. data/src/main/java/org/embulk/output/jdbc/BatchInsert.java +54 -54
  8. data/src/main/java/org/embulk/output/jdbc/JdbcColumn.java +59 -23
  9. data/src/main/java/org/embulk/output/jdbc/JdbcColumnOption.java +34 -0
  10. data/src/main/java/org/embulk/output/jdbc/JdbcOutputConnection.java +95 -114
  11. data/src/main/java/org/embulk/output/jdbc/JdbcOutputConnector.java +8 -8
  12. data/src/main/java/org/embulk/output/jdbc/JdbcSchema.java +60 -37
  13. data/src/main/java/org/embulk/output/jdbc/JdbcUtils.java +155 -155
  14. data/src/main/java/org/embulk/output/jdbc/StandardBatchInsert.java +8 -5
  15. data/src/main/java/org/embulk/output/jdbc/setter/BigDecimalColumnSetter.java +70 -0
  16. data/src/main/java/org/embulk/output/jdbc/setter/BooleanColumnSetter.java +54 -52
  17. data/src/main/java/org/embulk/output/jdbc/setter/ByteColumnSetter.java +76 -0
  18. data/src/main/java/org/embulk/output/jdbc/setter/ColumnSetter.java +10 -91
  19. data/src/main/java/org/embulk/output/jdbc/setter/ColumnSetterFactory.java +189 -137
  20. data/src/main/java/org/embulk/output/jdbc/setter/ColumnSetterVisitor.java +96 -0
  21. data/src/main/java/org/embulk/output/jdbc/setter/DefaultValueSetter.java +48 -0
  22. data/src/main/java/org/embulk/output/jdbc/setter/DoubleColumnSetter.java +61 -51
  23. data/src/main/java/org/embulk/output/jdbc/setter/FloatColumnSetter.java +61 -0
  24. data/src/main/java/org/embulk/output/jdbc/setter/IntColumnSetter.java +76 -0
  25. data/src/main/java/org/embulk/output/jdbc/setter/LongColumnSetter.java +72 -62
  26. data/src/main/java/org/embulk/output/jdbc/setter/NStringColumnSetter.java +59 -0
  27. data/src/main/java/org/embulk/output/jdbc/setter/NullColumnSetter.java +53 -43
  28. data/src/main/java/org/embulk/output/jdbc/setter/NullDefaultValueSetter.java +105 -0
  29. data/src/main/java/org/embulk/output/jdbc/setter/PassThroughColumnSetter.java +56 -0
  30. data/src/main/java/org/embulk/output/jdbc/setter/ShortColumnSetter.java +76 -0
  31. data/src/main/java/org/embulk/output/jdbc/setter/SkipColumnSetter.java +43 -38
  32. data/src/main/java/org/embulk/output/jdbc/setter/SqlDateColumnSetter.java +63 -0
  33. data/src/main/java/org/embulk/output/jdbc/setter/SqlTimeColumnSetter.java +55 -0
  34. data/src/main/java/org/embulk/output/jdbc/setter/SqlTimestampColumnSetter.java +55 -48
  35. data/src/main/java/org/embulk/output/jdbc/setter/StringColumnSetter.java +59 -48
  36. data/src/test/java/org/embulk/output/TestJdbcOutputPlugin.java +5 -5
  37. metadata +16 -4
  38. data/classpath/embulk-output-jdbc-0.2.4.jar +0 -0
  39. data/src/main/java/org/embulk/output/jdbc/RetryExecutor.java +0 -105
@@ -0,0 +1,63 @@
1
+ package org.embulk.output.jdbc.setter;
2
+
3
+ import java.io.IOException;
4
+ import java.sql.SQLException;
5
+ import java.sql.Date;
6
+ import org.joda.time.DateTimeZone;
7
+ import org.embulk.spi.time.Timestamp;
8
+ import org.embulk.output.jdbc.JdbcColumn;
9
+ import org.embulk.output.jdbc.BatchInsert;
10
+
11
+ public class SqlDateColumnSetter
12
+ extends ColumnSetter
13
+ {
14
+ private final DateTimeZone timeZone;
15
+
16
+ public SqlDateColumnSetter(BatchInsert batch, JdbcColumn column,
17
+ DefaultValueSetter defaultValue,
18
+ DateTimeZone timeZone)
19
+ {
20
+ super(batch, column, defaultValue);
21
+ this.timeZone = timeZone;
22
+ }
23
+
24
+ @Override
25
+ public void nullValue() throws IOException, SQLException
26
+ {
27
+ defaultValue.setSqlDate();
28
+ }
29
+
30
+ @Override
31
+ public void booleanValue(boolean v) throws IOException, SQLException
32
+ {
33
+ defaultValue.setSqlDate();
34
+ }
35
+
36
+ @Override
37
+ public void longValue(long v) throws IOException, SQLException
38
+ {
39
+ defaultValue.setSqlDate();
40
+ }
41
+
42
+ @Override
43
+ public void doubleValue(double v) throws IOException, SQLException
44
+ {
45
+ defaultValue.setSqlDate();
46
+ }
47
+
48
+ @Override
49
+ public void stringValue(String v) throws IOException, SQLException
50
+ {
51
+ defaultValue.setSqlDate();
52
+ }
53
+
54
+ @Override
55
+ public void timestampValue(Timestamp v) throws IOException, SQLException
56
+ {
57
+ // JavaDoc of java.sql.Time says:
58
+ // >> To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated.
59
+ long normalized = timeZone.convertUTCToLocal(v.toEpochMilli());
60
+ Date d = new Date(normalized);
61
+ batch.setSqlDate(d, getSqlType());
62
+ }
63
+ }
@@ -0,0 +1,55 @@
1
+ package org.embulk.output.jdbc.setter;
2
+
3
+ import java.io.IOException;
4
+ import java.sql.SQLException;
5
+ import java.sql.Time;
6
+ import org.embulk.spi.time.Timestamp;
7
+ import org.embulk.output.jdbc.JdbcColumn;
8
+ import org.embulk.output.jdbc.BatchInsert;
9
+
10
+ public class SqlTimeColumnSetter
11
+ extends ColumnSetter
12
+ {
13
+ public SqlTimeColumnSetter(BatchInsert batch, JdbcColumn column,
14
+ DefaultValueSetter defaultValue)
15
+ {
16
+ super(batch, column, defaultValue);
17
+ }
18
+
19
+ @Override
20
+ public void nullValue() throws IOException, SQLException
21
+ {
22
+ defaultValue.setSqlTime();
23
+ }
24
+
25
+ @Override
26
+ public void booleanValue(boolean v) throws IOException, SQLException
27
+ {
28
+ defaultValue.setSqlTime();
29
+ }
30
+
31
+ @Override
32
+ public void longValue(long v) throws IOException, SQLException
33
+ {
34
+ defaultValue.setSqlTime();
35
+ }
36
+
37
+ @Override
38
+ public void doubleValue(double v) throws IOException, SQLException
39
+ {
40
+ defaultValue.setSqlTime();
41
+ }
42
+
43
+ @Override
44
+ public void stringValue(String v) throws IOException, SQLException
45
+ {
46
+ defaultValue.setSqlTime();
47
+ }
48
+
49
+ @Override
50
+ public void timestampValue(Timestamp v) throws IOException, SQLException
51
+ {
52
+ Time t = new Time(v.toEpochMilli());
53
+ batch.setSqlTime(t, getSqlType());
54
+ }
55
+ }
@@ -1,48 +1,55 @@
1
- package org.embulk.output.jdbc.setter;
2
-
3
- import java.io.IOException;
4
- import java.sql.SQLException;
5
- import java.math.RoundingMode;
6
- import com.google.common.math.DoubleMath;
7
- import org.embulk.spi.PageReader;
8
- import org.embulk.spi.time.Timestamp;
9
- import org.embulk.output.jdbc.JdbcColumn;
10
- import org.embulk.output.jdbc.BatchInsert;
11
-
12
- public class SqlTimestampColumnSetter
13
- extends ColumnSetter
14
- {
15
- public SqlTimestampColumnSetter(BatchInsert batch, PageReader pageReader,
16
- JdbcColumn column)
17
- {
18
- super(batch, pageReader, column);
19
- }
20
-
21
- protected void booleanValue(boolean v) throws IOException, SQLException
22
- {
23
- nullValue();
24
- }
25
-
26
- protected void longValue(long v) throws IOException, SQLException
27
- {
28
- nullValue();
29
- }
30
-
31
- protected void doubleValue(double v) throws IOException, SQLException
32
- {
33
- nullValue();
34
- }
35
-
36
- protected void stringValue(String v) throws IOException, SQLException
37
- {
38
- // TODO parse time?
39
- nullValue();
40
- }
41
-
42
- protected void timestampValue(Timestamp v) throws IOException, SQLException
43
- {
44
- java.sql.Timestamp t = new java.sql.Timestamp(v.toEpochMilli());
45
- t.setNanos(v.getNano());
46
- batch.setSqlTimestamp(t, getSqlType());
47
- }
48
- }
1
+ package org.embulk.output.jdbc.setter;
2
+
3
+ import java.io.IOException;
4
+ import java.sql.SQLException;
5
+ import org.embulk.spi.time.Timestamp;
6
+ import org.embulk.output.jdbc.JdbcColumn;
7
+ import org.embulk.output.jdbc.BatchInsert;
8
+
9
+ public class SqlTimestampColumnSetter
10
+ extends ColumnSetter
11
+ {
12
+ public SqlTimestampColumnSetter(BatchInsert batch, JdbcColumn column,
13
+ DefaultValueSetter defaultValue)
14
+ {
15
+ super(batch, column, defaultValue);
16
+ }
17
+
18
+ @Override
19
+ public void nullValue() throws IOException, SQLException
20
+ {
21
+ defaultValue.setSqlTimestamp();
22
+ }
23
+
24
+ @Override
25
+ public void booleanValue(boolean v) throws IOException, SQLException
26
+ {
27
+ defaultValue.setSqlTimestamp();
28
+ }
29
+
30
+ @Override
31
+ public void longValue(long v) throws IOException, SQLException
32
+ {
33
+ defaultValue.setSqlTimestamp();
34
+ }
35
+
36
+ @Override
37
+ public void doubleValue(double v) throws IOException, SQLException
38
+ {
39
+ defaultValue.setSqlTimestamp();
40
+ }
41
+
42
+ @Override
43
+ public void stringValue(String v) throws IOException, SQLException
44
+ {
45
+ defaultValue.setSqlTimestamp();
46
+ }
47
+
48
+ @Override
49
+ public void timestampValue(Timestamp v) throws IOException, SQLException
50
+ {
51
+ java.sql.Timestamp t = new java.sql.Timestamp(v.toEpochMilli());
52
+ t.setNanos(v.getNano());
53
+ batch.setSqlTimestamp(t, getSqlType());
54
+ }
55
+ }
@@ -1,48 +1,59 @@
1
- package org.embulk.output.jdbc.setter;
2
-
3
- import java.io.IOException;
4
- import java.sql.SQLException;
5
- import org.embulk.spi.ColumnVisitor;
6
- import org.embulk.spi.PageReader;
7
- import org.embulk.spi.time.Timestamp;
8
- import org.embulk.spi.time.TimestampFormatter;
9
- import org.embulk.output.jdbc.JdbcColumn;
10
- import org.embulk.output.jdbc.BatchInsert;
11
-
12
- public class StringColumnSetter
13
- extends ColumnSetter
14
- {
15
- private final TimestampFormatter timestampFormatter;
16
-
17
- public StringColumnSetter(BatchInsert batch, PageReader pageReader,
18
- JdbcColumn column, TimestampFormatter timestampFormatter)
19
- {
20
- super(batch, pageReader, column);
21
- this.timestampFormatter = timestampFormatter;
22
- }
23
-
24
- protected void booleanValue(boolean v) throws IOException, SQLException
25
- {
26
- batch.setString(Boolean.toString(v));
27
- }
28
-
29
- protected void longValue(long v) throws IOException, SQLException
30
- {
31
- batch.setString(Long.toString(v));
32
- }
33
-
34
- protected void doubleValue(double v) throws IOException, SQLException
35
- {
36
- batch.setString(Double.toString(v));
37
- }
38
-
39
- protected void stringValue(String v) throws IOException, SQLException
40
- {
41
- batch.setString(v);
42
- }
43
-
44
- protected void timestampValue(Timestamp v) throws IOException, SQLException
45
- {
46
- batch.setString(timestampFormatter.format(v));
47
- }
48
- }
1
+ package org.embulk.output.jdbc.setter;
2
+
3
+ import java.io.IOException;
4
+ import java.sql.SQLException;
5
+ import org.embulk.spi.ColumnVisitor;
6
+ import org.embulk.spi.time.Timestamp;
7
+ import org.embulk.spi.time.TimestampFormatter;
8
+ import org.embulk.output.jdbc.JdbcColumn;
9
+ import org.embulk.output.jdbc.BatchInsert;
10
+
11
+ public class StringColumnSetter
12
+ extends ColumnSetter
13
+ {
14
+ private final TimestampFormatter timestampFormatter;
15
+
16
+ public StringColumnSetter(BatchInsert batch, JdbcColumn column,
17
+ DefaultValueSetter defaultValue,
18
+ TimestampFormatter timestampFormatter)
19
+ {
20
+ super(batch, column, defaultValue);
21
+ this.timestampFormatter = timestampFormatter;
22
+ }
23
+
24
+ @Override
25
+ public void nullValue() throws IOException, SQLException
26
+ {
27
+ defaultValue.setString();
28
+ }
29
+
30
+ @Override
31
+ public void booleanValue(boolean v) throws IOException, SQLException
32
+ {
33
+ batch.setString(Boolean.toString(v));
34
+ }
35
+
36
+ @Override
37
+ public void longValue(long v) throws IOException, SQLException
38
+ {
39
+ batch.setString(Long.toString(v));
40
+ }
41
+
42
+ @Override
43
+ public void doubleValue(double v) throws IOException, SQLException
44
+ {
45
+ batch.setString(Double.toString(v));
46
+ }
47
+
48
+ @Override
49
+ public void stringValue(String v) throws IOException, SQLException
50
+ {
51
+ batch.setString(v);
52
+ }
53
+
54
+ @Override
55
+ public void timestampValue(Timestamp v) throws IOException, SQLException
56
+ {
57
+ batch.setString(timestampFormatter.format(v));
58
+ }
59
+ }
@@ -1,5 +1,5 @@
1
- package org.embulk.output;
2
-
3
- public class TestJdbcOutputPlugin
4
- {
5
- }
1
+ package org.embulk.output;
2
+
3
+ public class TestJdbcOutputPlugin
4
+ {
5
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-output-jdbc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
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-05-12 00:00:00.000000000 Z
11
+ date: 2015-05-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Inserts or updates records to a table.
14
14
  email:
@@ -23,23 +23,35 @@ files:
23
23
  - src/main/java/org/embulk/output/jdbc/AbstractJdbcOutputPlugin.java
24
24
  - src/main/java/org/embulk/output/jdbc/BatchInsert.java
25
25
  - src/main/java/org/embulk/output/jdbc/JdbcColumn.java
26
+ - src/main/java/org/embulk/output/jdbc/JdbcColumnOption.java
26
27
  - src/main/java/org/embulk/output/jdbc/JdbcOutputConnection.java
27
28
  - src/main/java/org/embulk/output/jdbc/JdbcOutputConnector.java
28
29
  - src/main/java/org/embulk/output/jdbc/JdbcSchema.java
29
30
  - src/main/java/org/embulk/output/jdbc/JdbcUtils.java
30
- - src/main/java/org/embulk/output/jdbc/RetryExecutor.java
31
31
  - src/main/java/org/embulk/output/jdbc/StandardBatchInsert.java
32
+ - src/main/java/org/embulk/output/jdbc/setter/BigDecimalColumnSetter.java
32
33
  - src/main/java/org/embulk/output/jdbc/setter/BooleanColumnSetter.java
34
+ - src/main/java/org/embulk/output/jdbc/setter/ByteColumnSetter.java
33
35
  - src/main/java/org/embulk/output/jdbc/setter/ColumnSetter.java
34
36
  - src/main/java/org/embulk/output/jdbc/setter/ColumnSetterFactory.java
37
+ - src/main/java/org/embulk/output/jdbc/setter/ColumnSetterVisitor.java
38
+ - src/main/java/org/embulk/output/jdbc/setter/DefaultValueSetter.java
35
39
  - src/main/java/org/embulk/output/jdbc/setter/DoubleColumnSetter.java
40
+ - src/main/java/org/embulk/output/jdbc/setter/FloatColumnSetter.java
41
+ - src/main/java/org/embulk/output/jdbc/setter/IntColumnSetter.java
36
42
  - src/main/java/org/embulk/output/jdbc/setter/LongColumnSetter.java
43
+ - src/main/java/org/embulk/output/jdbc/setter/NStringColumnSetter.java
37
44
  - src/main/java/org/embulk/output/jdbc/setter/NullColumnSetter.java
45
+ - src/main/java/org/embulk/output/jdbc/setter/NullDefaultValueSetter.java
46
+ - src/main/java/org/embulk/output/jdbc/setter/PassThroughColumnSetter.java
47
+ - src/main/java/org/embulk/output/jdbc/setter/ShortColumnSetter.java
38
48
  - src/main/java/org/embulk/output/jdbc/setter/SkipColumnSetter.java
49
+ - src/main/java/org/embulk/output/jdbc/setter/SqlDateColumnSetter.java
50
+ - src/main/java/org/embulk/output/jdbc/setter/SqlTimeColumnSetter.java
39
51
  - src/main/java/org/embulk/output/jdbc/setter/SqlTimestampColumnSetter.java
40
52
  - src/main/java/org/embulk/output/jdbc/setter/StringColumnSetter.java
41
53
  - src/test/java/org/embulk/output/TestJdbcOutputPlugin.java
42
- - classpath/embulk-output-jdbc-0.2.4.jar
54
+ - classpath/embulk-output-jdbc-0.3.0.jar
43
55
  homepage: https://github.com/embulk/embulk-output-jdbc
44
56
  licenses:
45
57
  - Apache 2.0
@@ -1,105 +0,0 @@
1
- package org.embulk.output.jdbc;
2
-
3
- import java.util.concurrent.Callable;
4
- import java.util.concurrent.ExecutionException;
5
-
6
- public class RetryExecutor
7
- {
8
- public static RetryExecutor retryExecutor()
9
- {
10
- return new RetryExecutor();
11
- }
12
-
13
- public static abstract class IdempotentOperation<T> implements Callable<T>
14
- {
15
- public abstract T call() throws Exception;
16
-
17
- public void onRetry(Throwable exception, int retryCount, int retryLimit, int retryWait)
18
- { }
19
-
20
- public void onGiveup(Throwable firstException, Throwable lastException)
21
- { }
22
-
23
- public abstract boolean isRetryableException(Throwable exception);
24
- }
25
-
26
- private int retryLimit = 3;
27
- private int initialRetryWait = 500;
28
- private int maxRetryWait = 30*60*1000;
29
-
30
- private RetryExecutor()
31
- { }
32
-
33
- public RetryExecutor setRetryLimit(int count)
34
- {
35
- this.retryLimit = count;
36
- return this;
37
- }
38
-
39
- public RetryExecutor setInitialRetryWait(int msec)
40
- {
41
- this.initialRetryWait = msec;
42
- return this;
43
- }
44
-
45
- public RetryExecutor setMaxRetryWait(int msec)
46
- {
47
- this.maxRetryWait = msec;
48
- return this;
49
- }
50
-
51
- public <T> T runInterruptible(IdempotentOperation<T> op) throws InterruptedException, ExecutionException
52
- {
53
- return run(op, true);
54
- }
55
-
56
- public <T> T run(IdempotentOperation<T> op) throws ExecutionException
57
- {
58
- try {
59
- return run(op, false);
60
- } catch (InterruptedException ex) {
61
- throw new ExecutionException("Unexpected interruption", ex);
62
- }
63
- }
64
-
65
- private <T> T run(IdempotentOperation<T> op, boolean interruptible)
66
- throws InterruptedException, ExecutionException
67
- {
68
- int retryWait = initialRetryWait;
69
- int retryCount = 0;
70
-
71
- Throwable firstException = null;
72
-
73
- while(true) {
74
- try {
75
- return op.call();
76
- } catch (Throwable exception) {
77
- if (firstException == null) {
78
- firstException = exception;
79
- }
80
- if (!op.isRetryableException(exception) || retryCount >= retryLimit) {
81
- op.onGiveup(firstException, exception);
82
- throw new ExecutionException(firstException);
83
- }
84
-
85
- retryCount++;
86
- op.onRetry(exception, retryCount, retryLimit, retryWait);
87
-
88
- try {
89
- Thread.sleep(retryWait);
90
- } catch (InterruptedException ex) {
91
- if (interruptible) {
92
- throw ex;
93
- }
94
- }
95
-
96
- retryWait *= 2; // exponential back-off
97
-
98
- if (retryWait > maxRetryWait) {
99
- retryWait = maxRetryWait;
100
- }
101
- }
102
- }
103
- }
104
- }
105
-