[jOOQ/jOOQ#12425] Backport pattern matching for instanceof (WIP)

This commit is contained in:
Lukas Eder 2021-10-07 22:45:19 +02:00
parent cb564c8387
commit 43ab2fbf7c
31 changed files with 123 additions and 165 deletions

View File

@ -29916,7 +29916,7 @@ public class DSL {
DataType t = DefaultDataType.getDataType(DEFAULT, type, (DataType) SQLDataType.OTHER);
if (t instanceof LegacyConvertedDataType)
return new DataTypeProxy((AbstractDataType) t);
return new DataTypeProxy((LegacyConvertedDataType) t);
else if (t != SQLDataType.OTHER)
return t;
else

View File

@ -1322,7 +1322,7 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
if (array instanceof Object[])
return Convert.convert(array, type);
else if (array instanceof Array)
return convertArray(((Array) array), type);
return convertArray((Array) array, type);
return null;
}
@ -3451,9 +3451,7 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
* LOB, if the argument is a lob.
*/
private static final Object unlob(Object object) throws SQLException {
if (object instanceof Blob) {
Blob blob = (Blob) object;
if (object instanceof Blob) { Blob blob = (Blob) object;
try {
return blob.getBytes(1, (int) blob.length());
}
@ -3461,9 +3459,7 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
JDBCUtils.safeFree(blob);
}
}
else if (object instanceof Clob) {
Clob clob = (Clob) object;
else if (object instanceof Clob) { Clob clob = (Clob) object;
try {
return clob.getSubString(1, (int) clob.length());
}

View File

@ -76,15 +76,12 @@ public class DefaultCloseableDSLContext extends DefaultDSLContext implements Clo
ConnectionProvider cp = configuration().connectionProvider();
ConnectionFactory cf = configuration().connectionFactory();
if (cp instanceof DefaultCloseableConnectionProvider) {
DefaultConnectionProvider dcp = (DefaultCloseableConnectionProvider) cp;
if (cp instanceof DefaultCloseableConnectionProvider) { DefaultCloseableConnectionProvider dcp = (DefaultCloseableConnectionProvider) cp;
JDBCUtils.safeClose(dcp.connection);
dcp.connection = null;
}
if (cf instanceof DefaultConnectionFactory) {
DefaultConnectionFactory dcf = (DefaultConnectionFactory) cf;
if (cf instanceof DefaultConnectionFactory) { DefaultConnectionFactory dcf = (DefaultConnectionFactory) cf;
if (dcf.finalize) {
R2DBC.block(dcf.connection.close());
dcf.connection = null;

View File

@ -1229,9 +1229,8 @@ public class DefaultConfiguration extends AbstractConfiguration {
if (newTransactionProvider instanceof ThreadLocalTransactionProvider)
this.connectionProvider = ((ThreadLocalTransactionProvider) newTransactionProvider).localConnectionProvider;
}
else {
else
this.transactionProvider = new NoTransactionProvider();
}
return this;
}

View File

@ -150,8 +150,7 @@ public class DefaultRecordUnmapper<E, R extends Record> implements RecordUnmappe
if (source == null)
return null;
if (source instanceof Object[]) {
Object[] array = (Object[]) source;
if (source instanceof Object[]) { Object[] array = (Object[]) source;
int size = rowType.size();
Record record = newRecord();
@ -177,8 +176,8 @@ public class DefaultRecordUnmapper<E, R extends Record> implements RecordUnmappe
if (source == null)
return null;
if (source instanceof Iterable) {
Iterator<?> it = ((Iterable<?>) source).iterator();
if (source instanceof Iterable) { Iterable<?> iterable = (Iterable<?>) source;
Iterator<?> it = iterable.iterator();
int size = rowType.size();
Record record = newRecord();
@ -206,8 +205,7 @@ public class DefaultRecordUnmapper<E, R extends Record> implements RecordUnmappe
// [#1987] Distinguish between various types to load data from
// Maps are loaded using a {field-name -> value} convention
if (source instanceof Map) {
Map<?, ?> map = (Map<?, ?>) source;
if (source instanceof Map) { Map<?, ?> map = (Map<?, ?>) source;
Record record = newRecord();
for (int i = 0; i < fields.length; i++) {

View File

@ -278,8 +278,8 @@ final class FieldsImpl<R extends Record> extends AbstractQueryPart implements Re
}
private final String tableName(Field<?> field) {
if (field instanceof TableField) {
Table<?> table = ((TableField<?, ?>) field).getTable();
if (field instanceof TableField) { TableField<?, ?> f = (TableField<?, ?>) field;
Table<?> table = f.getTable();
if (table != null)
return table.getName();

View File

@ -828,7 +828,7 @@ final class InsertImpl<R extends Record, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10
// [#8606] The column index is relevant when adding a value to a plain SQL multi row INSERT
// statement that does not have any field list.
if (object instanceof Field)
((AbstractStoreQuery<R>) delegate).addValue(field, index, (Field<T>) object);
((AbstractStoreQuery<R>) delegate).addValue(field, index, (Field) object);
else if (object instanceof FieldLike)
((AbstractStoreQuery<R>) delegate).addValue(field, index, ((FieldLike) object).asField());
else if (field != null)

View File

@ -249,11 +249,11 @@ public final class Internal {
public static final Name createPathAlias(Table<?> child, ForeignKey<?, ?> path) {
Name name = DSL.name(path.getName());
if (child instanceof TableImpl) {
Table<?> ancestor = ((TableImpl<?>) child).child;
if (child instanceof TableImpl) { TableImpl<?> t = (TableImpl<?>) child;
Table<?> ancestor = t.child;
if (ancestor != null)
name = createPathAlias(ancestor, ((TableImpl<?>) child).childPath).append(name);
name = createPathAlias(ancestor, t.childPath).append(name);
else
name = child.getQualifiedName().append(name);
}

View File

@ -503,25 +503,25 @@ final class Interpreter {
// TODO: ReverseIterable is not a viable approach if we also allow constraints to be added this way
if (query.$addFirst()) {
for (Field<?> f : assertFields(query, reverseIterable(query.$add())))
addField(existing, 0, (UnqualifiedName) f.getUnqualifiedName(), ((Field<?>) f).getDataType());
addField(existing, 0, (UnqualifiedName) f.getUnqualifiedName(), f.getDataType());
}
else if (query.$addBefore() != null) {
int index = indexOrFail(existing.fields, query.$addBefore());
for (Field<?> f : assertFields(query, reverseIterable(query.$add())))
addField(existing, index, (UnqualifiedName) f.getUnqualifiedName(), ((Field<?>) f).getDataType());
addField(existing, index, (UnqualifiedName) f.getUnqualifiedName(), f.getDataType());
}
else if (query.$addAfter() != null) {
int index = indexOrFail(existing.fields, query.$addAfter()) + 1;
for (Field<?> f : assertFields(query, reverseIterable(query.$add())))
addField(existing, index, (UnqualifiedName) f.getUnqualifiedName(), ((Field<?>) f).getDataType());
addField(existing, index, (UnqualifiedName) f.getUnqualifiedName(), f.getDataType());
}
else {
for (FieldOrConstraint fc : query.$add())
if (fc instanceof Field)
addField(existing, Integer.MAX_VALUE, (UnqualifiedName) fc.getUnqualifiedName(), ((Field<?>) fc).getDataType());
else if (fc instanceof Constraint)
else if (fc instanceof ConstraintImpl)
addConstraint(query, (ConstraintImpl) fc, existing);
else
throw unsupportedQuery(query);

View File

@ -55,7 +55,7 @@ final class ModeDeferred implements OrderedAggregateFunctionOfDeferredType {
public final <T> AggregateFilterStep<T> withinGroupOrderBy(OrderField<T> field) {
DataType<T> type = field instanceof SortFieldImpl
? ((SortFieldImpl<T>) field).getField().getDataType()
: field instanceof Field
: field instanceof AbstractField
? ((AbstractField<T>) field).getDataType()
: (DataType<T>) SQLDataType.NUMERIC;

View File

@ -138,10 +138,10 @@ final class MultisetDataType<R extends Record> extends DefaultDataType<Result<R>
public Result<R> convert(Object object) {
// [#3884] TODO: Move this logic into JSONReader to make it more generally useful
if (object instanceof List) {
if (object instanceof List) { List l = (List) object;
ResultImpl<R> result = new ResultImpl<>(CTX.configuration(), row);
for (Object record : (List) object)
for (Object record : l)
result.add(newRecord(true, recordType, row, CTX.configuration())
.operate(r -> {

View File

@ -81,8 +81,6 @@ final class Neg<T> extends AbstractTransformable<T> implements QOM.Neg<T> {
return this;
}

View File

@ -75,8 +75,7 @@ final class ParamCollector extends AbstractBindContext {
@Override
protected final void bindInternal(QueryPartInternal internal) {
if (internal instanceof Param) {
Param<?> param = (Param<?>) internal;
if (internal instanceof Param) { Param<?> param = (Param<?>) internal;
// [#3131] Inlined parameters should not be returned in some contexts
if (includeInlinedParams || !param.isInline()) {

View File

@ -6264,9 +6264,9 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
: ((Field) left).isDocument();
not = parseKeywordIf("DISTINCT FROM") == not;
if (left instanceof Field) {
if (left instanceof Field) { Field f = (Field) left;
Field right = toField(parseConcat());
return not ? ((Field) left).isNotDistinctFrom(right) : ((Field) left).isDistinctFrom(right);
return not ? f.isNotDistinctFrom(right) : f.isDistinctFrom(right);
}
else {
Row right = parseRow(((Row) left).size(), true);
@ -7210,22 +7210,20 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
}
private final Condition toCondition(QueryPart part) {
if (part == null) {
if (part == null)
return null;
}
else if (part instanceof Condition) {
else if (part instanceof Condition)
return (Condition) part;
}
else if (part instanceof Field) {
DataType dataType = ((Field) part).getDataType();
else if (part instanceof Field) { Field f = (Field) part;
DataType dataType = f.getDataType();
Class<?> type = dataType.getType();
if (type == Boolean.class)
return condition((Field) part);
return condition(f);
// [#11631] [#12394] Numeric expressions are booleans in MySQL
else if (dataType.isNumeric())
return ((Field) part).ne(zero());
return f.ne(zero());
// [#7266] Support parsing column references as predicates
else if (type == Object.class && (part instanceof TableFieldImpl || part instanceof Val))
@ -7241,7 +7239,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
if (part == null)
return null;
else if (part instanceof Field)
return (Field) part;
return (Field<?>) part;
else if (part instanceof Condition)
return field((Condition) part);
else if (part instanceof Row)
@ -7254,7 +7252,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
if (part == null)
return null;
else if (part instanceof Field)
return (Field) part;
return (Field<?>) part;
else if (part instanceof Condition)
return field((Condition) part);
else
@ -8238,11 +8236,11 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
FieldOrRow r = parseFieldOrRow();
List<Field<?>> list = null;
if (r instanceof Field) {
if (r instanceof Field) { Field<?> f = (Field<?>) r;
while (parseIf(',')) {
if (list == null) {
list = new ArrayList<>();
list.add((Field) r);
list.add(f);
}
// TODO Allow for nesting ROWs
@ -11093,9 +11091,9 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
Object nameOrSpecification = parseWindowNameOrSpecification(true);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=494897
Field<?> result = (nameOrSpecification instanceof Name)
Field<?> result = nameOrSpecification instanceof Name
? s3.over((Name) nameOrSpecification)
: (nameOrSpecification instanceof WindowSpecification)
: nameOrSpecification instanceof WindowSpecification
? s3.over((WindowSpecification) nameOrSpecification)
: s3.over();
@ -14099,12 +14097,9 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
// [#11054] Use a VisitListener to find actual Params in the expression tree,
// which may have more refined DataTypes attached to them, from context
dsl.configuration().deriveAppending(onVisitStart(ctx -> {
if (ctx.queryPart() instanceof Param) {
Param<?> p = (Param<?>) ctx.queryPart();
if (!params.containsKey(p.getParamName()))
params.put(p.getParamName(), p);
}
if (ctx.queryPart() instanceof Param)
if (!params.containsKey(((Param<?>) ctx.queryPart()).getParamName()))
params.put(((Param<?>) ctx.queryPart()).getParamName(), (Param<?>) ctx.queryPart());
})).dsl().render(result);
for (String name : bindParams.keySet())
@ -14186,11 +14181,11 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
for (Value<Table<?>> t : tables) {
Value<Field<?>> f;
if (t.value() instanceof JoinTable) {
if (t.value() instanceof JoinTable) { JoinTable j = (JoinTable) t.value();
found = resolveInTableScope(
asList(
new Value<>(t.scopeLevel(), ((JoinTable) t.value()).lhs),
new Value<>(t.scopeLevel(), ((JoinTable) t.value()).rhs)
new Value<>(t.scopeLevel(), j.lhs),
new Value<>(t.scopeLevel(), j.rhs)
),
lookupName, lookup, found
);

View File

@ -3933,8 +3933,7 @@ public final class QOM {
) {
// TODO: Support also arrays, sets, etc.
if (q instanceof List) {
List<?> l = (List<?>) q;
if (q instanceof List) { List<?> l = (List<?>) q;
List<Object> r = null;
for (int i = 0; i < l.size(); i++) {
@ -3982,9 +3981,7 @@ public final class QOM {
if (test(abort, current)) return current;
for (int i = 0; i < parts.length; i++) {
if (parts[i] instanceof QueryPart) {
QueryPart p = (QueryPart) parts[i];
if (parts[i] instanceof QueryPart) { QueryPart p = (QueryPart) parts[i];
if (test(recurse, p)) {
current = p.$traverse(current, abort, recurse, accumulate);
if (test(abort, current)) return current;

View File

@ -84,8 +84,7 @@ final class QualifiedName extends AbstractName {
UnqualifiedName[] result = new UnqualifiedName[qualifiedName.length];
for (int i = 0; i < qualifiedName.length; i++)
if (qualifiedName[i] instanceof QualifiedName) {
QualifiedName q = (QualifiedName) qualifiedName[i];
if (qualifiedName[i] instanceof QualifiedName) { QualifiedName q = (QualifiedName) qualifiedName[i];
result[i] = q.qualifiedName[q.qualifiedName.length - 1];
}
else if (qualifiedName[i] instanceof UnqualifiedName)

View File

@ -83,9 +83,7 @@ class QueryPartCollectionView<T extends QueryPart> extends AbstractQueryPart imp
QueryPartCollectionView(Collection<T> wrapped) {
this.wrapped = wrapped != null ? wrapped : Collections.emptyList();
if (wrapped instanceof QueryPartCollectionView) {
QueryPartCollectionView<T> v = (QueryPartCollectionView<T>) wrapped;
if (wrapped instanceof QueryPartCollectionView) { QueryPartCollectionView<T> v = (QueryPartCollectionView<T>) wrapped;
this.qualify = v.qualify;
this.separator = v.separator;
this.mapper = v.mapper;

View File

@ -1136,14 +1136,11 @@ final class ResultImpl<R extends Record> extends AbstractResult<R> implements Re
@Override
public boolean equals(Object obj) {
if (this == obj) {
if (this == obj)
return true;
}
if (obj instanceof ResultImpl) {
ResultImpl<R> other = (ResultImpl<R>) obj;
return records.equals(other.records);
}
if (obj instanceof ResultImpl)
return records.equals(((ResultImpl<?>) obj).records);
return false;
}

View File

@ -1455,8 +1455,8 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
}
default boolean hasLimit1() {
if (this instanceof Select) {
SelectQueryImpl<?> s = Tools.selectQueryImpl((Select<?>) this);
if (this instanceof Select) { Select<?> q = (Select<?>) this;
SelectQueryImpl<?> s = Tools.selectQueryImpl(q);
if (s != null) {
Limit l = s.getLimit();

View File

@ -123,14 +123,11 @@ final class ResultsImpl extends AbstractList<Result<Record>> implements Results
@Override
public boolean equals(Object obj) {
if (this == obj) {
if (this == obj)
return true;
}
if (obj instanceof ResultsImpl) {
ResultsImpl other = (ResultsImpl) obj;
return resultsOrRows.equals(other.resultsOrRows);
}
if (obj instanceof ResultsImpl)
return resultsOrRows.equals(((ResultsImpl) obj).resultsOrRows);
return false;
}

View File

@ -120,8 +120,8 @@ implements
return;
}
else if (decimals instanceof Param) {
Integer decimalsValue = ((Param<Integer>) decimals).getValue();
else if (decimals instanceof Param) { Param<Integer> p = (Param<Integer>) decimals;
Integer decimalsValue = p.getValue();
Field<?> factor = DSL.val(java.math.BigDecimal.ONE.movePointRight(decimalsValue));
Field<T> mul = imul(value, factor);

View File

@ -90,9 +90,8 @@ final class SQLResultQuery extends AbstractResultQuery<Record> implements UEmpty
@Override
public final Clause[] clauses(Context<?> ctx) {
if (delegate instanceof QueryPartInternal) {
if (delegate instanceof QueryPartInternal)
return ((QueryPartInternal) delegate).clauses(ctx);
}
return null;
}

View File

@ -378,8 +378,7 @@ public class SchemaImpl extends AbstractNamed implements Schema {
// [#2144] SchemaImpl equality can be decided without executing the
// rather expensive implementation of AbstractQueryPart.equals()
if (that instanceof SchemaImpl) {
SchemaImpl other = (SchemaImpl) that;
if (that instanceof SchemaImpl) { SchemaImpl other = (SchemaImpl) that;
return
// [#7172] [#10274] Cannot use getQualifiedName() yet here

View File

@ -1235,7 +1235,6 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
@SuppressWarnings({ "rawtypes", "unchecked" })
@ -1244,9 +1243,9 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
// [#3564] TODO: Extract and merge this with getSelectResolveSomeAsterisks0()
List<Field<?>> partitionBy = new ArrayList<>(distinctOn.size());
for (SelectFieldOrAsterisk f : distinctOn)
if (f instanceof Field)
partitionBy.add((Field<?>) f);
for (SelectFieldOrAsterisk s : distinctOn)
if (s instanceof Field)
partitionBy.add((Field<?>) s);
Field<Integer> rn = rowNumber().over(partitionBy(partitionBy).orderBy(orderBy)).as("rn");
@ -2592,9 +2591,7 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
}
private final void transformInlineDerivedTable0(Table<?> table, TableList result, ConditionProviderImpl where) {
if (table instanceof InlineDerivedTable) {
InlineDerivedTable<?> t = (InlineDerivedTable<?>) table;
if (table instanceof InlineDerivedTable) { InlineDerivedTable<?> t = (InlineDerivedTable<?>) table;
result.add(t.table());
where.addConditions(t.condition());
}
@ -2605,9 +2602,7 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
}
private final Table<?> transformInlineDerivedTables0(Table<?> table, ConditionProviderImpl where) {
if (table instanceof InlineDerivedTable) {
InlineDerivedTable<?> t = (InlineDerivedTable<?>) table;
if (table instanceof InlineDerivedTable) { InlineDerivedTable<?> t = (InlineDerivedTable<?>) table;
where.addConditions(t.condition());
return t.table();
}
@ -2953,8 +2948,6 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
@ -3706,33 +3699,35 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
// [#7921] TODO Find a better, more efficient way to resolve asterisks
SelectFieldList<SelectFieldOrAsterisk> list = getSelectResolveImplicitAsterisks();
for (SelectFieldOrAsterisk f : list)
if (f instanceof Field<?>)
result.add(getResolveProjection(c, (Field<?>) f));
else if (f instanceof QualifiedAsterisk)
if (((QualifiedAsteriskImpl) f).fields.isEmpty())
for (SelectFieldOrAsterisk s : list)
if (s instanceof Field)
result.add(getResolveProjection(c, (Field<?>) s));
else if (s instanceof QualifiedAsteriskImpl) { QualifiedAsteriskImpl q = (QualifiedAsteriskImpl) s;
if (q.fields.isEmpty())
if (resolveSupported)
result.addAll(Arrays.asList(((QualifiedAsterisk) f).qualifier().fields()));
result.addAll(Arrays.asList(q.qualifier().fields()));
else
result.add(f);
result.add(s);
else if (resolveExcept)
result.addAll(subtract(Arrays.asList(((QualifiedAsterisk) f).qualifier().fields()), (((QualifiedAsteriskImpl) f).fields)));
result.addAll(subtract(Arrays.asList(((QualifiedAsterisk) s).qualifier().fields()), (((QualifiedAsteriskImpl) s).fields)));
else
result.add(f);
else if (f instanceof Asterisk)
if (((AsteriskImpl) f).fields.isEmpty())
result.add(s);
}
else if (s instanceof AsteriskImpl) { AsteriskImpl a = (AsteriskImpl) s;
if (a.fields.isEmpty())
if (resolveSupported || resolveUnqualifiedCombined && list.size() > 1)
result.addAll(resolveAsterisk(new QueryPartList<>()));
else
result.add(f);
result.add(s);
else if (resolveExcept)
result.addAll(resolveAsterisk(new QueryPartList<>(), ((AsteriskImpl) f).fields));
result.addAll(resolveAsterisk(new QueryPartList<>(), a.fields));
else
result.add(f);
else if (f instanceof Row)
result.add(getResolveProjection(c, new RowField<Row, Record>((Row) f)));
result.add(s);
}
else if (s instanceof Row)
result.add(getResolveProjection(c, new RowField<Row, Record>((Row) s)));
else
throw new AssertionError("Type not supported: " + f);
throw new AssertionError("Type not supported: " + s);
return result;
}

View File

@ -316,8 +316,7 @@ implements
@Override
public boolean equals(Object that) {
if (that instanceof SequenceFunction)
return method == ((SequenceFunction<?>) that).method
&& sequence.equals(((SequenceFunction<?>) that).sequence);
return method == ((SequenceFunction<?>) that).method && sequence.equals(((SequenceFunction<?>) that).sequence);
else
return super.equals(that);
}

View File

@ -214,9 +214,9 @@ implements
this.child = child;
this.childPath = path == null ? null : Tools.aliasedKey((ForeignKey) path, child, this);
}
else if (aliased instanceof TableImpl) {
this.child = ((TableImpl<?>) aliased).child;
this.childPath = ((TableImpl) aliased).childPath;
else if (aliased instanceof TableImpl) { TableImpl t = (TableImpl) aliased;
this.child = t.child;
this.childPath = t.childPath;
}
else {
this.child = null;
@ -473,8 +473,7 @@ implements
// [#2144] TableImpl equality can be decided without executing the
// rather expensive implementation of AbstractQueryPart.equals()
if (that instanceof TableImpl) {
TableImpl<?> other = (TableImpl<?>) that;
if (that instanceof TableImpl) { TableImpl<?> other = (TableImpl<?>) that;
return
// [#7172] [#10274] Cannot use getQualifiedName() yet here

View File

@ -1371,7 +1371,7 @@ final class Tools {
}
static final SortField<?>[] sortFields(OrderField<?>[] fields) {
if (fields instanceof SortField<?>[])
if (fields instanceof SortField[])
return (SortField<?>[]) fields;
else
return map(fields, o -> sortField(o), SortField[]::new);
@ -2481,8 +2481,7 @@ final class Tools {
private static final RuntimeException exception(Cursor<?> cursor, RuntimeException e) {
// [#8877] Make sure these exceptions pass through ExecuteListeners as well
if (cursor instanceof CursorImpl) {
CursorImpl<?> c = (CursorImpl<?>) cursor;
if (cursor instanceof CursorImpl) { CursorImpl<?> c = (CursorImpl<?>) cursor;
c.ctx.exception(e);
c.listener.exception(c.ctx);
return c.ctx.exception();
@ -2553,8 +2552,8 @@ final class Tools {
*/
@SuppressWarnings("null")
static final void renderAndBind(Context<?> ctx, String sql, List<QueryPart> substitutes) {
RenderContext render = (RenderContext) ((ctx instanceof RenderContext) ? ctx : null);
BindContext bind = (BindContext) ((ctx instanceof BindContext) ? ctx : null);
RenderContext render = ctx instanceof RenderContext ? (RenderContext) ctx : null;
BindContext bind = ctx instanceof BindContext ? (BindContext) ctx : null;
int substituteIndex = 0;
char[] sqlChars = sql.toCharArray();
@ -2958,8 +2957,8 @@ final class Tools {
for (Object substitute : substitutes) {
// [#1432] Distinguish between QueryParts and other objects
if (substitute instanceof QueryPart) {
result.add((QueryPart) substitute);
if (substitute instanceof QueryPart) { QueryPart q = (QueryPart) substitute;
result.add(q);
}
else {
@SuppressWarnings("unchecked")
@ -3498,7 +3497,7 @@ final class Tools {
@SuppressWarnings({ "unchecked", "rawtypes" })
static final <R extends Record> SelectQueryImpl<R> selectQueryImpl(QueryPart part) {
if (part instanceof SelectQueryImpl)
return (SelectQueryImpl<R>) part;
return (SelectQueryImpl) part;
else if (part instanceof SelectImpl)
return (SelectQueryImpl<R>) ((SelectImpl) part).getDelegate();
else if (part instanceof ScalarSubquery)
@ -4029,8 +4028,8 @@ final class Tools {
@Override
public boolean equals(Object obj) {
if (obj instanceof SourceMethod) {
Method other = ((SourceMethod) obj).method;
if (obj instanceof SourceMethod) { SourceMethod s = (SourceMethod) obj;
Method other = s.method;
if (method.getName().equals(other.getName())) {
Class<?>[] p1 = method.getParameterTypes();
@ -5168,7 +5167,7 @@ final class Tools {
static final void toSQLDDLTypeDeclaration(Context<?> ctx, DataType<?> type) {
// [#10376] TODO: Move some of this logic into DataType
DataType<?> elementType = (type instanceof ArrayDataType)
DataType<?> elementType = type instanceof ArrayDataType
? ((ArrayDataType<?>) type).elementType
: type;
@ -5638,18 +5637,20 @@ final class Tools {
* Look up a field in a table, or create a new qualified field from the table.
*/
static final Field<?> tableField(Table<?> table, Object field) {
if (field instanceof Field<?>)
if (field instanceof Field)
return (Field<?>) field;
else if (field instanceof Name)
else if (field instanceof Name) { Name n = (Name) field;
if (table.fieldsRow().size() == 0)
return DSL.field(table.getQualifiedName().append(((Name) field).unqualifiedName())) ;
return DSL.field(table.getQualifiedName().append(n.unqualifiedName())) ;
else
return table.field((Name) field);
else if (field instanceof String)
return table.field(n);
}
else if (field instanceof String) { String s = (String) field;
if (table.fieldsRow().size() == 0)
return DSL.field(table.getQualifiedName().append((String) field));
return DSL.field(table.getQualifiedName().append(s));
else
return table.field((String) field);
return table.field(s);
}
else
throw new IllegalArgumentException("Field type not supported: " + field);
}
@ -6377,9 +6378,7 @@ final class Tools {
if (abort != null && abort.test(result))
return result;
if (t instanceof JoinTable) {
JoinTable j = (JoinTable) t;
if (t instanceof JoinTable) { JoinTable j = (JoinTable) t;
if (recurseLhs == null || recurseLhs.test(j)) {
result = traverseJoins(j.lhs, result, abort, recurseLhs, recurseRhs, joinTypeFunction, tableFunction);

View File

@ -119,8 +119,8 @@ final class TranslatingMetaProvider implements MetaProvider {
final Locale locale = SettingsTools.interpreterLocale(ctx.settings());
if (nameCase != null && nameCase != RenderNameCase.AS_IS) {
ctx.configuration().set(onVisitStart(c -> {
if (c.queryPart() instanceof Name) {
Name[] parts = ((Name) c.queryPart()).parts();
if (c.queryPart() instanceof Name) { Name n = (Name) c.queryPart();
Name[] parts = n.parts();
boolean changed = false;
for (int i = 0; i < parts.length; i++) {

View File

@ -118,11 +118,11 @@ final class Val<T> extends AbstractParam<T> implements QOM.Val<T>, UEmpty {
// [#10438] A user defined data type could was not provided explicitly,
// when wrapping a bind value in DSL::val or DSL::inline
if (getDataType() instanceof DataTypeProxy) {
if (getDataType() instanceof DataTypeProxy) { DataTypeProxy<?> p = (DataTypeProxy<?>) getDataType();
// [#9492] Maintain legacy static type registry behaviour for now
if (((DataTypeProxy<?>) getDataType()).type() instanceof LegacyConvertedDataType && type == SQLDataType.OTHER) {
type = (DataType) ((DataTypeProxy<?>) getDataType()).type();
if (p.type() instanceof LegacyConvertedDataType && type == SQLDataType.OTHER) {
type = (DataType) p.type();
if (legacyWarnings.size() < 8 && legacyWarnings.put(type.getType(), "") == null)
log.warn("Deprecation", "User-defined, converted data type " + type.getType() + " was registered statically, which will be unsupported in the future, see https://github.com/jOOQ/jOOQ/issues/9492. Please use explicit data types in generated code, or e.g. with DSL.val(Object, DataType), or DSL.inline(Object, DataType).", new SQLWarning("Static type registry usage"));
@ -166,7 +166,7 @@ final class Val<T> extends AbstractParam<T> implements QOM.Val<T>, UEmpty {
else
acceptDefaultEmbeddable(ctx);
}
else if (ctx instanceof RenderContext) {
else if (ctx instanceof RenderContext) { RenderContext r = (RenderContext) ctx;
ParamType paramType = ctx.paramType();
if (isInline(ctx))
@ -180,7 +180,7 @@ final class Val<T> extends AbstractParam<T> implements QOM.Val<T>, UEmpty {
try {
getBinding().sql(new DefaultBindingSQLContext<>(ctx.configuration(), ctx.data(), (RenderContext) ctx, value, getBindVariable(ctx)));
getBinding().sql(new DefaultBindingSQLContext<>(ctx.configuration(), ctx.data(), r, value, getBindVariable(ctx)));
}
catch (SQLException e) {
throw new DataAccessException("Error while generating SQL for Binding", e);

View File

@ -267,8 +267,7 @@ public class LoggerListener extends DefaultExecuteListener {
if (context.renderContext() != null) {
QueryPart part = context.queryPart();
if (part instanceof Param<?>) {
Param<?> param = (Param<?>) part;
if (part instanceof Param) { Param<?> param = (Param<?>) part;
Object value = param.getValue();
if (value instanceof String && ((String) value).length() > maxLength) {

View File

@ -162,8 +162,8 @@ public class MockResultSetMetaData implements ResultSetMetaData, Serializable {
rs.checkNotClosed();
Field<?> field = rs.result.field(column - 1);
if (field instanceof TableField) {
Table<?> table = ((TableField<?, ?>) field).getTable();
if (field instanceof TableField) { TableField<?, ?> f = (TableField<?, ?>) field;
Table<?> table = f.getTable();
if (table != null) {
Schema schema = table.getSchema();
@ -208,12 +208,11 @@ public class MockResultSetMetaData implements ResultSetMetaData, Serializable {
rs.checkNotClosed();
Field<?> field = rs.result.field(column - 1);
if (field instanceof TableField) {
Table<?> table = ((TableField<?, ?>) field).getTable();
if (field instanceof TableField) { TableField<?, ?> f = (TableField<?, ?>) field;
Table<?> table = f.getTable();
if (table != null) {
if (table != null)
return table.getName();
}
}
// By default, no table is available