Search in sources :

Example 1 with JavaZoneIdProperty

use of org.simpleflatmapper.map.property.time.JavaZoneIdProperty in project SimpleFlatMapper by arnaudroger.

the class PreparedStatementFieldMapperFactoryTest method testJavaYearMonth.

@Test
public void testJavaYearMonth() throws Exception {
    java.time.YearMonth value = java.time.YearMonth.now();
    java.time.ZoneId zoneId = ZoneId.of("America/Los_Angeles");
    newFieldMapperAndMapToPS(new ConstantGetter<Object, java.time.YearMonth>(value), java.time.YearMonth.class, new JavaZoneIdProperty(zoneId));
    newFieldMapperAndMapToPS(NullGetter.<Object, java.time.YearMonth>getter(), java.time.YearMonth.class);
    verify(ps).setDate(1, new java.sql.Date(value.atDay(1).atStartOfDay(zoneId).toInstant().toEpochMilli()));
    verify(ps).setNull(2, Types.DATE);
}
Also used : DbObject(org.simpleflatmapper.test.beans.DbObject) JavaZoneIdProperty(org.simpleflatmapper.map.property.time.JavaZoneIdProperty) ZoneId(java.time.ZoneId) java.sql(java.sql) Test(org.junit.Test) ResultSetGetterFactoryTest(org.simpleflatmapper.jdbc.test.impl.getter.ResultSetGetterFactoryTest)

Example 2 with JavaZoneIdProperty

use of org.simpleflatmapper.map.property.time.JavaZoneIdProperty in project SimpleFlatMapper by arnaudroger.

the class PreparedStatementFieldMapperFactoryTest method testJavaLocalDateTime.

// IFJAVA8_START
@Test
public void testJavaLocalDateTime() throws Exception {
    java.time.LocalDateTime value = java.time.LocalDateTime.now();
    java.time.ZoneId zoneId = ZoneId.of("America/Los_Angeles");
    newFieldMapperAndMapToPS(new ConstantGetter<Object, java.time.LocalDateTime>(value), java.time.LocalDateTime.class, new JavaZoneIdProperty(zoneId));
    newFieldMapperAndMapToPS(NullGetter.<Object, java.time.LocalDateTime>getter(), java.time.LocalDateTime.class);
    verify(ps).setTimestamp(1, new Timestamp(value.atZone(zoneId).toInstant().toEpochMilli()));
    verify(ps).setNull(2, Types.TIMESTAMP);
}
Also used : DbObject(org.simpleflatmapper.test.beans.DbObject) JavaZoneIdProperty(org.simpleflatmapper.map.property.time.JavaZoneIdProperty) ZoneId(java.time.ZoneId) Test(org.junit.Test) ResultSetGetterFactoryTest(org.simpleflatmapper.jdbc.test.impl.getter.ResultSetGetterFactoryTest)

Example 3 with JavaZoneIdProperty

use of org.simpleflatmapper.map.property.time.JavaZoneIdProperty in project SimpleFlatMapper by arnaudroger.

the class SettableDataSetterFactoryTest method testJava8TimeLDT.

// IFJAVA8_START
@Test
public void testJava8TimeLDT() throws Exception {
    Setter<SettableByIndexData, LocalDateTime> setter = factory.getSetter(newPM(LocalDateTime.class, DataType.timestamp()));
    LocalDateTime ldt = LocalDateTime.now();
    setter.set(statement, ldt);
    setter.set(statement, null);
    verify(statement).setDate(0, Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant()));
    verify(statement).setToNull(0);
    final ZoneId zoneId = ZoneId.ofOffset("UTC", ZoneOffset.ofHours(2));
    Setter<SettableByIndexData, LocalDateTime> setterTz = factory.getSetter(newPM(LocalDateTime.class, DataType.timestamp(), new JavaZoneIdProperty(zoneId)));
    setterTz.set(statement, ldt);
    verify(statement).setDate(1, Date.from(ldt.atZone(zoneId).toInstant()));
}
Also used : LocalDateTime(java.time.LocalDateTime) ZoneId(java.time.ZoneId) JavaZoneIdProperty(org.simpleflatmapper.map.property.time.JavaZoneIdProperty) Test(org.junit.Test)

Example 4 with JavaZoneIdProperty

use of org.simpleflatmapper.map.property.time.JavaZoneIdProperty in project SimpleFlatMapper by arnaudroger.

the class PreparedStatementFieldMapperFactoryTest method testJavaLocalDate.

@Test
public void testJavaLocalDate() throws Exception {
    java.time.LocalDate value = java.time.LocalDate.now();
    java.time.ZoneId zoneId = ZoneId.of("America/Los_Angeles");
    newFieldMapperAndMapToPS(new ConstantGetter<Object, java.time.LocalDate>(value), java.time.LocalDate.class, new JavaZoneIdProperty(zoneId));
    newFieldMapperAndMapToPS(NullGetter.<Object, java.time.LocalDate>getter(), java.time.LocalDate.class);
    verify(ps).setDate(1, new java.sql.Date(value.atStartOfDay(zoneId).toInstant().toEpochMilli()));
    verify(ps).setNull(2, Types.DATE);
}
Also used : LocalDate(java.time.LocalDate) DbObject(org.simpleflatmapper.test.beans.DbObject) JavaZoneIdProperty(org.simpleflatmapper.map.property.time.JavaZoneIdProperty) LocalDate(java.time.LocalDate) ZoneId(java.time.ZoneId) java.sql(java.sql) Test(org.junit.Test) ResultSetGetterFactoryTest(org.simpleflatmapper.jdbc.test.impl.getter.ResultSetGetterFactoryTest)

Example 5 with JavaZoneIdProperty

use of org.simpleflatmapper.map.property.time.JavaZoneIdProperty in project SimpleFlatMapper by arnaudroger.

the class PreparedStatementFieldMapperFactoryTest method testJavaLocalTime.

@Test
public void testJavaLocalTime() throws Exception {
    java.time.LocalTime value = java.time.LocalTime.now();
    java.time.ZoneId zoneId = ZoneId.of("America/Los_Angeles");
    newFieldMapperAndMapToPS(new ConstantGetter<Object, java.time.LocalTime>(value), java.time.LocalTime.class, new JavaZoneIdProperty(zoneId));
    newFieldMapperAndMapToPS(NullGetter.<Object, java.time.LocalTime>getter(), java.time.LocalTime.class);
    verify(ps).setTime(1, new Time(value.atDate(LocalDate.now()).atZone(zoneId).toInstant().toEpochMilli()));
    verify(ps).setNull(2, Types.TIME);
}
Also used : DbObject(org.simpleflatmapper.test.beans.DbObject) JavaZoneIdProperty(org.simpleflatmapper.map.property.time.JavaZoneIdProperty) ZoneId(java.time.ZoneId) Test(org.junit.Test) ResultSetGetterFactoryTest(org.simpleflatmapper.jdbc.test.impl.getter.ResultSetGetterFactoryTest)

Aggregations

ZoneId (java.time.ZoneId)7 Test (org.junit.Test)7 JavaZoneIdProperty (org.simpleflatmapper.map.property.time.JavaZoneIdProperty)7 ResultSetGetterFactoryTest (org.simpleflatmapper.jdbc.test.impl.getter.ResultSetGetterFactoryTest)5 DbObject (org.simpleflatmapper.test.beans.DbObject)5 java.sql (java.sql)3 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1