embulk-output-jdbc 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
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,96 @@
1
+ package org.embulk.output.jdbc.setter;
2
+
3
+ import java.io.IOException;
4
+ import java.sql.SQLException;
5
+ import org.embulk.spi.Column;
6
+ import org.embulk.spi.ColumnVisitor;
7
+ import org.embulk.spi.PageReader;
8
+ import org.embulk.spi.time.Timestamp;
9
+
10
+ public class ColumnSetterVisitor
11
+ implements ColumnVisitor
12
+ {
13
+ private final PageReader pageReader;
14
+ private final ColumnSetter setter;
15
+
16
+ public ColumnSetterVisitor(PageReader pageReader, ColumnSetter setter)
17
+ {
18
+ this.pageReader = pageReader;
19
+ this.setter = setter;
20
+ }
21
+
22
+ @Override
23
+ public void booleanColumn(Column column)
24
+ {
25
+ try {
26
+ if (pageReader.isNull(column)) {
27
+ setter.nullValue();
28
+ } else {
29
+ setter.booleanValue(pageReader.getBoolean(column));
30
+ }
31
+ } catch (IOException | SQLException ex) {
32
+ // TODO exception class
33
+ throw new RuntimeException(ex);
34
+ }
35
+ }
36
+
37
+ @Override
38
+ public void longColumn(Column column)
39
+ {
40
+ try {
41
+ if (pageReader.isNull(column)) {
42
+ setter.nullValue();
43
+ } else {
44
+ setter.longValue(pageReader.getLong(column));
45
+ }
46
+ } catch (IOException | SQLException ex) {
47
+ // TODO exception class
48
+ throw new RuntimeException(ex);
49
+ }
50
+ }
51
+
52
+ @Override
53
+ public void doubleColumn(Column column)
54
+ {
55
+ try {
56
+ if (pageReader.isNull(column)) {
57
+ setter.nullValue();
58
+ } else {
59
+ setter.doubleValue(pageReader.getDouble(column));
60
+ }
61
+ } catch (IOException | SQLException ex) {
62
+ // TODO exception class
63
+ throw new RuntimeException(ex);
64
+ }
65
+ }
66
+
67
+ @Override
68
+ public void stringColumn(Column column)
69
+ {
70
+ try {
71
+ if (pageReader.isNull(column)) {
72
+ setter.nullValue();
73
+ } else {
74
+ setter.stringValue(pageReader.getString(column));
75
+ }
76
+ } catch (IOException | SQLException ex) {
77
+ // TODO exception class
78
+ throw new RuntimeException(ex);
79
+ }
80
+ }
81
+
82
+ @Override
83
+ public void timestampColumn(Column column)
84
+ {
85
+ try {
86
+ if (pageReader.isNull(column)) {
87
+ setter.nullValue();
88
+ } else {
89
+ setter.timestampValue(pageReader.getTimestamp(column));
90
+ }
91
+ } catch (IOException | SQLException ex) {
92
+ // TODO exception class
93
+ throw new RuntimeException(ex);
94
+ }
95
+ }
96
+ }
@@ -0,0 +1,48 @@
1
+ package org.embulk.output.jdbc.setter;
2
+
3
+ import java.io.IOException;
4
+ import java.sql.SQLException;
5
+ import org.embulk.output.jdbc.JdbcColumn;
6
+ import org.embulk.output.jdbc.BatchInsert;
7
+
8
+ public abstract class DefaultValueSetter
9
+ {
10
+ protected final BatchInsert batch;
11
+ protected final JdbcColumn column;
12
+
13
+ public DefaultValueSetter(BatchInsert batch, JdbcColumn column)
14
+ {
15
+ this.batch = batch;
16
+ this.column = column;
17
+ }
18
+
19
+ public abstract void setNull() throws IOException, SQLException;
20
+
21
+ public abstract void setBoolean() throws IOException, SQLException;
22
+
23
+ public abstract void setByte() throws IOException, SQLException;
24
+
25
+ public abstract void setShort() throws IOException, SQLException;
26
+
27
+ public abstract void setInt() throws IOException, SQLException;
28
+
29
+ public abstract void setLong() throws IOException, SQLException;
30
+
31
+ public abstract void setFloat() throws IOException, SQLException;
32
+
33
+ public abstract void setDouble() throws IOException, SQLException;
34
+
35
+ public abstract void setBigDecimal() throws IOException, SQLException;
36
+
37
+ public abstract void setString() throws IOException, SQLException;
38
+
39
+ public abstract void setNString() throws IOException, SQLException;
40
+
41
+ public abstract void setBytes() throws IOException, SQLException;
42
+
43
+ public abstract void setSqlDate() throws IOException, SQLException;
44
+
45
+ public abstract void setSqlTime() throws IOException, SQLException;
46
+
47
+ public abstract void setSqlTimestamp() throws IOException, SQLException;
48
+ }
@@ -1,51 +1,61 @@
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.output.jdbc.JdbcColumn;
9
- import org.embulk.output.jdbc.BatchInsert;
10
-
11
- public class DoubleColumnSetter
12
- extends ColumnSetter
13
- {
14
- public DoubleColumnSetter(BatchInsert batch, PageReader pageReader,
15
- JdbcColumn column)
16
- {
17
- super(batch, pageReader, column);
18
- }
19
-
20
- protected void booleanValue(boolean v) throws IOException, SQLException
21
- {
22
- batch.setDouble(v ? 1.0 : 0.0);
23
- }
24
-
25
- protected void longValue(long v) throws IOException, SQLException
26
- {
27
- batch.setDouble((double) v);
28
- }
29
-
30
- protected void doubleValue(double v) throws IOException, SQLException
31
- {
32
- batch.setDouble(v);
33
- }
34
-
35
- protected void stringValue(String v) throws IOException, SQLException
36
- {
37
- double dv;
38
- try {
39
- dv = Double.parseDouble(v);
40
- } catch (NumberFormatException e) {
41
- nullValue();
42
- return;
43
- }
44
- batch.setDouble(dv);
45
- }
46
-
47
- protected void timestampValue(Timestamp v) throws IOException, SQLException
48
- {
49
- nullValue();
50
- }
51
- }
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.output.jdbc.JdbcColumn;
8
+ import org.embulk.output.jdbc.BatchInsert;
9
+
10
+ public class DoubleColumnSetter
11
+ extends ColumnSetter
12
+ {
13
+ public DoubleColumnSetter(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.setDouble();
23
+ }
24
+
25
+ @Override
26
+ public void booleanValue(boolean v) throws IOException, SQLException
27
+ {
28
+ batch.setDouble(v ? 1.0 : 0.0);
29
+ }
30
+
31
+ @Override
32
+ public void longValue(long v) throws IOException, SQLException
33
+ {
34
+ batch.setDouble((double) v);
35
+ }
36
+
37
+ @Override
38
+ public void doubleValue(double v) throws IOException, SQLException
39
+ {
40
+ batch.setDouble(v);
41
+ }
42
+
43
+ @Override
44
+ public void stringValue(String v) throws IOException, SQLException
45
+ {
46
+ double dv;
47
+ try {
48
+ dv = Double.parseDouble(v);
49
+ } catch (NumberFormatException e) {
50
+ defaultValue.setDouble();
51
+ return;
52
+ }
53
+ batch.setDouble(dv);
54
+ }
55
+
56
+ @Override
57
+ public void timestampValue(Timestamp v) throws IOException, SQLException
58
+ {
59
+ defaultValue.setDouble();
60
+ }
61
+ }
@@ -0,0 +1,61 @@
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.output.jdbc.JdbcColumn;
8
+ import org.embulk.output.jdbc.BatchInsert;
9
+
10
+ public class FloatColumnSetter
11
+ extends ColumnSetter
12
+ {
13
+ public FloatColumnSetter(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.setFloat();
23
+ }
24
+
25
+ @Override
26
+ public void booleanValue(boolean v) throws IOException, SQLException
27
+ {
28
+ batch.setFloat(v ? (float) 1.0 : (float) 0.0);
29
+ }
30
+
31
+ @Override
32
+ public void longValue(long v) throws IOException, SQLException
33
+ {
34
+ batch.setFloat((float) v);
35
+ }
36
+
37
+ @Override
38
+ public void doubleValue(double v) throws IOException, SQLException
39
+ {
40
+ batch.setFloat((float) v);
41
+ }
42
+
43
+ @Override
44
+ public void stringValue(String v) throws IOException, SQLException
45
+ {
46
+ float fv;
47
+ try {
48
+ fv = Float.parseFloat(v);
49
+ } catch (NumberFormatException e) {
50
+ defaultValue.setFloat();
51
+ return;
52
+ }
53
+ batch.setFloat(fv);
54
+ }
55
+
56
+ @Override
57
+ public void timestampValue(Timestamp v) throws IOException, SQLException
58
+ {
59
+ defaultValue.setFloat();
60
+ }
61
+ }
@@ -0,0 +1,76 @@
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.ColumnVisitor;
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 IntColumnSetter
13
+ extends ColumnSetter
14
+ {
15
+ public IntColumnSetter(BatchInsert batch, JdbcColumn column,
16
+ DefaultValueSetter defaultValue)
17
+ {
18
+ super(batch, column, defaultValue);
19
+ }
20
+
21
+ @Override
22
+ public void nullValue() throws IOException, SQLException
23
+ {
24
+ defaultValue.setInt();
25
+ }
26
+
27
+ @Override
28
+ public void booleanValue(boolean v) throws IOException, SQLException
29
+ {
30
+ batch.setInt(v ? 1 : 0);
31
+ }
32
+
33
+ @Override
34
+ public void longValue(long v) throws IOException, SQLException
35
+ {
36
+ if (v > Integer.MAX_VALUE || v < Integer.MIN_VALUE) {
37
+ defaultValue.setInt();
38
+ } else {
39
+ batch.setInt((int) v);
40
+ }
41
+ }
42
+
43
+ @Override
44
+ public void doubleValue(double v) throws IOException, SQLException
45
+ {
46
+ long lv;
47
+ try {
48
+ // TODO configurable rounding mode
49
+ lv = DoubleMath.roundToLong(v, RoundingMode.HALF_UP);
50
+ } catch (ArithmeticException ex) {
51
+ // NaN / Infinite / -Infinite
52
+ defaultValue.setInt();
53
+ return;
54
+ }
55
+ longValue(lv);
56
+ }
57
+
58
+ @Override
59
+ public void stringValue(String v) throws IOException, SQLException
60
+ {
61
+ int iv;
62
+ try {
63
+ iv = Integer.parseInt(v);
64
+ } catch (NumberFormatException e) {
65
+ defaultValue.setInt();
66
+ return;
67
+ }
68
+ batch.setInt(iv);
69
+ }
70
+
71
+ @Override
72
+ public void timestampValue(Timestamp v) throws IOException, SQLException
73
+ {
74
+ defaultValue.setInt();
75
+ }
76
+ }
@@ -1,62 +1,72 @@
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.ColumnVisitor;
8
- import org.embulk.spi.PageReader;
9
- import org.embulk.spi.time.Timestamp;
10
- import org.embulk.output.jdbc.JdbcColumn;
11
- import org.embulk.output.jdbc.BatchInsert;
12
-
13
- public class LongColumnSetter
14
- extends ColumnSetter
15
- {
16
- public LongColumnSetter(BatchInsert batch, PageReader pageReader,
17
- JdbcColumn column)
18
- {
19
- super(batch, pageReader, column);
20
- }
21
-
22
- protected void booleanValue(boolean v) throws IOException, SQLException
23
- {
24
- batch.setLong(v ? 1L : 0L);
25
- }
26
-
27
- protected void longValue(long v) throws IOException, SQLException
28
- {
29
- batch.setLong(v);
30
- }
31
-
32
- protected void doubleValue(double v) throws IOException, SQLException
33
- {
34
- long lv;
35
- try {
36
- // TODO configurable rounding mode
37
- lv = DoubleMath.roundToLong(v, RoundingMode.HALF_UP);
38
- } catch (ArithmeticException ex) {
39
- // NaN / Infinite / -Infinite
40
- nullValue();
41
- return;
42
- }
43
- batch.setLong(lv);
44
- }
45
-
46
- protected void stringValue(String v) throws IOException, SQLException
47
- {
48
- long lv;
49
- try {
50
- lv = Long.parseLong(v);
51
- } catch (NumberFormatException e) {
52
- nullValue();
53
- return;
54
- }
55
- batch.setLong(lv);
56
- }
57
-
58
- protected void timestampValue(Timestamp v) throws IOException, SQLException
59
- {
60
- nullValue();
61
- }
62
- }
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.ColumnVisitor;
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 LongColumnSetter
13
+ extends ColumnSetter
14
+ {
15
+ public LongColumnSetter(BatchInsert batch, JdbcColumn column,
16
+ DefaultValueSetter defaultValue)
17
+ {
18
+ super(batch, column, defaultValue);
19
+ }
20
+
21
+ @Override
22
+ public void nullValue() throws IOException, SQLException
23
+ {
24
+ defaultValue.setLong();
25
+ }
26
+
27
+ @Override
28
+ public void booleanValue(boolean v) throws IOException, SQLException
29
+ {
30
+ batch.setLong(v ? 1L : 0L);
31
+ }
32
+
33
+ @Override
34
+ public void longValue(long v) throws IOException, SQLException
35
+ {
36
+ batch.setLong(v);
37
+ }
38
+
39
+ @Override
40
+ public void doubleValue(double v) throws IOException, SQLException
41
+ {
42
+ long lv;
43
+ try {
44
+ // TODO configurable rounding mode
45
+ lv = DoubleMath.roundToLong(v, RoundingMode.HALF_UP);
46
+ } catch (ArithmeticException ex) {
47
+ // NaN / Infinite / -Infinite
48
+ defaultValue.setLong();
49
+ return;
50
+ }
51
+ batch.setLong(lv);
52
+ }
53
+
54
+ @Override
55
+ public void stringValue(String v) throws IOException, SQLException
56
+ {
57
+ long lv;
58
+ try {
59
+ lv = Long.parseLong(v);
60
+ } catch (NumberFormatException e) {
61
+ defaultValue.setLong();
62
+ return;
63
+ }
64
+ batch.setLong(lv);
65
+ }
66
+
67
+ @Override
68
+ public void timestampValue(Timestamp v) throws IOException, SQLException
69
+ {
70
+ defaultValue.setLong();
71
+ }
72
+ }