Skip to content

Commit

Permalink
Replace org.embulk.spi.time.Timestamp to java.time.Instant
Browse files Browse the repository at this point in the history
  • Loading branch information
dmikurube committed Aug 19, 2020
1 parent 59b4a05 commit 7ea8fc6
Show file tree
Hide file tree
Showing 27 changed files with 68 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.Calendar;
import java.io.IOException;
import java.sql.SQLException;
import org.embulk.spi.time.Timestamp;
import java.time.Instant;

public interface BatchInsert
{
Expand Down Expand Up @@ -47,9 +47,9 @@ public interface BatchInsert

public void setBytes(byte[] v) throws IOException, SQLException;

public void setSqlDate(Timestamp v, Calendar cal) throws IOException, SQLException;
public void setSqlDate(Instant v, Calendar cal) throws IOException, SQLException;

public void setSqlTime(Timestamp v, Calendar cal) throws IOException, SQLException;
public void setSqlTime(Instant v, Calendar cal) throws IOException, SQLException;

public void setSqlTimestamp(Timestamp v, Calendar cal) throws IOException, SQLException;
public void setSqlTimestamp(Instant v, Calendar cal) throws IOException, SQLException;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.embulk.output.jdbc;

import java.time.Instant;
import org.embulk.spi.Column;
import org.embulk.spi.time.Timestamp;
import org.msgpack.value.Value;


public class MemoryRecord implements Record
{
private final Object[] values;
Expand Down Expand Up @@ -40,9 +39,9 @@ public String getString(Column column)
return (String)getValue(column);
}

public Timestamp getTimestamp(Column column)
public Instant getTimestamp(Column column)
{
return (Timestamp)getValue(column);
return ((org.embulk.spi.time.Timestamp) getValue(column)).getInstant();
}

public Value getJson(Column column)
Expand All @@ -60,4 +59,3 @@ public void setValue(Column column, Object value)
values[column.getIndex()] = value;
}
}

Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package org.embulk.output.jdbc;

import java.time.Instant;
import java.util.ArrayList;
import java.util.List;

import org.embulk.spi.Column;
import org.embulk.spi.Page;
import org.embulk.spi.PageReader;
import org.embulk.spi.time.Timestamp;
import org.msgpack.value.Value;


