@Override public LocalDate convertToMapped(Class<? extends LocalDate> type, java.sql.Date value) { if (value == null) { return null; } return value.toLocalDate(); } }
@Override public LocalDate toJavaType(Column column, Class<?> entityType, Date value) { return value.toLocalDate(); }
Date date = r.getDate(); LocalDate localD = date.toLocalDate();
LocalDate ld = new java.sql.Date(date.getTime()).toLocalDate();
import java.time.LocalDate; import javax.persistence.AttributeConverter; import javax.persistence.Converter; @Converter public class LocalDatePersistenceConverter implements AttributeConverter<LocalDate, java.sql.Date> { @Override public java.sql.Date convertToDatabaseColumn(LocalDate entityValue) { if (entityValue != null) { return java.sql.Date.valueOf(entityValue); } return null; } @Override public LocalDate convertToEntityAttribute(java.sql.Date databaseValue) { if (databaseValue != null) { return databaseValue.toLocalDate(); } return null; } }
@Override public LocalDate convertToEntityAttribute(Date date) { return date == null ? null : date.toLocalDate(); } }
/** * Get the ISO 8601 formatted representation of the given {@link java.sql.Date}, which contains a date but no time or * timezone information. * * @param date the date value; may not be null * @param zoneId the timezone identifier or offset where the date 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.Date date, ZoneId zoneId, TemporalAdjuster adjuster) { LocalDate localDate = date.toLocalDate(); if (adjuster != null) { localDate = localDate.with(adjuster); } ZonedDateTime zdt = ZonedDateTime.of(localDate, LocalTime.MIDNIGHT, zoneId); return zdt.format(FORMATTER); }
/** * Get the ISO 8601 formatted representation of the given {@link java.sql.Date}, which contains a date but no time or * timezone information. * * @param date the date value * @param zoneId the timezone identifier or offset where the date 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.Date date, ZoneId zoneId, TemporalAdjuster adjuster) { LocalDate localDate = date.toLocalDate(); if (adjuster != null) { localDate = localDate.with(adjuster); } ZonedDateTime zdt = ZonedDateTime.of(localDate, LocalTime.MIDNIGHT, zoneId); return zdt.format(FORMATTER); }
@Override public <X> LocalDate wrap(X value, WrapperOptions options) { if ( value == null ) { return null; } if ( LocalDate.class.isInstance( value ) ) { return (LocalDate) value; } if ( Timestamp.class.isInstance( value ) ) { final Timestamp ts = (Timestamp) value; return LocalDateTime.ofInstant( ts.toInstant(), ZoneId.systemDefault() ).toLocalDate(); } if ( Long.class.isInstance( value ) ) { final Instant instant = Instant.ofEpochMilli( (Long) value ); return LocalDateTime.ofInstant( instant, ZoneId.systemDefault() ).toLocalDate(); } if ( Calendar.class.isInstance( value ) ) { final Calendar calendar = (Calendar) value; return LocalDateTime.ofInstant( calendar.toInstant(), calendar.getTimeZone().toZoneId() ).toLocalDate(); } if ( Date.class.isInstance( value ) ) { if ( java.sql.Date.class.isInstance( value ) ) { return ((java.sql.Date) value).toLocalDate(); } else { return Instant.ofEpochMilli( ((Date) value).getTime() ).atZone( ZoneId.systemDefault() ).toLocalDate(); } } throw unknownWrap( value.getClass() ); }
@Override public DateColumn appendObj(Object obj) { if (obj == null) { return appendMissing(); } if (obj instanceof java.sql.Date) { return append(((java.sql.Date) obj).toLocalDate()); } if (obj instanceof LocalDate) { return append((LocalDate) obj); } throw new IllegalArgumentException("Cannot append " + obj.getClass().getName() + " to DateColumn"); }
return ((java.sql.Date)obj).toLocalDate();
return ((java.sql.Date) date).toLocalDate(); else return Instant.ofEpochMilli(date.getTime()).atZone(zone).toLocalDate();
LocalDate date = sqlDate.toLocalDate(); return LocalDateTime.of(date, LocalTime.MIDNIGHT);
protected void verifyPerson(DatePerson bean) { assertEquals("Bubba", bean.getLastName()); assertEquals(22L, bean.getAge()); assertEquals(new java.sql.Date(1221222L).toLocalDate(), bean.getBirthDate()); assertEquals(new BigDecimal("1234.56"), bean.getBalance()); }
@Override public LocalDate toBeanType(Object value) { if (value instanceof java.sql.Date) { return ((java.sql.Date) value).toLocalDate(); } return (LocalDate) value; }
} else if ( obj instanceof java.sql.Date ){ java.sql.Date date = (java.sql.Date)obj; append(DateTimeFormatter.ISO_DATE.format(date.toLocalDate())); } else if ( obj instanceof java.sql.Timestamp ){ java.sql.Timestamp ts = (java.sql.Timestamp)obj;
return type.cast(LocalDate.MIN); return type.cast(dateValue.toLocalDate()); } else if (sqlType == Types.TIMESTAMP) { LocalDateTime localDateTimeValue = getLocalDateTime(columnIndex);
@Override public YearMonth toBeanType(Object value) { if (value instanceof YearMonth) return (YearMonth) value; if (value instanceof LocalDate) return fromLocalDate((LocalDate) value); if (value == null) return null; return fromLocalDate(BasicTypeConverter.toDate(value).toLocalDate()); }
@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 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"))); }