Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added configuration to disable optimisticCast for Date, Time and Date… #168

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,19 @@ public final class JDBCStatementHelper {
private static final Pattern UUID = Pattern.compile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$");

private final boolean castUUID;
private final boolean castDate;
private final boolean castTime;
private final boolean castDateTime;

public JDBCStatementHelper() {
this(new JsonObject());
}

public JDBCStatementHelper(JsonObject config) {
this.castUUID = config.getBoolean("castUUID", false);
this.castDate = config.getBoolean("castDate", true);
this.castTime = config.getBoolean("castTime", true);
this.castDateTime = config.getBoolean("castDateTime", true);
}

public void fillStatement(PreparedStatement statement, JsonArray in) throws SQLException {
Expand Down Expand Up @@ -272,7 +278,7 @@ public Object optimisticCast(String value) {

try {
// sql time
if (TIME.matcher(value).matches()) {
if (castTime && TIME.matcher(value).matches()) {
// convert from local time to instant
Instant instant = LocalTime.parse(value).atDate(LocalDate.of(1970, 1, 1)).toInstant(ZoneOffset.UTC);
// calculate the timezone offset in millis
Expand All @@ -282,7 +288,7 @@ public Object optimisticCast(String value) {
}

// sql date
if (DATE.matcher(value).matches()) {
if (castDate && DATE.matcher(value).matches()) {
// convert from local date to instant
Instant instant = LocalDate.parse(value).atTime(LocalTime.of(0, 0, 0, 0)).toInstant(ZoneOffset.UTC);
// calculate the timezone offset in millis
Expand All @@ -292,7 +298,7 @@ public Object optimisticCast(String value) {
}

// sql timestamp
if (DATETIME.matcher(value).matches()) {
if (castDateTime && DATETIME.matcher(value).matches()) {
Instant instant = Instant.from(ISO_INSTANT.parse(value));
return Timestamp.from(instant);
}
Expand Down