[jOOQ/jOOQ#13601] Derby boolean expressions have to be wrapped in parentheses when passed to COALESCE
This commit is contained in:
parent
e41d0d281c
commit
7cfee02d44
61
jOOQ/src/main/java/org/jooq/impl/AbstractDelegateField.java
Normal file
61
jOOQ/src/main/java/org/jooq/impl/AbstractDelegateField.java
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 org.jooq.Context;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.impl.QOM.UTransient;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
abstract class AbstractDelegateField<T> extends AbstractField<T> implements UTransient {
|
||||
|
||||
private Field<T> delegate;
|
||||
|
||||
AbstractDelegateField(Field<T> delegate) {
|
||||
super(delegate.getQualifiedName(), delegate.getDataType(), delegate.getCommentPart());
|
||||
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public /* non-final */ void accept(Context<?> ctx) {
|
||||
ctx.visit(delegate);
|
||||
}
|
||||
}
|
||||
@ -78,6 +78,14 @@ final class Coalesce<T> extends AbstractField<T> implements QOM.Coalesce<T> {
|
||||
|
||||
|
||||
|
||||
case DERBY: {
|
||||
// [#13601] Workaround for https://issues.apache.org/jira/browse/DERBY-7139
|
||||
ctx.visit(DSL.function(N_COALESCE, getDataType(),
|
||||
Tools.map(fields, f -> f.getType() == Boolean.class ? new ParenthesisedField<>(f) : f, Field[]::new)
|
||||
));
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
ctx.visit(DSL.function(N_COALESCE, getDataType(), fields));
|
||||
break;
|
||||
|
||||
@ -103,6 +103,9 @@ implements
|
||||
|
||||
|
||||
|
||||
case DERBY:
|
||||
return false;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -116,7 +119,6 @@ implements
|
||||
|
||||
|
||||
case CUBRID:
|
||||
case DERBY:
|
||||
case FIREBIRD:
|
||||
case IGNITE:
|
||||
case POSTGRES:
|
||||
@ -162,6 +164,10 @@ implements
|
||||
|
||||
|
||||
|
||||
|
||||
case DERBY:
|
||||
ctx.visit(DSL.coalesce(value, defaultValue));
|
||||
break;
|
||||
|
||||
|
||||
|
||||
@ -176,7 +182,6 @@ implements
|
||||
|
||||
|
||||
case CUBRID:
|
||||
case DERBY:
|
||||
case FIREBIRD:
|
||||
case IGNITE:
|
||||
case POSTGRES:
|
||||
|
||||
63
jOOQ/src/main/java/org/jooq/impl/ParenthesisedField.java
Normal file
63
jOOQ/src/main/java/org/jooq/impl/ParenthesisedField.java
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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 org.jooq.Context;
|
||||
import org.jooq.Field;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
final class ParenthesisedField<T> extends AbstractDelegateField<T> {
|
||||
|
||||
ParenthesisedField(Field<T> delegate) {
|
||||
super(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
final boolean parenthesised(Context<?> ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
ctx.sql('(');
|
||||
super.accept(ctx);
|
||||
ctx.sql(')');
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user