[jOOQ/jOOQ#16432] Add support for the CBRT() and ROOT() functions
This commit is contained in:
parent
0b6991a4d3
commit
b995b0c015
211
jOOQ/src/main/java/org/jooq/impl/Cbrt.java
Normal file
211
jOOQ/src/main/java/org/jooq/impl/Cbrt.java
Normal file
@ -0,0 +1,211 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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: https://www.jooq.org/legal/licensing
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
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.impl.Tools.ExtendedDataKey.*;
|
||||
import static org.jooq.impl.Tools.SimpleDataKey.*;
|
||||
import static org.jooq.SQLDialect.*;
|
||||
|
||||
import org.jooq.*;
|
||||
import org.jooq.Function1;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.conf.*;
|
||||
import org.jooq.impl.*;
|
||||
import org.jooq.impl.QOM.*;
|
||||
import org.jooq.tools.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.*;
|
||||
import java.util.stream.*;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
|
||||
/**
|
||||
* The <code>CBRT</code> statement.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unused" })
|
||||
final class Cbrt
|
||||
extends
|
||||
AbstractField<BigDecimal>
|
||||
implements
|
||||
QOM.Cbrt
|
||||
{
|
||||
|
||||
final Field<? extends Number> value;
|
||||
|
||||
Cbrt(
|
||||
Field<? extends Number> value
|
||||
) {
|
||||
super(
|
||||
N_CBRT,
|
||||
allNotNull(NUMERIC, value)
|
||||
);
|
||||
|
||||
this.value = nullSafeNotNull(value, INTEGER);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: QueryPart API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
final boolean parenthesised(Context<?> ctx) {
|
||||
switch (ctx.family()) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case CUBRID:
|
||||
case DERBY:
|
||||
case FIREBIRD:
|
||||
case H2:
|
||||
case HSQLDB:
|
||||
case IGNITE:
|
||||
case MARIADB:
|
||||
case MYSQL:
|
||||
case SQLITE:
|
||||
return false;
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
switch (ctx.family()) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case CUBRID:
|
||||
case DERBY:
|
||||
case FIREBIRD:
|
||||
case H2:
|
||||
case HSQLDB:
|
||||
case IGNITE:
|
||||
case MARIADB:
|
||||
case MYSQL:
|
||||
case SQLITE:
|
||||
ctx.visit(DSL.root(value, inline(3.0)));
|
||||
break;
|
||||
|
||||
default:
|
||||
ctx.visit(function(N_CBRT, getDataType(), value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: Query Object Model
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public final Field<? extends Number> $arg1() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final QOM.Cbrt $arg1(Field<? extends Number> newValue) {
|
||||
return $constructor().apply(newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Function1<? super Field<? extends Number>, ? extends QOM.Cbrt> $constructor() {
|
||||
return (a1) -> new Cbrt(a1);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: The Object API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (that instanceof QOM.Cbrt o) {
|
||||
return
|
||||
StringUtils.equals($value(), o.$value())
|
||||
;
|
||||
}
|
||||
else
|
||||
return super.equals(that);
|
||||
}
|
||||
}
|
||||
@ -18326,6 +18326,26 @@ public class DSL {
|
||||
return new BitXor<>(arg1, arg2);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>CBRT</code> function.
|
||||
*
|
||||
* @param value is wrapped as {@link DSL#val(Object)}.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static Field<BigDecimal> cbrt(Number value) {
|
||||
return new Cbrt(Tools.field(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>CBRT</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static Field<BigDecimal> cbrt(Field<? extends Number> value) {
|
||||
return new Cbrt(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>CEIL</code> function.
|
||||
* <p>
|
||||
@ -18701,6 +18721,49 @@ public class DSL {
|
||||
return new Rand();
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>ROOT</code> function.
|
||||
*
|
||||
* @param value is wrapped as {@link DSL#val(Object)}.
|
||||
* @param degree is wrapped as {@link DSL#val(Object)}.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static Field<BigDecimal> root(Number value, Number degree) {
|
||||
return new Root(Tools.field(value), Tools.field(degree));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>ROOT</code> function.
|
||||
*
|
||||
* @param value is wrapped as {@link DSL#val(Object)}.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static Field<BigDecimal> root(Number value, Field<? extends Number> degree) {
|
||||
return new Root(Tools.field(value), degree);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>ROOT</code> function.
|
||||
*
|
||||
* @param degree is wrapped as {@link DSL#val(Object)}.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static Field<BigDecimal> root(Field<? extends Number> value, Number degree) {
|
||||
return new Root(value, Tools.field(degree));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>ROOT</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static Field<BigDecimal> root(Field<? extends Number> value, Field<? extends Number> degree) {
|
||||
return new Root(value, degree);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>ROUND</code> function.
|
||||
* <p>
|
||||
|
||||
@ -404,6 +404,7 @@ final class Names {
|
||||
static final Name N_BOOL_OR = systemName("bool_or");
|
||||
static final Name N_BYTE_LENGTH = systemName("byte_length");
|
||||
static final Name N_CARDINALITY = systemName("cardinality");
|
||||
static final Name N_CBRT = systemName("cbrt");
|
||||
static final Name N_CEIL = systemName("ceil");
|
||||
static final Name N_CEILING = systemName("ceiling");
|
||||
static final Name N_CHAR = systemName("char");
|
||||
@ -534,6 +535,7 @@ final class Names {
|
||||
static final Name N_RETURN_ = systemName("return_");
|
||||
static final Name N_REVERSE = systemName("reverse");
|
||||
static final Name N_RIGHT = systemName("right");
|
||||
static final Name N_ROOT = systemName("root");
|
||||
static final Name N_ROUND = systemName("round");
|
||||
static final Name N_ROWNUM = systemName("rownum");
|
||||
static final Name N_RPAD = systemName("rpad");
|
||||
|
||||
@ -8813,6 +8813,8 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
|
||||
return coth((Field) parseFieldNumericOpParenthesised());
|
||||
else if (parseFunctionNameIf("COT"))
|
||||
return cot((Field) parseFieldNumericOpParenthesised());
|
||||
else if (parseFunctionNameIf("CBRT"))
|
||||
return parseFunctionArgs1(DSL::cbrt);
|
||||
else if (parseFunctionNameIf("CONTAINS"))
|
||||
return parseFunctionArgs2((f1, f2) -> f1.contains(f2));
|
||||
else if ((field = parseNextvalCurrvalIf(SequenceMethod.CURRVAL)) != null)
|
||||
@ -9265,6 +9267,8 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
|
||||
return parseFunctionArgs1(f -> parseWindowFunction(null, null, ratioToReport(f)));
|
||||
else if (parseKeywordIf("RSHIFT", "RIGHT_SHIFT"))
|
||||
return parseFunctionArgs2(() -> toField(parseNumericOp()), (f1, f2) -> shr(f1, f2));
|
||||
else if (parseFunctionNameIf("ROOT"))
|
||||
return parseFunctionArgs2(DSL::sqrt, DSL::root);
|
||||
else if (parseFunctionNameIf("ROW"))
|
||||
return parseTuple();
|
||||
|
||||
|
||||
@ -7052,6 +7052,42 @@ public final class QOM {
|
||||
// BitXor
|
||||
{}
|
||||
|
||||
/**
|
||||
* The <code>CBRT</code> function.
|
||||
*/
|
||||
public static final Cbrt Cbrt() {
|
||||
return new org.jooq.impl.Cbrt(
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>CBRT</code> function.
|
||||
*/
|
||||
public static final Cbrt Cbrt(
|
||||
Field<? extends Number> value
|
||||
) {
|
||||
return new org.jooq.impl.Cbrt(
|
||||
value
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>CBRT</code> function.
|
||||
*/
|
||||
public /*sealed*/ interface Cbrt
|
||||
extends
|
||||
UReturnsNullOnNullInput,
|
||||
UOperator1<Field<? extends Number>, Cbrt>,
|
||||
org.jooq.Field<BigDecimal>
|
||||
//permits
|
||||
// Cbrt
|
||||
{
|
||||
@NotNull default Field<? extends Number> $value() { return $arg1(); }
|
||||
@CheckReturnValue
|
||||
@NotNull default Cbrt $value(Field<? extends Number> newValue) { return $arg1(newValue); }
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>CEIL</code> function.
|
||||
* <p>
|
||||
@ -7771,6 +7807,48 @@ public final class QOM {
|
||||
// Rand
|
||||
{}
|
||||
|
||||
/**
|
||||
* The <code>ROOT</code> function.
|
||||
*/
|
||||
public static final Root Root() {
|
||||
return new org.jooq.impl.Root(
|
||||
null,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>ROOT</code> function.
|
||||
*/
|
||||
public static final Root Root(
|
||||
Field<? extends Number> value,
|
||||
Field<? extends Number> degree
|
||||
) {
|
||||
return new org.jooq.impl.Root(
|
||||
value,
|
||||
degree
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>ROOT</code> function.
|
||||
*/
|
||||
public /*sealed*/ interface Root
|
||||
extends
|
||||
UReturnsNullOnNullInput,
|
||||
UOperator2<Field<? extends Number>, Field<? extends Number>, Root>,
|
||||
org.jooq.Field<BigDecimal>
|
||||
//permits
|
||||
// Root
|
||||
{
|
||||
@NotNull default Field<? extends Number> $value() { return $arg1(); }
|
||||
@CheckReturnValue
|
||||
@NotNull default Root $value(Field<? extends Number> newValue) { return $arg1(newValue); }
|
||||
@NotNull default Field<? extends Number> $degree() { return $arg2(); }
|
||||
@CheckReturnValue
|
||||
@NotNull default Root $degree(Field<? extends Number> newDegree) { return $arg2(newDegree); }
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>ROUND</code> function.
|
||||
* <p>
|
||||
|
||||
225
jOOQ/src/main/java/org/jooq/impl/Root.java
Normal file
225
jOOQ/src/main/java/org/jooq/impl/Root.java
Normal file
@ -0,0 +1,225 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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: https://www.jooq.org/legal/licensing
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
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.impl.Tools.ExtendedDataKey.*;
|
||||
import static org.jooq.impl.Tools.SimpleDataKey.*;
|
||||
import static org.jooq.SQLDialect.*;
|
||||
|
||||
import org.jooq.*;
|
||||
import org.jooq.Function1;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.conf.*;
|
||||
import org.jooq.impl.*;
|
||||
import org.jooq.impl.QOM.*;
|
||||
import org.jooq.tools.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.*;
|
||||
import java.util.stream.*;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
|
||||
/**
|
||||
* The <code>ROOT</code> statement.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unused" })
|
||||
final class Root
|
||||
extends
|
||||
AbstractField<BigDecimal>
|
||||
implements
|
||||
QOM.Root
|
||||
{
|
||||
|
||||
final Field<? extends Number> value;
|
||||
final Field<? extends Number> degree;
|
||||
|
||||
Root(
|
||||
Field<? extends Number> value,
|
||||
Field<? extends Number> degree
|
||||
) {
|
||||
super(
|
||||
N_ROOT,
|
||||
allNotNull(NUMERIC, value, degree)
|
||||
);
|
||||
|
||||
this.value = nullSafeNotNull(value, INTEGER);
|
||||
this.degree = nullSafeNotNull(degree, INTEGER);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: QueryPart API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
final boolean parenthesised(Context<?> ctx) {
|
||||
switch (ctx.family()) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case CUBRID:
|
||||
case DERBY:
|
||||
case FIREBIRD:
|
||||
case H2:
|
||||
case HSQLDB:
|
||||
case IGNITE:
|
||||
case MARIADB:
|
||||
case MYSQL:
|
||||
case SQLITE:
|
||||
return false;
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
switch (ctx.family()) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case CUBRID:
|
||||
case DERBY:
|
||||
case FIREBIRD:
|
||||
case H2:
|
||||
case HSQLDB:
|
||||
case IGNITE:
|
||||
case MARIADB:
|
||||
case MYSQL:
|
||||
case SQLITE:
|
||||
ctx.visit(DSL.power(value, idiv(inline(1.0), degree)));
|
||||
break;
|
||||
|
||||
default:
|
||||
ctx.visit(function(N_ROOT, getDataType(), value, degree));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: Query Object Model
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public final Field<? extends Number> $arg1() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Field<? extends Number> $arg2() {
|
||||
return degree;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final QOM.Root $arg1(Field<? extends Number> newValue) {
|
||||
return $constructor().apply(newValue, $arg2());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final QOM.Root $arg2(Field<? extends Number> newValue) {
|
||||
return $constructor().apply($arg1(), newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Function2<? super Field<? extends Number>, ? super Field<? extends Number>, ? extends QOM.Root> $constructor() {
|
||||
return (a1, a2) -> new Root(a1, a2);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: The Object API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (that instanceof QOM.Root o) {
|
||||
return
|
||||
StringUtils.equals($value(), o.$value()) &&
|
||||
StringUtils.equals($degree(), o.$degree())
|
||||
;
|
||||
}
|
||||
else
|
||||
return super.equals(that);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user