/**
* Record read by PageReader.
* The class will save read records for retry.
Expand Down Expand Up @@ -62,9 +61,9 @@ public String getString(Column column)
return save(column, pageReader.getString(column));
}

public Timestamp getTimestamp(Column column)
public Instant getTimestamp(Column column)
{
return save(column, pageReader.getTimestamp(column));
return save(column, pageReader.getTimestamp(column).getInstant());
}

public Value getJson(Column column)
Expand Down Expand Up @@ -93,4 +92,3 @@ private <T> T save(Column column, T value)
return value;
}
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.embulk.output.jdbc;

import java.time.Instant;
import org.embulk.spi.Column;
import org.embulk.spi.time.Timestamp;
import org.msgpack.value.Value;

public interface Record
Expand All @@ -16,8 +16,7 @@ public interface Record

String getString(Column column);

Timestamp getTimestamp(Column column);
Instant getTimestamp(Column column);

Value getJson(Column column);
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import java.sql.SQLException;
import java.sql.Date;
import java.sql.Time;
import java.time.Instant;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.embulk.spi.time.Timestamp;

public class StandardBatchInsert
implements BatchInsert
Expand Down Expand Up @@ -184,7 +184,7 @@ public void setBytes(byte[] v) throws IOException, SQLException
nextColumn(v.length + 4);
}

public void setSqlDate(Timestamp v, Calendar cal) throws IOException, SQLException
public void setSqlDate(final Instant v, final Calendar cal) throws IOException, SQLException
{
// JavaDoc of java.sql.Time says:
// >> To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated.
Expand All @@ -197,14 +197,14 @@ public void setSqlDate(Timestamp v, Calendar cal) throws IOException, SQLExcepti
nextColumn(32);
}

public void setSqlTime(Timestamp v, Calendar cal) throws IOException, SQLException
public void setSqlTime(final Instant v, final Calendar cal) throws IOException, SQLException
{
Time t = new Time(v.toEpochMilli());
batch.setTime(index, t, cal);
nextColumn(32);
}

public void setSqlTimestamp(Timestamp v, Calendar cal) throws IOException, SQLException
public void setSqlTimestamp(final Instant v, final Calendar cal) throws IOException, SQLException
{
java.sql.Timestamp t = new java.sql.Timestamp(v.toEpochMilli());
t.setNanos(v.getNano());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.math.BigDecimal;
import java.io.IOException;
import java.sql.SQLException;
import java.time.Instant;

import org.embulk.spi.time.Timestamp;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.output.jdbc.BatchInsert;
import org.msgpack.value.Value;
Expand Down Expand Up @@ -63,7 +63,7 @@ public void stringValue(String v) throws IOException, SQLException
}

@Override
public void timestampValue(Timestamp v) throws IOException, SQLException
public void timestampValue(final Instant v) throws IOException, SQLException
{
defaultValue.setBigDecimal();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.io.IOException;
import java.sql.SQLException;
import java.time.Instant;

import org.embulk.spi.time.Timestamp;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.output.jdbc.BatchInsert;
import org.msgpack.value.Value;
Expand Down Expand Up @@ -48,7 +48,7 @@ public void stringValue(String v) throws IOException, SQLException
}

@Override
public void timestampValue(Timestamp v) throws IOException, SQLException
public void timestampValue(final Instant v) throws IOException, SQLException
{
defaultValue.setBoolean();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import java.io.IOException;
import java.sql.SQLException;
import java.math.RoundingMode;
import java.time.Instant;

import com.google.common.math.DoubleMath;

import org.embulk.spi.time.Timestamp;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.output.jdbc.BatchInsert;
import org.msgpack.value.Value;
Expand Down Expand Up @@ -71,7 +71,7 @@ public void stringValue(String v) throws IOException, SQLException
}

@Override
public void timestampValue(Timestamp v) throws IOException, SQLException
public void timestampValue(final Instant v) throws IOException, SQLException
{
defaultValue.setByte();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import java.io.IOException;
import java.sql.SQLException;
import java.time.Instant;

import org.embulk.output.jdbc.BatchInsert;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.spi.time.Timestamp;
import org.msgpack.value.Value;

public abstract class ColumnSetter
Expand Down Expand Up @@ -42,7 +42,7 @@ public int getSqlType()

public abstract void stringValue(String v) throws IOException, SQLException;

public abstract void timestampValue(Timestamp v) throws IOException, SQLException;
public abstract void timestampValue(final Instant v) throws IOException, SQLException;

public abstract void jsonValue(Value v) throws IOException, SQLException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.io.IOException;
import java.sql.SQLException;
import java.time.Instant;

import org.embulk.spi.time.Timestamp;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.output.jdbc.BatchInsert;
import org.msgpack.value.Value;
Expand Down Expand Up @@ -55,7 +55,7 @@ public void stringValue(String v) throws IOException, SQLException
}

@Override
public void timestampValue(Timestamp v) throws IOException, SQLException
public void timestampValue(final Instant v) throws IOException, SQLException
{
defaultValue.setDouble();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.io.IOException;
import java.sql.SQLException;
import java.time.Instant;

import org.embulk.spi.time.Timestamp;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.output.jdbc.BatchInsert;
import org.msgpack.value.Value;
Expand Down Expand Up @@ -55,7 +55,7 @@ public void stringValue(String v) throws IOException, SQLException
}

@Override
public void timestampValue(Timestamp v) throws IOException, SQLException
public void timestampValue(final Instant v) throws IOException, SQLException
{
defaultValue.setFloat();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import java.io.IOException;
import java.sql.SQLException;
import java.math.RoundingMode;
import java.time.Instant;

import com.google.common.math.DoubleMath;

import org.embulk.spi.time.Timestamp;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.output.jdbc.BatchInsert;
import org.msgpack.value.Value;
Expand Down Expand Up @@ -71,7 +71,7 @@ public void stringValue(String v) throws IOException, SQLException
}

@Override
public void timestampValue(Timestamp v) throws IOException, SQLException
public void timestampValue(final Instant v) throws IOException, SQLException
{
defaultValue.setInt();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.io.IOException;
import java.sql.SQLException;
import java.time.Instant;

import org.embulk.spi.time.Timestamp;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.output.jdbc.BatchInsert;
import org.msgpack.value.Value;
Expand Down Expand Up @@ -48,7 +48,7 @@ public void stringValue(String v) throws IOException, SQLException
}

@Override
public void timestampValue(Timestamp v) throws IOException, SQLException
public void timestampValue(final Instant v) throws IOException, SQLException
{
defaultValue.setJson();
}
Expand All @@ -58,4 +58,3 @@ public void jsonValue(Value v) throws IOException, SQLException {
batch.setString(v.toJson());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import java.io.IOException;
import java.sql.SQLException;
import java.math.RoundingMode;
import java.time.Instant;

import com.google.common.math.DoubleMath;

import org.embulk.spi.time.Timestamp;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.output.jdbc.BatchInsert;
import org.msgpack.value.Value;
Expand Down Expand Up @@ -67,7 +67,7 @@ public void stringValue(String v) throws IOException, SQLException
}

@Override
public void timestampValue(Timestamp v) throws IOException, SQLException
public void timestampValue(final Instant v) throws IOException, SQLException
{
defaultValue.setLong();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.io.IOException;
import java.sql.SQLException;
import java.time.Instant;

import org.embulk.spi.time.Timestamp;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.output.jdbc.BatchInsert;
import org.embulk.util.timestamp.TimestampFormatter;
Expand Down Expand Up @@ -53,9 +53,9 @@ public void stringValue(String v) throws IOException, SQLException
}

@Override
public void timestampValue(Timestamp v) throws IOException, SQLException
public void timestampValue(final Instant v) throws IOException, SQLException
{
batch.setNString(timestampFormatter.format(v.getInstant()));
batch.setNString(timestampFormatter.format(v));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.io.IOException;
import java.sql.SQLException;
import java.time.Instant;

import org.embulk.spi.time.Timestamp;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.output.jdbc.BatchInsert;
import org.msgpack.value.Value;
Expand Down Expand Up @@ -42,7 +42,7 @@ public void stringValue(String v) throws IOException, SQLException
}

@Override
public void timestampValue(Timestamp v) throws IOException, SQLException
public void timestampValue(final Instant v) throws IOException, SQLException
{
defaultValue.setNull();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.util.Calendar;
import java.io.IOException;
import java.sql.SQLException;
import java.time.Instant;

import org.embulk.spi.time.Timestamp;
import org.embulk.output.jdbc.JdbcColumn;
import org.embulk.output.jdbc.BatchInsert;
import org.msgpack.value.Value;
Expand Down Expand Up @@ -53,7 +53,7 @@ public void stringValue(String v) throws IOException, SQLException
}

@Override
public void timestampValue(Timestamp v) throws IOException, SQLException
public void timestampValue(final Instant v) throws IOException, SQLException
{
batch.setSqlTimestamp(v, calendar);
}
Expand Down
Loading

0 comments on commit 7ea8fc6

Please sign in to comment.