mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-13 21:01:01 +08:00
Tests and fixes
This commit is contained in:
parent
ab37f52cf5
commit
d0e770d5db
@ -35,13 +35,12 @@ public class JSR310InstantType extends AbstractJSR310DateTimeType<Instant> {
|
||||
@Nullable
|
||||
@Override
|
||||
public Instant getValue(ResultSet rs, int startIndex) throws SQLException {
|
||||
Date date = rs.getDate(startIndex, utc());
|
||||
return date != null ? Instant.from(date.toInstant()) : null;
|
||||
Timestamp timestamp = rs.getTimestamp(startIndex, utc());
|
||||
return timestamp != null ? timestamp.toInstant() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(PreparedStatement st, int startIndex, Instant value) throws SQLException {
|
||||
java.util.Date from = Date.from(value);
|
||||
st.setDate(startIndex, new Date(from.getTime()), utc());
|
||||
st.setTimestamp(startIndex, new Timestamp(value.toEpochMilli()), utc());
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,13 +36,12 @@ public class JSR310LocalDateTimeType extends AbstractJSR310DateTimeType<LocalDat
|
||||
@Nullable
|
||||
@Override
|
||||
public LocalDateTime getValue(ResultSet rs, int startIndex) throws SQLException {
|
||||
Date date = rs.getDate(startIndex, utc());
|
||||
return date != null ? LocalDateTime.from(date.toInstant()) : null;
|
||||
Timestamp timestamp = rs.getTimestamp(startIndex, utc());
|
||||
return timestamp != null ? LocalDateTime.from(timestamp.toInstant()) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(PreparedStatement st, int startIndex, LocalDateTime value) throws SQLException {
|
||||
java.util.Date from = Date.from(value.toInstant(ZoneOffset.UTC));
|
||||
st.setDate(startIndex, new Date(from.getTime()), utc());
|
||||
st.setTimestamp(startIndex, new Timestamp(value.toInstant(ZoneOffset.UTC).toEpochMilli()), utc());
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,6 +42,6 @@ public class JSR310LocalTimeType extends AbstractJSR310DateTimeType<LocalTime> {
|
||||
|
||||
@Override
|
||||
public void setValue(PreparedStatement st, int startIndex, LocalTime value) throws SQLException {
|
||||
st.setTime(startIndex, new Time(value.toNanoOfDay() / 1000000), utc());
|
||||
st.setTime(startIndex, Time.valueOf(value), utc());
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package com.querydsl.sql.types;
|
||||
|
||||
import java.sql.*;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@ -36,13 +37,12 @@ public class JSR310OffsetDateTimeType extends AbstractJSR310DateTimeType<OffsetD
|
||||
@Nullable
|
||||
@Override
|
||||
public OffsetDateTime getValue(ResultSet rs, int startIndex) throws SQLException {
|
||||
Date date = rs.getDate(startIndex, utc());
|
||||
return date != null ? OffsetDateTime.from(date.toInstant()) : null;
|
||||
Timestamp timestamp = rs.getTimestamp(startIndex, utc());
|
||||
return timestamp != null ? OffsetDateTime.ofInstant(timestamp.toInstant(), ZoneOffset.UTC) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(PreparedStatement st, int startIndex, OffsetDateTime value) throws SQLException {
|
||||
java.util.Date from = Date.from(value.toInstant());
|
||||
st.setDate(startIndex, new Date(from.getTime()), utc());
|
||||
st.setTimestamp(startIndex, new Timestamp(value.toInstant().toEpochMilli()), utc());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.querydsl.sql.types;
|
||||
|
||||
import java.sql.*;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -36,13 +37,12 @@ public class JSR310ZonedDateTimeType extends AbstractJSR310DateTimeType<ZonedDat
|
||||
@Nullable
|
||||
@Override
|
||||
public ZonedDateTime getValue(ResultSet rs, int startIndex) throws SQLException {
|
||||
Date date = rs.getDate(startIndex, utc());
|
||||
return date != null ? ZonedDateTime.from(date.toInstant()) : null;
|
||||
Timestamp timestamp = rs.getTimestamp(startIndex, utc());
|
||||
return timestamp != null ? ZonedDateTime.ofInstant(timestamp.toInstant(), ZoneOffset.UTC) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(PreparedStatement st, int startIndex, ZonedDateTime value) throws SQLException {
|
||||
java.util.Date from = Date.from(value.toInstant());
|
||||
st.setDate(startIndex, new Date(from.getTime()), utc());
|
||||
st.setTimestamp(startIndex, new Timestamp(value.toInstant().toEpochMilli()), utc());
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
package com.querydsl.sql.types;
|
||||
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class JSR310InstantTypeTest {
|
||||
private static final Calendar UTC = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
private JSR310InstantType type = new JSR310InstantType();
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
UTC.setTimeInMillis(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Set() throws SQLException {
|
||||
Instant value = Instant.now();
|
||||
Timestamp ts = new Timestamp(value.toEpochMilli());
|
||||
|
||||
PreparedStatement stmt = EasyMock.createNiceMock(PreparedStatement.class);
|
||||
stmt.setTimestamp(0, ts, UTC);
|
||||
EasyMock.replay(stmt);
|
||||
|
||||
type.setValue(stmt, 0, value);
|
||||
EasyMock.verify(stmt);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
package com.querydsl.sql.types;
|
||||
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class JSR310LocalDateTimeTypeTest {
|
||||
|
||||
private static final Calendar UTC = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
private JSR310LocalDateTimeType type = new JSR310LocalDateTimeType();
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
UTC.setTimeInMillis(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Set() throws SQLException {
|
||||
LocalDateTime value = LocalDateTime.now();
|
||||
Timestamp ts = new Timestamp(value.toInstant(ZoneOffset.UTC).toEpochMilli());
|
||||
|
||||
PreparedStatement stmt = EasyMock.createNiceMock(PreparedStatement.class);
|
||||
stmt.setTimestamp(0, ts, UTC);
|
||||
EasyMock.replay(stmt);
|
||||
|
||||
type.setValue(stmt, 0, value);
|
||||
EasyMock.verify(stmt);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package com.querydsl.sql.types;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class JSR310LocalDateTypeTest {
|
||||
private static final Calendar UTC = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
private JSR310LocalDateType type = new JSR310LocalDateType();
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
UTC.setTimeInMillis(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Set() throws SQLException {
|
||||
LocalDate value = LocalDate.now();
|
||||
Date date = Date.valueOf(value);
|
||||
|
||||
PreparedStatement stmt = EasyMock.createNiceMock(PreparedStatement.class);
|
||||
stmt.setDate(0, date, UTC);
|
||||
EasyMock.replay(stmt);
|
||||
|
||||
type.setValue(stmt, 0, value);
|
||||
EasyMock.verify(stmt);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package com.querydsl.sql.types;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Time;
|
||||
import java.time.LocalTime;
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class JSR310LocalTimeTypeTest {
|
||||
private static final Calendar UTC = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
private JSR310LocalTimeType type = new JSR310LocalTimeType();
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
UTC.setTimeInMillis(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Set() throws SQLException {
|
||||
LocalTime value = LocalTime.now();
|
||||
Time time = Time.valueOf(value);
|
||||
|
||||
PreparedStatement stmt = EasyMock.createNiceMock(PreparedStatement.class);
|
||||
stmt.setTime(0, time, UTC);
|
||||
EasyMock.replay(stmt);
|
||||
|
||||
type.setValue(stmt, 0, value);
|
||||
EasyMock.verify(stmt);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
package com.querydsl.sql.types;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class JSR310OffsetDateTimeTypeTest {
|
||||
|
||||
private static final Calendar UTC = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
private JSR310OffsetDateTimeType type = new JSR310OffsetDateTimeType();
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
UTC.setTimeInMillis(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Set() throws SQLException {
|
||||
OffsetDateTime value = OffsetDateTime.now();
|
||||
Timestamp ts = new Timestamp(value.toInstant().toEpochMilli());
|
||||
|
||||
PreparedStatement stmt = EasyMock.createNiceMock(PreparedStatement.class);
|
||||
stmt.setTimestamp(0, ts, UTC);
|
||||
EasyMock.replay(stmt);
|
||||
|
||||
type.setValue(stmt, 0, value);
|
||||
EasyMock.verify(stmt);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
package com.querydsl.sql.types;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Time;
|
||||
import java.time.OffsetTime;
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class JSR310OffsetTimeTypeTest {
|
||||
|
||||
private static final Calendar UTC = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
private JSR310OffsetTimeType type = new JSR310OffsetTimeType();
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
UTC.setTimeInMillis(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Set() throws SQLException {
|
||||
OffsetTime value = OffsetTime.now();
|
||||
Time time = Time.valueOf(value.toLocalTime());
|
||||
|
||||
PreparedStatement stmt = EasyMock.createNiceMock(PreparedStatement.class);
|
||||
stmt.setTime(0, time, UTC);
|
||||
EasyMock.replay(stmt);
|
||||
|
||||
type.setValue(stmt, 0, value);
|
||||
EasyMock.verify(stmt);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
package com.querydsl.sql.types;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class JSR310ZonedDateTimeTypeTest {
|
||||
|
||||
private static final Calendar UTC = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
private JSR310ZonedDateTimeType type = new JSR310ZonedDateTimeType();
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
UTC.setTimeInMillis(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Set() throws SQLException {
|
||||
ZonedDateTime value = ZonedDateTime.now();
|
||||
Timestamp ts = new Timestamp(value.toInstant().toEpochMilli());
|
||||
|
||||
PreparedStatement stmt = EasyMock.createNiceMock(PreparedStatement.class);
|
||||
stmt.setTimestamp(0, ts, UTC);
|
||||
EasyMock.replay(stmt);
|
||||
|
||||
type.setValue(stmt, 0, value);
|
||||
EasyMock.verify(stmt);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user