@Override public LocalTime convertToMapped(Class<? extends LocalTime> type, java.sql.Time value) { if (value == null) { return null; } return value.toLocalTime(); } }
@Override public LocalTime toJavaType(Column column, Class<?> entityType, Time value) { return value.toLocalTime(); }
private static LocalTime getLocalTime(ResultSet r, int i) throws SQLException { Time time = r.getTime(i); return time == null ? null : time.toLocalTime(); }
@Override public LocalTime convertToEntityAttribute(Time time) { return time == null ? null : time.toLocalTime(); } }
/** * Get the ISO 8601 formatted representation of the given {@link java.sql.Time}, which contains time but no date or timezone * information. * * @param time the JDBC time value; may not be null * @param zoneId the timezone identifier or offset where the time is defined * @param adjuster the optional component that adjusts the local date value before obtaining the epoch day; may be null if no * adjustment is necessary * @return the ISO 8601 formatted string */ public static String toIsoString(java.sql.Time time, ZoneId zoneId, TemporalAdjuster adjuster) { LocalTime localTime = time.toLocalTime(); if (adjuster != null) { localTime = localTime.with(adjuster); } ZonedDateTime zdt = ZonedDateTime.of(Conversions.EPOCH, localTime, zoneId); return zdt.format(FORMATTER); }
/** * Get the ISO 8601 formatted representation of the given {@link java.sql.Time}, which contains time but no date or timezone * information. * * @param time the JDBC time value * @param zoneId the timezone identifier or offset where the time is defined * @param adjuster the optional component that adjusts the local date value before obtaining the epoch day; may be null if no * adjustment is necessary * @return the ISO 8601 formatted string */ public static String toIsoString(java.sql.Time time, ZoneId zoneId, TemporalAdjuster adjuster) { LocalTime localTime = time.toLocalTime(); if (adjuster != null) { localTime = localTime.with(adjuster); } ZonedDateTime zdt = ZonedDateTime.of(Conversions.EPOCH, localTime, zoneId); return zdt.format(FORMATTER); }
return ( (Time) value ).toLocalTime().atOffset( OffsetDateTime.now().getOffset() );
@Test public void testLocallyUnrepresentableTimeLiterals() { LocalDateTime localTimeThatDidNotExist = LocalDateTime.of(2017, 4, 2, 2, 10); checkState(ZoneId.systemDefault().getRules().getValidOffsets(localTimeThatDidNotExist).isEmpty(), "This test assumes certain JVM time zone"); // This tests that both Presto runner and H2 can return TIMESTAMP value that never happened in JVM's zone (e.g. is not representable using java.sql.Timestamp) @Language("SQL") String sql = DateTimeFormatter.ofPattern("'SELECT TIMESTAMP '''uuuu-MM-dd HH:mm:ss''").format(localTimeThatDidNotExist); assertEquals(computeScalar(sql), localTimeThatDidNotExist); // this tests Presto and the QueryRunner assertQuery(sql); // this tests H2QueryRunner LocalDate localDateThatDidNotHaveMidnight = LocalDate.of(1970, 1, 1); checkState(ZoneId.systemDefault().getRules().getValidOffsets(localDateThatDidNotHaveMidnight.atStartOfDay()).isEmpty(), "This test assumes certain JVM time zone"); // This tests that both Presto runner and H2 can return DATE value for a day which midnight never happened in JVM's zone (e.g. is not exactly representable using java.sql.Date) sql = DateTimeFormatter.ofPattern("'SELECT DATE '''uuuu-MM-dd''").format(localDateThatDidNotHaveMidnight); assertEquals(computeScalar(sql), localDateThatDidNotHaveMidnight); // this tests Presto and the QueryRunner assertQuery(sql); // this tests H2QueryRunner LocalTime localTimeThatDidNotOccurOn19700101 = LocalTime.of(0, 10); checkState(ZoneId.systemDefault().getRules().getValidOffsets(localTimeThatDidNotOccurOn19700101.atDate(LocalDate.ofEpochDay(0))).isEmpty(), "This test assumes certain JVM time zone"); checkState(!Objects.equals(java.sql.Time.valueOf(localTimeThatDidNotOccurOn19700101).toLocalTime(), localTimeThatDidNotOccurOn19700101), "This test assumes certain JVM time zone"); sql = DateTimeFormatter.ofPattern("'SELECT TIME '''HH:mm:ss''").format(localTimeThatDidNotOccurOn19700101); assertEquals(computeScalar(sql), localTimeThatDidNotOccurOn19700101); // this tests Presto and the QueryRunner assertQuery(sql); // this tests H2QueryRunner } }
} else if ( obj instanceof java.sql.Time ){ java.sql.Time time = (java.sql.Time)obj; append(DateTimeFormatter.ISO_LOCAL_TIME.format(time.toLocalTime())); } else if ( obj instanceof java.sql.Date ){ java.sql.Date date = (java.sql.Date)obj;
private static LocalTime getLocalTime(Time time) { if (time != null) { return time.toLocalTime(); } return null; } }
LocalTime localTime = Time.valueOf("00:00:00").toLocalTime(); java.util.Date date = new java.util.Date(Timestamp.toEpochMillis(localTime, MySqlValueConverters::adjustTemporal)); assertThat(schemaG.defaultValue()).isEqualTo(date);
@Override public LocalTime read(DataReader dataReader) throws SQLException { Time time = dataReader.getTime(); return (time == null) ? null : time.toLocalTime(); }
@Override public LocalTime toBeanType(Object value) { if (value instanceof LocalTime) return (LocalTime) value; if (value == null) return null; return BasicTypeConverter.toTime(value).toLocalTime(); }
case TIME: Time time = resultSet.getTime(columnIndex); object = time != null ? time.toLocalTime() : null; break; case BINARY:
return ((java.sql.Time)value).toLocalTime();
@Test public void testLoadJdbcSelect() throws Exception { testCall(db, "CALL apoc.load.jdbc('jdbc:derby:derbyDB','SELECT * FROM PERSON')", (row) -> assertEquals( Util.map("NAME", "John", "HIRE_DATE", hireDate.toLocalDate(),"EFFECTIVE_FROM_DATE", effectiveFromDate.toLocalDateTime(), "TEST_TIME", time.toLocalTime(), "NULL_DATE", null), row.get("row"))); } @Test
@Test public void testLoadJdbc() throws Exception { testCall(db, "CALL apoc.load.jdbc('jdbc:derby:derbyDB','PERSON')", (row) -> assertEquals( Util.map("NAME", "John", "HIRE_DATE", hireDate.toLocalDate(), "EFFECTIVE_FROM_DATE", effectiveFromDate.toLocalDateTime(), "TEST_TIME", time.toLocalTime(), "NULL_DATE", null), row.get("row"))); }
@Test public void testLoadJdbcParams() throws Exception { testCall(db, "CALL apoc.load.jdbc('jdbc:derby:derbyDB','SELECT * FROM PERSON WHERE NAME = ?',['John'])", // YIELD row RETURN row (row) -> assertEquals( Util.map("NAME", "John", "HIRE_DATE", hireDate.toLocalDate(), "EFFECTIVE_FROM_DATE", effectiveFromDate.toLocalDateTime(), "TEST_TIME", time.toLocalTime(), "NULL_DATE", null), row.get("row"))); }
@Test public void testLoadJdbcKey() throws Exception { testCall(db, "CALL apoc.load.jdbc('derby','PERSON')", (row) -> assertEquals( Util.map("NAME", "John", "HIRE_DATE", hireDate.toLocalDate(), "EFFECTIVE_FROM_DATE", effectiveFromDate.toLocalDateTime(), "TEST_TIME", time.toLocalTime(), "NULL_DATE", null), row.get("row"))); }
@Test public void testLoadJdbcParamsWithConfigLocalDateTime() throws Exception { testCall(db, "CALL apoc.load.jdbc('jdbc:derby:derbyDB','SELECT * FROM PERSON WHERE NAME = ?',['John'])", (row) -> assertEquals( Util.map("NAME", "John", "HIRE_DATE", hireDate.toLocalDate(), "EFFECTIVE_FROM_DATE", effectiveFromDate.toLocalDateTime(), "TEST_TIME", time.toLocalTime(), "NULL_DATE", null), row.get("row"))); ZoneId asiaTokio = ZoneId.of("Asia/Tokyo"); testCall(db, "CALL apoc.load.jdbc('jdbc:derby:derbyDB','SELECT * FROM PERSON WHERE NAME = ?',['John'], {config})", map("config", map("timezone", asiaTokio.toString())), (row) -> { assertEquals( Util.map("NAME", "John", "HIRE_DATE", hireDate.toLocalDate(), "EFFECTIVE_FROM_DATE", effectiveFromDate.toInstant().atZone(asiaTokio).toOffsetDateTime(), "TEST_TIME", time.toLocalTime(), "NULL_DATE", null), row.get("row")); }); }