提交 0875ef24 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Use class constants from LocalDateTimeUtils directly

上级 933f97cc
...@@ -3815,15 +3815,15 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS ...@@ -3815,15 +3815,15 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS
return type.cast(value.getObject()); return type.cast(value.getObject());
} else if (DataType.isGeometryClass(type)) { } else if (DataType.isGeometryClass(type)) {
return type.cast(value.getObject()); return type.cast(value.getObject());
} else if (LocalDateTimeUtils.isLocalDate(type)) { } else if (type == LocalDateTimeUtils.LOCAL_DATE) {
return type.cast(LocalDateTimeUtils.valueToLocalDate(value)); return type.cast(LocalDateTimeUtils.valueToLocalDate(value));
} else if (LocalDateTimeUtils.isLocalTime(type)) { } else if (type == LocalDateTimeUtils.LOCAL_TIME) {
return type.cast(LocalDateTimeUtils.valueToLocalTime(value)); return type.cast(LocalDateTimeUtils.valueToLocalTime(value));
} else if (LocalDateTimeUtils.isLocalDateTime(type)) { } else if (type == LocalDateTimeUtils.LOCAL_DATE_TIME) {
return type.cast(LocalDateTimeUtils.valueToLocalDateTime(value)); return type.cast(LocalDateTimeUtils.valueToLocalDateTime(value));
} else if (LocalDateTimeUtils.isInstant(type)) { } else if (type == LocalDateTimeUtils.INSTANT) {
return type.cast(LocalDateTimeUtils.valueToInstant(value)); return type.cast(LocalDateTimeUtils.valueToInstant(value));
} else if (LocalDateTimeUtils.isOffsetDateTime(type)) { } else if (type == LocalDateTimeUtils.OFFSET_DATE_TIME) {
return type.cast(LocalDateTimeUtils.valueToOffsetDateTime(value)); return type.cast(LocalDateTimeUtils.valueToOffsetDateTime(value));
} else { } else {
throw unsupported(type.getName()); throw unsupported(type.getName());
......
...@@ -40,16 +40,27 @@ import org.h2.value.ValueTimestampTimeZone; ...@@ -40,16 +40,27 @@ import org.h2.value.ValueTimestampTimeZone;
*/ */
public class LocalDateTimeUtils { public class LocalDateTimeUtils {
// Class<java.time.LocalDate> /**
private static final Class<?> LOCAL_DATE; * {@code Class<java.time.LocalDate>} or {@code null}.
// Class<java.time.LocalTime> */
private static final Class<?> LOCAL_TIME; public static final Class<?> LOCAL_DATE;
// Class<java.time.LocalDateTime> /**
private static final Class<?> LOCAL_DATE_TIME; * {@code Class<java.time.LocalTime>} or {@code null}.
// Class<java.time.Instant> */
private static final Class<?> INSTANT; public static final Class<?> LOCAL_TIME;
// Class<java.time.OffsetDateTime> /**
private static final Class<?> OFFSET_DATE_TIME; * {@code Class<java.time.LocalDateTime>} or {@code null}.
*/
public static final Class<?> LOCAL_DATE_TIME;
/**
* {@code Class<java.time.Instant>} or {@code null}.
*/
public static final Class<?> INSTANT;
/**
* {@code Class<java.time.OffsetDateTime>} or {@code null}.
*/
public static final Class<?> OFFSET_DATE_TIME;
// Class<java.time.ZoneOffset> // Class<java.time.ZoneOffset>
private static final Class<?> ZONE_OFFSET; private static final Class<?> ZONE_OFFSET;
...@@ -191,52 +202,6 @@ public class LocalDateTimeUtils { ...@@ -191,52 +202,6 @@ public class LocalDateTimeUtils {
return IS_JAVA8_DATE_API_PRESENT; return IS_JAVA8_DATE_API_PRESENT;
} }
/**
* Returns the class java.time.LocalDate.
*
* @return the class java.time.LocalDate, null on Java 7
*/
public static Class<?> getLocalDateClass() {
return LOCAL_DATE;
}
/**
* Returns the class java.time.LocalTime.
*
* @return the class java.time.LocalTime, null on Java 7
*/
public static Class<?> getLocalTimeClass() {
return LOCAL_TIME;
}
/**
* Returns the class java.time.LocalDateTime.
*
* @return the class java.time.LocalDateTime, null on Java 7
*/
public static Class<?> getLocalDateTimeClass() {
return LOCAL_DATE_TIME;
}
/**
* Returns the class java.time.Instant.
*
* @return the class java.time.Instant, null on Java 7
*/
public static Class<?> getInstantClass() {
return INSTANT;
}
/**
* Returns the class java.time.OffsetDateTime.
*
* @return the class java.time.OffsetDateTime, null on Java 7
*/
public static Class<?> getOffsetDateTimeClass() {
return OFFSET_DATE_TIME;
}
/** /**
* Parses an ISO date string into a java.time.LocalDate. * Parses an ISO date string into a java.time.LocalDate.
* *
...@@ -312,66 +277,6 @@ public class LocalDateTimeUtils { ...@@ -312,66 +277,6 @@ public class LocalDateTimeUtils {
} }
} }
/**
* Checks if the given class is LocalDate.
*
* <p>This method can be called from Java 7.</p>
*
* @param clazz the class to check
* @return if the class is LocalDate
*/
public static boolean isLocalDate(Class<?> clazz) {
return LOCAL_DATE == clazz;
}
/**
* Checks if the given class is LocalTime.
*
* <p>This method can be called from Java 7.</p>
*
* @param clazz the class to check
* @return if the class is LocalTime
*/
public static boolean isLocalTime(Class<?> clazz) {
return LOCAL_TIME == clazz;
}
/**
* Checks if the given class is LocalDateTime.
*
* <p>This method can be called from Java 7.</p>
*
* @param clazz the class to check
* @return if the class is LocalDateTime
*/
public static boolean isLocalDateTime(Class<?> clazz) {
return LOCAL_DATE_TIME == clazz;
}
/**
* Checks if the given class is Instant.
*
* <p>This method can be called from Java 7.</p>
*
* @param clazz the class to check
* @return if the class is Instant
*/
public static boolean isInstant(Class<?> clazz) {
return INSTANT == clazz;
}
/**
* Checks if the given class is OffsetDateTime.
*
* <p>This method can be called from Java 7.</p>
*
* @param clazz the class to check
* @return if the class is OffsetDateTime
*/
public static boolean isOffsetDateTime(Class<?> clazz) {
return OFFSET_DATE_TIME == clazz;
}
/** /**
* Converts a value to a LocalDate. * Converts a value to a LocalDate.
* *
......
...@@ -1016,13 +1016,13 @@ public class DataType { ...@@ -1016,13 +1016,13 @@ public class DataType {
return Value.ARRAY; return Value.ARRAY;
} else if (isGeometryClass(x)) { } else if (isGeometryClass(x)) {
return Value.GEOMETRY; return Value.GEOMETRY;
} else if (LocalDateTimeUtils.isLocalDate(x)) { } else if (LocalDateTimeUtils.LOCAL_DATE == x) {
return Value.DATE; return Value.DATE;
} else if (LocalDateTimeUtils.isLocalTime(x)) { } else if (LocalDateTimeUtils.LOCAL_TIME == x) {
return Value.TIME; return Value.TIME;
} else if (LocalDateTimeUtils.isLocalDateTime(x)) { } else if (LocalDateTimeUtils.LOCAL_DATE_TIME == x) {
return Value.TIMESTAMP; return Value.TIMESTAMP;
} else if (LocalDateTimeUtils.isOffsetDateTime(x)) { } else if (LocalDateTimeUtils.OFFSET_DATE_TIME == x) {
return Value.TIMESTAMP_TZ; return Value.TIMESTAMP_TZ;
} else { } else {
if (JdbcUtils.customDataTypesHandler != null) { if (JdbcUtils.customDataTypesHandler != null) {
...@@ -1141,15 +1141,15 @@ public class DataType { ...@@ -1141,15 +1141,15 @@ public class DataType {
return ValueStringFixed.get(((Character) x).toString()); return ValueStringFixed.get(((Character) x).toString());
} else if (isGeometry(x)) { } else if (isGeometry(x)) {
return ValueGeometry.getFromGeometry(x); return ValueGeometry.getFromGeometry(x);
} else if (LocalDateTimeUtils.isLocalDate(x.getClass())) { } else if (x.getClass() == LocalDateTimeUtils.LOCAL_DATE) {
return LocalDateTimeUtils.localDateToDateValue(x); return LocalDateTimeUtils.localDateToDateValue(x);
} else if (LocalDateTimeUtils.isLocalTime(x.getClass())) { } else if (x.getClass() == LocalDateTimeUtils.LOCAL_TIME) {
return LocalDateTimeUtils.localTimeToTimeValue(x); return LocalDateTimeUtils.localTimeToTimeValue(x);
} else if (LocalDateTimeUtils.isLocalDateTime(x.getClass())) { } else if (x.getClass() == LocalDateTimeUtils.LOCAL_DATE_TIME) {
return LocalDateTimeUtils.localDateTimeToValue(x); return LocalDateTimeUtils.localDateTimeToValue(x);
} else if (LocalDateTimeUtils.isInstant(x.getClass())) { } else if (x.getClass() == LocalDateTimeUtils.INSTANT) {
return LocalDateTimeUtils.instantToValue(x); return LocalDateTimeUtils.instantToValue(x);
} else if (LocalDateTimeUtils.isOffsetDateTime(x.getClass())) { } else if (x.getClass() == LocalDateTimeUtils.OFFSET_DATE_TIME) {
return LocalDateTimeUtils.offsetDateTimeToValue(x); return LocalDateTimeUtils.offsetDateTimeToValue(x);
} else if (x instanceof TimestampWithTimeZone) { } else if (x instanceof TimestampWithTimeZone) {
return ValueTimestampTimeZone.get((TimestampWithTimeZone) x); return ValueTimestampTimeZone.get((TimestampWithTimeZone) x);
......
...@@ -177,7 +177,7 @@ public class TestCallableStatement extends TestBase { ...@@ -177,7 +177,7 @@ public class TestCallableStatement extends TestBase {
assertEquals("2000-01-01", call.getDate(1).toString()); assertEquals("2000-01-01", call.getDate(1).toString());
if (LocalDateTimeUtils.isJava8DateApiPresent()) { if (LocalDateTimeUtils.isJava8DateApiPresent()) {
assertEquals("2000-01-01", call.getObject(1, assertEquals("2000-01-01", call.getObject(1,
LocalDateTimeUtils.getLocalDateClass()).toString()); LocalDateTimeUtils.LOCAL_DATE).toString());
} }
call.setTime(2, java.sql.Time.valueOf("01:02:03")); call.setTime(2, java.sql.Time.valueOf("01:02:03"));
...@@ -186,7 +186,7 @@ public class TestCallableStatement extends TestBase { ...@@ -186,7 +186,7 @@ public class TestCallableStatement extends TestBase {
assertEquals("01:02:03", call.getTime(1).toString()); assertEquals("01:02:03", call.getTime(1).toString());
if (LocalDateTimeUtils.isJava8DateApiPresent()) { if (LocalDateTimeUtils.isJava8DateApiPresent()) {
assertEquals("01:02:03", call.getObject(1, assertEquals("01:02:03", call.getObject(1,
LocalDateTimeUtils.getLocalTimeClass()).toString()); LocalDateTimeUtils.LOCAL_TIME).toString());
} }
call.setTimestamp(2, java.sql.Timestamp.valueOf( call.setTimestamp(2, java.sql.Timestamp.valueOf(
...@@ -196,7 +196,7 @@ public class TestCallableStatement extends TestBase { ...@@ -196,7 +196,7 @@ public class TestCallableStatement extends TestBase {
assertEquals("2001-02-03 04:05:06.789", call.getTimestamp(1).toString()); assertEquals("2001-02-03 04:05:06.789", call.getTimestamp(1).toString());
if (LocalDateTimeUtils.isJava8DateApiPresent()) { if (LocalDateTimeUtils.isJava8DateApiPresent()) {
assertEquals("2001-02-03T04:05:06.789", call.getObject(1, assertEquals("2001-02-03T04:05:06.789", call.getObject(1,
LocalDateTimeUtils.getLocalDateTimeClass()).toString()); LocalDateTimeUtils.LOCAL_DATE_TIME).toString());
} }
call.setBoolean(2, true); call.setBoolean(2, true);
...@@ -283,25 +283,25 @@ public class TestCallableStatement extends TestBase { ...@@ -283,25 +283,25 @@ public class TestCallableStatement extends TestBase {
assertEquals("2001-02-03 10:20:30.0", call.getTimestamp("D").toString()); assertEquals("2001-02-03 10:20:30.0", call.getTimestamp("D").toString());
if (LocalDateTimeUtils.isJava8DateApiPresent()) { if (LocalDateTimeUtils.isJava8DateApiPresent()) {
assertEquals("2001-02-03T10:20:30", call.getObject(4, assertEquals("2001-02-03T10:20:30", call.getObject(4,
LocalDateTimeUtils.getLocalDateTimeClass()).toString()); LocalDateTimeUtils.LOCAL_DATE_TIME).toString());
assertEquals("2001-02-03T10:20:30", call.getObject("D", assertEquals("2001-02-03T10:20:30", call.getObject("D",
LocalDateTimeUtils.getLocalDateTimeClass()).toString()); LocalDateTimeUtils.LOCAL_DATE_TIME).toString());
} }
assertEquals("10:20:30", call.getTime(4).toString()); assertEquals("10:20:30", call.getTime(4).toString());
assertEquals("10:20:30", call.getTime("D").toString()); assertEquals("10:20:30", call.getTime("D").toString());
if (LocalDateTimeUtils.isJava8DateApiPresent()) { if (LocalDateTimeUtils.isJava8DateApiPresent()) {
assertEquals("10:20:30", call.getObject(4, assertEquals("10:20:30", call.getObject(4,
LocalDateTimeUtils.getLocalTimeClass()).toString()); LocalDateTimeUtils.LOCAL_TIME).toString());
assertEquals("10:20:30", call.getObject("D", assertEquals("10:20:30", call.getObject("D",
LocalDateTimeUtils.getLocalTimeClass()).toString()); LocalDateTimeUtils.LOCAL_TIME).toString());
} }
assertEquals("2001-02-03", call.getDate(4).toString()); assertEquals("2001-02-03", call.getDate(4).toString());
assertEquals("2001-02-03", call.getDate("D").toString()); assertEquals("2001-02-03", call.getDate("D").toString());
if (LocalDateTimeUtils.isJava8DateApiPresent()) { if (LocalDateTimeUtils.isJava8DateApiPresent()) {
assertEquals("2001-02-03", call.getObject(4, assertEquals("2001-02-03", call.getObject(4,
LocalDateTimeUtils.getLocalDateClass()).toString()); LocalDateTimeUtils.LOCAL_DATE).toString());
assertEquals("2001-02-03", call.getObject("D", assertEquals("2001-02-03", call.getObject("D",
LocalDateTimeUtils.getLocalDateClass()).toString()); LocalDateTimeUtils.LOCAL_DATE).toString());
} }
assertEquals(100, call.getInt(1)); assertEquals(100, call.getInt(1));
......
...@@ -634,14 +634,14 @@ public class TestPreparedStatement extends TestBase { ...@@ -634,14 +634,14 @@ public class TestPreparedStatement extends TestBase {
prep.setObject(1, localDate); prep.setObject(1, localDate);
ResultSet rs = prep.executeQuery(); ResultSet rs = prep.executeQuery();
rs.next(); rs.next();
Object localDate2 = rs.getObject(1, LocalDateTimeUtils.getLocalDateClass()); Object localDate2 = rs.getObject(1, LocalDateTimeUtils.LOCAL_DATE);
assertEquals(localDate, localDate2); assertEquals(localDate, localDate2);
rs.close(); rs.close();
localDate = LocalDateTimeUtils.parseLocalDate("-0509-01-01"); localDate = LocalDateTimeUtils.parseLocalDate("-0509-01-01");
prep.setObject(1, localDate); prep.setObject(1, localDate);
rs = prep.executeQuery(); rs = prep.executeQuery();
rs.next(); rs.next();
localDate2 = rs.getObject(1, LocalDateTimeUtils.getLocalDateClass()); localDate2 = rs.getObject(1, LocalDateTimeUtils.LOCAL_DATE);
assertEquals(localDate, localDate2); assertEquals(localDate, localDate2);
rs.close(); rs.close();
} }
...@@ -655,14 +655,14 @@ public class TestPreparedStatement extends TestBase { ...@@ -655,14 +655,14 @@ public class TestPreparedStatement extends TestBase {
prep.setObject(1, localTime); prep.setObject(1, localTime);
ResultSet rs = prep.executeQuery(); ResultSet rs = prep.executeQuery();
rs.next(); rs.next();
Object localTime2 = rs.getObject(1, LocalDateTimeUtils.getLocalTimeClass()); Object localTime2 = rs.getObject(1, LocalDateTimeUtils.LOCAL_TIME);
assertEquals(localTime, localTime2); assertEquals(localTime, localTime2);
rs.close(); rs.close();
localTime = LocalDateTimeUtils.parseLocalTime("04:05:06.123456789"); localTime = LocalDateTimeUtils.parseLocalTime("04:05:06.123456789");
prep.setObject(1, localTime); prep.setObject(1, localTime);
rs = prep.executeQuery(); rs = prep.executeQuery();
rs.next(); rs.next();
localTime2 = rs.getObject(1, LocalDateTimeUtils.getLocalTimeClass()); localTime2 = rs.getObject(1, LocalDateTimeUtils.LOCAL_TIME);
assertEquals(localTime, localTime2); assertEquals(localTime, localTime2);
rs.close(); rs.close();
} }
...@@ -676,7 +676,7 @@ public class TestPreparedStatement extends TestBase { ...@@ -676,7 +676,7 @@ public class TestPreparedStatement extends TestBase {
prep.setObject(1, localDateTime); prep.setObject(1, localDateTime);
ResultSet rs = prep.executeQuery(); ResultSet rs = prep.executeQuery();
rs.next(); rs.next();
Object localDateTime2 = rs.getObject(1, LocalDateTimeUtils.getLocalDateTimeClass()); Object localDateTime2 = rs.getObject(1, LocalDateTimeUtils.LOCAL_DATE_TIME);
assertEquals(localDateTime, localDateTime2); assertEquals(localDateTime, localDateTime2);
rs.close(); rs.close();
} }
...@@ -691,7 +691,7 @@ public class TestPreparedStatement extends TestBase { ...@@ -691,7 +691,7 @@ public class TestPreparedStatement extends TestBase {
prep.setObject(1, offsetDateTime); prep.setObject(1, offsetDateTime);
ResultSet rs = prep.executeQuery(); ResultSet rs = prep.executeQuery();
rs.next(); rs.next();
Object offsetDateTime2 = rs.getObject(1, LocalDateTimeUtils.getOffsetDateTimeClass()); Object offsetDateTime2 = rs.getObject(1, LocalDateTimeUtils.OFFSET_DATE_TIME);
assertEquals(offsetDateTime, offsetDateTime2); assertEquals(offsetDateTime, offsetDateTime2);
assertFalse(rs.next()); assertFalse(rs.next());
rs.close(); rs.close();
...@@ -699,7 +699,7 @@ public class TestPreparedStatement extends TestBase { ...@@ -699,7 +699,7 @@ public class TestPreparedStatement extends TestBase {
prep.setObject(1, offsetDateTime, 2014); // Types.TIMESTAMP_WITH_TIMEZONE prep.setObject(1, offsetDateTime, 2014); // Types.TIMESTAMP_WITH_TIMEZONE
rs = prep.executeQuery(); rs = prep.executeQuery();
rs.next(); rs.next();
offsetDateTime2 = rs.getObject(1, LocalDateTimeUtils.getOffsetDateTimeClass()); offsetDateTime2 = rs.getObject(1, LocalDateTimeUtils.OFFSET_DATE_TIME);
assertEquals(offsetDateTime, offsetDateTime2); assertEquals(offsetDateTime, offsetDateTime2);
assertFalse(rs.next()); assertFalse(rs.next());
rs.close(); rs.close();
...@@ -710,14 +710,14 @@ public class TestPreparedStatement extends TestBase { ...@@ -710,14 +710,14 @@ public class TestPreparedStatement extends TestBase {
return; return;
} }
Method timestampToInstant = Timestamp.class.getMethod("toInstant"), Method timestampToInstant = Timestamp.class.getMethod("toInstant"),
now = LocalDateTimeUtils.getInstantClass().getMethod("now"); now = LocalDateTimeUtils.INSTANT.getMethod("now");
PreparedStatement prep = conn.prepareStatement("SELECT ?"); PreparedStatement prep = conn.prepareStatement("SELECT ?");
Object instant1 = now.invoke(null); Object instant1 = now.invoke(null);
prep.setObject(1, instant1); prep.setObject(1, instant1);
ResultSet rs = prep.executeQuery(); ResultSet rs = prep.executeQuery();
rs.next(); rs.next();
Object instant2 = rs.getObject(1, LocalDateTimeUtils.getInstantClass()); Object instant2 = rs.getObject(1, LocalDateTimeUtils.INSTANT);
assertEquals(instant1, instant2); assertEquals(instant1, instant2);
Timestamp ts = rs.getTimestamp(1); Timestamp ts = rs.getTimestamp(1);
assertEquals(instant1, timestampToInstant.invoke(ts)); assertEquals(instant1, timestampToInstant.invoke(ts));
...@@ -727,7 +727,7 @@ public class TestPreparedStatement extends TestBase { ...@@ -727,7 +727,7 @@ public class TestPreparedStatement extends TestBase {
prep.setTimestamp(1, ts); prep.setTimestamp(1, ts);
rs = prep.executeQuery(); rs = prep.executeQuery();
rs.next(); rs.next();
instant2 = rs.getObject(1, LocalDateTimeUtils.getInstantClass()); instant2 = rs.getObject(1, LocalDateTimeUtils.INSTANT);
assertEquals(instant1, instant2); assertEquals(instant1, instant2);
assertFalse(rs.next()); assertFalse(rs.next());
rs.close(); rs.close();
......
...@@ -1350,34 +1350,34 @@ public class TestResultSet extends TestBase { ...@@ -1350,34 +1350,34 @@ public class TestResultSet extends TestBase {
assertEquals("1800-01-01", rs.getDate("value").toString()); assertEquals("1800-01-01", rs.getDate("value").toString());
if (LocalDateTimeUtils.isJava8DateApiPresent()) { if (LocalDateTimeUtils.isJava8DateApiPresent()) {
assertEquals("1800-01-01", rs.getObject("value", assertEquals("1800-01-01", rs.getObject("value",
LocalDateTimeUtils.getLocalDateClass()).toString()); LocalDateTimeUtils.LOCAL_DATE).toString());
} }
assertEquals("00:00:00", rs.getTime("value").toString()); assertEquals("00:00:00", rs.getTime("value").toString());
if (LocalDateTimeUtils.isJava8DateApiPresent()) { if (LocalDateTimeUtils.isJava8DateApiPresent()) {
assertEquals("00:00", rs.getObject("value", assertEquals("00:00", rs.getObject("value",
LocalDateTimeUtils.getLocalTimeClass()).toString()); LocalDateTimeUtils.LOCAL_TIME).toString());
} }
assertEquals("1800-01-01 00:00:00.0", rs.getTimestamp("value").toString()); assertEquals("1800-01-01 00:00:00.0", rs.getTimestamp("value").toString());
if (LocalDateTimeUtils.isJava8DateApiPresent()) { if (LocalDateTimeUtils.isJava8DateApiPresent()) {
assertEquals("1800-01-01T00:00", rs.getObject("value", assertEquals("1800-01-01T00:00", rs.getObject("value",
LocalDateTimeUtils.getLocalDateTimeClass()).toString()); LocalDateTimeUtils.LOCAL_DATE_TIME).toString());
} }
rs.next(); rs.next();
assertEquals("9999-12-31", rs.getDate("Value").toString()); assertEquals("9999-12-31", rs.getDate("Value").toString());
if (LocalDateTimeUtils.isJava8DateApiPresent()) { if (LocalDateTimeUtils.isJava8DateApiPresent()) {
assertEquals("9999-12-31", rs.getObject("Value", assertEquals("9999-12-31", rs.getObject("Value",
LocalDateTimeUtils.getLocalDateClass()).toString()); LocalDateTimeUtils.LOCAL_DATE).toString());
} }
assertEquals("23:59:59", rs.getTime("Value").toString()); assertEquals("23:59:59", rs.getTime("Value").toString());
if (LocalDateTimeUtils.isJava8DateApiPresent()) { if (LocalDateTimeUtils.isJava8DateApiPresent()) {
assertEquals("23:59:59", rs.getObject("Value", assertEquals("23:59:59", rs.getObject("Value",
LocalDateTimeUtils.getLocalTimeClass()).toString()); LocalDateTimeUtils.LOCAL_TIME).toString());
} }
assertEquals("9999-12-31 23:59:59.0", rs.getTimestamp("Value").toString()); assertEquals("9999-12-31 23:59:59.0", rs.getTimestamp("Value").toString());
if (LocalDateTimeUtils.isJava8DateApiPresent()) { if (LocalDateTimeUtils.isJava8DateApiPresent()) {
assertEquals("9999-12-31T23:59:59", rs.getObject("Value", assertEquals("9999-12-31T23:59:59", rs.getObject("Value",
LocalDateTimeUtils.getLocalDateTimeClass()).toString()); LocalDateTimeUtils.LOCAL_DATE_TIME).toString());
} }
rs.next(); rs.next();
...@@ -1386,7 +1386,7 @@ public class TestResultSet extends TestBase { ...@@ -1386,7 +1386,7 @@ public class TestResultSet extends TestBase {
assertTrue(rs.getTimestamp(2) == null && rs.wasNull()); assertTrue(rs.getTimestamp(2) == null && rs.wasNull());
if (LocalDateTimeUtils.isJava8DateApiPresent()) { if (LocalDateTimeUtils.isJava8DateApiPresent()) {
assertTrue(rs.getObject(2, assertTrue(rs.getObject(2,
LocalDateTimeUtils.getLocalDateTimeClass()) == null && rs.wasNull()); LocalDateTimeUtils.LOCAL_DATE_TIME) == null && rs.wasNull());
} }
assertTrue(!rs.next()); assertTrue(!rs.next());
...@@ -1409,15 +1409,15 @@ public class TestResultSet extends TestBase { ...@@ -1409,15 +1409,15 @@ public class TestResultSet extends TestBase {
assertEquals("2007-08-09 10:11:12.141516171", ts.toString()); assertEquals("2007-08-09 10:11:12.141516171", ts.toString());
if (LocalDateTimeUtils.isJava8DateApiPresent()) { if (LocalDateTimeUtils.isJava8DateApiPresent()) {
assertEquals("2001-02-03", rs.getObject(1, assertEquals("2001-02-03", rs.getObject(1,
LocalDateTimeUtils.getLocalDateClass()).toString()); LocalDateTimeUtils.LOCAL_DATE).toString());
} }
if (LocalDateTimeUtils.isJava8DateApiPresent()) { if (LocalDateTimeUtils.isJava8DateApiPresent()) {
assertEquals("14:15:16", rs.getObject(2, assertEquals("14:15:16", rs.getObject(2,
LocalDateTimeUtils.getLocalTimeClass()).toString()); LocalDateTimeUtils.LOCAL_TIME).toString());
} }
if (LocalDateTimeUtils.isJava8DateApiPresent()) { if (LocalDateTimeUtils.isJava8DateApiPresent()) {
assertEquals("2007-08-09T10:11:12.141516171", assertEquals("2007-08-09T10:11:12.141516171",
rs.getObject(3, LocalDateTimeUtils.getLocalDateTimeClass()) rs.getObject(3, LocalDateTimeUtils.LOCAL_DATE_TIME)
.toString()); .toString());
} }
......
...@@ -65,7 +65,7 @@ public class TestTimeStampWithTimeZone extends TestBase { ...@@ -65,7 +65,7 @@ public class TestTimeStampWithTimeZone extends TestBase {
assertEquals(new TimestampWithTimeZone(1008673L, 43200000000000L, (short) 15), ts); assertEquals(new TimestampWithTimeZone(1008673L, 43200000000000L, (short) 15), ts);
if (LocalDateTimeUtils.isJava8DateApiPresent()) { if (LocalDateTimeUtils.isJava8DateApiPresent()) {
assertEquals("1970-01-01T12:00+00:15", rs.getObject(1, assertEquals("1970-01-01T12:00+00:15", rs.getObject(1,
LocalDateTimeUtils.getOffsetDateTimeClass()).toString()); LocalDateTimeUtils.OFFSET_DATE_TIME).toString());
} }
rs.next(); rs.next();
ts = (TimestampWithTimeZone) rs.getObject(1); ts = (TimestampWithTimeZone) rs.getObject(1);
...@@ -76,7 +76,7 @@ public class TestTimeStampWithTimeZone extends TestBase { ...@@ -76,7 +76,7 @@ public class TestTimeStampWithTimeZone extends TestBase {
assertEquals(1L, ts.getNanosSinceMidnight()); assertEquals(1L, ts.getNanosSinceMidnight());
if (LocalDateTimeUtils.isJava8DateApiPresent()) { if (LocalDateTimeUtils.isJava8DateApiPresent()) {
assertEquals("2016-09-24T00:00:00.000000001+00:01", rs.getObject(1, assertEquals("2016-09-24T00:00:00.000000001+00:01", rs.getObject(1,
LocalDateTimeUtils.getOffsetDateTimeClass()).toString()); LocalDateTimeUtils.OFFSET_DATE_TIME).toString());
} }
rs.next(); rs.next();
ts = (TimestampWithTimeZone) rs.getObject(1); ts = (TimestampWithTimeZone) rs.getObject(1);
...@@ -87,7 +87,7 @@ public class TestTimeStampWithTimeZone extends TestBase { ...@@ -87,7 +87,7 @@ public class TestTimeStampWithTimeZone extends TestBase {
assertEquals(1L, ts.getNanosSinceMidnight()); assertEquals(1L, ts.getNanosSinceMidnight());
if (LocalDateTimeUtils.isJava8DateApiPresent()) { if (LocalDateTimeUtils.isJava8DateApiPresent()) {
assertEquals("2016-09-24T00:00:00.000000001-00:01", rs.getObject(1, assertEquals("2016-09-24T00:00:00.000000001-00:01", rs.getObject(1,
LocalDateTimeUtils.getOffsetDateTimeClass()).toString()); LocalDateTimeUtils.OFFSET_DATE_TIME).toString());
} }
rs.next(); rs.next();
ts = (TimestampWithTimeZone) rs.getObject(1); ts = (TimestampWithTimeZone) rs.getObject(1);
...@@ -96,7 +96,7 @@ public class TestTimeStampWithTimeZone extends TestBase { ...@@ -96,7 +96,7 @@ public class TestTimeStampWithTimeZone extends TestBase {
assertEquals(1, ts.getDay()); assertEquals(1, ts.getDay());
if (LocalDateTimeUtils.isJava8DateApiPresent()) { if (LocalDateTimeUtils.isJava8DateApiPresent()) {
assertEquals("2016-01-01T05:00+10:00", rs.getObject(1, assertEquals("2016-01-01T05:00+10:00", rs.getObject(1,
LocalDateTimeUtils.getOffsetDateTimeClass()).toString()); LocalDateTimeUtils.OFFSET_DATE_TIME).toString());
} }
rs.next(); rs.next();
ts = (TimestampWithTimeZone) rs.getObject(1); ts = (TimestampWithTimeZone) rs.getObject(1);
...@@ -105,7 +105,7 @@ public class TestTimeStampWithTimeZone extends TestBase { ...@@ -105,7 +105,7 @@ public class TestTimeStampWithTimeZone extends TestBase {
assertEquals(31, ts.getDay()); assertEquals(31, ts.getDay());
if (LocalDateTimeUtils.isJava8DateApiPresent()) { if (LocalDateTimeUtils.isJava8DateApiPresent()) {
assertEquals("2015-12-31T19:00-10:00", rs.getObject(1, assertEquals("2015-12-31T19:00-10:00", rs.getObject(1,
LocalDateTimeUtils.getOffsetDateTimeClass()).toString()); LocalDateTimeUtils.OFFSET_DATE_TIME).toString());
} }
ResultSetMetaData metaData = rs.getMetaData(); ResultSetMetaData metaData = rs.getMetaData();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论