[jOOQ/jOOQ#11232] Support parsing MINVALUE() and MAXVALUE()
This commit is contained in:
parent
1c58bc1966
commit
51ebec9fc5
@ -89,7 +89,6 @@ import static org.jooq.SQLDialect.SQLITE;
|
||||
// ...
|
||||
// ...
|
||||
// ...
|
||||
import static org.jooq.impl.Internal.imul;
|
||||
import static org.jooq.impl.Keywords.K_CUBE;
|
||||
import static org.jooq.impl.Keywords.K_GROUPING_SETS;
|
||||
import static org.jooq.impl.Names.N_IF;
|
||||
@ -144,12 +143,7 @@ import java.util.function.Function;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.jooq.AggregateFunction;
|
||||
import org.jooq.AlterIndexOnStep;
|
||||
import org.jooq.AlterIndexStep;
|
||||
import org.jooq.AlterSequenceStep;
|
||||
import org.jooq.AlterTableStep;
|
||||
import org.jooq.AlterTypeStep;
|
||||
import org.jooq.AlterViewStep;
|
||||
import org.jooq.ArrayAggOrderByStep;
|
||||
// ...
|
||||
import org.jooq.Asterisk;
|
||||
@ -162,7 +156,6 @@ import org.jooq.CharacterSet;
|
||||
import org.jooq.CloseableDSLContext;
|
||||
import org.jooq.Collation;
|
||||
import org.jooq.Comment;
|
||||
import org.jooq.CommentOnIsStep;
|
||||
import org.jooq.CommonTableExpression;
|
||||
import org.jooq.Condition;
|
||||
import org.jooq.Configuration;
|
||||
@ -193,7 +186,6 @@ import org.jooq.ConstraintForeignKeyReferencesStep9;
|
||||
import org.jooq.ConstraintForeignKeyReferencesStepN;
|
||||
import org.jooq.ConstraintTypeStep;
|
||||
// ...
|
||||
import org.jooq.CreateIndexStep;
|
||||
import org.jooq.CreateTableColumnStep;
|
||||
import org.jooq.CreateTypeStep;
|
||||
import org.jooq.CreateViewAsStep;
|
||||
@ -205,10 +197,7 @@ import org.jooq.Delete;
|
||||
import org.jooq.DeleteUsingStep;
|
||||
import org.jooq.DerivedColumnList;
|
||||
import org.jooq.Domain;
|
||||
import org.jooq.DropIndexOnStep;
|
||||
import org.jooq.DropTableStep;
|
||||
import org.jooq.DropTypeStep;
|
||||
import org.jooq.DropViewFinalStep;
|
||||
// ...
|
||||
import org.jooq.False;
|
||||
import org.jooq.Field;
|
||||
@ -367,7 +356,6 @@ import org.jooq.Support;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableLike;
|
||||
import org.jooq.True;
|
||||
import org.jooq.TruncateIdentityStep;
|
||||
import org.jooq.UDTRecord;
|
||||
import org.jooq.Update;
|
||||
import org.jooq.UpdateSetFirstStep;
|
||||
@ -20570,6 +20558,7 @@ public class DSL {
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
@SafeVarargs
|
||||
public static <T> Field<T> greatest(T value, T... values) {
|
||||
return greatest(Tools.field(value), Tools.fieldsArray(values));
|
||||
}
|
||||
@ -20585,6 +20574,7 @@ public class DSL {
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
@SafeVarargs
|
||||
public static <T> Field<T> greatest(Field<T> field, Field<?>... others) {
|
||||
return new Greatest<>(Tools.nullSafeDataType(field), Tools.nullSafe(combine(field, others)));
|
||||
}
|
||||
@ -20602,6 +20592,7 @@ public class DSL {
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
@SafeVarargs
|
||||
public static <T> Field<T> least(T value, T... values) {
|
||||
return least(Tools.field(value), Tools.fieldsArray(values));
|
||||
}
|
||||
@ -20617,6 +20608,7 @@ public class DSL {
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
@SafeVarargs
|
||||
public static <T> Field<T> least(Field<T> field, Field<?>... others) {
|
||||
return new Least<>(Tools.nullSafeDataType(field), Tools.nullSafe(combine(field, others)));
|
||||
}
|
||||
|
||||
@ -39,6 +39,7 @@ package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.DSL.function;
|
||||
import static org.jooq.impl.Names.N_GREATEST;
|
||||
import static org.jooq.impl.Names.N_MAXVALUE;
|
||||
|
||||
import org.jooq.Context;
|
||||
import org.jooq.DataType;
|
||||
@ -106,7 +107,7 @@ final class Greatest<T> extends AbstractField<T> {
|
||||
}
|
||||
|
||||
case FIREBIRD:
|
||||
ctx.visit(function("maxvalue", getDataType(), args));
|
||||
ctx.visit(function(N_MAXVALUE, getDataType(), args));
|
||||
return;
|
||||
|
||||
case SQLITE:
|
||||
@ -114,7 +115,7 @@ final class Greatest<T> extends AbstractField<T> {
|
||||
return;
|
||||
|
||||
default:
|
||||
ctx.visit(function("greatest", getDataType(), args));
|
||||
ctx.visit(function(N_GREATEST, getDataType(), args));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,6 +39,7 @@ package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.DSL.function;
|
||||
import static org.jooq.impl.Names.N_LEAST;
|
||||
import static org.jooq.impl.Names.N_MINVALUE;
|
||||
|
||||
import org.jooq.Context;
|
||||
import org.jooq.DataType;
|
||||
@ -105,7 +106,7 @@ final class Least<T> extends AbstractField<T> {
|
||||
}
|
||||
|
||||
case FIREBIRD:
|
||||
ctx.visit(function("minvalue", getDataType(), args));
|
||||
ctx.visit(function(N_MINVALUE, getDataType(), args));
|
||||
return;
|
||||
|
||||
case SQLITE:
|
||||
@ -113,7 +114,7 @@ final class Least<T> extends AbstractField<T> {
|
||||
return;
|
||||
|
||||
default:
|
||||
ctx.visit(function("least", getDataType(), args));
|
||||
ctx.visit(function(N_LEAST, getDataType(), args));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,9 +186,11 @@ final class Names {
|
||||
static final Name N_LOWER = unquotedName("lower");
|
||||
static final Name N_LPAD = unquotedName("lpad");
|
||||
static final Name N_LTRIM = unquotedName("ltrim");
|
||||
static final Name N_MAXVALUE = unquotedName("maxvalue");
|
||||
static final Name N_MD5 = unquotedName("md5");
|
||||
static final Name N_MEDIAN = unquotedName("median");
|
||||
static final Name N_MID = unquotedName("mid");
|
||||
static final Name N_MINVALUE = unquotedName("minvalue");
|
||||
static final Name N_MOD = unquotedName("mod");
|
||||
static final Name N_MODE = unquotedName("mode");
|
||||
static final Name N_NANO100_BETWEEN = unquotedName("nano100_between");
|
||||
|
||||
@ -6960,6 +6960,11 @@ final class ParserContext {
|
||||
else if (parseFunctionNameIf("MD5"))
|
||||
return md5((Field) parseFieldParenthesised(S));
|
||||
|
||||
if ((field = parseFieldGreatestIf()) != null)
|
||||
return field;
|
||||
else if ((field = parseFieldLeastIf()) != null)
|
||||
return field;
|
||||
|
||||
break;
|
||||
|
||||
case 'N':
|
||||
@ -8109,7 +8114,7 @@ final class ParserContext {
|
||||
}
|
||||
|
||||
private final Field<?> parseFieldLeastIf() {
|
||||
if (parseFunctionNameIf("LEAST")) {
|
||||
if (parseFunctionNameIf("LEAST", "MINVALUE")) {
|
||||
parse('(');
|
||||
List<Field<?>> fields = parseFields();
|
||||
parse(')');
|
||||
@ -8121,7 +8126,7 @@ final class ParserContext {
|
||||
}
|
||||
|
||||
private final Field<?> parseFieldGreatestIf() {
|
||||
if (parseFunctionNameIf("GREATEST")) {
|
||||
if (parseFunctionNameIf("GREATEST", "MAXVALUE")) {
|
||||
parse('(');
|
||||
List<Field<?>> fields = parseFields();
|
||||
parse(')');
|
||||
|
||||
113
jOOQ/src/main/java/org/jooq/impl/Square.java
Normal file
113
jOOQ/src/main/java/org/jooq/impl/Square.java
Normal file
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* 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 static org.jooq.impl.DSL.*;
|
||||
import static org.jooq.impl.Internal.*;
|
||||
import static org.jooq.impl.Keywords.*;
|
||||
import static org.jooq.impl.Names.*;
|
||||
import static org.jooq.impl.SQLDataType.*;
|
||||
import static org.jooq.impl.Tools.*;
|
||||
import static org.jooq.impl.Tools.BooleanDataKey.*;
|
||||
import static org.jooq.SQLDialect.*;
|
||||
|
||||
import org.jooq.*;
|
||||
import org.jooq.conf.*;
|
||||
import org.jooq.impl.*;
|
||||
import org.jooq.tools.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* The <code>SQUARE</code> statement.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
|
||||
final class Square<T extends Number>
|
||||
extends
|
||||
AbstractField<T>
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Field<T> value;
|
||||
|
||||
Square(
|
||||
Field<T> value
|
||||
) {
|
||||
super(
|
||||
N_SQUARE,
|
||||
allNotNull((DataType) dataType(INTEGER, value, false), value)
|
||||
);
|
||||
|
||||
this.value = nullSafeNotNull(value, INTEGER);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: QueryPart API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
private static final Set<SQLDialect> NO_SUPPORT_SQUARE = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE);
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
if (NO_SUPPORT_SQUARE.contains(ctx.dialect()))
|
||||
ctx.visit(value.times(value));
|
||||
else
|
||||
ctx.visit(N_SQUARE).sql('(').visit(value).sql(')');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// The Object API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (that instanceof Square) {
|
||||
return
|
||||
StringUtils.equals(value, ((Square) that).value)
|
||||
;
|
||||
}
|
||||
else
|
||||
return super.equals(that);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user