Compare commits
No commits in common. "fdc3fcd3e2ff133f187186a49cf9c4f22bfe74db" and "0d750fbe06ebda18612700107352d083d3e097d5" have entirely different histories.
fdc3fcd3e2
...
0d750fbe06
22 changed files with 404 additions and 309 deletions
gradle.properties
jdbc-mariadb/src/main/java/org/xbib/jdbc/mariadb
jdbc-oracle/src/main/java/org/xbib/jdbc/oracle
jdbc-postgresql/src/main/java/org/xbib/jdbc/postgresql
jdbc-query/src
main/java/org/xbib/jdbc/query
DatabaseImpl.javaFlavor.javaRow.javaRowsAdapter.javaSchema.javaSqlArgs.javaSqlInsert.javaSqlInsertImpl.javaSqlSelect.javaSqlSelectImpl.javaSqlUpdate.javaSqlUpdateImpl.javaStatementAdapter.java
flavor
test/java/org/xbib/jdbc/query/test
jdbc-test/src/main/java/org/xbib/jdbc/test
|
@ -1,3 +1,3 @@
|
|||
group = org.xbib
|
||||
name = database
|
||||
version = 2.5.0
|
||||
version = 2.4.0
|
||||
|
|
|
@ -117,6 +117,11 @@ public class MariaDB implements Flavor {
|
|||
return "datetime(3)"; // 3 = millisecond resolution
|
||||
}
|
||||
|
||||
@Override
|
||||
public String typeZonedDateTime() {
|
||||
return "datetime(3)"; // 3 = millisecond resolution
|
||||
}
|
||||
|
||||
@Override
|
||||
public String typeLocalDate() {
|
||||
return "date";
|
||||
|
|
|
@ -96,6 +96,11 @@ public class Oracle implements Flavor {
|
|||
return "timestamp with time zone";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String typeZonedDateTime() {
|
||||
return "timestamp with time zone";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String typeLocalDate() {
|
||||
// well, this is a full blown timestamp in Oracle
|
||||
|
|
|
@ -114,6 +114,11 @@ public class Postgresql implements Flavor {
|
|||
return "timestamp with time zone";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String typeZonedDateTime() {
|
||||
return "timestamp with time zone";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String typeLocalDate() {
|
||||
return "date";
|
||||
|
|
|
@ -12,8 +12,6 @@ import java.sql.Timestamp;
|
|||
import java.time.Duration;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -479,7 +477,6 @@ public class DatabaseImpl implements Database {
|
|||
case Boolean b -> sql.argBoolean(k, b);
|
||||
case LocalDate localDate -> sql.argLocalDate(k, localDate);
|
||||
case LocalDateTime localDateTime -> sql.argLocalDateTime(k, localDateTime);
|
||||
case OffsetDateTime offsetDateTime -> sql.argOffsetDateTime(k, offsetDateTime);
|
||||
case null, default ->
|
||||
throw new DatabaseException("unknown type for param: " + (v != null ? v.getClass() : "null"));
|
||||
}
|
||||
|
@ -498,9 +495,7 @@ public class DatabaseImpl implements Database {
|
|||
case Long l -> sql.argLong(k, l);
|
||||
case Boolean b -> sql.argBoolean(k, b);
|
||||
case LocalDate localDate -> sql.argLocalDate(k, localDate);
|
||||
case LocalTime localTime -> sql.argLocalTime(k, localTime);
|
||||
case LocalDateTime localDateTime -> sql.argLocalDateTime(k, localDateTime);
|
||||
case OffsetDateTime offsetDateTime -> sql.argOffsetDateTime(k, offsetDateTime);
|
||||
case null -> sql.argNull(k);
|
||||
default -> throw new DatabaseException("unknown type for param: " + v.getClass());
|
||||
}
|
||||
|
@ -519,9 +514,7 @@ public class DatabaseImpl implements Database {
|
|||
case Long l -> sql.argLong(k, l);
|
||||
case Boolean b -> sql.argBoolean(k, b);
|
||||
case LocalDate localDate -> sql.argLocalDate(k, localDate);
|
||||
case LocalTime localTime -> sql.argLocalTime(k, localTime);
|
||||
case LocalDateTime localDateTime -> sql.argLocalDateTime(k, localDateTime);
|
||||
case OffsetDateTime offsetDateTime -> sql.argOffsetDateTime(k, offsetDateTime);
|
||||
case null -> sql.argNull(k);
|
||||
default -> throw new DatabaseException("unknown type for param: " + v.getClass());
|
||||
}
|
||||
|
@ -545,7 +538,6 @@ public class DatabaseImpl implements Database {
|
|||
case "java.lang.Boolean" -> row.add(rows.getBooleanOrFalse(i + 1));
|
||||
case "java.sql.Clob", "oracle.jdbc.OracleClob" -> row.add(rows.getClobStringOrEmpty(i + 1));
|
||||
case "java.sql.Date" -> row.add(rows.getLocalDateOrNull(i + 1));
|
||||
case "java.sql.Time" -> row.add(rows.getLocalTimeOrNull(i + 1));
|
||||
case "oracle.sql.TIMESTAMPTZ" -> row.add(rows.getOffsetDateTimeOrNull(i + 1));
|
||||
case "java.sql.Timestamp", "oracle.sql.TIMESTAMP" -> row.add(rows.getLocalDateTimeOrNull(i + 1));
|
||||
case "java.math.BigDecimal" -> row.add(rows.getBigDecimalOrNull(i + 1));
|
||||
|
|
|
@ -44,6 +44,8 @@ public interface Flavor {
|
|||
|
||||
String typeOffsetDateTime();
|
||||
|
||||
String typeZonedDateTime();
|
||||
|
||||
String typeLocalDate();
|
||||
|
||||
boolean useStringForClob();
|
||||
|
|
|
@ -4,10 +4,12 @@ import java.io.InputStream;
|
|||
import java.io.Reader;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
/**
|
||||
* Interface for reading results from a database query.
|
||||
|
@ -356,17 +358,11 @@ public interface Row {
|
|||
|
||||
InputStream getBlobInputStreamOrEmpty(String columnName);
|
||||
|
||||
LocalDate getLocalDateOrNull();
|
||||
Instant getInstantOrNull();
|
||||
|
||||
LocalDate getLocalDateOrNull(int columnOneBased);
|
||||
Instant getInstantOrNull(int columnOneBased);
|
||||
|
||||
LocalDate getLocalDateOrNull(String columnName);
|
||||
|
||||
LocalTime getLocalTimeOrNull();
|
||||
|
||||
LocalTime getLocalTimeOrNull(int columnOneBased);
|
||||
|
||||
LocalTime getLocalTimeOrNull(String columnName);
|
||||
Instant getInstantOrNull(String columnName);
|
||||
|
||||
LocalDateTime getLocalDateTimeOrNull();
|
||||
|
||||
|
@ -379,4 +375,35 @@ public interface Row {
|
|||
OffsetDateTime getOffsetDateTimeOrNull(int columnOneBase);
|
||||
|
||||
OffsetDateTime getOffsetDateTimeOrNull(String columnName);
|
||||
|
||||
ZonedDateTime getZonedDateTimeOrNull();
|
||||
|
||||
ZonedDateTime getZonedDateTimeOrNull(int columnOneBase);
|
||||
|
||||
ZonedDateTime getZonedDateTimeOrNull(String columnName);
|
||||
|
||||
/**
|
||||
* Retrieve column as LocalDate, .i.e, date with no time.
|
||||
*
|
||||
* @return LocalDate of the database column value
|
||||
*/
|
||||
LocalDate getLocalDateOrNull();
|
||||
|
||||
/**
|
||||
* Get the Date field, with no timestamp
|
||||
*
|
||||
* @param columnOneBased column number starting at 1, not 0
|
||||
* @return LocalDate of the column value
|
||||
*/
|
||||
|
||||
LocalDate getLocalDateOrNull(int columnOneBased);
|
||||
|
||||
/**
|
||||
* Get the Date field, with no timestamp
|
||||
*
|
||||
* @param columnName column name to retrieve
|
||||
* @return LocalDate of the column value
|
||||
*/
|
||||
|
||||
LocalDate getLocalDateOrNull(String columnName);
|
||||
}
|
||||
|
|
|
@ -9,10 +9,11 @@ import java.math.RoundingMode;
|
|||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
/**
|
||||
* Safely wrap a ResultSet and provide access to the data it contains.
|
||||
|
@ -656,54 +657,25 @@ class RowsAdapter implements Rows {
|
|||
}
|
||||
|
||||
@Override
|
||||
public LocalDate getLocalDateOrNull() {
|
||||
return getLocalDateOrNull(column++);
|
||||
public Instant getInstantOrNull() {
|
||||
return getInstantOrNull(column++);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate getLocalDateOrNull(int columnOneBased) {
|
||||
public Instant getInstantOrNull(int columnOneBased) {
|
||||
try {
|
||||
column = columnOneBased + 1;
|
||||
java.sql.Date val = rs.getDate(columnOneBased);
|
||||
return val == null ? null : val.toLocalDate();
|
||||
return rs.getObject(columnOneBased, Instant.class);
|
||||
} catch (SQLException e) {
|
||||
throw new DatabaseException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate getLocalDateOrNull(String columnName) {
|
||||
public Instant getInstantOrNull(String columnName) {
|
||||
try {
|
||||
column = rs.findColumn(columnName) + 1;
|
||||
java.sql.Date val = rs.getDate(columnName);
|
||||
return val == null ? null : val.toLocalDate();
|
||||
} catch (SQLException e) {
|
||||
throw new DatabaseException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalTime getLocalTimeOrNull() {
|
||||
return getLocalTimeOrNull(column++);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalTime getLocalTimeOrNull(int columnOneBased) {
|
||||
try {
|
||||
column = columnOneBased + 1;
|
||||
java.sql.Time val = rs.getTime(columnOneBased);
|
||||
return val == null ? null : val.toLocalTime();
|
||||
} catch (SQLException e) {
|
||||
throw new DatabaseException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalTime getLocalTimeOrNull(String columnName) {
|
||||
try {
|
||||
column = rs.findColumn(columnName) + 1;
|
||||
java.sql.Time val = rs.getTime(columnName);
|
||||
return val == null ? null : val.toLocalTime();
|
||||
return rs.getObject(columnName, Instant.class);
|
||||
} catch (SQLException e) {
|
||||
throw new DatabaseException(e);
|
||||
}
|
||||
|
@ -734,6 +706,33 @@ class RowsAdapter implements Rows {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate getLocalDateOrNull() {
|
||||
return getLocalDateOrNull(column++);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate getLocalDateOrNull(int columnOneBased) {
|
||||
try {
|
||||
column = columnOneBased + 1;
|
||||
java.sql.Date val = rs.getDate(columnOneBased);
|
||||
return val == null ? null : val.toLocalDate();
|
||||
} catch (SQLException e) {
|
||||
throw new DatabaseException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate getLocalDateOrNull(String columnName) {
|
||||
try {
|
||||
column = rs.findColumn(columnName) + 1;
|
||||
java.sql.Date val = rs.getDate(columnName);
|
||||
return val == null ? null : val.toLocalDate();
|
||||
} catch (SQLException e) {
|
||||
throw new DatabaseException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public OffsetDateTime getOffsetDateTimeOrNull() {
|
||||
return getOffsetDateTimeOrNull(column++);
|
||||
|
@ -759,6 +758,31 @@ class RowsAdapter implements Rows {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZonedDateTime getZonedDateTimeOrNull() {
|
||||
return getZonedDateTimeOrNull(column++);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZonedDateTime getZonedDateTimeOrNull(int columnOneBased) {
|
||||
try {
|
||||
column = columnOneBased + 1;
|
||||
return rs.getObject(columnOneBased, ZonedDateTime.class);
|
||||
} catch (SQLException e) {
|
||||
throw new DatabaseException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZonedDateTime getZonedDateTimeOrNull(String columnName) {
|
||||
try {
|
||||
column = rs.findColumn(columnName) + 1;
|
||||
return rs.getObject(columnName, ZonedDateTime.class);
|
||||
} catch (SQLException e) {
|
||||
throw new DatabaseException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer rowCount() {
|
||||
try {
|
||||
|
|
|
@ -238,6 +238,9 @@ public class Schema {
|
|||
case OffsetDateTime:
|
||||
sql.append(flavor.typeOffsetDateTime());
|
||||
break;
|
||||
case ZonedDateTime:
|
||||
sql.append(flavor.typeZonedDateTime());
|
||||
break;
|
||||
case LocalDate:
|
||||
sql.append(flavor.typeLocalDate());
|
||||
break;
|
||||
|
@ -415,6 +418,7 @@ public class Schema {
|
|||
Instant,
|
||||
LocalDateTime,
|
||||
OffsetDateTime,
|
||||
ZonedDateTime,
|
||||
LocalDate,
|
||||
Boolean
|
||||
}
|
||||
|
@ -935,6 +939,10 @@ public class Schema {
|
|||
return asType(ColumnType.OffsetDateTime);
|
||||
}
|
||||
|
||||
public Column asZonedateTime() {
|
||||
return asType(ColumnType.ZonedDateTime);
|
||||
}
|
||||
|
||||
public Column asLocalDate() {
|
||||
return asType(ColumnType.LocalDate);
|
||||
}
|
||||
|
|
|
@ -8,8 +8,6 @@ import java.sql.SQLException;
|
|||
import java.sql.Types;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
@ -135,28 +133,7 @@ public class SqlArgs implements SqlInsert.Apply, SqlUpdate.Apply, SqlSelect.Appl
|
|||
invocations.add(new Invocation(ColumnType.String, argName, arg));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public SqlArgs argLocalDate(LocalDate arg) {
|
||||
invocations.add(new Invocation(ColumnType.LocalDate, null, arg));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlArgs argLocalDate(String argName, LocalDate arg) {
|
||||
invocations.add(new Invocation(ColumnType.LocalDate, argName, arg));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlArgs argLocalTime(LocalTime arg) {
|
||||
invocations.add(new Invocation(ColumnType.LocalTime, null, arg));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlArgs argLocalTime(String argName, LocalTime arg) {
|
||||
invocations.add(new Invocation(ColumnType.LocalTime, argName, arg));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public SqlArgs argLocalDateTime(LocalDateTime arg) {
|
||||
invocations.add(new Invocation(ColumnType.LocalDateTime, null, arg));
|
||||
return this;
|
||||
|
@ -166,14 +143,14 @@ public class SqlArgs implements SqlInsert.Apply, SqlUpdate.Apply, SqlSelect.Appl
|
|||
invocations.add(new Invocation(ColumnType.LocalDateTime, argName, arg));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlArgs argOffsetDateTime(OffsetDateTime arg) {
|
||||
invocations.add(new Invocation(ColumnType.OffsetDateTime, null, arg));
|
||||
|
||||
public SqlArgs argLocalDate(LocalDate arg) {
|
||||
invocations.add(new Invocation(ColumnType.LocalDate, null, arg));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlArgs argOffsetDateTime(String argName, OffsetDateTime arg) {
|
||||
invocations.add(new Invocation(ColumnType.OffsetDateTime, argName, arg));
|
||||
|
||||
public SqlArgs argLocalDate(String argName, LocalDate arg) {
|
||||
invocations.add(new Invocation(ColumnType.LocalDate, argName, arg));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -186,17 +163,7 @@ public class SqlArgs implements SqlInsert.Apply, SqlUpdate.Apply, SqlSelect.Appl
|
|||
invocations.add(new Invocation(ColumnType.LocalDateTimeNowPerDb, argName, null));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlArgs argOffsetDateTimeNowPerDb() {
|
||||
invocations.add(new Invocation(ColumnType.OffsetDateTimeNowPerDb, null, null));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlArgs argOffsetDateTimeNowPerDb(String argName) {
|
||||
invocations.add(new Invocation(ColumnType.OffsetDateTimeNowPerDb, argName, null));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public SqlArgs argBlobBytes(byte[] arg) {
|
||||
invocations.add(new Invocation(ColumnType.BlobBytes, null, arg));
|
||||
return this;
|
||||
|
@ -316,6 +283,12 @@ public class SqlArgs implements SqlInsert.Apply, SqlUpdate.Apply, SqlSelect.Appl
|
|||
}
|
||||
break;
|
||||
case String:
|
||||
if (i.argName == null) {
|
||||
select.argString((String) i.arg);
|
||||
} else {
|
||||
select.argString(i.argName, (String) i.arg);
|
||||
}
|
||||
break;
|
||||
case ClobString:
|
||||
if (i.argName == null) {
|
||||
select.argString((String) i.arg);
|
||||
|
@ -326,6 +299,7 @@ public class SqlArgs implements SqlInsert.Apply, SqlUpdate.Apply, SqlSelect.Appl
|
|||
case ClobStream:
|
||||
throw new DatabaseException("Don't use Clob stream parameters with select statements");
|
||||
case BlobBytes:
|
||||
throw new DatabaseException("Don't use Blob parameters with select statements");
|
||||
case BlobStream:
|
||||
throw new DatabaseException("Don't use Blob parameters with select statements");
|
||||
case LocalDate:
|
||||
|
@ -335,13 +309,6 @@ public class SqlArgs implements SqlInsert.Apply, SqlUpdate.Apply, SqlSelect.Appl
|
|||
select.argLocalDate(i.argName, (LocalDate) i.arg);
|
||||
}
|
||||
break;
|
||||
case LocalTime:
|
||||
if (i.argName == null) {
|
||||
select.argLocalTime((LocalTime) i.arg);
|
||||
} else {
|
||||
select.argLocalTime(i.argName, (LocalTime) i.arg);
|
||||
}
|
||||
break;
|
||||
case LocalDateTime:
|
||||
if (i.argName == null) {
|
||||
select.argLocalDateTime((LocalDateTime) i.arg);
|
||||
|
@ -349,13 +316,6 @@ public class SqlArgs implements SqlInsert.Apply, SqlUpdate.Apply, SqlSelect.Appl
|
|||
select.argLocalDateTime(i.argName, (LocalDateTime) i.arg);
|
||||
}
|
||||
break;
|
||||
case OffsetDateTime:
|
||||
if (i.argName == null) {
|
||||
select.argOffsetDateTime((OffsetDateTime) i.arg);
|
||||
} else {
|
||||
select.argOffsetDateTime(i.argName, (OffsetDateTime) i.arg);
|
||||
}
|
||||
break;
|
||||
case LocalDateTimeNowPerDb:
|
||||
if (i.argName == null) {
|
||||
select.argLocalDateTimeNowPerDb();
|
||||
|
@ -363,13 +323,6 @@ public class SqlArgs implements SqlInsert.Apply, SqlUpdate.Apply, SqlSelect.Appl
|
|||
select.argLocalDateTimeNowPerDb(i.argName);
|
||||
}
|
||||
break;
|
||||
case OffsetDateTimeNowPerDb:
|
||||
if (i.argName == null) {
|
||||
select.argOffsetDateTimeNowPerDb();
|
||||
} else {
|
||||
select.argOffsetDateTimeNowPerDb(i.argName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -463,13 +416,6 @@ public class SqlArgs implements SqlInsert.Apply, SqlUpdate.Apply, SqlSelect.Appl
|
|||
insert.argLocalDate(i.argName, (LocalDate) i.arg);
|
||||
}
|
||||
break;
|
||||
case LocalTime:
|
||||
if (i.argName == null) {
|
||||
insert.argLocalTime((LocalTime) i.arg);
|
||||
} else {
|
||||
insert.argLocalTime(i.argName, (LocalTime) i.arg);
|
||||
}
|
||||
break;
|
||||
case LocalDateTime:
|
||||
if (i.argName == null) {
|
||||
insert.argLocalDateTime((LocalDateTime) i.arg);
|
||||
|
@ -484,13 +430,6 @@ public class SqlArgs implements SqlInsert.Apply, SqlUpdate.Apply, SqlSelect.Appl
|
|||
insert.argLocalDateTimeNowPerDb(i.argName);
|
||||
}
|
||||
break;
|
||||
case OffsetDateTimeNowPerDb:
|
||||
if (i.argName == null) {
|
||||
insert.argOffsetDateTimeNowPerDb();
|
||||
} else {
|
||||
insert.argOffsetDateTimeNowPerDb(i.argName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -584,13 +523,6 @@ public class SqlArgs implements SqlInsert.Apply, SqlUpdate.Apply, SqlSelect.Appl
|
|||
update.argLocalDate(i.argName, (LocalDate) i.arg);
|
||||
}
|
||||
break;
|
||||
case LocalTime:
|
||||
if (i.argName == null) {
|
||||
update.argLocalTime((LocalTime) i.arg);
|
||||
} else {
|
||||
update.argLocalTime(i.argName, (LocalTime) i.arg);
|
||||
}
|
||||
break;
|
||||
case LocalDateTime:
|
||||
if (i.argName == null) {
|
||||
update.argLocalDateTime((LocalDateTime) i.arg);
|
||||
|
@ -605,13 +537,6 @@ public class SqlArgs implements SqlInsert.Apply, SqlUpdate.Apply, SqlSelect.Appl
|
|||
update.argLocalDateTimeNowPerDb(i.argName);
|
||||
}
|
||||
break;
|
||||
case OffsetDateTimeNowPerDb:
|
||||
if (i.argName == null) {
|
||||
update.argOffsetDateTimeNowPerDb();
|
||||
} else {
|
||||
update.argOffsetDateTimeNowPerDb(i.argName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -647,11 +572,8 @@ public class SqlArgs implements SqlInsert.Apply, SqlUpdate.Apply, SqlSelect.Appl
|
|||
BlobBytes,
|
||||
BlobStream,
|
||||
LocalDate,
|
||||
LocalTime,
|
||||
LocalDateTime,
|
||||
LocalDateTimeNowPerDb,
|
||||
OffsetDateTime,
|
||||
OffsetDateTimeNowPerDb
|
||||
LocalDateTimeNowPerDb
|
||||
}
|
||||
|
||||
private static class Invocation {
|
||||
|
@ -769,15 +691,15 @@ public class SqlArgs implements SqlInsert.Apply, SqlUpdate.Apply, SqlSelect.Appl
|
|||
args.argLocalDate(names[i], r.getLocalDateOrNull());
|
||||
break;
|
||||
case Types.TIMESTAMP:
|
||||
case Types.TIMESTAMP_WITH_TIMEZONE:
|
||||
if (this.scale[i] == 0) {
|
||||
// If the scale is 0, this is a LocalDate (no time/timezone).
|
||||
// Anything with a time will have a non-zero scale
|
||||
args.argLocalDate(names[i], r.getLocalDateOrNull());
|
||||
} else {
|
||||
args.argLocalDateTime(names[i], r.getLocalDateTimeOrNull());
|
||||
}
|
||||
break;
|
||||
case Types.TIMESTAMP_WITH_TIMEZONE:
|
||||
args.argOffsetDateTime(names[i], r.getOffsetDateTimeOrNull());
|
||||
break;
|
||||
case Types.NVARCHAR:
|
||||
case Types.VARCHAR:
|
||||
case Types.CHAR:
|
||||
|
|
|
@ -3,10 +3,12 @@ package org.xbib.jdbc.query;
|
|||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
/**
|
||||
* Interface for configuring (setting parameters) and executing a chunk of SQL.
|
||||
|
@ -41,13 +43,9 @@ public interface SqlInsert {
|
|||
|
||||
SqlInsert argString( String argName, String arg);
|
||||
|
||||
SqlInsert argLocalDate(LocalDate arg);
|
||||
SqlInsert argInstant(Instant arg);
|
||||
|
||||
SqlInsert argLocalDate(String argName, LocalDate arg);
|
||||
|
||||
SqlInsert argLocalTime(LocalTime arg);
|
||||
|
||||
SqlInsert argLocalTime(String argName, LocalTime arg);
|
||||
SqlInsert argInstant(String argName, Instant arg);
|
||||
|
||||
SqlInsert argLocalDateTime(LocalDateTime arg);
|
||||
|
||||
|
@ -57,14 +55,18 @@ public interface SqlInsert {
|
|||
|
||||
SqlInsert argOffsetDateTime(String argName, OffsetDateTime arg);
|
||||
|
||||
SqlInsert argZonedDateTime(ZonedDateTime arg);
|
||||
|
||||
SqlInsert argZonedDateTime(String argName, ZonedDateTime arg);
|
||||
|
||||
SqlInsert argLocalDate(LocalDate arg);
|
||||
|
||||
SqlInsert argLocalDate( String argName, LocalDate arg);
|
||||
|
||||
SqlInsert argLocalDateTimeNowPerDb();
|
||||
|
||||
SqlInsert argLocalDateTimeNowPerDb(String argName);
|
||||
|
||||
SqlInsert argOffsetDateTimeNowPerDb();
|
||||
|
||||
SqlInsert argOffsetDateTimeNowPerDb(String argName);
|
||||
|
||||
SqlInsert argBlobBytes(byte[] arg);
|
||||
|
||||
SqlInsert argBlobBytes(String argName, byte[] arg);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.xbib.jdbc.query;
|
||||
|
||||
import java.sql.Types;
|
||||
import java.time.LocalTime;
|
||||
import org.xbib.jdbc.query.util.DebugSql;
|
||||
import org.xbib.jdbc.query.util.InternalStringReader;
|
||||
import org.xbib.jdbc.query.util.Metric;
|
||||
|
@ -14,9 +13,11 @@ import java.sql.Connection;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
@ -142,6 +143,16 @@ public class SqlInsertImpl implements SqlInsert {
|
|||
return namedArg(argName, adaptor.nullString(arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlInsert argInstant(Instant arg) {
|
||||
return positionalArg(adaptor.nullInstant(arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlInsert argInstant(String argName, Instant arg) {
|
||||
return namedArg(argName, adaptor.nullInstant(arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlInsert argLocalDateTime(LocalDateTime arg) {
|
||||
return positionalArg(adaptor.nullLocalDateTime(arg));
|
||||
|
@ -153,23 +164,13 @@ public class SqlInsertImpl implements SqlInsert {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SqlInsert argLocalDate(LocalDate arg) {
|
||||
return positionalArg(adaptor.nullLocalDate(arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlInsert argLocalDate(String argName, LocalDate arg) {
|
||||
public SqlInsert argLocalDate( String argName, LocalDate arg) {
|
||||
return namedArg(argName, adaptor.nullLocalDate(arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlInsert argLocalTime(LocalTime arg) {
|
||||
return positionalArg(adaptor.nullLocalTime(arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlInsert argLocalTime(String argName, LocalTime arg) {
|
||||
return namedArg(argName, adaptor.nullLocalTime(arg));
|
||||
public SqlInsert argLocalDate(LocalDate arg) {
|
||||
return positionalArg(adaptor.nullLocalDate(arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -182,6 +183,16 @@ public class SqlInsertImpl implements SqlInsert {
|
|||
return namedArg(argName, adaptor.nullOffsetDateTime(arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlInsert argZonedDateTime(ZonedDateTime arg) {
|
||||
return positionalArg(adaptor.nullZonedDateTime(arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlInsert argZonedDateTime(String argName, ZonedDateTime arg) {
|
||||
return namedArg(argName, adaptor.nullZonedDateTime(arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlInsert argLocalDateTimeNowPerDb() {
|
||||
if (options.useClientClock()) {
|
||||
|
@ -198,22 +209,6 @@ public class SqlInsertImpl implements SqlInsert {
|
|||
return namedArg(argName, new RewriteArg(options.flavor().dbTimeMillis()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlInsert argOffsetDateTimeNowPerDb() {
|
||||
if (options.useClientClock()) {
|
||||
return positionalArg(adaptor.nullOffsetDateTime(OffsetDateTime.now()));
|
||||
}
|
||||
return positionalArg(new RewriteArg(options.flavor().dbTimeMillis()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlInsert argOffsetDateTimeNowPerDb(String argName) {
|
||||
if (options.useClientClock()) {
|
||||
return namedArg(argName, adaptor.nullOffsetDateTime(OffsetDateTime.now()));
|
||||
}
|
||||
return namedArg(argName, new RewriteArg(options.flavor().dbTimeMillis()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlInsert argBlobBytes(byte[] arg) {
|
||||
return positionalArg(adaptor.nullBytes(arg));
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package org.xbib.jdbc.query;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -40,13 +41,9 @@ public interface SqlSelect {
|
|||
|
||||
SqlSelect argString( String argName, String arg);
|
||||
|
||||
SqlSelect argLocalDate(LocalDate arg);
|
||||
SqlSelect argInstant(Instant arg);
|
||||
|
||||
SqlSelect argLocalDate(String argName, LocalDate arg);
|
||||
|
||||
SqlSelect argLocalTime(LocalTime arg);
|
||||
|
||||
SqlSelect argLocalTime(String argName, LocalTime arg);
|
||||
SqlSelect argInstant(String argName, Instant arg);
|
||||
|
||||
SqlSelect argLocalDateTime(LocalDateTime arg);
|
||||
|
||||
|
@ -56,14 +53,22 @@ public interface SqlSelect {
|
|||
|
||||
SqlSelect argOffsetDateTime(String argName, OffsetDateTime arg);
|
||||
|
||||
SqlSelect argZonedDateTime(ZonedDateTime arg);
|
||||
|
||||
SqlSelect argZonedDateTime(String argName, ZonedDateTime arg);
|
||||
|
||||
SqlSelect argLocalDate(LocalDate arg);
|
||||
|
||||
SqlSelect argLocalDate(String argName, LocalDate arg);
|
||||
|
||||
SqlSelect argInstantNowPerDb();
|
||||
|
||||
SqlSelect argInstantNowPerDb(String argName);
|
||||
|
||||
SqlSelect argLocalDateTimeNowPerDb();
|
||||
|
||||
SqlSelect argLocalDateTimeNowPerDb(String argName);
|
||||
|
||||
SqlSelect argOffsetDateTimeNowPerDb();
|
||||
|
||||
SqlSelect argOffsetDateTimeNowPerDb(String argName);
|
||||
|
||||
SqlSelect withTimeoutSeconds(int seconds);
|
||||
|
||||
SqlSelect withMaxRows(int rows);
|
||||
|
@ -126,13 +131,17 @@ public interface SqlSelect {
|
|||
*/
|
||||
List<String> queryStrings();
|
||||
|
||||
Instant queryInstantOrNull();
|
||||
|
||||
List<Instant> queryInstants();
|
||||
|
||||
LocalDateTime queryLocalDateTimeOrNull();
|
||||
|
||||
List<LocalDateTime> queryLocalDateTimes();
|
||||
|
||||
OffsetDateTime queryOffsetDateTimeOrNull();
|
||||
ZonedDateTime queryZonedDateTimeOrNull();
|
||||
|
||||
List<OffsetDateTime> queryOffsetDateTimes();
|
||||
List<ZonedDateTime> queryZonedDateTimes();
|
||||
|
||||
LocalDate queryLocalDateOrNull();
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.xbib.jdbc.query;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import org.xbib.jdbc.query.util.DebugSql;
|
||||
import org.xbib.jdbc.query.util.Metric;
|
||||
import org.xbib.jdbc.query.util.RewriteArg;
|
||||
|
@ -10,9 +9,11 @@ import java.sql.Connection;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -136,6 +137,16 @@ public class SqlSelectImpl implements SqlSelect {
|
|||
return namedArg(argName, adaptor.nullString(arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlSelect argInstant(Instant arg) {
|
||||
return positionalArg(adaptor.nullInstant(arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlSelect argInstant(String argName, Instant arg) {
|
||||
return namedArg(argName, adaptor.nullInstant(arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlSelect argLocalDateTime(LocalDateTime arg) {
|
||||
return positionalArg(adaptor.nullLocalDateTime(arg));
|
||||
|
@ -156,6 +167,16 @@ public class SqlSelectImpl implements SqlSelect {
|
|||
return namedArg(argName, adaptor.nullOffsetDateTime(arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlSelect argZonedDateTime(ZonedDateTime arg) {
|
||||
return positionalArg(adaptor.nullZonedDateTime(arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlSelect argZonedDateTime(String argName, ZonedDateTime arg) {
|
||||
return namedArg(argName, adaptor.nullZonedDateTime(arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlSelect argLocalDate(LocalDate arg) {
|
||||
return positionalArg(adaptor.nullLocalDate(arg));
|
||||
|
@ -167,13 +188,19 @@ public class SqlSelectImpl implements SqlSelect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SqlSelect argLocalTime(LocalTime arg) {
|
||||
return positionalArg(adaptor.nullLocalTime(arg));
|
||||
public SqlSelect argInstantNowPerDb() {
|
||||
if (options.useClientClock()) {
|
||||
return positionalArg(adaptor.nullInstant(Instant.now()));
|
||||
}
|
||||
return positionalArg(new RewriteArg(options.flavor().dbTimeMillis()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlSelect argLocalTime(String argName, LocalTime arg) {
|
||||
return namedArg(argName, adaptor.nullLocalTime(arg));
|
||||
public SqlSelect argInstantNowPerDb(String argName) {
|
||||
if (options.useClientClock()) {
|
||||
return namedArg(argName, adaptor.nullInstant(Instant.now()));
|
||||
}
|
||||
return namedArg(argName, new RewriteArg(options.flavor().dbTimeMillis()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -191,23 +218,7 @@ public class SqlSelectImpl implements SqlSelect {
|
|||
}
|
||||
return namedArg(argName, new RewriteArg(options.flavor().dbTimeMillis()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlSelect argOffsetDateTimeNowPerDb() {
|
||||
if (options.useClientClock()) {
|
||||
return positionalArg(adaptor.nullOffsetDateTime(OffsetDateTime.now()));
|
||||
}
|
||||
return positionalArg(new RewriteArg(options.flavor().dbTimeMillis()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlSelect argOffsetDateTimeNowPerDb(String argName) {
|
||||
if (options.useClientClock()) {
|
||||
return namedArg(argName, adaptor.nullOffsetDateTime(OffsetDateTime.now()));
|
||||
}
|
||||
return namedArg(argName, new RewriteArg(options.flavor().dbTimeMillis()));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SqlSelect withTimeoutSeconds(int seconds) {
|
||||
timeoutSeconds = seconds;
|
||||
|
@ -467,6 +478,31 @@ public class SqlSelectImpl implements SqlSelect {
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instant queryInstantOrNull() {
|
||||
return queryWithTimeout(rs -> {
|
||||
if (rs.next()) {
|
||||
return rs.getInstantOrNull(1);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Instant> queryInstants() {
|
||||
return queryWithTimeout(rs -> {
|
||||
List<Instant> result = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
Instant value = rs.getInstantOrNull(1);
|
||||
if (value != null) {
|
||||
result.add(value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public LocalDateTime queryLocalDateTimeOrNull() {
|
||||
return queryWithTimeout(rs -> {
|
||||
|
@ -492,17 +528,32 @@ public class SqlSelectImpl implements SqlSelect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public OffsetDateTime queryOffsetDateTimeOrNull() {
|
||||
return null;
|
||||
public ZonedDateTime queryZonedDateTimeOrNull() {
|
||||
return queryWithTimeout(rs -> {
|
||||
if (rs.next()) {
|
||||
return rs.getZonedDateTimeOrNull(1);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OffsetDateTime> queryOffsetDateTimes() {
|
||||
return List.of();
|
||||
public List<ZonedDateTime> queryZonedDateTimes() {
|
||||
return queryWithTimeout(rs -> {
|
||||
List<ZonedDateTime> result = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
ZonedDateTime value = rs.getZonedDateTimeOrNull(1);
|
||||
if (value != null) {
|
||||
result.add(value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate queryLocalDateOrNull() {
|
||||
// Date without time
|
||||
return queryWithTimeout(rs -> {
|
||||
if (rs.next()) {
|
||||
return rs.getLocalDateOrNull(1);
|
||||
|
@ -513,6 +564,7 @@ public class SqlSelectImpl implements SqlSelect {
|
|||
|
||||
@Override
|
||||
public List<LocalDate> queryLocalDates() {
|
||||
// Date without time
|
||||
return queryWithTimeout(rs -> {
|
||||
List<LocalDate> result = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
|
|
|
@ -5,8 +5,6 @@ import java.io.Reader;
|
|||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
/**
|
||||
* Interface for configuring (setting parameters) and executing a chunk of SQL.
|
||||
|
@ -40,31 +38,19 @@ public interface SqlUpdate {
|
|||
SqlUpdate argString(String arg);
|
||||
|
||||
SqlUpdate argString(String argName, String arg);
|
||||
|
||||
SqlUpdate argLocalDateTime(LocalDateTime arg);
|
||||
|
||||
SqlUpdate argLocalDateTime(String argName, LocalDateTime arg);
|
||||
|
||||
SqlUpdate argLocalDate(LocalDate arg);
|
||||
|
||||
SqlUpdate argLocalDate(String argName, LocalDate arg);
|
||||
|
||||
SqlUpdate argLocalTime(LocalTime arg);
|
||||
|
||||
SqlUpdate argLocalTime(String argName, LocalTime arg);
|
||||
|
||||
SqlUpdate argLocalDateTime(LocalDateTime arg);
|
||||
|
||||
SqlUpdate argLocalDateTime(String argName, LocalDateTime arg);
|
||||
|
||||
SqlUpdate argOffsetDateTime(OffsetDateTime arg);
|
||||
|
||||
SqlUpdate argOffsetDateTime(String argName, OffsetDateTime arg);
|
||||
|
||||
SqlUpdate argLocalDateTimeNowPerDb();
|
||||
|
||||
SqlUpdate argLocalDateTimeNowPerDb(String argName);
|
||||
|
||||
SqlUpdate argOffsetDateTimeNowPerDb();
|
||||
|
||||
SqlUpdate argOffsetDateTimeNowPerDb(String argName);
|
||||
|
||||
SqlUpdate argBlobBytes(byte[] arg);
|
||||
|
||||
SqlUpdate argBlobBytes(String argName, byte[] arg);
|
||||
|
|
|
@ -2,8 +2,6 @@ package org.xbib.jdbc.query;
|
|||
|
||||
import java.sql.Statement;
|
||||
import java.sql.Types;
|
||||
import java.time.LocalTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import org.xbib.jdbc.query.util.DebugSql;
|
||||
import org.xbib.jdbc.query.util.InternalStringReader;
|
||||
import org.xbib.jdbc.query.util.Metric;
|
||||
|
@ -29,7 +27,7 @@ import java.util.logging.Logger;
|
|||
*/
|
||||
public class SqlUpdateImpl implements SqlUpdate {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(SqlUpdateImpl.class.getName());
|
||||
private static final Logger log = Logger.getLogger(Database.class.getName());
|
||||
|
||||
private final Connection connection;
|
||||
|
||||
|
@ -132,16 +130,6 @@ public class SqlUpdateImpl implements SqlUpdate {
|
|||
return namedArg(argName, adaptor.nullLocalDateTime(arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlUpdate argOffsetDateTime(OffsetDateTime arg) {
|
||||
return positionalArg(adaptor.nullOffsetDateTime(arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlUpdate argOffsetDateTime(String argName, OffsetDateTime arg) {
|
||||
return namedArg(argName, adaptor.nullOffsetDateTime(arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlUpdate argLocalDate(LocalDate arg) {
|
||||
return positionalArg(adaptor.nullLocalDate(arg));
|
||||
|
@ -152,16 +140,6 @@ public class SqlUpdateImpl implements SqlUpdate {
|
|||
return namedArg(argName, adaptor.nullLocalDate(arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlUpdate argLocalTime(LocalTime arg) {
|
||||
return positionalArg(adaptor.nullLocalTime(arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlUpdate argLocalTime(String argName, LocalTime arg) {
|
||||
return namedArg(argName, adaptor.nullLocalTime(arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlUpdate argLocalDateTimeNowPerDb() {
|
||||
if (options.useClientClock()) {
|
||||
|
@ -178,22 +156,6 @@ public class SqlUpdateImpl implements SqlUpdate {
|
|||
return namedArg(argName, new RewriteArg(options.flavor().dbTimeMillis()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlUpdate argOffsetDateTimeNowPerDb() {
|
||||
if (options.useClientClock()) {
|
||||
return positionalArg(adaptor.nullOffsetDateTime(OffsetDateTime.now()));
|
||||
}
|
||||
return positionalArg(new RewriteArg(options.flavor().dbTimeMillis()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlUpdate argOffsetDateTimeNowPerDb(String argName) {
|
||||
if (options.useClientClock()) {
|
||||
return namedArg(argName, adaptor.nullOffsetDateTime(OffsetDateTime.now()));
|
||||
}
|
||||
return namedArg(argName, new RewriteArg(options.flavor().dbTimeMillis()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlUpdate argBlobBytes(byte[] arg) {
|
||||
return positionalArg(adaptor.nullBytes(arg));
|
||||
|
@ -296,7 +258,7 @@ public class SqlUpdateImpl implements SqlUpdate {
|
|||
throw new DatabaseException("Batch insert requires parameters");
|
||||
}
|
||||
PreparedStatement ps = null;
|
||||
Metric metric = new Metric(logger.isLoggable(Level.FINE));
|
||||
Metric metric = new Metric(log.isLoggable(Level.FINE));
|
||||
String executeSql = sql;
|
||||
List<Object> firstRowParameters = null;
|
||||
List<List<Object>> parameters = new ArrayList<>();
|
||||
|
@ -338,19 +300,19 @@ public class SqlUpdateImpl implements SqlUpdate {
|
|||
logEx = e;
|
||||
throw DatabaseException.wrap(DebugSql.exceptionMessage(executeSql, firstRowParameters, errorCode, options), e);
|
||||
} finally {
|
||||
adaptor.closeQuietly(ps, logger);
|
||||
adaptor.closeQuietly(ps, log);
|
||||
metric.done("close");
|
||||
if (isSuccess) {
|
||||
DebugSql.logSuccess("Insert", logger, metric, executeSql, firstRowParameters, options);
|
||||
DebugSql.logSuccess("Insert", log, metric, executeSql, firstRowParameters, options);
|
||||
} else {
|
||||
DebugSql.logError("Insert", logger, metric, errorCode, executeSql, firstRowParameters, options, logEx);
|
||||
DebugSql.logError("Insert", log, metric, errorCode, executeSql, firstRowParameters, options, logEx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int updateInternal(int expectedNumAffectedRows) {
|
||||
PreparedStatement ps = null;
|
||||
Metric metric = new Metric(logger.isLoggable(Level.FINE));
|
||||
Metric metric = new Metric(log.isLoggable(Level.FINE));
|
||||
String executeSql = sql;
|
||||
List<Object> parameters = null;
|
||||
boolean isSuccess = false;
|
||||
|
@ -384,12 +346,12 @@ public class SqlUpdateImpl implements SqlUpdate {
|
|||
logEx = e;
|
||||
throw DatabaseException.wrap(DebugSql.exceptionMessage(executeSql, parameters, errorCode, options), e);
|
||||
} finally {
|
||||
adaptor.closeQuietly(ps, logger);
|
||||
adaptor.closeQuietly(ps, log);
|
||||
metric.done("close");
|
||||
if (isSuccess) {
|
||||
DebugSql.logSuccess("Update", logger, metric, executeSql, parameters, options);
|
||||
DebugSql.logSuccess("Update", log, metric, executeSql, parameters, options);
|
||||
} else {
|
||||
DebugSql.logError("Update", logger, metric, errorCode, executeSql, parameters, options, logEx);
|
||||
DebugSql.logError("Update", log, metric, errorCode, executeSql, parameters, options, logEx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,11 +11,13 @@ import java.sql.SQLException;
|
|||
import java.sql.Statement;
|
||||
import java.sql.Timestamp;
|
||||
import java.sql.Types;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
@ -95,10 +97,18 @@ public class StatementAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
public Object nullInstant(Instant arg) {
|
||||
return arg == null ? new SqlNull(Types.TIMESTAMP) : Timestamp.valueOf(arg.atOffset(ZoneOffset.UTC).toLocalDateTime());
|
||||
}
|
||||
|
||||
public Object nullLocalDateTime(LocalDateTime arg) {
|
||||
return arg == null ? new SqlNull(Types.TIMESTAMP) : Timestamp.valueOf(arg);
|
||||
}
|
||||
|
||||
public Object nullZonedDateTime(ZonedDateTime arg) {
|
||||
return arg == null ? new SqlNull(Types.TIMESTAMP) : Timestamp.valueOf(arg.toLocalDateTime());
|
||||
}
|
||||
|
||||
public Object nullOffsetDateTime(OffsetDateTime arg) {
|
||||
return arg == null ? new SqlNull(Types.TIMESTAMP) : Timestamp.valueOf(arg.toLocalDateTime());
|
||||
}
|
||||
|
@ -107,10 +117,6 @@ public class StatementAdapter {
|
|||
return arg == null ? new SqlNull(Types.DATE) : java.sql.Date.valueOf(arg);
|
||||
}
|
||||
|
||||
public Object nullLocalTime(LocalTime arg) {
|
||||
return arg == null ? new SqlNull(Types.TIME) : java.sql.Time.valueOf(arg);
|
||||
}
|
||||
|
||||
public Object nullNumeric(Number arg) {
|
||||
if (arg == null) {
|
||||
return new SqlNull(Types.NUMERIC);
|
||||
|
|
|
@ -110,6 +110,11 @@ public class Derby implements Flavor {
|
|||
return "timestamptz";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String typeZonedDateTime() {
|
||||
return "timestamptz";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String typeLocalDate() {
|
||||
return "date";
|
||||
|
|
|
@ -110,6 +110,11 @@ public class H2 implements Flavor {
|
|||
return "timestamptz";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String typeZonedDateTime() {
|
||||
return "timestamptz";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String typeLocalDate() {
|
||||
return "date";
|
||||
|
|
|
@ -110,6 +110,11 @@ public class Hsql implements Flavor {
|
|||
return "timestamp with time zone";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String typeZonedDateTime() {
|
||||
return "timestamp with time zone";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String typeLocalDate() {
|
||||
return "date";
|
||||
|
|
|
@ -10,9 +10,12 @@ import java.io.StringReader;
|
|||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.Types;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -578,6 +581,23 @@ public class RowStub {
|
|||
return new ByteArrayInputStream(getBlobBytesOrZeroLen(columnName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instant getInstantOrNull() {
|
||||
return toInstant(rows.get(row)[++col]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instant getInstantOrNull(int columnOneBased) {
|
||||
col = columnOneBased;
|
||||
return toInstant(rows.get(row)[columnOneBased - 1]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instant getInstantOrNull(String columnName) {
|
||||
col = columnIndexByName(columnName) + 1;
|
||||
return toInstant(rows.get(row)[columnIndexByName(columnName)]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDateTime getLocalDateTimeOrNull() {
|
||||
return toLocalDateTime(rows.get(row)[++col]);
|
||||
|
@ -612,6 +632,23 @@ public class RowStub {
|
|||
return toOffsetDateTime(rows.get(row)[columnIndexByName(columnName)]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZonedDateTime getZonedDateTimeOrNull() {
|
||||
return toZonedDateTime(rows.get(row)[++col]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZonedDateTime getZonedDateTimeOrNull(int columnOneBased) {
|
||||
col = columnOneBased;
|
||||
return toZonedDateTime(rows.get(row)[columnOneBased - 1]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZonedDateTime getZonedDateTimeOrNull(String columnName) {
|
||||
col = columnIndexByName(columnName) + 1;
|
||||
return toZonedDateTime(rows.get(row)[columnIndexByName(columnName)]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate getLocalDateOrNull() {
|
||||
return toLocalDate(rows.get(row)[++col]);
|
||||
|
@ -698,13 +735,28 @@ public class RowStub {
|
|||
return (BigDecimal) o;
|
||||
}
|
||||
|
||||
private Instant toInstant(Object o) {
|
||||
if (o instanceof String s) {
|
||||
if (s.length() == "yyyy-MM-dd".length()) {
|
||||
return Instant.parse(s);
|
||||
}
|
||||
if (s.length() == "yyyy-MM-ddThh:mm:ss".length()) {
|
||||
return Instant.parse(s);
|
||||
}
|
||||
throw new DatabaseException("Didn't understand date string: " + s);
|
||||
}
|
||||
return (Instant) o;
|
||||
}
|
||||
|
||||
private LocalDateTime toLocalDateTime(Object o) {
|
||||
if (o instanceof String s) {
|
||||
if (s.length() == "yyyy-MM-dd".length()) {
|
||||
return LocalDateTime.parse(s, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
return LocalDateTime.parse(s, DateTimeFormatter.ofPattern("yyyy-MM-dd"))
|
||||
.atZone(ZoneId.systemDefault()).toLocalDateTime();
|
||||
}
|
||||
if (s.length() == "yyyy-MM-ddThh:mm:ss".length()) {
|
||||
return LocalDateTime.parse(s, DateTimeFormatter.ofPattern("yyyy-MM-ddThh:mm:ss"));
|
||||
return LocalDateTime.parse(s, DateTimeFormatter.ofPattern("yyyy-MM-ddThh:mm:ss"))
|
||||
.atZone(ZoneId.systemDefault()).toLocalDateTime();
|
||||
}
|
||||
throw new DatabaseException("Didn't understand date string: " + s);
|
||||
}
|
||||
|
@ -724,6 +776,19 @@ public class RowStub {
|
|||
return (OffsetDateTime) o;
|
||||
}
|
||||
|
||||
private ZonedDateTime toZonedDateTime(Object o) {
|
||||
if (o instanceof String s) {
|
||||
if (s.length() == "yyyy-MM-dd".length()) {
|
||||
return ZonedDateTime.parse(s, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
}
|
||||
if (s.length() == "yyyy-MM-ddThh:mm:ss".length()) {
|
||||
return ZonedDateTime.parse(s, DateTimeFormatter.ofPattern("yyyy-MM-ddThh:mm:ss"));
|
||||
}
|
||||
throw new DatabaseException("Didn't understand date string: " + s);
|
||||
}
|
||||
return (ZonedDateTime) o;
|
||||
}
|
||||
|
||||
private LocalDate toLocalDate(Object o) {
|
||||
if (o instanceof String) {
|
||||
return LocalDate.parse((String) o);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.xbib.jdbc.test;
|
||||
|
||||
import java.time.Instant;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -26,12 +25,14 @@ import java.io.Reader;
|
|||
import java.io.StringReader;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Month;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
|
@ -69,6 +70,8 @@ public abstract class CommonTest {
|
|||
|
||||
protected OffsetDateTime offsetDateTimeNow;
|
||||
|
||||
protected ZonedDateTime zonedDateTimeNow;
|
||||
|
||||
protected abstract DatabaseProvider createDatabaseProvider(OptionsOverride options) throws Exception;
|
||||
|
||||
@BeforeEach
|
||||
|
@ -76,6 +79,7 @@ public abstract class CommonTest {
|
|||
localDateTimeNow = LocalDateTime.now().truncatedTo(ChronoUnit.MILLIS);
|
||||
localDateNow = LocalDate.now();
|
||||
offsetDateTimeNow = OffsetDateTime.now();
|
||||
zonedDateTimeNow = ZonedDateTime.now();
|
||||
dbp = createDatabaseProvider(new OptionsOverride() {
|
||||
});
|
||||
db = dbp.get();
|
||||
|
@ -149,10 +153,11 @@ public abstract class CommonTest {
|
|||
.addColumn("date_millis").asLocalDateTime().table()
|
||||
.addColumn("local_date").asLocalDate().table()
|
||||
.addColumn("offset_date_time").asOffsetDateTime().table()
|
||||
.addColumn("tz_date_time").asZonedateTime().table()
|
||||
.schema()
|
||||
.execute(db);
|
||||
BigDecimal bigDecimal = new BigDecimal("5.3");
|
||||
db.toInsert("insert into dbtest values (?,?,?,?,?,?,?,?,?,?,?,?)")
|
||||
db.toInsert("insert into dbtest values (?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
||||
.argInteger(1)
|
||||
.argLong(2L)
|
||||
.argFloat(3.2f)
|
||||
|
@ -165,9 +170,10 @@ public abstract class CommonTest {
|
|||
.argLocalDateTime(localDateTimeNow)
|
||||
.argLocalDate(localDateNow)
|
||||
.argOffsetDateTime(offsetDateTimeNow)
|
||||
.argZonedDateTime(zonedDateTimeNow)
|
||||
.insert(1);
|
||||
db.toSelect("select nbr_integer, nbr_long, nbr_float, nbr_double, nbr_big_decimal, str_varchar, str_fixed, str_lob, "
|
||||
+ "bin_blob, date_millis, local_date, offset_date_time from dbtest")
|
||||
+ "bin_blob, date_millis, local_date, offset_date_time, tz_date_time from dbtest")
|
||||
.query((RowsHandler<Void>) rs -> {
|
||||
assertTrue(rs.next());
|
||||
assertEquals(Integer.valueOf(1), rs.getIntegerOrNull(1));
|
||||
|
@ -214,11 +220,14 @@ public abstract class CommonTest {
|
|||
rs.getOffsetDateTimeOrNull(12).truncatedTo(ChronoUnit.SECONDS));
|
||||
assertEquals(offsetDateTimeNow.truncatedTo(ChronoUnit.SECONDS),
|
||||
rs.getOffsetDateTimeOrNull("offset_date_time").truncatedTo(ChronoUnit.SECONDS));
|
||||
// org.postgresql.util.PSQLException: conversion to class java.time.ZonedDateTime from timestamptz not supported
|
||||
// assertEquals(zonedDateTimeNow, rs.getZonedDateTimeOrNull(13));
|
||||
// assertEquals(zonedDateTimeNow, rs.getZonedDateTimeOrNull("tz_date_time"));
|
||||
return null;
|
||||
});
|
||||
// Repeat the above query, using the various methods that automatically infer the column
|
||||
db.toSelect("select nbr_integer, nbr_long, nbr_float, nbr_double, nbr_big_decimal, str_varchar, str_fixed, str_lob, "
|
||||
+ "bin_blob, date_millis, local_date, offset_date_time from dbtest")
|
||||
+ "bin_blob, date_millis, local_date, offset_date_time, tz_date_time from dbtest")
|
||||
.query((RowsHandler<Void>) rs -> {
|
||||
assertTrue(rs.next());
|
||||
assertEquals(Integer.valueOf(1), rs.getIntegerOrNull());
|
||||
|
@ -233,10 +242,12 @@ public abstract class CommonTest {
|
|||
assertEquals(localDateTimeNow, rs.getLocalDateTimeOrNull());
|
||||
assertEquals(localDateNow, rs.getLocalDateOrNull());
|
||||
assertEquals(offsetDateTimeNow.truncatedTo(ChronoUnit.SECONDS), rs.getOffsetDateTimeOrNull().truncatedTo(ChronoUnit.SECONDS));
|
||||
// org.postgresql.util.PSQLException: conversion to class java.time.ZonedDateTime from timestamptz not supported
|
||||
//assertEquals(zonedDateTimeNow, rs.getZonedDateTimeOrNull());
|
||||
return null;
|
||||
});
|
||||
db.toSelect("select nbr_integer, nbr_long, nbr_float, nbr_double, nbr_big_decimal, str_varchar, str_fixed, str_lob, "
|
||||
+ "bin_blob, date_millis, local_date, offset_date_time from dbtest")
|
||||
+ "bin_blob, date_millis, local_date, offset_date_time, tz_date_time from dbtest")
|
||||
.query((RowsHandler<Void>) rs -> {
|
||||
assertTrue(rs.next());
|
||||
assertEquals(1, rs.getIntegerOrZero());
|
||||
|
@ -251,6 +262,8 @@ public abstract class CommonTest {
|
|||
assertEquals(localDateTimeNow, rs.getLocalDateTimeOrNull());
|
||||
assertEquals(localDateNow, rs.getLocalDateOrNull());
|
||||
assertEquals(offsetDateTimeNow.truncatedTo(ChronoUnit.SECONDS), rs.getOffsetDateTimeOrNull().truncatedTo(ChronoUnit.SECONDS));
|
||||
// org.postgresql.util.PSQLException: conversion to class java.time.ZonedDateTime from timestamptz not supported
|
||||
//assertEquals(zonedDateTimeNow, rs.getZonedDateTimeOrNull());
|
||||
return null;
|
||||
});
|
||||
db.toSelect("select str_lob, bin_blob from dbtest").query((RowsHandler<Void>) rs -> {
|
||||
|
|
Loading…
Reference in a new issue