use of java.time.OffsetDateTime in project dropwizard by dropwizard.
the class OffsetDateTimeArgumentTest method apply.
@Test
public void apply() throws Exception {
final Instant now = OffsetDateTime.now().toInstant();
final OffsetDateTime dateTime = OffsetDateTime.ofInstant(now, ZoneId.systemDefault());
new OffsetDateTimeArgument(dateTime, Optional.empty()).apply(1, statement, context);
Mockito.verify(statement).setTimestamp(1, Timestamp.from(now));
}
use of java.time.OffsetDateTime in project dropwizard by dropwizard.
the class OffsetDateTimeMapperTest method mapColumnByIndex.
@Test
public void mapColumnByIndex() throws Exception {
final Instant now = OffsetDateTime.now().toInstant();
when(resultSet.getTimestamp(1)).thenReturn(Timestamp.from(now));
OffsetDateTime actual = new OffsetDateTimeMapper().mapColumn(resultSet, 1, null);
assertThat(actual).isEqualTo(OffsetDateTime.ofInstant(now, ZoneId.systemDefault()));
}
use of java.time.OffsetDateTime in project dropwizard by dropwizard.
the class OffsetDateTimeMapperTest method mapColumnByName.
@Test
public void mapColumnByName() throws Exception {
final Instant now = OffsetDateTime.now().toInstant();
when(resultSet.getTimestamp("name")).thenReturn(Timestamp.from(now));
OffsetDateTime actual = new OffsetDateTimeMapper().mapColumn(resultSet, "name", null);
assertThat(actual).isEqualTo(OffsetDateTime.ofInstant(now, ZoneId.systemDefault()));
}
use of java.time.OffsetDateTime in project hibernate-orm by hibernate.
the class OffsetDateTimeTest method testOffsetDateTimeWithHoursZoneOffset.
@Test
public void testOffsetDateTimeWithHoursZoneOffset() {
final OffsetDateTime expectedStartDate = OffsetDateTime.of(2015, 1, 1, 0, 0, 0, 0, ZoneOffset.ofHours(5));
saveOffsetDateTimeEventWithStartDate(expectedStartDate);
checkSavedOffsetDateTimeIsEqual(expectedStartDate);
compareSavedOffsetDateTimeWith(expectedStartDate);
}
use of java.time.OffsetDateTime in project jOOQ by jOOQ.
the class DefaultBinding method get.
@SuppressWarnings("unchecked")
@Override
public void get(BindingGetResultSetContext<U> ctx) throws SQLException {
T result = null;
if (type == Blob.class) {
result = (T) ctx.resultSet().getBlob(ctx.index());
} else if (type == Boolean.class) {
result = (T) wasNull(ctx.resultSet(), Boolean.valueOf(ctx.resultSet().getBoolean(ctx.index())));
} else if (type == BigInteger.class) {
// The SQLite JDBC driver doesn't support BigDecimals
if (ctx.configuration().dialect() == SQLDialect.SQLITE) {
result = Convert.convert(ctx.resultSet().getString(ctx.index()), (Class<T>) BigInteger.class);
} else {
BigDecimal b = ctx.resultSet().getBigDecimal(ctx.index());
result = (T) (b == null ? null : b.toBigInteger());
}
} else if (type == BigDecimal.class) {
// The SQLite JDBC driver doesn't support BigDecimals
if (ctx.configuration().dialect() == SQLDialect.SQLITE) {
result = Convert.convert(ctx.resultSet().getString(ctx.index()), (Class<T>) BigDecimal.class);
} else {
result = (T) ctx.resultSet().getBigDecimal(ctx.index());
}
} else if (type == Byte.class) {
result = (T) wasNull(ctx.resultSet(), Byte.valueOf(ctx.resultSet().getByte(ctx.index())));
} else if (type == byte[].class) {
result = (T) ctx.resultSet().getBytes(ctx.index());
} else if (type == Clob.class) {
result = (T) ctx.resultSet().getClob(ctx.index());
} else if (type == Date.class) {
result = (T) getDate(ctx.family(), ctx.resultSet(), ctx.index());
} else if (type == Double.class) {
result = (T) wasNull(ctx.resultSet(), Double.valueOf(ctx.resultSet().getDouble(ctx.index())));
} else if (type == Float.class) {
result = (T) wasNull(ctx.resultSet(), Float.valueOf(ctx.resultSet().getFloat(ctx.index())));
} else if (type == Integer.class) {
result = (T) wasNull(ctx.resultSet(), Integer.valueOf(ctx.resultSet().getInt(ctx.index())));
} else if (type == LocalDate.class) {
result = (T) localDate(getDate(ctx.family(), ctx.resultSet(), ctx.index()));
} else if (type == LocalTime.class) {
result = (T) localTime(getTime(ctx.family(), ctx.resultSet(), ctx.index()));
} else if (type == LocalDateTime.class) {
result = (T) localDateTime(getTimestamp(ctx.family(), ctx.resultSet(), ctx.index()));
} else if (type == Long.class) {
result = (T) wasNull(ctx.resultSet(), Long.valueOf(ctx.resultSet().getLong(ctx.index())));
} else if (type == OffsetTime.class) {
result = (T) offsetTime(ctx.resultSet().getString(ctx.index()));
} else if (type == OffsetDateTime.class) {
result = (T) offsetDateTime(ctx.resultSet().getString(ctx.index()));
} else if (type == Short.class) {
result = (T) wasNull(ctx.resultSet(), Short.valueOf(ctx.resultSet().getShort(ctx.index())));
} else if (type == String.class) {
result = (T) ctx.resultSet().getString(ctx.index());
} else if (type == Time.class) {
result = (T) getTime(ctx.family(), ctx.resultSet(), ctx.index());
} else if (type == Timestamp.class) {
result = (T) getTimestamp(ctx.family(), ctx.resultSet(), ctx.index());
} else if (type == YearToMonth.class) {
if (ctx.family() == POSTGRES) {
Object object = ctx.resultSet().getObject(ctx.index());
result = (T) (object == null ? null : PostgresUtils.toYearToMonth(object));
} else {
String string = ctx.resultSet().getString(ctx.index());
result = (T) (string == null ? null : YearToMonth.valueOf(string));
}
} else if (type == DayToSecond.class) {
if (ctx.family() == POSTGRES) {
Object object = ctx.resultSet().getObject(ctx.index());
result = (T) (object == null ? null : PostgresUtils.toDayToSecond(object));
} else {
String string = ctx.resultSet().getString(ctx.index());
result = (T) (string == null ? null : DayToSecond.valueOf(string));
}
} else if (type == UByte.class) {
result = (T) Convert.convert(ctx.resultSet().getString(ctx.index()), UByte.class);
} else if (type == UShort.class) {
result = (T) Convert.convert(ctx.resultSet().getString(ctx.index()), UShort.class);
} else if (type == UInteger.class) {
result = (T) Convert.convert(ctx.resultSet().getString(ctx.index()), UInteger.class);
} else if (type == ULong.class) {
result = (T) Convert.convert(ctx.resultSet().getString(ctx.index()), ULong.class);
} else if (type == UUID.class) {
switch(ctx.family()) {
// java.util.UUID data type
case H2:
case POSTGRES:
{
result = (T) ctx.resultSet().getObject(ctx.index());
break;
}
// emulates the type
default:
{
result = (T) Convert.convert(ctx.resultSet().getString(ctx.index()), UUID.class);
break;
}
}
} else // The type byte[] is handled earlier. byte[][] can be handled here
if (type.isArray()) {
switch(ctx.family()) {
case POSTGRES:
{
result = pgGetArray(ctx, ctx.resultSet(), type, ctx.index());
break;
}
default:
// Note: due to a HSQLDB bug, it is not recommended to call rs.getObject() here:
// See https://sourceforge.net/tracker/?func=detail&aid=3181365&group_id=23316&atid=378131
result = (T) convertArray(ctx.resultSet().getArray(ctx.index()), (Class<? extends Object[]>) type);
break;
}
} else if (EnumType.class.isAssignableFrom(type)) {
result = (T) getEnumType((Class<EnumType>) type, ctx.resultSet().getString(ctx.index()));
} else if (Record.class.isAssignableFrom(type)) {
switch(ctx.family()) {
case POSTGRES:
result = (T) pgNewRecord(type, null, ctx.resultSet().getObject(ctx.index()));
break;
default:
result = (T) ctx.resultSet().getObject(ctx.index(), typeMap(type, ctx.configuration()));
break;
}
} else if (Result.class.isAssignableFrom(type)) {
ResultSet nested = (ResultSet) ctx.resultSet().getObject(ctx.index());
result = (T) DSL.using(ctx.configuration()).fetch(nested);
} else {
result = (T) unlob(ctx.resultSet().getObject(ctx.index()));
}
// [#4372] Attach records if possible / required
if (result instanceof Attachable && attachRecords(ctx.configuration()))
((Attachable) result).attach(ctx.configuration());
ctx.value(converter.from(result));
}
Aggregations