[jOOQ/jOOQ#12425] Refactor internal transformation utilities

We already had a few internal expression tree transformation utilities,
which can now be refactored in favour of more generic QOM transformation
tools. The refactoring includes:

- And::transform and Or::transform
- ANSI JOIN to Oracle (+) JOIN transformation (fixing some limitations)
This commit is contained in:
Lukas Eder 2021-10-06 21:26:03 +02:00
parent b14e51a453
commit c094b7b798
4 changed files with 9 additions and 125 deletions

View File

@ -120,28 +120,6 @@ implements
}
}
/**
* @deprecated - This will be implemented using QOM.replace, instead.
*/
@Deprecated
final Condition transform(java.util.function.Function<? super Condition, ? extends Condition> function) {
Condition t1 = arg1 instanceof And
? ((And) arg1).transform(function)
: arg1 instanceof Or
? ((And) arg1).transform(function)
: function.apply(arg1);
Condition t2 = arg2 instanceof And
? ((And) arg2).transform(function)
: arg2 instanceof Or
? ((Or) arg2).transform(function)
: function.apply(arg2);
if (t1 == arg1 && t2 == arg2)
return this;
else
return DSL.and(t1, t2);
}
@Override
final boolean isNullable() {
return ((AbstractCondition) arg1).isNullable() || ((AbstractCondition) arg2).isNullable();

View File

@ -120,28 +120,6 @@ implements
}
}
/**
* @deprecated - This will be implemented using QOM.replace, instead.
*/
@Deprecated
final Condition transform(java.util.function.Function<? super Condition, ? extends Condition> function) {
Condition t1 = arg1 instanceof And
? ((And) arg1).transform(function)
: arg1 instanceof Or
? ((And) arg1).transform(function)
: function.apply(arg1);
Condition t2 = arg2 instanceof And
? ((And) arg2).transform(function)
: arg2 instanceof Or
? ((Or) arg2).transform(function)
: function.apply(arg2);
if (t1 == arg1 && t2 == arg2)
return this;
else
return DSL.or(t1, t2);
}
@Override
final boolean isNullable() {
return ((AbstractCondition) arg1).isNullable() || ((AbstractCondition) arg2).isNullable();

View File

@ -1223,6 +1223,13 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
@ -2946,6 +2953,8 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp

View File

@ -1,81 +0,0 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
* database integrations.
*
* For more information, please visit: http://www.jooq.org/licenses
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq.impl;
import java.util.function.Function;
import org.jooq.Condition;
import org.jooq.Field;
import org.jooq.QueryPart;
import org.jooq.impl.QOM.CombinedCondition;
import org.jooq.impl.QOM.CompareCondition;
/**
* A simple, preliminary pattern matching implementation for {@link Condition}
* matching.
* <p>
* [#8800] Has been implemented to support transforming ANSI join to pre-ANSI
* join syntax. For outer join support, the {@link Condition} model needs to be
* transformed to yield {@link Field#plus()} expressions where applicable.
* <p>
* A future jOOQ version will refactor this implementation in favour of much
* more generic (and efficient) pattern matching of the {@link QueryPart}
* expression tree.
*
* @author Lukas Eder
*/
final class Transform {
final Function<Field<?>, Field<?>> fieldTransformer;
Transform(Function<Field<?>, Field<?>> fieldTransformer) {
this.fieldTransformer = fieldTransformer;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
Condition transform(Condition condition) {
if (condition instanceof ConditionProviderImpl)
return transform(((ConditionProviderImpl) condition).getWhere());
else if (condition instanceof CombinedCondition)
return transform((Condition) ((CombinedCondition) condition).$arg1()).and(transform((Condition) ((CombinedCondition) condition).$arg2()));
else if (condition instanceof CompareCondition)
return fieldTransformer.apply((Field) ((CompareCondition<?>) condition).$arg1()).eq((Field) fieldTransformer.apply((Field) ((CompareCondition<?>) condition).$arg2()));
else
return condition;
}
}