From be43c31a8a6715bd31794d90a71d06e6a419176b Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Fri, 19 Jan 2024 09:22:17 +0100 Subject: [PATCH] [jOOQ/jOOQ#16101] Support binary BIT_LENGTH() and OCTET_LENGTH() --- .../java/org/jooq/impl/BinaryBitLength.java | 156 +++++++++++++ .../main/java/org/jooq/impl/BinaryLength.java | 156 +++++++++++++ .../java/org/jooq/impl/BinaryOctetLength.java | 156 +++++++++++++ .../java/org/jooq/impl/BinaryOverlay.java | 217 ++++++++++++++++++ .../java/org/jooq/impl/BinaryPosition.java | 197 ++++++++++++++++ .../java/org/jooq/impl/BinarySubstring.java | 204 ++++++++++++++++ jOOQ/src/main/java/org/jooq/impl/DSL.java | 68 +++++- jOOQ/src/main/java/org/jooq/impl/Names.java | 2 + .../main/java/org/jooq/impl/ParserImpl.java | 42 +++- jOOQ/src/main/java/org/jooq/impl/QOM.java | 36 +++ 10 files changed, 1210 insertions(+), 24 deletions(-) create mode 100644 jOOQ/src/main/java/org/jooq/impl/BinaryBitLength.java create mode 100644 jOOQ/src/main/java/org/jooq/impl/BinaryLength.java create mode 100644 jOOQ/src/main/java/org/jooq/impl/BinaryOctetLength.java create mode 100644 jOOQ/src/main/java/org/jooq/impl/BinaryOverlay.java create mode 100644 jOOQ/src/main/java/org/jooq/impl/BinaryPosition.java create mode 100644 jOOQ/src/main/java/org/jooq/impl/BinarySubstring.java diff --git a/jOOQ/src/main/java/org/jooq/impl/BinaryBitLength.java b/jOOQ/src/main/java/org/jooq/impl/BinaryBitLength.java new file mode 100644 index 0000000000..171dce566d --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/BinaryBitLength.java @@ -0,0 +1,156 @@ +/* + * 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 BINARY BIT LENGTH statement. + */ +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class BinaryBitLength +extends + AbstractField +implements + QOM.BinaryBitLength +{ + + final Field bytes; + + BinaryBitLength( + Field bytes + ) { + super( + N_BINARY_BIT_LENGTH, + allNotNull(INTEGER, bytes) + ); + + this.bytes = nullSafeNotNull(bytes, VARBINARY); + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + @Override + final boolean parenthesised(Context ctx) { + return true; + } + + @Override + public final void accept(Context ctx) { + switch (ctx.family()) { + + + + + + + default: + ctx.visit(function(N_BIT_LENGTH, getDataType(), bytes)); + break; + } + } + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: Query Object Model + // ------------------------------------------------------------------------- + + @Override + public final Field $arg1() { + return bytes; + } + + @Override + public final QOM.BinaryBitLength $arg1(Field newValue) { + return $constructor().apply(newValue); + } + + @Override + public final Function1, ? extends QOM.BinaryBitLength> $constructor() { + return (a1) -> new BinaryBitLength(a1); + } + + // ------------------------------------------------------------------------- + // XXX: The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof QOM.BinaryBitLength o) { + return + StringUtils.equals($bytes(), o.$bytes()) + ; + } + else + return super.equals(that); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/BinaryLength.java b/jOOQ/src/main/java/org/jooq/impl/BinaryLength.java new file mode 100644 index 0000000000..0cfa88fb97 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/BinaryLength.java @@ -0,0 +1,156 @@ +/* + * 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 BINARY LENGTH statement. + */ +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class BinaryLength +extends + AbstractField +implements + QOM.BinaryLength +{ + + final Field bytes; + + BinaryLength( + Field bytes + ) { + super( + N_BINARY_LENGTH, + allNotNull(INTEGER, bytes) + ); + + this.bytes = nullSafeNotNull(bytes, VARBINARY); + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + @Override + final boolean parenthesised(Context ctx) { + return true; + } + + @Override + public final void accept(Context ctx) { + switch (ctx.family()) { + + + + + + + default: + ctx.visit(function(N_LENGTH, getDataType(), bytes)); + break; + } + } + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: Query Object Model + // ------------------------------------------------------------------------- + + @Override + public final Field $arg1() { + return bytes; + } + + @Override + public final QOM.BinaryLength $arg1(Field newValue) { + return $constructor().apply(newValue); + } + + @Override + public final Function1, ? extends QOM.BinaryLength> $constructor() { + return (a1) -> new BinaryLength(a1); + } + + // ------------------------------------------------------------------------- + // XXX: The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof QOM.BinaryLength o) { + return + StringUtils.equals($bytes(), o.$bytes()) + ; + } + else + return super.equals(that); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/BinaryOctetLength.java b/jOOQ/src/main/java/org/jooq/impl/BinaryOctetLength.java new file mode 100644 index 0000000000..af3bd2529b --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/BinaryOctetLength.java @@ -0,0 +1,156 @@ +/* + * 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 BINARY OCTET LENGTH statement. + */ +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class BinaryOctetLength +extends + AbstractField +implements + QOM.BinaryOctetLength +{ + + final Field bytes; + + BinaryOctetLength( + Field bytes + ) { + super( + N_BINARY_OCTET_LENGTH, + allNotNull(INTEGER, bytes) + ); + + this.bytes = nullSafeNotNull(bytes, VARBINARY); + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + @Override + final boolean parenthesised(Context ctx) { + return true; + } + + @Override + public final void accept(Context ctx) { + switch (ctx.family()) { + + + + + + + default: + ctx.visit(function(N_OCTET_LENGTH, getDataType(), bytes)); + break; + } + } + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: Query Object Model + // ------------------------------------------------------------------------- + + @Override + public final Field $arg1() { + return bytes; + } + + @Override + public final QOM.BinaryOctetLength $arg1(Field newValue) { + return $constructor().apply(newValue); + } + + @Override + public final Function1, ? extends QOM.BinaryOctetLength> $constructor() { + return (a1) -> new BinaryOctetLength(a1); + } + + // ------------------------------------------------------------------------- + // XXX: The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof QOM.BinaryOctetLength o) { + return + StringUtils.equals($bytes(), o.$bytes()) + ; + } + else + return super.equals(that); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/BinaryOverlay.java b/jOOQ/src/main/java/org/jooq/impl/BinaryOverlay.java new file mode 100644 index 0000000000..6bc895bb2a --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/BinaryOverlay.java @@ -0,0 +1,217 @@ +/* + * 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 BINARY OVERLAY statement. + */ +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class BinaryOverlay +extends + AbstractField +implements + QOM.BinaryOverlay +{ + + final Field in; + final Field placing; + final Field startIndex; + final Field length; + + BinaryOverlay( + Field in, + Field placing, + Field startIndex + ) { + super( + N_BINARY_OVERLAY, + allNotNull(VARBINARY, in, placing, startIndex) + ); + + this.in = nullSafeNotNull(in, VARBINARY); + this.placing = nullSafeNotNull(placing, VARBINARY); + this.startIndex = nullSafeNotNull(startIndex, INTEGER); + this.length = null; + } + + BinaryOverlay( + Field in, + Field placing, + Field startIndex, + Field length + ) { + super( + N_BINARY_OVERLAY, + allNotNull(VARBINARY, in, placing, startIndex, length) + ); + + this.in = nullSafeNotNull(in, VARBINARY); + this.placing = nullSafeNotNull(placing, VARBINARY); + this.startIndex = nullSafeNotNull(startIndex, INTEGER); + this.length = nullSafeNotNull(length, INTEGER); + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + + + @Override + public final void accept(Context ctx) { + + + + + + + + Overlay.accept0(ctx, + in, placing, startIndex, length, + DSL::binaryLength, DSL::binarySubstring, DSL::binarySubstring + ); + } + + + + + + + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: Query Object Model + // ------------------------------------------------------------------------- + + @Override + public final Field $arg1() { + return in; + } + + @Override + public final Field $arg2() { + return placing; + } + + @Override + public final Field $arg3() { + return startIndex; + } + + @Override + public final Field $arg4() { + return length; + } + + @Override + public final QOM.BinaryOverlay $arg1(Field newValue) { + return $constructor().apply(newValue, $arg2(), $arg3(), $arg4()); + } + + @Override + public final QOM.BinaryOverlay $arg2(Field newValue) { + return $constructor().apply($arg1(), newValue, $arg3(), $arg4()); + } + + @Override + public final QOM.BinaryOverlay $arg3(Field newValue) { + return $constructor().apply($arg1(), $arg2(), newValue, $arg4()); + } + + @Override + public final QOM.BinaryOverlay $arg4(Field newValue) { + return $constructor().apply($arg1(), $arg2(), $arg3(), newValue); + } + + @Override + public final Function4, ? super Field, ? super Field, ? super Field, ? extends QOM.BinaryOverlay> $constructor() { + return (a1, a2, a3, a4) -> new BinaryOverlay(a1, a2, a3, a4); + } + + // ------------------------------------------------------------------------- + // XXX: The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof QOM.BinaryOverlay o) { + return + StringUtils.equals($in(), o.$in()) && + StringUtils.equals($placing(), o.$placing()) && + StringUtils.equals($startIndex(), o.$startIndex()) && + StringUtils.equals($length(), o.$length()) + ; + } + else + return super.equals(that); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/BinaryPosition.java b/jOOQ/src/main/java/org/jooq/impl/BinaryPosition.java new file mode 100644 index 0000000000..b6008648fa --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/BinaryPosition.java @@ -0,0 +1,197 @@ +/* + * 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 BINARY POSITION statement. + */ +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class BinaryPosition +extends + AbstractField +implements + QOM.BinaryPosition +{ + + final Field in; + final Field search; + final Field startIndex; + + BinaryPosition( + Field in, + Field search + ) { + super( + N_BINARY_POSITION, + allNotNull(INTEGER, in, search) + ); + + this.in = nullSafeNotNull(in, VARBINARY); + this.search = nullSafeNotNull(search, VARBINARY); + this.startIndex = null; + } + + BinaryPosition( + Field in, + Field search, + Field startIndex + ) { + super( + N_BINARY_POSITION, + allNotNull(INTEGER, in, search, startIndex) + ); + + this.in = nullSafeNotNull(in, VARBINARY); + this.search = nullSafeNotNull(search, VARBINARY); + this.startIndex = nullSafeNotNull(startIndex, INTEGER); + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + + + @Override + public final void accept(Context ctx) { + + + + + + + + Position.accept0(ctx, in, search, startIndex, DSL::binaryPosition, DSL::binarySubstring); + } + + + + + + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: Query Object Model + // ------------------------------------------------------------------------- + + @Override + public final Field $arg1() { + return in; + } + + @Override + public final Field $arg2() { + return search; + } + + @Override + public final Field $arg3() { + return startIndex; + } + + @Override + public final QOM.BinaryPosition $arg1(Field newValue) { + return $constructor().apply(newValue, $arg2(), $arg3()); + } + + @Override + public final QOM.BinaryPosition $arg2(Field newValue) { + return $constructor().apply($arg1(), newValue, $arg3()); + } + + @Override + public final QOM.BinaryPosition $arg3(Field newValue) { + return $constructor().apply($arg1(), $arg2(), newValue); + } + + @Override + public final Function3, ? super Field, ? super Field, ? extends QOM.BinaryPosition> $constructor() { + return (a1, a2, a3) -> new BinaryPosition(a1, a2, a3); + } + + // ------------------------------------------------------------------------- + // XXX: The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof QOM.BinaryPosition o) { + return + StringUtils.equals($in(), o.$in()) && + StringUtils.equals($search(), o.$search()) && + StringUtils.equals($startIndex(), o.$startIndex()) + ; + } + else + return super.equals(that); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/BinarySubstring.java b/jOOQ/src/main/java/org/jooq/impl/BinarySubstring.java new file mode 100644 index 0000000000..e57a898ac2 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/BinarySubstring.java @@ -0,0 +1,204 @@ +/* + * 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 BINARY SUBSTRING statement. + */ +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class BinarySubstring +extends + AbstractField +implements + QOM.BinarySubstring +{ + + final Field string; + final Field startingPosition; + final Field length; + + BinarySubstring( + Field string, + Field startingPosition + ) { + super( + N_BINARY_SUBSTRING, + allNotNull(VARBINARY, string, startingPosition) + ); + + this.string = nullSafeNotNull(string, VARBINARY); + this.startingPosition = nullSafeNotNull(startingPosition, INTEGER); + this.length = null; + } + + BinarySubstring( + Field string, + Field startingPosition, + Field length + ) { + super( + N_BINARY_SUBSTRING, + allNotNull(VARBINARY, string, startingPosition, length) + ); + + this.string = nullSafeNotNull(string, VARBINARY); + this.startingPosition = nullSafeNotNull(startingPosition, INTEGER); + this.length = nullSafeNotNull(length, INTEGER); + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + @Override + final boolean parenthesised(Context ctx) { + return true; + } + + @Override + public final void accept(Context ctx) { + switch (ctx.family()) { + + + + + + + default: + if (length != null) + ctx.visit(function(N_SUBSTRING, getDataType(), string, startingPosition, length)); + else + ctx.visit(function(N_SUBSTRING, getDataType(), string, startingPosition)); + break; + } + } + + + + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: Query Object Model + // ------------------------------------------------------------------------- + + @Override + public final Field $arg1() { + return string; + } + + @Override + public final Field $arg2() { + return startingPosition; + } + + @Override + public final Field $arg3() { + return length; + } + + @Override + public final QOM.BinarySubstring $arg1(Field newValue) { + return $constructor().apply(newValue, $arg2(), $arg3()); + } + + @Override + public final QOM.BinarySubstring $arg2(Field newValue) { + return $constructor().apply($arg1(), newValue, $arg3()); + } + + @Override + public final QOM.BinarySubstring $arg3(Field newValue) { + return $constructor().apply($arg1(), $arg2(), newValue); + } + + @Override + public final Function3, ? super Field, ? super Field, ? extends QOM.BinarySubstring> $constructor() { + return (a1, a2, a3) -> new BinarySubstring(a1, a2, a3); + } + + // ------------------------------------------------------------------------- + // XXX: The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof QOM.BinarySubstring o) { + return + StringUtils.equals($string(), o.$string()) && + StringUtils.equals($startingPosition(), o.$startingPosition()) && + StringUtils.equals($length(), o.$length()) + ; + } + else + return super.equals(that); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 7c17427c72..e89a403142 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -20900,6 +20900,28 @@ public class DSL { // Binary functions // ------------------------------------------------------------------------- + /** + * The BINARY_BIT_LENGTH function. + *

+ * The length of a binary string in bits. + */ + @NotNull + @Support({ POSTGRES, YUGABYTEDB }) + public static Field binaryBitLength(byte[] bytes) { + return new BinaryBitLength(Tools.field(bytes)); + } + + /** + * The BINARY_BIT_LENGTH function. + *

+ * The length of a binary string in bits. + */ + @NotNull + @Support({ POSTGRES, YUGABYTEDB }) + public static Field binaryBitLength(Field bytes) { + return new BinaryBitLength(bytes); + } + /** * The BINARY_LENGTH function. *

@@ -21000,6 +21022,28 @@ public class DSL { return new BinaryMd5(bytes); } + /** + * The BINARY_OCTET_LENGTH function. + *

+ * The length of a binary string in octets. + */ + @NotNull + @Support + public static Field binaryOctetLength(byte[] bytes) { + return new BinaryOctetLength(Tools.field(bytes)); + } + + /** + * The BINARY_OCTET_LENGTH function. + *

+ * The length of a binary string in octets. + */ + @NotNull + @Support + public static Field binaryOctetLength(Field bytes) { + return new BinaryOctetLength(bytes); + } + /** * The BINARY_OVERLAY function. *

@@ -21072,7 +21116,7 @@ public class DSL { * @param startIndex The start index (1-based) from which to start looking for the substring. */ @NotNull - @Support + @Support({ POSTGRES, YUGABYTEDB }) public static Field binaryPosition(byte[] in, byte[] search, int startIndex) { return new BinaryPosition(Tools.field(in), Tools.field(search), Tools.field(startIndex)); } @@ -21087,7 +21131,7 @@ public class DSL { * @param startIndex The start index (1-based) from which to start looking for the substring. */ @NotNull - @Support + @Support({ POSTGRES, YUGABYTEDB }) public static Field binaryPosition(byte[] in, byte[] search, Field startIndex) { return new BinaryPosition(Tools.field(in), Tools.field(search), startIndex); } @@ -21102,7 +21146,7 @@ public class DSL { * @param startIndex The start index (1-based) from which to start looking for the substring. */ @NotNull - @Support + @Support({ POSTGRES, YUGABYTEDB }) public static Field binaryPosition(byte[] in, Field search, int startIndex) { return new BinaryPosition(Tools.field(in), search, Tools.field(startIndex)); } @@ -21117,7 +21161,7 @@ public class DSL { * @param startIndex The start index (1-based) from which to start looking for the substring. */ @NotNull - @Support + @Support({ POSTGRES, YUGABYTEDB }) public static Field binaryPosition(byte[] in, Field search, Field startIndex) { return new BinaryPosition(Tools.field(in), search, startIndex); } @@ -21132,7 +21176,7 @@ public class DSL { * @param startIndex The start index (1-based) from which to start looking for the substring. */ @NotNull - @Support + @Support({ POSTGRES, YUGABYTEDB }) public static Field binaryPosition(Field in, byte[] search, int startIndex) { return new BinaryPosition(in, Tools.field(search), Tools.field(startIndex)); } @@ -21147,7 +21191,7 @@ public class DSL { * @param startIndex The start index (1-based) from which to start looking for the substring. */ @NotNull - @Support + @Support({ POSTGRES, YUGABYTEDB }) public static Field binaryPosition(Field in, byte[] search, Field startIndex) { return new BinaryPosition(in, Tools.field(search), startIndex); } @@ -21162,7 +21206,7 @@ public class DSL { * @param startIndex The start index (1-based) from which to start looking for the substring. */ @NotNull - @Support + @Support({ POSTGRES, YUGABYTEDB }) public static Field binaryPosition(Field in, Field search, int startIndex) { return new BinaryPosition(in, search, Tools.field(startIndex)); } @@ -21177,7 +21221,7 @@ public class DSL { * @param startIndex The start index (1-based) from which to start looking for the substring. */ @NotNull - @Support + @Support({ POSTGRES, YUGABYTEDB }) public static Field binaryPosition(Field in, Field search, Field startIndex) { return new BinaryPosition(in, search, startIndex); } @@ -21191,7 +21235,7 @@ public class DSL { * @param search The substring to search for. */ @NotNull - @Support + @Support({ POSTGRES, YUGABYTEDB }) public static Field binaryPosition(byte[] in, byte[] search) { return new BinaryPosition(Tools.field(in), Tools.field(search)); } @@ -21205,7 +21249,7 @@ public class DSL { * @param search The substring to search for. */ @NotNull - @Support + @Support({ POSTGRES, YUGABYTEDB }) public static Field binaryPosition(byte[] in, Field search) { return new BinaryPosition(Tools.field(in), search); } @@ -21219,7 +21263,7 @@ public class DSL { * @param search The substring to search for. */ @NotNull - @Support + @Support({ POSTGRES, YUGABYTEDB }) public static Field binaryPosition(Field in, byte[] search) { return new BinaryPosition(in, Tools.field(search)); } @@ -21233,7 +21277,7 @@ public class DSL { * @param search The substring to search for. */ @NotNull - @Support + @Support({ POSTGRES, YUGABYTEDB }) public static Field binaryPosition(Field in, Field search) { return new BinaryPosition(in, search); } diff --git a/jOOQ/src/main/java/org/jooq/impl/Names.java b/jOOQ/src/main/java/org/jooq/impl/Names.java index 77f10d0e5d..2eb60e96b4 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Names.java +++ b/jOOQ/src/main/java/org/jooq/impl/Names.java @@ -330,9 +330,11 @@ final class Names { static final Name N_ATN = systemName("atn"); static final Name N_ATN2 = systemName("atn2"); static final Name N_AVG = systemName("avg"); + static final Name N_BINARY_BIT_LENGTH = systemName("binary_bit_length"); static final Name N_BINARY_LENGTH = systemName("binary_length"); static final Name N_BINARY_LTRIM = systemName("binary_ltrim"); static final Name N_BINARY_MD5 = systemName("binary_md5"); + static final Name N_BINARY_OCTET_LENGTH = systemName("binary_octet_length"); static final Name N_BINARY_OVERLAY = systemName("binary_overlay"); static final Name N_BINARY_POSITION = systemName("binary_position"); static final Name N_BINARY_RTRIM = systemName("binary_rtrim"); diff --git a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java index e905687c58..a4cdf7a679 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java @@ -98,6 +98,7 @@ import static org.jooq.impl.DSL.begin; import static org.jooq.impl.DSL.binaryLength; import static org.jooq.impl.DSL.binaryLtrim; import static org.jooq.impl.DSL.binaryMd5; +import static org.jooq.impl.DSL.binaryOctetLength; import static org.jooq.impl.DSL.binaryOverlay; import static org.jooq.impl.DSL.binaryRtrim; import static org.jooq.impl.DSL.binarySubstring; @@ -8667,7 +8668,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { case 'B': if (parseFunctionNameIf("BIT_LENGTH")) - return bitLength((Field) parseFieldParenthesised()); + return parseFunctionArgs1(binary1(DSL::binaryBitLength, DSL::bitLength)); else if (parseFunctionNameIf("BITGET", "BIT_GET")) return parseFunctionArgs2(DSL::bitGet); else if (parseFunctionNameIf("BITSET", "BIT_SET")) @@ -8704,7 +8705,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { else if (parseFunctionNameIf("CHARINDEX")) return parseFunctionArgs3( - (f1, f2) -> binary(f1, f2) ? DSL.binaryPosition(f2, f1) : DSL.position(f2, f1), + binary2(DSL::binaryPosition, DSL::position), (f1, f2, f3) -> binary(f1, f2) ? DSL.binaryPosition(f2, f1, f3) : DSL.position(f2, f1, f3) ); else if (parseFunctionNameIf("CHAR_LENGTH")) @@ -8909,7 +8910,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { return hour(parseFieldParenthesised()); else if (parseFunctionNameIf("HASH_MD5")) - return parseFunctionArgs1(f -> f.getDataType().isBinary() ? binaryMd5(f) : md5(f)); + return parseFunctionArgs1(binary1(DSL::binaryMd5, DSL::md5)); else if (parseFunctionNameIf("HEX")) return toHex((Field) parseFieldParenthesised()); @@ -8924,7 +8925,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { return isoDayOfWeek(parseFieldParenthesised()); else if (parseFunctionNameIf("INSTR")) return parseFunctionArgs3( - (f1, f2) -> binary(f1, f2) ? DSL.binaryPosition(f1, f2) : DSL.position(f1, f2), + binary2(DSL::binaryPosition, DSL::position), (f1, f2, f3) -> binary(f1, f2) ? DSL.binaryPosition(f1, f2, f3) : DSL.position(f1, f2, f3) ); else if (parseFunctionNameIf("INSERT")) @@ -8980,11 +8981,11 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { else if (parseFunctionNameIf("LPAD")) return parseFunctionArgs3(DSL::lpad, DSL::lpad); else if (parseFunctionNameIf("LTRIM")) - return parseFunctionArgs2(DSL::ltrim, (f1, f2) -> binary(f1, f2) ? binaryLtrim(f1, f2) : ltrim(f1, f2)); + return parseFunctionArgs2(DSL::ltrim, binary2(DSL::binaryLtrim, DSL::ltrim)); else if (parseFunctionNameIf("LEFT")) return parseFunctionArgs2(DSL::left); else if (parseFunctionNameIf("LENGTH", "LEN")) - return parseFunctionArgs1(f -> f.getDataType().isBinary() ? binaryLength(f) : length(f)); + return parseFunctionArgs1(binary1(DSL::binaryLength, DSL::length)); else if (parseFunctionNameIf("LENGTHB")) return octetLength((Field) parseFieldParenthesised()); else if (parseFunctionNameIf("LN", "LOGN")) @@ -9027,7 +9028,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { else if (parseFunctionNameIf("MID")) return parseFunctionArgs3(DSL::mid); else if (parseFunctionNameIf("MD5")) - return parseFunctionArgs1(f -> f.getDataType().isBinary() ? binaryMd5(f) : md5(f)); + return parseFunctionArgs1(binary1(DSL::binaryMd5, DSL::md5)); else if ((field = parseMultisetValueConstructorIf()) != null) return field; @@ -9087,7 +9088,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { else if ((field = parseFieldTranslateIf()) != null) return field; else if (parseFunctionNameIf("OCTET_LENGTH")) - return octetLength((Field) parseFieldParenthesised()); + return parseFunctionArgs1(binary1(DSL::binaryOctetLength, DSL::octetLength)); else if ((field = parseFieldObjectConstructIf()) != null) return field; else if (parseFunctionNameIf("OBJECT_KEYS")) @@ -9137,7 +9138,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { else if (parseFunctionNameIf("RPAD")) return parseFunctionArgs3(DSL::rpad, DSL::rpad); else if (parseFunctionNameIf("RTRIM")) - return parseFunctionArgs2(DSL::rtrim, (f1, f2) -> binary(f1, f2) ? binaryRtrim(f1, f2) : rtrim(f1, f2)); + return parseFunctionArgs2(DSL::rtrim, binary2(DSL::binaryRtrim, DSL::rtrim)); else if (parseFunctionNameIf("RIGHT")) return parseFunctionArgs2(DSL::right); else if (parseFunctionNameIf("RANDOM_UUID") && parseEmptyParens()) @@ -11376,10 +11377,28 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { return null; } + private final boolean binary(Field f1) { + return f1.getDataType().isBinary(); + } + private final boolean binary(Field f1, Field f2) { return f1.getDataType().isBinary() || f2.getDataType().isBinary(); } + private final Function1, ? extends Q> binary1( + Function1 binary, + Function1 nonBinary + ) { + return f1 -> binary(f1) ? binary.apply(f1) : nonBinary.apply(f1); + } + + private final Function2, ? super Field, ? extends Q> binary2( + Function2 binary, + Function2 nonBinary + ) { + return (f1, f2) -> binary(f1, f2) ? binary.apply(f1, f2) : nonBinary.apply(f1, f2); + } + private final Field parseFieldPositionIf() { if (parseFunctionNameIf("POSITION")) { parse('('); @@ -11534,7 +11553,6 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { boolean keywords = !substr; parse('('); Field f1 = parseField(); - boolean binary = f1.getDataType().isBinary(); if (substr || !(keywords = parseKeywordIf("FROM"))) parse(','); Field f2 = toField(parseNumericOp()); @@ -11545,10 +11563,10 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { parse(')'); return f3 == null - ? binary + ? binary(f1) ? DSL.binarySubstring(f1, f2) : DSL.substring(f1, f2) - : binary + : binary(f1) ? DSL.binarySubstring(f1, f2, f3) : DSL.substring(f1, f2, f3); } diff --git a/jOOQ/src/main/java/org/jooq/impl/QOM.java b/jOOQ/src/main/java/org/jooq/impl/QOM.java index fecfb90321..99d0859ee4 100644 --- a/jOOQ/src/main/java/org/jooq/impl/QOM.java +++ b/jOOQ/src/main/java/org/jooq/impl/QOM.java @@ -5826,6 +5826,24 @@ public final class QOM { // Uuid {} + /** + * The BINARY BIT LENGTH function. + *

+ * The length of a binary string in bits. + */ + public /*sealed*/ interface BinaryBitLength + extends + UReturnsNullOnNullInput, + UOperator1, BinaryBitLength>, + org.jooq.Field + //permits + // BinaryBitLength + { + @NotNull default Field $bytes() { return $arg1(); } + @CheckReturnValue + @NotNull default BinaryBitLength $bytes(Field newBytes) { return $arg1(newBytes); } + } + /** * The BINARY LENGTH function. *

@@ -5899,6 +5917,24 @@ public final class QOM { @NotNull default BinaryMd5 $bytes(Field newBytes) { return $arg1(newBytes); } } + /** + * The BINARY OCTET LENGTH function. + *

+ * The length of a binary string in octets. + */ + public /*sealed*/ interface BinaryOctetLength + extends + UReturnsNullOnNullInput, + UOperator1, BinaryOctetLength>, + org.jooq.Field + //permits + // BinaryOctetLength + { + @NotNull default Field $bytes() { return $arg1(); } + @CheckReturnValue + @NotNull default BinaryOctetLength $bytes(Field newBytes) { return $arg1(newBytes); } + } + /** * The BINARY OVERLAY function. *