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.
- checksums.yaml +4 -4
- data/build.gradle +2 -2
- data/classpath/embulk-output-jdbc-0.3.0.jar +0 -0
- data/lib/embulk/output/jdbc.rb +3 -3
- data/src/main/java/org/embulk/output/JdbcOutputPlugin.java +138 -120
- data/src/main/java/org/embulk/output/jdbc/AbstractJdbcOutputPlugin.java +964 -755
- data/src/main/java/org/embulk/output/jdbc/BatchInsert.java +54 -54
- data/src/main/java/org/embulk/output/jdbc/JdbcColumn.java +59 -23
- data/src/main/java/org/embulk/output/jdbc/JdbcColumnOption.java +34 -0
- data/src/main/java/org/embulk/output/jdbc/JdbcOutputConnection.java +95 -114
- data/src/main/java/org/embulk/output/jdbc/JdbcOutputConnector.java +8 -8
- data/src/main/java/org/embulk/output/jdbc/JdbcSchema.java +60 -37
- data/src/main/java/org/embulk/output/jdbc/JdbcUtils.java +155 -155
- data/src/main/java/org/embulk/output/jdbc/StandardBatchInsert.java +8 -5
- data/src/main/java/org/embulk/output/jdbc/setter/BigDecimalColumnSetter.java +70 -0
- data/src/main/java/org/embulk/output/jdbc/setter/BooleanColumnSetter.java +54 -52
- data/src/main/java/org/embulk/output/jdbc/setter/ByteColumnSetter.java +76 -0
- data/src/main/java/org/embulk/output/jdbc/setter/ColumnSetter.java +10 -91
- data/src/main/java/org/embulk/output/jdbc/setter/ColumnSetterFactory.java +189 -137
- data/src/main/java/org/embulk/output/jdbc/setter/ColumnSetterVisitor.java +96 -0
- data/src/main/java/org/embulk/output/jdbc/setter/DefaultValueSetter.java +48 -0
- data/src/main/java/org/embulk/output/jdbc/setter/DoubleColumnSetter.java +61 -51
- data/src/main/java/org/embulk/output/jdbc/setter/FloatColumnSetter.java +61 -0
- data/src/main/java/org/embulk/output/jdbc/setter/IntColumnSetter.java +76 -0
- data/src/main/java/org/embulk/output/jdbc/setter/LongColumnSetter.java +72 -62
- data/src/main/java/org/embulk/output/jdbc/setter/NStringColumnSetter.java +59 -0
- data/src/main/java/org/embulk/output/jdbc/setter/NullColumnSetter.java +53 -43
- data/src/main/java/org/embulk/output/jdbc/setter/NullDefaultValueSetter.java +105 -0
- data/src/main/java/org/embulk/output/jdbc/setter/PassThroughColumnSetter.java +56 -0
- data/src/main/java/org/embulk/output/jdbc/setter/ShortColumnSetter.java +76 -0
- data/src/main/java/org/embulk/output/jdbc/setter/SkipColumnSetter.java +43 -38
- data/src/main/java/org/embulk/output/jdbc/setter/SqlDateColumnSetter.java +63 -0
- data/src/main/java/org/embulk/output/jdbc/setter/SqlTimeColumnSetter.java +55 -0
- data/src/main/java/org/embulk/output/jdbc/setter/SqlTimestampColumnSetter.java +55 -48
- data/src/main/java/org/embulk/output/jdbc/setter/StringColumnSetter.java +59 -48
- data/src/test/java/org/embulk/output/TestJdbcOutputPlugin.java +5 -5
- metadata +16 -4
- data/classpath/embulk-output-jdbc-0.2.4.jar +0 -0
- data/src/main/java/org/embulk/output/jdbc/RetryExecutor.java +0 -105
@@ -0,0 +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.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 NStringColumnSetter
|
12
|
+
extends ColumnSetter
|
13
|
+
{
|
14
|
+
private final TimestampFormatter timestampFormatter;
|
15
|
+
|
16
|
+
public NStringColumnSetter(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.setNString();
|
28
|
+
}
|
29
|
+
|
30
|
+
@Override
|
31
|
+
public void booleanValue(boolean v) throws IOException, SQLException
|
32
|
+
{
|
33
|
+
batch.setNString(Boolean.toString(v));
|
34
|
+
}
|
35
|
+
|
36
|
+
@Override
|
37
|
+
public void longValue(long v) throws IOException, SQLException
|
38
|
+
{
|
39
|
+
batch.setNString(Long.toString(v));
|
40
|
+
}
|
41
|
+
|
42
|
+
@Override
|
43
|
+
public void doubleValue(double v) throws IOException, SQLException
|
44
|
+
{
|
45
|
+
batch.setNString(Double.toString(v));
|
46
|
+
}
|
47
|
+
|
48
|
+
@Override
|
49
|
+
public void stringValue(String v) throws IOException, SQLException
|
50
|
+
{
|
51
|
+
batch.setNString(v);
|
52
|
+
}
|
53
|
+
|
54
|
+
@Override
|
55
|
+
public void timestampValue(Timestamp v) throws IOException, SQLException
|
56
|
+
{
|
57
|
+
batch.setNString(timestampFormatter.format(v));
|
58
|
+
}
|
59
|
+
}
|
@@ -1,43 +1,53 @@
|
|
1
|
-
package org.embulk.output.jdbc.setter;
|
2
|
-
|
3
|
-
import java.io.IOException;
|
4
|
-
import java.sql.SQLException;
|
5
|
-
import org.embulk.spi.
|
6
|
-
import org.embulk.
|
7
|
-
import org.embulk.output.jdbc.
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
{
|
21
|
-
|
22
|
-
}
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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 NullColumnSetter
|
10
|
+
extends ColumnSetter
|
11
|
+
{
|
12
|
+
public NullColumnSetter(BatchInsert batch, JdbcColumn column,
|
13
|
+
DefaultValueSetter defaultValue)
|
14
|
+
{
|
15
|
+
super(batch, column, defaultValue);
|
16
|
+
}
|
17
|
+
|
18
|
+
@Override
|
19
|
+
public void booleanValue(boolean v) throws IOException, SQLException
|
20
|
+
{
|
21
|
+
defaultValue.setNull();
|
22
|
+
}
|
23
|
+
|
24
|
+
@Override
|
25
|
+
public void longValue(long v) throws IOException, SQLException
|
26
|
+
{
|
27
|
+
defaultValue.setNull();
|
28
|
+
}
|
29
|
+
|
30
|
+
@Override
|
31
|
+
public void doubleValue(double v) throws IOException, SQLException
|
32
|
+
{
|
33
|
+
defaultValue.setNull();
|
34
|
+
}
|
35
|
+
|
36
|
+
@Override
|
37
|
+
public void stringValue(String v) throws IOException, SQLException
|
38
|
+
{
|
39
|
+
defaultValue.setNull();
|
40
|
+
}
|
41
|
+
|
42
|
+
@Override
|
43
|
+
public void timestampValue(Timestamp v) throws IOException, SQLException
|
44
|
+
{
|
45
|
+
defaultValue.setNull();
|
46
|
+
}
|
47
|
+
|
48
|
+
@Override
|
49
|
+
public void nullValue() throws IOException, SQLException
|
50
|
+
{
|
51
|
+
defaultValue.setNull();
|
52
|
+
}
|
53
|
+
}
|
@@ -0,0 +1,105 @@
|
|
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 class NullDefaultValueSetter
|
9
|
+
extends DefaultValueSetter
|
10
|
+
{
|
11
|
+
public NullDefaultValueSetter(BatchInsert batch, JdbcColumn column)
|
12
|
+
{
|
13
|
+
super(batch, column);
|
14
|
+
}
|
15
|
+
|
16
|
+
@Override
|
17
|
+
public void setNull() throws IOException, SQLException
|
18
|
+
{
|
19
|
+
batch.setNull(column.getSqlType());
|
20
|
+
}
|
21
|
+
|
22
|
+
@Override
|
23
|
+
public void setBoolean() throws IOException, SQLException
|
24
|
+
{
|
25
|
+
batch.setNull(column.getSqlType());
|
26
|
+
}
|
27
|
+
|
28
|
+
@Override
|
29
|
+
public void setByte() throws IOException, SQLException
|
30
|
+
{
|
31
|
+
batch.setNull(column.getSqlType());
|
32
|
+
}
|
33
|
+
|
34
|
+
@Override
|
35
|
+
public void setShort() throws IOException, SQLException
|
36
|
+
{
|
37
|
+
batch.setNull(column.getSqlType());
|
38
|
+
}
|
39
|
+
|
40
|
+
@Override
|
41
|
+
public void setInt() throws IOException, SQLException
|
42
|
+
{
|
43
|
+
batch.setNull(column.getSqlType());
|
44
|
+
}
|
45
|
+
|
46
|
+
@Override
|
47
|
+
public void setLong() throws IOException, SQLException
|
48
|
+
{
|
49
|
+
batch.setNull(column.getSqlType());
|
50
|
+
}
|
51
|
+
|
52
|
+
@Override
|
53
|
+
public void setFloat() throws IOException, SQLException
|
54
|
+
{
|
55
|
+
batch.setNull(column.getSqlType());
|
56
|
+
}
|
57
|
+
|
58
|
+
@Override
|
59
|
+
public void setDouble() throws IOException, SQLException
|
60
|
+
{
|
61
|
+
batch.setNull(column.getSqlType());
|
62
|
+
}
|
63
|
+
|
64
|
+
@Override
|
65
|
+
public void setBigDecimal() throws IOException, SQLException
|
66
|
+
{
|
67
|
+
batch.setNull(column.getSqlType());
|
68
|
+
}
|
69
|
+
|
70
|
+
@Override
|
71
|
+
public void setString() throws IOException, SQLException
|
72
|
+
{
|
73
|
+
batch.setNull(column.getSqlType());
|
74
|
+
}
|
75
|
+
|
76
|
+
@Override
|
77
|
+
public void setNString() throws IOException, SQLException
|
78
|
+
{
|
79
|
+
batch.setNull(column.getSqlType());
|
80
|
+
}
|
81
|
+
|
82
|
+
@Override
|
83
|
+
public void setBytes() throws IOException, SQLException
|
84
|
+
{
|
85
|
+
batch.setNull(column.getSqlType());
|
86
|
+
}
|
87
|
+
|
88
|
+
@Override
|
89
|
+
public void setSqlDate() throws IOException, SQLException
|
90
|
+
{
|
91
|
+
batch.setNull(column.getSqlType());
|
92
|
+
}
|
93
|
+
|
94
|
+
@Override
|
95
|
+
public void setSqlTime() throws IOException, SQLException
|
96
|
+
{
|
97
|
+
batch.setNull(column.getSqlType());
|
98
|
+
}
|
99
|
+
|
100
|
+
@Override
|
101
|
+
public void setSqlTimestamp() throws IOException, SQLException
|
102
|
+
{
|
103
|
+
batch.setNull(column.getSqlType());
|
104
|
+
}
|
105
|
+
}
|
@@ -0,0 +1,56 @@
|
|
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.spi.time.TimestampFormatter;
|
7
|
+
import org.embulk.output.jdbc.JdbcColumn;
|
8
|
+
import org.embulk.output.jdbc.BatchInsert;
|
9
|
+
|
10
|
+
public class PassThroughColumnSetter
|
11
|
+
extends ColumnSetter
|
12
|
+
{
|
13
|
+
public PassThroughColumnSetter(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
|
+
batch.setNull(column.getSqlType());
|
23
|
+
}
|
24
|
+
|
25
|
+
@Override
|
26
|
+
public void booleanValue(boolean v) throws IOException, SQLException
|
27
|
+
{
|
28
|
+
batch.setBoolean(v);
|
29
|
+
}
|
30
|
+
|
31
|
+
@Override
|
32
|
+
public void longValue(long v) throws IOException, SQLException
|
33
|
+
{
|
34
|
+
batch.setLong(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
|
+
batch.setString(v);
|
47
|
+
}
|
48
|
+
|
49
|
+
@Override
|
50
|
+
public void timestampValue(Timestamp v) throws IOException, SQLException
|
51
|
+
{
|
52
|
+
java.sql.Timestamp t = new java.sql.Timestamp(v.toEpochMilli());
|
53
|
+
t.setNanos(v.getNano());
|
54
|
+
batch.setSqlTimestamp(t, getSqlType());
|
55
|
+
}
|
56
|
+
}
|
@@ -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 ShortColumnSetter
|
13
|
+
extends ColumnSetter
|
14
|
+
{
|
15
|
+
public ShortColumnSetter(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.setShort();
|
25
|
+
}
|
26
|
+
|
27
|
+
@Override
|
28
|
+
public void booleanValue(boolean v) throws IOException, SQLException
|
29
|
+
{
|
30
|
+
batch.setShort(v ? (short) 1 : (short) 0);
|
31
|
+
}
|
32
|
+
|
33
|
+
@Override
|
34
|
+
public void longValue(long v) throws IOException, SQLException
|
35
|
+
{
|
36
|
+
if (v > Short.MAX_VALUE || v < Short.MIN_VALUE) {
|
37
|
+
defaultValue.setShort();
|
38
|
+
} else {
|
39
|
+
batch.setShort((short) 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.setShort();
|
53
|
+
return;
|
54
|
+
}
|
55
|
+
longValue(lv);
|
56
|
+
}
|
57
|
+
|
58
|
+
@Override
|
59
|
+
public void stringValue(String v) throws IOException, SQLException
|
60
|
+
{
|
61
|
+
short sv;
|
62
|
+
try {
|
63
|
+
sv = Short.parseShort(v);
|
64
|
+
} catch (NumberFormatException e) {
|
65
|
+
defaultValue.setShort();
|
66
|
+
return;
|
67
|
+
}
|
68
|
+
batch.setShort(sv);
|
69
|
+
}
|
70
|
+
|
71
|
+
@Override
|
72
|
+
public void timestampValue(Timestamp v) throws IOException, SQLException
|
73
|
+
{
|
74
|
+
defaultValue.setShort();
|
75
|
+
}
|
76
|
+
}
|
@@ -1,38 +1,43 @@
|
|
1
|
-
package org.embulk.output.jdbc.setter;
|
2
|
-
|
3
|
-
import org.embulk.spi.
|
4
|
-
import org.embulk.
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
{
|
17
|
-
}
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
{
|
37
|
-
}
|
38
|
-
|
1
|
+
package org.embulk.output.jdbc.setter;
|
2
|
+
|
3
|
+
import org.embulk.spi.time.Timestamp;
|
4
|
+
import org.embulk.output.jdbc.BatchInsert;
|
5
|
+
|
6
|
+
public class SkipColumnSetter
|
7
|
+
extends ColumnSetter
|
8
|
+
{
|
9
|
+
public SkipColumnSetter(BatchInsert batch)
|
10
|
+
{
|
11
|
+
super(batch, null, null);
|
12
|
+
}
|
13
|
+
|
14
|
+
@Override
|
15
|
+
public void booleanValue(boolean v)
|
16
|
+
{
|
17
|
+
}
|
18
|
+
|
19
|
+
@Override
|
20
|
+
public void longValue(long v)
|
21
|
+
{
|
22
|
+
}
|
23
|
+
|
24
|
+
@Override
|
25
|
+
public void doubleValue(double v)
|
26
|
+
{
|
27
|
+
}
|
28
|
+
|
29
|
+
@Override
|
30
|
+
public void stringValue(String v)
|
31
|
+
{
|
32
|
+
}
|
33
|
+
|
34
|
+
@Override
|
35
|
+
public void timestampValue(Timestamp v)
|
36
|
+
{
|
37
|
+
}
|
38
|
+
|
39
|
+
@Override
|
40
|
+
public void nullValue()
|
41
|
+
{
|
42
|
+
}
|
43
|
+
}
|