[jOOQ/jOOQ#14581] Support 3-arg version of BIT_SET
This commit is contained in:
parent
99ade22a1f
commit
56d5cd6c3e
262
jOOQ/src/main/java/org/jooq/impl/BitGet.java
Normal file
262
jOOQ/src/main/java/org/jooq/impl/BitGet.java
Normal file
@ -0,0 +1,262 @@
|
||||
/*
|
||||
* 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.*;
|
||||
|
||||
|
||||
/**
|
||||
* The <code>BIT GET</code> statement.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
|
||||
final class BitGet<T extends Number>
|
||||
extends
|
||||
AbstractField<T>
|
||||
implements
|
||||
QOM.BitGet<T>
|
||||
{
|
||||
|
||||
final Field<T> value;
|
||||
final Field<? extends Number> bit;
|
||||
|
||||
BitGet(
|
||||
Field<T> value,
|
||||
Field<? extends Number> bit
|
||||
) {
|
||||
super(
|
||||
N_BIT_GET,
|
||||
allNotNull((DataType) dataType(INTEGER, value, false), value, bit)
|
||||
);
|
||||
|
||||
this.value = nullSafeNotNull(value, INTEGER);
|
||||
this.bit = nullSafeNotNull(bit, INTEGER);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: QueryPart API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
final boolean parenthesised(Context<?> ctx) {
|
||||
switch (ctx.family()) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case H2:
|
||||
return false;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case CUBRID:
|
||||
case FIREBIRD:
|
||||
case HSQLDB:
|
||||
case MARIADB:
|
||||
case MYSQL:
|
||||
case POSTGRES:
|
||||
case SQLITE:
|
||||
case YUGABYTEDB:
|
||||
return false;
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
switch (ctx.family()) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case H2:
|
||||
ctx.visit(case_(function(N_BITGET, BOOLEAN, value, bit)).when(trueCondition(), inline(1)).when(falseCondition(), inline(0)));
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case CUBRID:
|
||||
case FIREBIRD:
|
||||
case HSQLDB:
|
||||
case MARIADB:
|
||||
case MYSQL:
|
||||
case POSTGRES:
|
||||
case SQLITE:
|
||||
case YUGABYTEDB:
|
||||
ctx.visit(value.bitAnd((Field) one().shl(bit)).shr(bit));
|
||||
break;
|
||||
|
||||
default:
|
||||
ctx.visit(function(N_BIT_GET, getDataType(), value, bit));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: Query Object Model
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public final Field<T> $arg1() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Field<? extends Number> $arg2() {
|
||||
return bit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final QOM.BitGet<T> $arg1(Field<T> newValue) {
|
||||
return $constructor().apply(newValue, $arg2());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final QOM.BitGet<T> $arg2(Field<? extends Number> newValue) {
|
||||
return $constructor().apply($arg1(), newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Function2<? super Field<T>, ? super Field<? extends Number>, ? extends QOM.BitGet<T>> $constructor() {
|
||||
return (a1, a2) -> new BitGet<>(a1, a2);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: The Object API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (that instanceof QOM.BitGet<?> o) {
|
||||
return
|
||||
StringUtils.equals($value(), o.$value()) &&
|
||||
StringUtils.equals($bit(), o.$bit())
|
||||
;
|
||||
}
|
||||
else
|
||||
return super.equals(that);
|
||||
}
|
||||
}
|
||||
302
jOOQ/src/main/java/org/jooq/impl/BitSet.java
Normal file
302
jOOQ/src/main/java/org/jooq/impl/BitSet.java
Normal file
@ -0,0 +1,302 @@
|
||||
/*
|
||||
* 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.*;
|
||||
|
||||
|
||||
/**
|
||||
* The <code>BIT SET</code> statement.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
|
||||
final class BitSet<T extends Number>
|
||||
extends
|
||||
AbstractField<T>
|
||||
implements
|
||||
QOM.BitSet<T>
|
||||
{
|
||||
|
||||
final Field<T> value;
|
||||
final Field<? extends Number> bit;
|
||||
final Field<T> newValue;
|
||||
|
||||
BitSet(
|
||||
Field<T> value,
|
||||
Field<? extends Number> bit
|
||||
) {
|
||||
super(
|
||||
N_BIT_SET,
|
||||
allNotNull((DataType) dataType(INTEGER, value, false), value, bit)
|
||||
);
|
||||
|
||||
this.value = nullSafeNotNull(value, INTEGER);
|
||||
this.bit = nullSafeNotNull(bit, INTEGER);
|
||||
this.newValue = null;
|
||||
}
|
||||
|
||||
BitSet(
|
||||
Field<T> value,
|
||||
Field<? extends Number> bit,
|
||||
Field<T> newValue
|
||||
) {
|
||||
super(
|
||||
N_BIT_SET,
|
||||
allNotNull((DataType) dataType(INTEGER, value, false), value, bit, newValue)
|
||||
);
|
||||
|
||||
this.value = nullSafeNotNull(value, INTEGER);
|
||||
this.bit = nullSafeNotNull(bit, INTEGER);
|
||||
this.newValue = nullSafeNotNull(newValue, INTEGER);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: QueryPart API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
final boolean parenthesised(Context<?> ctx) {
|
||||
switch (ctx.family()) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case CUBRID:
|
||||
case FIREBIRD:
|
||||
case H2:
|
||||
case HSQLDB:
|
||||
case MARIADB:
|
||||
case MYSQL:
|
||||
case POSTGRES:
|
||||
case SQLITE:
|
||||
case YUGABYTEDB:
|
||||
return false;
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
switch (ctx.family()) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case CUBRID:
|
||||
case FIREBIRD:
|
||||
case H2:
|
||||
case HSQLDB:
|
||||
case MARIADB:
|
||||
case MYSQL:
|
||||
case POSTGRES:
|
||||
case SQLITE:
|
||||
case YUGABYTEDB: {
|
||||
if (newValue == null)
|
||||
ctx.visit(value.bitOr((Field) one().shl(bit)));
|
||||
else
|
||||
ctx.visit(case_(newValue).when((Field) zero(), value.bitAnd((Field) one().shl(bit).bitNot())).when((Field) one(), value.bitOr((Field) one().shl(bit))));
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
ctx.visit(function(N_BIT_SET, getDataType(), value, bit, newValue));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: Query Object Model
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public final Field<T> $arg1() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Field<? extends Number> $arg2() {
|
||||
return bit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Field<T> $arg3() {
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final QOM.BitSet<T> $arg1(Field<T> newValue) {
|
||||
return $constructor().apply(newValue, $arg2(), $arg3());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final QOM.BitSet<T> $arg2(Field<? extends Number> newValue) {
|
||||
return $constructor().apply($arg1(), newValue, $arg3());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final QOM.BitSet<T> $arg3(Field<T> newValue) {
|
||||
return $constructor().apply($arg1(), $arg2(), newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Function3<? super Field<T>, ? super Field<? extends Number>, ? super Field<T>, ? extends QOM.BitSet<T>> $constructor() {
|
||||
return (a1, a2, a3) -> new BitSet<>(a1, a2, a3);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX: The Object API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (that instanceof QOM.BitSet<?> o) {
|
||||
return
|
||||
StringUtils.equals($value(), o.$value()) &&
|
||||
StringUtils.equals($bit(), o.$bit()) &&
|
||||
StringUtils.equals($newValue(), o.$newValue())
|
||||
;
|
||||
}
|
||||
else
|
||||
return super.equals(that);
|
||||
}
|
||||
}
|
||||
@ -16471,29 +16471,6 @@ public class DSL {
|
||||
return new BitCount(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>BIT_GET</code> function.
|
||||
*
|
||||
* @param value is wrapped as {@link #val(Object)}.
|
||||
* @param bit is wrapped as {@link #val(Object)}.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB })
|
||||
public static <T extends Number> Field<T> bitGet(T value, int bit) {
|
||||
return new BitGet<>(Tools.field(value), Tools.field(bit));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>BIT_GET</code> function.
|
||||
*
|
||||
* @param value is wrapped as {@link #val(Object)}.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB })
|
||||
public static <T extends Number> Field<T> bitGet(T value, Field<? extends Number> bit) {
|
||||
return new BitGet<>(Tools.field(value), bit);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>BIT_GET</code> function.
|
||||
*
|
||||
@ -16666,24 +16643,44 @@ public class DSL {
|
||||
/**
|
||||
* The <code>BIT_SET</code> function.
|
||||
*
|
||||
* @param value is wrapped as {@link #val(Object)}.
|
||||
* @param bit is wrapped as {@link #val(Object)}.
|
||||
* @param newValue is wrapped as {@link #val(Object)}.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB })
|
||||
public static <T extends Number> Field<T> bitSet(T value, int bit) {
|
||||
return new BitSet<>(Tools.field(value), Tools.field(bit));
|
||||
public static <T extends Number> Field<T> bitSet(Field<T> value, int bit, T newValue) {
|
||||
return new BitSet<>(value, Tools.field(bit), Tools.field(newValue, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>BIT_SET</code> function.
|
||||
*
|
||||
* @param value is wrapped as {@link #val(Object)}.
|
||||
* @param bit is wrapped as {@link #val(Object)}.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB })
|
||||
public static <T extends Number> Field<T> bitSet(T value, Field<? extends Number> bit) {
|
||||
return new BitSet<>(Tools.field(value), bit);
|
||||
public static <T extends Number> Field<T> bitSet(Field<T> value, int bit, Field<T> newValue) {
|
||||
return new BitSet<>(value, Tools.field(bit), newValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>BIT_SET</code> function.
|
||||
*
|
||||
* @param newValue is wrapped as {@link #val(Object)}.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB })
|
||||
public static <T extends Number> Field<T> bitSet(Field<T> value, Field<? extends Number> bit, T newValue) {
|
||||
return new BitSet<>(value, bit, Tools.field(newValue, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>BIT_SET</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB })
|
||||
public static <T extends Number> Field<T> bitSet(Field<T> value, Field<? extends Number> bit, Field<T> newValue) {
|
||||
return new BitSet<>(value, bit, newValue);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -8453,6 +8453,10 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
|
||||
case 'B':
|
||||
if (parseFunctionNameIf("BIT_LENGTH"))
|
||||
return bitLength((Field) parseFieldParenthesised());
|
||||
else if (parseFunctionNameIf("BITGET", "BIT_GET"))
|
||||
return parseFunctionArgs2(DSL::bitGet);
|
||||
else if (parseFunctionNameIf("BITSET", "BIT_SET"))
|
||||
return parseFunctionArgs3(DSL::bitSet, DSL::bitSet);
|
||||
else if (parseFunctionNameIf("BITCOUNT", "BIT_COUNT"))
|
||||
return bitCount((Field) parseFieldNumericOpParenthesised());
|
||||
else if (parseKeywordIf("BIT_LSHIFT"))
|
||||
@ -8628,9 +8632,10 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
|
||||
case 'G':
|
||||
if (parseKeywordIf("GETDATE") && parseEmptyParens())
|
||||
return currentTimestamp();
|
||||
|
||||
else if (parseFunctionNameIf("GENGUID", "GENERATE_UUID", "GEN_RANDOM_UUID") && parseEmptyParens())
|
||||
return uuid();
|
||||
else if (parseFunctionNameIf("GET_BIT", "GETBIT"))
|
||||
return parseFunctionArgs2(DSL::bitGet);
|
||||
|
||||
else if ((field = parseFieldGreatestIf()) != null)
|
||||
return field;
|
||||
@ -8921,6 +8926,8 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
|
||||
return parseFunctionArgs3(DSL::splitPart);
|
||||
else if (parseFunctionNameIf("SYSUUID") && parseEmptyParensIf())
|
||||
return uuid();
|
||||
else if (parseFunctionNameIf("SET_BIT", "SETBIT"))
|
||||
return parseFunctionArgs3(DSL::bitSet, DSL::bitSet);
|
||||
|
||||
else if (parseFunctionNameIf("SECOND"))
|
||||
return second(parseFieldParenthesised());
|
||||
|
||||
@ -3868,7 +3868,7 @@ public final class QOM {
|
||||
public /*sealed*/ interface BitSet<T extends Number>
|
||||
extends
|
||||
UReturnsNullOnNullInput,
|
||||
UOperator2<Field<T>, Field<? extends Number>, BitSet<T>>,
|
||||
UOperator3<Field<T>, Field<? extends Number>, Field<T>, BitSet<T>>,
|
||||
org.jooq.Field<T>
|
||||
//permits
|
||||
// BitSet
|
||||
@ -3879,6 +3879,9 @@ public final class QOM {
|
||||
@NotNull default Field<? extends Number> $bit() { return $arg2(); }
|
||||
@CheckReturnValue
|
||||
@NotNull default BitSet<T> $bit(Field<? extends Number> newBit) { return $arg2(newBit); }
|
||||
@Nullable default Field<T> $newValue() { return $arg3(); }
|
||||
@CheckReturnValue
|
||||
@NotNull default BitSet<T> $newValue(Field<T> newNewValue) { return $arg3(newNewValue); }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user