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,70 @@
|
|
1
|
+
package org.embulk.output.jdbc.setter;
|
2
|
+
|
3
|
+
import java.math.BigDecimal;
|
4
|
+
import java.io.IOException;
|
5
|
+
import java.sql.SQLException;
|
6
|
+
import org.embulk.spi.ColumnVisitor;
|
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 BigDecimalColumnSetter
|
13
|
+
extends ColumnSetter
|
14
|
+
{
|
15
|
+
private static final BigDecimal ZERO = BigDecimal.valueOf(0L);
|
16
|
+
private static final BigDecimal ONE = BigDecimal.valueOf(1L);
|
17
|
+
|
18
|
+
public BigDecimalColumnSetter(BatchInsert batch, JdbcColumn column,
|
19
|
+
DefaultValueSetter defaultValue)
|
20
|
+
{
|
21
|
+
super(batch, column, defaultValue);
|
22
|
+
}
|
23
|
+
|
24
|
+
@Override
|
25
|
+
public void nullValue() throws IOException, SQLException
|
26
|
+
{
|
27
|
+
defaultValue.setBigDecimal();
|
28
|
+
}
|
29
|
+
|
30
|
+
@Override
|
31
|
+
public void booleanValue(boolean v) throws IOException, SQLException
|
32
|
+
{
|
33
|
+
batch.setBigDecimal(v ? ONE : ZERO);
|
34
|
+
}
|
35
|
+
|
36
|
+
@Override
|
37
|
+
public void longValue(long v) throws IOException, SQLException
|
38
|
+
{
|
39
|
+
batch.setBigDecimal(BigDecimal.valueOf(v));
|
40
|
+
}
|
41
|
+
|
42
|
+
@Override
|
43
|
+
public void doubleValue(double v) throws IOException, SQLException
|
44
|
+
{
|
45
|
+
if (Double.isNaN(v) || Double.isInfinite(v)) {
|
46
|
+
defaultValue.setBigDecimal();
|
47
|
+
} else {
|
48
|
+
batch.setBigDecimal(BigDecimal.valueOf(v));
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
@Override
|
53
|
+
public void stringValue(String v) throws IOException, SQLException
|
54
|
+
{
|
55
|
+
BigDecimal dv;
|
56
|
+
try {
|
57
|
+
dv = new BigDecimal(v);
|
58
|
+
} catch (NumberFormatException ex) {
|
59
|
+
defaultValue.setBigDecimal();
|
60
|
+
return;
|
61
|
+
}
|
62
|
+
batch.setBigDecimal(dv);
|
63
|
+
}
|
64
|
+
|
65
|
+
@Override
|
66
|
+
public void timestampValue(Timestamp v) throws IOException, SQLException
|
67
|
+
{
|
68
|
+
defaultValue.setBigDecimal();
|
69
|
+
}
|
70
|
+
}
|
@@ -1,52 +1,54 @@
|
|
1
|
-
package org.embulk.output.jdbc.setter;
|
2
|
-
|
3
|
-
import java.io.IOException;
|
4
|
-
import java.sql.SQLException;
|
5
|
-
import com.google.common.collect.ImmutableSet;
|
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
|
-
batch.setBoolean(v > 0.0);
|
41
|
-
}
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
1
|
+
package org.embulk.output.jdbc.setter;
|
2
|
+
|
3
|
+
import java.io.IOException;
|
4
|
+
import java.sql.SQLException;
|
5
|
+
import com.google.common.collect.ImmutableSet;
|
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 BooleanColumnSetter
|
11
|
+
extends ColumnSetter
|
12
|
+
{
|
13
|
+
public BooleanColumnSetter(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.setBoolean();
|
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.setBoolean(v > 0);
|
35
|
+
}
|
36
|
+
|
37
|
+
@Override
|
38
|
+
public void doubleValue(double v) throws IOException, SQLException
|
39
|
+
{
|
40
|
+
batch.setBoolean(v > 0.0);
|
41
|
+
}
|
42
|
+
|
43
|
+
@Override
|
44
|
+
public void stringValue(String v) throws IOException, SQLException
|
45
|
+
{
|
46
|
+
defaultValue.setBoolean();
|
47
|
+
}
|
48
|
+
|
49
|
+
@Override
|
50
|
+
public void timestampValue(Timestamp v) throws IOException, SQLException
|
51
|
+
{
|
52
|
+
defaultValue.setBoolean();
|
53
|
+
}
|
54
|
+
}
|
@@ -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 ByteColumnSetter
|
13
|
+
extends ColumnSetter
|
14
|
+
{
|
15
|
+
public ByteColumnSetter(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.setByte();
|
25
|
+
}
|
26
|
+
|
27
|
+
@Override
|
28
|
+
public void booleanValue(boolean v) throws IOException, SQLException
|
29
|
+
{
|
30
|
+
batch.setByte(v ? (byte) 1 : (byte) 0);
|
31
|
+
}
|
32
|
+
|
33
|
+
@Override
|
34
|
+
public void longValue(long v) throws IOException, SQLException
|
35
|
+
{
|
36
|
+
if (v > Byte.MAX_VALUE || v < Byte.MIN_VALUE) {
|
37
|
+
defaultValue.setByte();
|
38
|
+
} else {
|
39
|
+
batch.setByte((byte) 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.setByte();
|
53
|
+
return;
|
54
|
+
}
|
55
|
+
longValue(lv);
|
56
|
+
}
|
57
|
+
|
58
|
+
@Override
|
59
|
+
public void stringValue(String v) throws IOException, SQLException
|
60
|
+
{
|
61
|
+
byte sv;
|
62
|
+
try {
|
63
|
+
sv = Byte.parseByte(v);
|
64
|
+
} catch (NumberFormatException e) {
|
65
|
+
defaultValue.setByte();
|
66
|
+
return;
|
67
|
+
}
|
68
|
+
batch.setByte(sv);
|
69
|
+
}
|
70
|
+
|
71
|
+
@Override
|
72
|
+
public void timestampValue(Timestamp v) throws IOException, SQLException
|
73
|
+
{
|
74
|
+
defaultValue.setByte();
|
75
|
+
}
|
76
|
+
}
|
@@ -3,25 +3,22 @@ package org.embulk.output.jdbc.setter;
|
|
3
3
|
import java.io.IOException;
|
4
4
|
import java.sql.SQLException;
|
5
5
|
import org.embulk.spi.Column;
|
6
|
-
import org.embulk.spi.ColumnVisitor;
|
7
|
-
import org.embulk.spi.PageReader;
|
8
6
|
import org.embulk.spi.time.Timestamp;
|
9
7
|
import org.embulk.output.jdbc.JdbcColumn;
|
10
8
|
import org.embulk.output.jdbc.BatchInsert;
|
11
9
|
|
12
10
|
public abstract class ColumnSetter
|
13
|
-
implements ColumnVisitor
|
14
11
|
{
|
15
12
|
protected final BatchInsert batch;
|
16
|
-
protected final PageReader pageReader;
|
17
13
|
protected final JdbcColumn column;
|
14
|
+
protected final DefaultValueSetter defaultValue;
|
18
15
|
|
19
|
-
public ColumnSetter(BatchInsert batch,
|
20
|
-
|
16
|
+
public ColumnSetter(BatchInsert batch, JdbcColumn column,
|
17
|
+
DefaultValueSetter defaultValue)
|
21
18
|
{
|
22
19
|
this.batch = batch;
|
23
|
-
this.pageReader = pageReader;
|
24
20
|
this.column = column;
|
21
|
+
this.defaultValue = defaultValue;
|
25
22
|
}
|
26
23
|
|
27
24
|
public JdbcColumn getColumn()
|
@@ -34,93 +31,15 @@ public abstract class ColumnSetter
|
|
34
31
|
return column.getSqlType();
|
35
32
|
}
|
36
33
|
|
37
|
-
public void
|
38
|
-
{
|
39
|
-
try {
|
40
|
-
if (pageReader.isNull(column)) {
|
41
|
-
nullValue();
|
42
|
-
} else {
|
43
|
-
booleanValue(pageReader.getBoolean(column));
|
44
|
-
}
|
45
|
-
} catch (IOException | SQLException ex) {
|
46
|
-
// TODO exception class
|
47
|
-
throw new RuntimeException(ex);
|
48
|
-
}
|
49
|
-
}
|
50
|
-
|
51
|
-
public void longColumn(Column column)
|
52
|
-
{
|
53
|
-
try {
|
54
|
-
if (pageReader.isNull(column)) {
|
55
|
-
nullValue();
|
56
|
-
} else {
|
57
|
-
longValue(pageReader.getLong(column));
|
58
|
-
}
|
59
|
-
} catch (IOException | SQLException ex) {
|
60
|
-
// TODO exception class
|
61
|
-
throw new RuntimeException(ex);
|
62
|
-
}
|
63
|
-
}
|
64
|
-
|
65
|
-
public void doubleColumn(Column column)
|
66
|
-
{
|
67
|
-
try {
|
68
|
-
if (pageReader.isNull(column)) {
|
69
|
-
nullValue();
|
70
|
-
} else {
|
71
|
-
doubleValue(pageReader.getDouble(column));
|
72
|
-
}
|
73
|
-
} catch (IOException | SQLException ex) {
|
74
|
-
// TODO exception class
|
75
|
-
throw new RuntimeException(ex);
|
76
|
-
}
|
77
|
-
}
|
78
|
-
|
79
|
-
public void stringColumn(Column column)
|
80
|
-
{
|
81
|
-
try {
|
82
|
-
if (pageReader.isNull(column)) {
|
83
|
-
nullValue();
|
84
|
-
} else {
|
85
|
-
stringValue(pageReader.getString(column));
|
86
|
-
}
|
87
|
-
} catch (IOException | SQLException ex) {
|
88
|
-
// TODO exception class
|
89
|
-
throw new RuntimeException(ex);
|
90
|
-
}
|
91
|
-
}
|
92
|
-
|
93
|
-
public void timestampColumn(Column column)
|
94
|
-
{
|
95
|
-
try {
|
96
|
-
if (pageReader.isNull(column)) {
|
97
|
-
nullValue();
|
98
|
-
} else {
|
99
|
-
timestampValue(pageReader.getTimestamp(column));
|
100
|
-
}
|
101
|
-
} catch (IOException | SQLException ex) {
|
102
|
-
// TODO exception class
|
103
|
-
throw new RuntimeException(ex);
|
104
|
-
}
|
105
|
-
}
|
106
|
-
|
107
|
-
protected void nullValue() throws IOException, SQLException
|
108
|
-
{
|
109
|
-
try {
|
110
|
-
batch.setNull(getSqlType());
|
111
|
-
} catch (IOException | SQLException ex) {
|
112
|
-
// TODO exception class
|
113
|
-
throw new RuntimeException(ex);
|
114
|
-
}
|
115
|
-
}
|
34
|
+
public abstract void nullValue() throws IOException, SQLException;
|
116
35
|
|
117
|
-
|
36
|
+
public abstract void booleanValue(boolean v) throws IOException, SQLException;
|
118
37
|
|
119
|
-
|
38
|
+
public abstract void longValue(long v) throws IOException, SQLException;
|
120
39
|
|
121
|
-
|
40
|
+
public abstract void doubleValue(double v) throws IOException, SQLException;
|
122
41
|
|
123
|
-
|
42
|
+
public abstract void stringValue(String v) throws IOException, SQLException;
|
124
43
|
|
125
|
-
|
44
|
+
public abstract void timestampValue(Timestamp v) throws IOException, SQLException;
|
126
45
|
}
|
@@ -1,137 +1,189 @@
|
|
1
|
-
package org.embulk.output.jdbc.setter;
|
2
|
-
|
3
|
-
import java.sql.Types;
|
4
|
-
import org.
|
5
|
-
import org.embulk.spi.
|
6
|
-
import org.embulk.output.jdbc.BatchInsert;
|
7
|
-
import org.embulk.output.jdbc.JdbcColumn;
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
protected final
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
{
|
18
|
-
this.batch = batch;
|
19
|
-
this.
|
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
|
-
case
|
48
|
-
return new
|
49
|
-
|
50
|
-
|
51
|
-
case
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
case
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
//
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
case Types.
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
case Types.
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
case Types.
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
1
|
+
package org.embulk.output.jdbc.setter;
|
2
|
+
|
3
|
+
import java.sql.Types;
|
4
|
+
import org.joda.time.DateTimeZone;
|
5
|
+
import org.embulk.spi.time.TimestampFormatter;
|
6
|
+
import org.embulk.output.jdbc.BatchInsert;
|
7
|
+
import org.embulk.output.jdbc.JdbcColumn;
|
8
|
+
import org.embulk.output.jdbc.JdbcColumnOption;
|
9
|
+
import org.embulk.config.ConfigException;
|
10
|
+
|
11
|
+
public class ColumnSetterFactory
|
12
|
+
{
|
13
|
+
protected final BatchInsert batch;
|
14
|
+
protected final DateTimeZone defaultTimeZone;
|
15
|
+
|
16
|
+
public ColumnSetterFactory(BatchInsert batch, DateTimeZone defaultTimeZone)
|
17
|
+
{
|
18
|
+
this.batch = batch;
|
19
|
+
this.defaultTimeZone = defaultTimeZone;
|
20
|
+
}
|
21
|
+
|
22
|
+
public SkipColumnSetter newSkipColumnSetter()
|
23
|
+
{
|
24
|
+
return new SkipColumnSetter(batch);
|
25
|
+
}
|
26
|
+
|
27
|
+
public DefaultValueSetter newDefaultValueSetter(JdbcColumn column, JdbcColumnOption option)
|
28
|
+
{
|
29
|
+
return new NullDefaultValueSetter(batch, column);
|
30
|
+
}
|
31
|
+
|
32
|
+
public ColumnSetter newColumnSetter(JdbcColumn column, JdbcColumnOption option)
|
33
|
+
{
|
34
|
+
switch (option.getValueType()) {
|
35
|
+
case "coalesce":
|
36
|
+
return newCoalesceColumnSetter(column, option);
|
37
|
+
case "byte":
|
38
|
+
return new ByteColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
39
|
+
case "short":
|
40
|
+
return new ShortColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
41
|
+
case "int":
|
42
|
+
return new IntColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
43
|
+
case "long":
|
44
|
+
return new LongColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
45
|
+
case "double":
|
46
|
+
return new DoubleColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
47
|
+
case "float":
|
48
|
+
return new FloatColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
49
|
+
case "boolean":
|
50
|
+
return new BooleanColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
51
|
+
case "string":
|
52
|
+
return new StringColumnSetter(batch, column, newDefaultValueSetter(column, option), newTimestampFormatter(option));
|
53
|
+
case "nstring":
|
54
|
+
return new NStringColumnSetter(batch, column, newDefaultValueSetter(column, option), newTimestampFormatter(option));
|
55
|
+
case "date":
|
56
|
+
return new SqlDateColumnSetter(batch, column, newDefaultValueSetter(column, option), getTimeZone(option));
|
57
|
+
case "time":
|
58
|
+
return new SqlTimeColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
59
|
+
case "timestamp":
|
60
|
+
return new SqlTimestampColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
61
|
+
case "decimal":
|
62
|
+
return new BigDecimalColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
63
|
+
case "null":
|
64
|
+
return new NullColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
65
|
+
case "pass":
|
66
|
+
return new PassThroughColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
67
|
+
default:
|
68
|
+
throw new ConfigException(String.format("Unknown value_type '%s' for column '%s'", option.getValueType(), column.getName()));
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
protected TimestampFormatter newTimestampFormatter(JdbcColumnOption option)
|
73
|
+
{
|
74
|
+
return new TimestampFormatter(
|
75
|
+
option.getJRuby(),
|
76
|
+
option.getTimestampFormat().getFormat(),
|
77
|
+
option.getTimeZone().or(defaultTimeZone));
|
78
|
+
}
|
79
|
+
|
80
|
+
protected DateTimeZone getTimeZone(JdbcColumnOption option)
|
81
|
+
{
|
82
|
+
return option.getTimeZone().or(defaultTimeZone);
|
83
|
+
}
|
84
|
+
|
85
|
+
public ColumnSetter newCoalesceColumnSetter(JdbcColumn column, JdbcColumnOption option)
|
86
|
+
{
|
87
|
+
switch(column.getSqlType()) {
|
88
|
+
// setByte
|
89
|
+
case Types.TINYINT:
|
90
|
+
return new ByteColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
91
|
+
|
92
|
+
// setShort
|
93
|
+
case Types.SMALLINT:
|
94
|
+
return new ShortColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
95
|
+
|
96
|
+
// setInt
|
97
|
+
case Types.INTEGER:
|
98
|
+
return new IntColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
99
|
+
|
100
|
+
// setLong
|
101
|
+
case Types.BIGINT:
|
102
|
+
return new LongColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
103
|
+
|
104
|
+
// setDouble
|
105
|
+
case Types.DOUBLE:
|
106
|
+
case Types.FLOAT:
|
107
|
+
return new DoubleColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
108
|
+
|
109
|
+
// setFloat
|
110
|
+
case Types.REAL:
|
111
|
+
return new FloatColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
112
|
+
|
113
|
+
// setBool
|
114
|
+
case Types.BOOLEAN:
|
115
|
+
case Types.BIT: // JDBC BIT is boolean, unlike SQL-92
|
116
|
+
return new BooleanColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
117
|
+
|
118
|
+
// setString, Clob
|
119
|
+
case Types.CHAR:
|
120
|
+
case Types.VARCHAR:
|
121
|
+
case Types.LONGVARCHAR:
|
122
|
+
case Types.CLOB:
|
123
|
+
return new StringColumnSetter(batch, column, newDefaultValueSetter(column, option), newTimestampFormatter(option));
|
124
|
+
|
125
|
+
// setNString, NClob
|
126
|
+
case Types.NCHAR:
|
127
|
+
case Types.NVARCHAR:
|
128
|
+
case Types.LONGNVARCHAR:
|
129
|
+
return new NStringColumnSetter(batch, column, newDefaultValueSetter(column, option), newTimestampFormatter(option));
|
130
|
+
|
131
|
+
// TODO
|
132
|
+
//// setBytes Blob
|
133
|
+
//case Types.BINARY:
|
134
|
+
//case Types.VARBINARY:
|
135
|
+
//case Types.LONGVARBINARY:
|
136
|
+
//case Types.BLOB:
|
137
|
+
// return new BytesColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
138
|
+
|
139
|
+
// Time
|
140
|
+
case Types.DATE:
|
141
|
+
return new SqlDateColumnSetter(batch, column, newDefaultValueSetter(column, option), getTimeZone(option));
|
142
|
+
case Types.TIME:
|
143
|
+
return new SqlTimeColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
144
|
+
case Types.TIMESTAMP:
|
145
|
+
return new SqlTimestampColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
146
|
+
|
147
|
+
// Null
|
148
|
+
case Types.NULL:
|
149
|
+
return new NullColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
150
|
+
|
151
|
+
// BigDecimal
|
152
|
+
case Types.NUMERIC:
|
153
|
+
case Types.DECIMAL:
|
154
|
+
return new BigDecimalColumnSetter(batch, column, newDefaultValueSetter(column, option));
|
155
|
+
|
156
|
+
// others
|
157
|
+
case Types.ARRAY: // array
|
158
|
+
case Types.STRUCT: // map
|
159
|
+
case Types.REF:
|
160
|
+
case Types.DATALINK:
|
161
|
+
case Types.SQLXML: // XML
|
162
|
+
case Types.ROWID:
|
163
|
+
case Types.DISTINCT:
|
164
|
+
case Types.JAVA_OBJECT:
|
165
|
+
case Types.OTHER:
|
166
|
+
default:
|
167
|
+
throw unsupportedOperationException(column);
|
168
|
+
}
|
169
|
+
}
|
170
|
+
|
171
|
+
//private static String[] UNSUPPORTED = new String[] {
|
172
|
+
// "ARRAY",
|
173
|
+
// "STRUCT",
|
174
|
+
// "REF",
|
175
|
+
// "DATALINK",
|
176
|
+
// "SQLXML",
|
177
|
+
// "ROWID",
|
178
|
+
// "DISTINCT",
|
179
|
+
// "OTHER",
|
180
|
+
//};
|
181
|
+
|
182
|
+
private static UnsupportedOperationException unsupportedOperationException(JdbcColumn column)
|
183
|
+
{
|
184
|
+
throw new UnsupportedOperationException(
|
185
|
+
String.format("Unsupported type %s (sqlType=%d, size=%d, scale=%d)",
|
186
|
+
column.getDeclaredType().or(column.getSimpleTypeName()),
|
187
|
+
column.getSqlType(), column.getSizeTypeParameter(), column.getScaleTypeParameter()));
|
188
|
+
}
|
189
|
+
}
|