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.
- 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,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.
|
7
|
-
import org.embulk.
|
8
|
-
import org.embulk.output.jdbc.
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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.
|
9
|
-
import org.embulk.
|
10
|
-
import org.embulk.output.jdbc.
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
+
}
|