From c2805f964f7378f729470482fda596bd959e8c6e Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Tue, 8 Dec 2020 22:40:23 +0100 Subject: [PATCH] [jOOQ/jOOQ#11061] [jOOQ/jOOQ#11070] [jOOQ/jOOQ#11091] LENGTH Including CHAR_LENGTH, BIT_LENGTH, OCTET_LENGTH --- jOOQ/src/main/java/org/jooq/impl/Ascii.java | 49 +-- .../main/java/org/jooq/impl/BitLength.java | 60 ++-- .../main/java/org/jooq/impl/CharLength.java | 57 ++-- jOOQ/src/main/java/org/jooq/impl/DSL.java | 281 +++++++++--------- .../main/java/org/jooq/impl/OctetLength.java | 61 ++-- 5 files changed, 281 insertions(+), 227 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/impl/Ascii.java b/jOOQ/src/main/java/org/jooq/impl/Ascii.java index 34b296b2b1..c7594927e7 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Ascii.java +++ b/jOOQ/src/main/java/org/jooq/impl/Ascii.java @@ -37,34 +37,47 @@ */ package org.jooq.impl; -import static org.jooq.impl.Names.N_ASC; -import static org.jooq.impl.Names.N_ASCII; -import static org.jooq.impl.Names.N_ASCII_VAL; -import static org.jooq.impl.SQLDataType.INTEGER; -import static org.jooq.impl.SQLDataType.VARCHAR; -import static org.jooq.impl.Tools.nullSafeNotNull; +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.Context; -import org.jooq.Field; +import org.jooq.*; +import org.jooq.impl.*; + +import java.util.*; /** - * @author Lukas Eder + * The ASCII statement. */ -final class Ascii extends AbstractField { +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class Ascii +extends + AbstractField +{ - /** - * Generated UID - */ - private static final long serialVersionUID = -7273879239726265322L; + private static final long serialVersionUID = 1L; - private final Field string; + private final Field string; - Ascii(Field string) { - super(N_ASCII, INTEGER.nullable(string == null || string.getDataType().nullable())); + Ascii( + Field string + ) { + super(N_ASCII, allNotNull(INTEGER, string)); this.string = nullSafeNotNull(string, VARCHAR); } + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + + @Override public final void accept(Context ctx) { switch (ctx.family()) { @@ -89,4 +102,6 @@ final class Ascii extends AbstractField { break; } } + + } diff --git a/jOOQ/src/main/java/org/jooq/impl/BitLength.java b/jOOQ/src/main/java/org/jooq/impl/BitLength.java index 1e30d34e14..8b5ae4fc77 100644 --- a/jOOQ/src/main/java/org/jooq/impl/BitLength.java +++ b/jOOQ/src/main/java/org/jooq/impl/BitLength.java @@ -37,39 +37,47 @@ */ package org.jooq.impl; -import static org.jooq.impl.DSL.function; -import static org.jooq.impl.DSL.inline; -import static org.jooq.impl.Names.N_BIT_LENGTH; -import static org.jooq.impl.Names.N_CHAR_LENGTH; -import static org.jooq.impl.Names.N_DATALENGTH; -import static org.jooq.impl.Names.N_LEN; -import static org.jooq.impl.Names.N_LENGTH; -import static org.jooq.impl.Names.N_LENGTHB; -import static org.jooq.impl.SQLDataType.INTEGER; -import static org.jooq.impl.SQLDataType.VARCHAR; -import static org.jooq.impl.Tools.nullSafeNotNull; +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.Context; -import org.jooq.Field; +import org.jooq.*; +import org.jooq.impl.*; + +import java.util.*; /** - * @author Lukas Eder + * The BIT LENGTH statement. */ -final class BitLength extends AbstractField { +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class BitLength +extends + AbstractField +{ - /** - * Generated UID - */ - private static final long serialVersionUID = 1484652553287331042L; + private static final long serialVersionUID = 1L; - private final Field field; + private final Field string; - BitLength(Field field) { - super(N_BIT_LENGTH, INTEGER.nullable(field == null || field.getDataType().nullable())); + BitLength( + Field string + ) { + super(N_BIT_LENGTH, allNotNull(INTEGER, string)); - this.field = nullSafeNotNull(field, VARCHAR); + this.string = nullSafeNotNull(string, VARCHAR); } + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + + @Override public void accept(Context ctx) { switch (ctx.family()) { @@ -97,12 +105,14 @@ final class BitLength extends AbstractField { case DERBY: case SQLITE: - ctx.visit(inline(8).times(function(N_LENGTH, getDataType(), field))); + ctx.visit(inline(8).times(function(N_LENGTH, getDataType(), string))); break; default: - ctx.visit(function(N_BIT_LENGTH, getDataType(), field)); + ctx.visit(function(N_BIT_LENGTH, getDataType(), string)); break; } } + + } diff --git a/jOOQ/src/main/java/org/jooq/impl/CharLength.java b/jOOQ/src/main/java/org/jooq/impl/CharLength.java index 835c108e92..7972d52810 100644 --- a/jOOQ/src/main/java/org/jooq/impl/CharLength.java +++ b/jOOQ/src/main/java/org/jooq/impl/CharLength.java @@ -37,36 +37,47 @@ */ package org.jooq.impl; -import static org.jooq.impl.DSL.function; -import static org.jooq.impl.Names.N_BIT_LENGTH; -import static org.jooq.impl.Names.N_CHAR_LENGTH; -import static org.jooq.impl.Names.N_LEN; -import static org.jooq.impl.Names.N_LENGTH; -import static org.jooq.impl.SQLDataType.INTEGER; -import static org.jooq.impl.SQLDataType.VARCHAR; -import static org.jooq.impl.Tools.nullSafeNotNull; +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.Context; -import org.jooq.Field; +import org.jooq.*; +import org.jooq.impl.*; + +import java.util.*; /** - * @author Lukas Eder + * The CHAR LENGTH statement. */ -final class CharLength extends AbstractField { +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class CharLength +extends + AbstractField +{ - /** - * Generated UID - */ - private static final long serialVersionUID = 1484652553287331042L; + private static final long serialVersionUID = 1L; - private final Field field; + private final Field string; - CharLength(Field field) { - super(N_CHAR_LENGTH, INTEGER.nullable(field == null || field.getDataType().nullable())); + CharLength( + Field string + ) { + super(N_CHAR_LENGTH, allNotNull(INTEGER, string)); - this.field = nullSafeNotNull(field, VARCHAR); + this.string = nullSafeNotNull(string, VARCHAR); } + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + + @Override public void accept(Context ctx) { switch (ctx.family()) { @@ -86,12 +97,14 @@ final class CharLength extends AbstractField { case DERBY: case SQLITE: - ctx.visit(function(N_LENGTH, getDataType(), field)); + ctx.visit(function(N_LENGTH, getDataType(), string)); break; default: - ctx.visit(function(N_CHAR_LENGTH, getDataType(), field)); + ctx.visit(function(N_CHAR_LENGTH, getDataType(), string)); break; } } + + } diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index bcaee61146..e7ef4c9dd1 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -14899,6 +14899,60 @@ public class DSL { return new Abs(number); } + /** + * The ASCII function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + public static Field ascii(String string) { + return new Ascii(Tools.field(string)); + } + + /** + * The ASCII function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + public static Field ascii(Field string) { + return new Ascii(string); + } + + /** + * The BIT_LENGTH function. + */ + @NotNull + @Support + public static Field bitLength(String string) { + return new BitLength(Tools.field(string)); + } + + /** + * The BIT_LENGTH function. + */ + @NotNull + @Support + public static Field bitLength(Field string) { + return new BitLength(string); + } + + /** + * The CHAR_LENGTH function. + */ + @NotNull + @Support + public static Field charLength(String string) { + return new CharLength(Tools.field(string)); + } + + /** + * The CHAR_LENGTH function. + */ + @NotNull + @Support + public static Field charLength(Field string) { + return new CharLength(string); + } + /** * The LEFT function. */ @@ -14935,6 +14989,24 @@ public class DSL { return new Left(string, length); } + /** + * The LENGTH function, an alias for the CHAR_LENGTH function. + */ + @NotNull + @Support + public static Field length(String string) { + return charLength(Tools.field(string)); + } + + /** + * The LENGTH function, an alias for the CHAR_LENGTH function. + */ + @NotNull + @Support + public static Field length(Field string) { + return charLength(string); + } + /** * The LOWER function. */ @@ -15061,6 +15133,78 @@ public class DSL { return new Ltrim(string); } + /** + * The MID function, an alias for the SUBSTRING function. + */ + @NotNull + @Support + public static Field mid(Field string, int startingPosition, int length) { + return substring(string, Tools.field(startingPosition), Tools.field(length)); + } + + /** + * The MID function, an alias for the SUBSTRING function. + */ + @NotNull + @Support + public static Field mid(Field string, int startingPosition, Field length) { + return substring(string, Tools.field(startingPosition), length); + } + + /** + * The MID function, an alias for the SUBSTRING function. + */ + @NotNull + @Support + public static Field mid(Field string, Field startingPosition, int length) { + return substring(string, startingPosition, Tools.field(length)); + } + + /** + * The MID function, an alias for the SUBSTRING function. + */ + @NotNull + @Support + public static Field mid(Field string, Field startingPosition, Field length) { + return substring(string, startingPosition, length); + } + + /** + * The MID function, an alias for the SUBSTRING function. + */ + @NotNull + @Support + public static Field mid(Field string, int startingPosition) { + return substring(string, Tools.field(startingPosition)); + } + + /** + * The MID function, an alias for the SUBSTRING function. + */ + @NotNull + @Support + public static Field mid(Field string, Field startingPosition) { + return substring(string, startingPosition); + } + + /** + * The OCTET_LENGTH function. + */ + @NotNull + @Support + public static Field octetLength(String string) { + return new OctetLength(Tools.field(string)); + } + + /** + * The OCTET_LENGTH function. + */ + @NotNull + @Support + public static Field octetLength(Field string) { + return new OctetLength(string); + } + /** * The POSITION function. */ @@ -15823,29 +15967,6 @@ public class DSL { return overlay(in, placing, startIndex, length); } - /** - * Get the ascii(field) function. - * - * @see #ascii(Field) - */ - @NotNull - @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - public static Field ascii(String field) { - return ascii(Tools.field(field)); - } - - /** - * Get the ascii(field) function. - *

- * This renders the ascii function: - *

ascii([field])
- */ - @NotNull - @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - public static Field ascii(Field field) { - return new Ascii(field); - } - /** * Get the concat(field, value) function. * @@ -15895,120 +16016,6 @@ public class DSL { return new Concat(Tools.nullSafe(fields)); } - /** - * Get the mid(field, startingPosition, length) function. - * - * @see #substring(Field, Field, Field) - */ - @NotNull - @Support - public static Field mid(Field field, int startingPosition, int length) { - return substring(field, Tools.field(startingPosition), Tools.field(length)); - } - - /** - * Get the mid(field, startingPosition, length) function. - *

- * This renders the substr or substring function: - *

substr([field], [startingPosition], [length]) or
-     * substring([field], [startingPosition], [length])
- */ - @NotNull - @Support - public static Field mid(Field field, Field startingPosition, Field length) { - return substring(field, startingPosition, length); - } - - /** - * Get the length of a VARCHAR type. This is a synonym for - * {@link #charLength(String)}. - * - * @see #charLength(String) - */ - @NotNull - @Support - public static Field length(String value) { - return length(Tools.field(value)); - } - - /** - * Get the length of a VARCHAR type. This is a synonym for - * {@link #charLength(Field)}. - * - * @see #charLength(Field) - */ - @NotNull - @Support - public static Field length(Field field) { - return charLength(field); - } - - /** - * Get the char_length(field) function. - *

- * This translates into any dialect - */ - @NotNull - @Support - public static Field charLength(String value) { - return charLength(Tools.field(value)); - } - - /** - * Get the char_length(field) function. - *

- * This translates into any dialect - */ - @NotNull - @Support - public static Field charLength(Field field) { - return new CharLength(field); - } - - /** - * Get the bit_length(field) function. - *

- * This translates into any dialect - */ - @NotNull - @Support - public static Field bitLength(String value) { - return bitLength(Tools.field(value)); - } - - /** - * Get the bit_length(field) function. - *

- * This translates into any dialect - */ - @NotNull - @Support - public static Field bitLength(Field field) { - return new BitLength(field); - } - - /** - * Get the octet_length(field) function. - *

- * This translates into any dialect - */ - @NotNull - @Support - public static Field octetLength(String value) { - return octetLength(Tools.field(value)); - } - - /** - * Get the octet_length(field) function. - *

- * This translates into any dialect - */ - @NotNull - @Support - public static Field octetLength(Field field) { - return new OctetLength(field); - } - // ------------------------------------------------------------------------ // XXX Hash function factory // ------------------------------------------------------------------------ diff --git a/jOOQ/src/main/java/org/jooq/impl/OctetLength.java b/jOOQ/src/main/java/org/jooq/impl/OctetLength.java index e4f96aa020..447841775f 100644 --- a/jOOQ/src/main/java/org/jooq/impl/OctetLength.java +++ b/jOOQ/src/main/java/org/jooq/impl/OctetLength.java @@ -37,40 +37,47 @@ */ package org.jooq.impl; -import static org.jooq.impl.DSL.function; -import static org.jooq.impl.DSL.inline; -import static org.jooq.impl.Names.N_BIT_LENGTH; -import static org.jooq.impl.Names.N_CHAR_LENGTH; -import static org.jooq.impl.Names.N_DATALENGTH; -import static org.jooq.impl.Names.N_LEN; -import static org.jooq.impl.Names.N_LENGTH; -import static org.jooq.impl.Names.N_LENGTHB; -import static org.jooq.impl.Names.N_OCTET_LENGTH; -import static org.jooq.impl.SQLDataType.INTEGER; -import static org.jooq.impl.SQLDataType.VARCHAR; -import static org.jooq.impl.Tools.nullSafeNotNull; +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.Context; -import org.jooq.Field; +import org.jooq.*; +import org.jooq.impl.*; + +import java.util.*; /** - * @author Lukas Eder + * The OCTET LENGTH statement. */ -final class OctetLength extends AbstractField { +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class OctetLength +extends + AbstractField +{ - /** - * Generated UID - */ - private static final long serialVersionUID = 1484652553287331042L; + private static final long serialVersionUID = 1L; - private final Field field; + private final Field string; - OctetLength(Field field) { - super(N_BIT_LENGTH, INTEGER.nullable(field == null || field.getDataType().nullable())); + OctetLength( + Field string + ) { + super(N_OCTET_LENGTH, allNotNull(INTEGER, string)); - this.field = nullSafeNotNull(field, VARCHAR); + this.string = nullSafeNotNull(string, VARCHAR); } + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + + @Override public void accept(Context ctx) { switch (ctx.family()) { @@ -93,12 +100,14 @@ final class OctetLength extends AbstractField { case DERBY: case SQLITE: - ctx.visit(function(N_LENGTH, getDataType(), field)); + ctx.visit(function(N_LENGTH, getDataType(), string)); break; default: - ctx.visit(function(N_OCTET_LENGTH, getDataType(), field)); + ctx.visit(function(N_OCTET_LENGTH, getDataType(), string)); break; } } + + }