Skip to content

Commit 9cc3249

Browse files
committed
Replace Embulk's TimestampFormatter to embulk-util-timestamp's
1 parent 10016dd commit 9cc3249

File tree

11 files changed

+23
-25
lines changed

11 files changed

+23
-25
lines changed

build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ subprojects {
4141

4242
dependencies {
4343
compileOnly "org.embulk:embulk-core:0.9.23"
44+
compile "org.embulk:embulk-util-timestamp:0.2.0"
4445

4546
testCompile "org.embulk:embulk-core:0.9.23"
4647
testCompile "org.embulk:embulk-test:0.9.23"
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# This is a Gradle generated file for dependency locking.
22
# Manual edits can break the build and are not advised.
33
# This file is expected to be part of source control.
4+
org.embulk:embulk-util-rubytime:0.3.0
5+
org.embulk:embulk-util-timestamp:0.2.0
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# This is a Gradle generated file for dependency locking.
22
# Manual edits can break the build and are not advised.
33
# This file is expected to be part of source control.
4+
org.embulk:embulk-util-rubytime:0.3.0
5+
org.embulk:embulk-util-timestamp:0.2.0

embulk-output-jdbc/src/main/java/org/embulk/output/jdbc/setter/ColumnSetterFactory.java

+4-21
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
import org.embulk.config.ConfigSource;
99
import org.embulk.config.Task;
1010
import org.embulk.spi.Exec;
11-
import org.embulk.spi.time.TimestampFormatter;
1211
import org.embulk.output.jdbc.BatchInsert;
1312
import org.embulk.output.jdbc.JdbcColumn;
1413
import org.embulk.output.jdbc.JdbcColumnOption;
1514
import org.embulk.config.ConfigException;
15+
import org.embulk.util.timestamp.TimestampFormatter;
1616

1717
public class ColumnSetterFactory
1818
{
@@ -77,28 +77,11 @@ public ColumnSetter newColumnSetter(JdbcColumn column, JdbcColumnOption option)
7777
}
7878
}
7979

80-
private static interface FormatterIntlTask extends Task, TimestampFormatter.Task {}
81-
private static interface FormatterIntlColumnOption extends Task, TimestampFormatter.TimestampColumnOption {}
82-
8380
protected TimestampFormatter newTimestampFormatter(JdbcColumnOption option)
8481
{
85-
// TODO: Switch to a newer TimestampFormatter constructor after a reasonable interval.
86-
// Traditional constructor is used here for compatibility.
87-
final ConfigSource configSource = Exec.newConfigSource();
88-
configSource.set("format", option.getTimestampFormat().getFormat());
89-
configSource.set("timezone", getTimeZone(option));
90-
91-
final FormatterIntlTask task = Exec.newConfigSource().loadConfig(FormatterIntlTask.class);
92-
final Optional<? extends TimestampFormatter.TimestampColumnOption> columnOption =
93-
Optional.ofNullable(configSource.loadConfig(FormatterIntlColumnOption.class));
94-
95-
return TimestampFormatter.of(
96-
columnOption.isPresent()
97-
? columnOption.get().getFormat().or(task.getDefaultTimestampFormat())
98-
: task.getDefaultTimestampFormat(),
99-
columnOption.isPresent()
100-
? columnOption.get().getTimeZoneId().or(task.getDefaultTimeZoneId())
101-
: task.getDefaultTimeZoneId());
82+
final String format = option.getTimestampFormat().getFormat();
83+
final String timezone = option.getTimeZone().orElse(this.defaultTimeZone);
84+
return TimestampFormatter.builder(format, true).setDefaultZoneFromString(timezone).build();
10285
}
10386

10487
protected Calendar newCalendar(JdbcColumnOption option)

embulk-output-jdbc/src/main/java/org/embulk/output/jdbc/setter/NStringColumnSetter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import java.sql.SQLException;
55

66
import org.embulk.spi.time.Timestamp;
7-
import org.embulk.spi.time.TimestampFormatter;
87
import org.embulk.output.jdbc.JdbcColumn;
98
import org.embulk.output.jdbc.BatchInsert;
9+
import org.embulk.util.timestamp.TimestampFormatter;
1010
import org.msgpack.value.Value;
1111

1212
public class NStringColumnSetter
@@ -55,7 +55,7 @@ public void stringValue(String v) throws IOException, SQLException
5555
@Override
5656
public void timestampValue(Timestamp v) throws IOException, SQLException
5757
{
58-
batch.setNString(timestampFormatter.format(v));
58+
batch.setNString(timestampFormatter.format(v.getInstant()));
5959
}
6060

6161
@Override

embulk-output-jdbc/src/main/java/org/embulk/output/jdbc/setter/StringColumnSetter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import java.sql.SQLException;
55

66
import org.embulk.spi.time.Timestamp;
7-
import org.embulk.spi.time.TimestampFormatter;
87
import org.embulk.output.jdbc.JdbcColumn;
98
import org.embulk.output.jdbc.BatchInsert;
9+
import org.embulk.util.timestamp.TimestampFormatter;
1010
import org.msgpack.value.Value;
1111

1212
public class StringColumnSetter
@@ -55,7 +55,7 @@ public void stringValue(String v) throws IOException, SQLException
5555
@Override
5656
public void timestampValue(Timestamp v) throws IOException, SQLException
5757
{
58-
batch.setString(timestampFormatter.format(v));
58+
batch.setString(timestampFormatter.format(v.getInstant()));
5959
}
6060

6161
@Override
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# This is a Gradle generated file for dependency locking.
22
# Manual edits can break the build and are not advised.
33
# This file is expected to be part of source control.
4+
org.embulk:embulk-util-rubytime:0.3.0
5+
org.embulk:embulk-util-timestamp:0.2.0
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# This is a Gradle generated file for dependency locking.
22
# Manual edits can break the build and are not advised.
33
# This file is expected to be part of source control.
4+
org.embulk:embulk-util-rubytime:0.3.0
5+
org.embulk:embulk-util-timestamp:0.2.0
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# This is a Gradle generated file for dependency locking.
22
# Manual edits can break the build and are not advised.
33
# This file is expected to be part of source control.
4+
org.embulk:embulk-util-rubytime:0.3.0
5+
org.embulk:embulk-util-timestamp:0.2.0

embulk-output-redshift/gradle/dependency-locks/embulkPluginRuntime.lockfile

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ commons-logging:commons-logging:1.2
1212
org.apache.httpcomponents:httpclient:4.5.5
1313
org.apache.httpcomponents:httpcore:4.4.9
1414
org.embulk.input.s3:embulk-util-aws-credentials:0.3.5
15+
org.embulk:embulk-util-rubytime:0.3.0
16+
org.embulk:embulk-util-timestamp:0.2.0
1517
org.postgresql:postgresql:9.4-1205-jdbc41
1618
org.slf4j:jcl-over-slf4j:1.7.12
1719
software.amazon.ion:ion-java:1.0.2

embulk-output-sqlserver/gradle/dependency-locks/embulkPluginRuntime.lockfile

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
# This file is expected to be part of source control.
44
com.microsoft.sqlserver:mssql-jdbc:7.2.2.jre8
55
net.sourceforge.jtds:jtds:1.3.1
6+
org.embulk:embulk-util-rubytime:0.3.0
7+
org.embulk:embulk-util-timestamp:0.2.0

0 commit comments

Comments
 (0)