[jOOQ/jOOQ#11738] Added the optional, provided ojdbc dependency

This commit is contained in:
Lukas Eder 2021-03-31 11:41:40 +02:00
parent 83103e8811
commit bf531df8f2
7 changed files with 73 additions and 70 deletions

View File

@ -104,6 +104,18 @@
<artifactId>jaxb-api</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>

View File

@ -58,6 +58,8 @@ import org.jooq.Converter;
import org.jooq.Converters;
import org.jooq.tools.jdbc.JDBCUtils;
// ...
/**
* A binding that takes binary values but binds them as {@link Blob} to at the
* JDBC level.
@ -148,8 +150,6 @@ public class BlobBinding implements Binding<byte[], byte[]> {
default: {
blob = localConnection().createBlob();
break;

View File

@ -58,6 +58,8 @@ import org.jooq.Converter;
import org.jooq.Converters;
import org.jooq.tools.jdbc.JDBCUtils;
// ...
/**
* A binding that takes binary values but binds them as {@link Clob} to at the
* JDBC level.
@ -148,8 +150,6 @@ public class ClobBinding implements Binding<String, String> {
default: {
clob = localConnection().createClob();
break;

View File

@ -74,21 +74,17 @@ import static org.jooq.SQLDialect.SQLITE;
// ...
// ...
// ...
import static org.jooq.conf.ParamType.INLINED;
import static org.jooq.impl.DSL.cast;
import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.inline;
import static org.jooq.impl.DSL.log;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.power;
import static org.jooq.impl.DSL.sqrt;
import static org.jooq.impl.DSL.using;
import static org.jooq.impl.DefaultBinding.DefaultDoubleBinding.REQUIRES_LITERAL_CAST;
import static org.jooq.impl.DefaultBinding.DefaultDoubleBinding.infinity;
import static org.jooq.impl.DefaultBinding.DefaultDoubleBinding.nan;
import static org.jooq.impl.DefaultExecuteContext.localTargetConnection;
import static org.jooq.impl.DefaultExecuteContext.targetPreparedStatement;
import static org.jooq.impl.Keywords.K_ARRAY;
import static org.jooq.impl.Keywords.K_AS;
import static org.jooq.impl.Keywords.K_BLOB;
@ -223,6 +219,7 @@ import org.jooq.tools.jdbc.JDBCUtils;
import org.jooq.tools.jdbc.MockArray;
import org.jooq.tools.jdbc.MockResultSet;
import org.jooq.tools.reflect.Reflect;
import org.jooq.tools.reflect.ReflectException;
import org.jooq.types.DayToSecond;
import org.jooq.types.UByte;
import org.jooq.types.UInteger;
@ -234,6 +231,11 @@ import org.jooq.util.postgres.PostgresUtils;
// ...
// ...
// ...
// ...
// ...
/**
* @author Lukas Eder
*/
@ -2345,6 +2347,31 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
super(dataType, converter);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
static final Field<?> nan(BindingSQLContext<?> ctx, DataType<?> type) {
switch (ctx.family()) {
@ -2951,7 +2978,6 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
else
throw new UnsupportedOperationException("Type " + dataType + " is not supported");
}
@ -2989,9 +3015,6 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
else
throw new UnsupportedOperationException("Type " + dataType + " is not supported");
}
@ -3042,8 +3065,6 @@ public class DefaultBinding<T, U> implements Binding<T, U> {

View File

@ -69,6 +69,7 @@ import org.jooq.ExecuteContext;
import org.jooq.ExecuteType;
import org.jooq.Insert;
import org.jooq.Merge;
// ...
import org.jooq.Query;
import org.jooq.Record;
import org.jooq.Result;
@ -82,6 +83,8 @@ import org.jooq.tools.jdbc.JDBCUtils;
import org.jetbrains.annotations.NotNull;
// ...
/**
* A default implementation for the {@link ExecuteContext}.
*
@ -296,43 +299,6 @@ class DefaultExecuteContext implements ExecuteContext {
log.info("Could not unwrap native Connection type. Consider implementing an org.jooq.UnwrapperProvider");
return result;
}
/**
* Get the registered connection's "target connection" if applicable.
* <p>
* This will try to unwrap any native connection if it has been wrapped with
* any of:
* <ul>
* <li><code>org.apache.commons.dbcp.DelegatingPreparedStatement</code></li>
* <li>...</li>
* </ul>
*/
static final PreparedStatement targetPreparedStatement(Configuration configuration, PreparedStatement stmt) {
PreparedStatement result = stmt;
log.info("Could not unwrap native PreparedStatement type. Consider implementing an org.jooq.UnwrapperProvider");
return result;
}
// ------------------------------------------------------------------------
// XXX: Constructors

View File

@ -55,11 +55,12 @@ import org.jooq.EnumType;
import org.jooq.Record;
import org.jooq.exception.DataTypeException;
import org.jooq.tools.StringUtils;
import org.jooq.tools.reflect.Reflect;
import org.jooq.types.DayToSecond;
import org.jooq.types.YearToMonth;
import org.jooq.types.YearToSecond;
import org.postgresql.util.PGInterval;
/**
* A collection of utilities to cover the Postgres JDBC driver's missing
* implementations.
@ -239,18 +240,18 @@ public class PostgresUtils {
public static DayToSecond toDayToSecond(Object pgInterval) {
boolean negative = pgInterval.toString().contains("-");
Reflect i = on(pgInterval);
if (negative) {
i.call("scale", -1);
}
PGInterval i = (PGInterval) pgInterval;
if (negative)
i.scale(-1);
Double seconds = i.call("getSeconds").get();
Double seconds = i.getSeconds();
DayToSecond result = new DayToSecond(
i.call("getDays").get(),
i.call("getHours").get(),
i.call("getMinutes").get(),
i.getDays(),
i.getHours(),
i.getMinutes(),
seconds.intValue(),
(int) (1000000000 * (seconds - seconds.intValue())));
(int) (1000000000 * (seconds - seconds.intValue()))
);
if (negative)
result = result.neg();
@ -264,14 +265,11 @@ public class PostgresUtils {
public static YearToMonth toYearToMonth(Object pgInterval) {
boolean negative = pgInterval.toString().contains("-");
Reflect i = on(pgInterval);
if (negative) {
i.call("scale", -1);
}
PGInterval i = (PGInterval) pgInterval;
if (negative)
i.scale(-1);
YearToMonth result = new YearToMonth(
i.call("getYears").get(),
i.call("getMonths").get());
YearToMonth result = new YearToMonth(i.getYears(), i.getMonths());
if (negative)
result = result.neg();

10
pom.xml
View File

@ -31,10 +31,11 @@
<sqlite.version>3.32.3.2</sqlite.version>
<derby.version>10.14.2.0</derby.version>
<hsqldb.version>2.5.1</hsqldb.version>
<sqlserver.version>9.2.1.jre11</sqlserver.version>
<!-- JDBC drivers for jOOQ-xyz-extensions modules -->
<!-- JDBC drivers for jOOQ-xyz-extensions modules and vendor-specific API access -->
<postgres.version>42.2.19</postgres.version>
<sqlserver.version>9.2.1.jre11</sqlserver.version>
<oracle.version>21.1.0.0</oracle.version>
<!-- From JDK 11 onwards, we need to depend on the JAXB API explicitly -->
<jaxb.version>2.3.1</jaxb.version>
@ -321,6 +322,11 @@
<!-- jooq-meta-extensions and integration tests have this dependency -->
<dependency>
<groupId>org.hibernate</groupId>