![JAR search and dependency download from the Maven repository](/logo.png)
org.sfm.jdbc.impl.getter.time.JavaOffsetDateTimeResultSetGetter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simpleFlatMapper Show documentation
Show all versions of simpleFlatMapper Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
package org.sfm.jdbc.impl.getter.time;
import org.sfm.jdbc.JdbcColumnKey;
import org.sfm.reflect.Getter;
import java.sql.ResultSet;
import java.time.*;
import java.time.temporal.TemporalAccessor;
import java.util.Date;
public class JavaOffsetDateTimeResultSetGetter implements Getter {
private final int index;
private final ZoneId zone;
public JavaOffsetDateTimeResultSetGetter(JdbcColumnKey key, ZoneId zoneId) {
this.index = key.getIndex();
this.zone = zoneId;
}
@Override
public OffsetDateTime get(ResultSet target) throws Exception {
Object o = target.getObject(index);
if (o == null) {
return null;
}
if (o instanceof Date) {
final Instant instant = Instant.ofEpochMilli(((Date) o).getTime());
return instant.atOffset(zone.getRules().getOffset(instant));
}
if (o instanceof OffsetDateTime) {
return (OffsetDateTime) o;
}
if (o instanceof ZonedDateTime) {
return ((ZonedDateTime)o).toOffsetDateTime();
}
if (o instanceof LocalDateTime) {
final LocalDateTime localDateTime = (LocalDateTime) o;
return localDateTime.atOffset(zone.getRules().getOffset(localDateTime));
}
if (o instanceof TemporalAccessor) {
return OffsetDateTime.from((TemporalAccessor) o);
}
throw new IllegalArgumentException("Cannot convert " + o + " to OffsetDateTime");
}
@Override
public String toString() {
return "JavaOffsetDateTimeResultSetGetter{" +
"column=" + index +
'}';
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy