diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 0dbe43977f..1b6fc72297 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -14953,6 +14953,114 @@ public class DSL { return new Lower(string); } + /** + * The LPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field lpad(String string, int length, String character) { + return new Lpad(Tools.field(string), Tools.field(length), Tools.field(character)); + } + + /** + * The LPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field lpad(String string, int length, Field character) { + return new Lpad(Tools.field(string), Tools.field(length), character); + } + + /** + * The LPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field lpad(String string, Field length, String character) { + return new Lpad(Tools.field(string), length, Tools.field(character)); + } + + /** + * The LPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field lpad(String string, Field length, Field character) { + return new Lpad(Tools.field(string), length, character); + } + + /** + * The LPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field lpad(Field string, int length, String character) { + return new Lpad(string, Tools.field(length), Tools.field(character)); + } + + /** + * The LPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field lpad(Field string, int length, Field character) { + return new Lpad(string, Tools.field(length), character); + } + + /** + * The LPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field lpad(Field string, Field length, String character) { + return new Lpad(string, length, Tools.field(character)); + } + + /** + * The LPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field lpad(Field string, Field length, Field character) { + return new Lpad(string, length, character); + } + + /** + * The LPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field lpad(String string, int length) { + return new Lpad(Tools.field(string), Tools.field(length)); + } + + /** + * The LPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field lpad(String string, Field length) { + return new Lpad(Tools.field(string), length); + } + + /** + * The LPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field lpad(Field string, int length) { + return new Lpad(string, Tools.field(length)); + } + + /** + * The LPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field lpad(Field string, Field length) { + return new Lpad(string, length); + } + /** * The LTRIM function. */ @@ -15313,6 +15421,114 @@ public class DSL { return new Right(string, length); } + /** + * The RPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field rpad(String string, int length, String character) { + return new Rpad(Tools.field(string), Tools.field(length), Tools.field(character)); + } + + /** + * The RPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field rpad(String string, int length, Field character) { + return new Rpad(Tools.field(string), Tools.field(length), character); + } + + /** + * The RPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field rpad(String string, Field length, String character) { + return new Rpad(Tools.field(string), length, Tools.field(character)); + } + + /** + * The RPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field rpad(String string, Field length, Field character) { + return new Rpad(Tools.field(string), length, character); + } + + /** + * The RPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field rpad(Field string, int length, String character) { + return new Rpad(string, Tools.field(length), Tools.field(character)); + } + + /** + * The RPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field rpad(Field string, int length, Field character) { + return new Rpad(string, Tools.field(length), character); + } + + /** + * The RPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field rpad(Field string, Field length, String character) { + return new Rpad(string, length, Tools.field(character)); + } + + /** + * The RPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field rpad(Field string, Field length, Field character) { + return new Rpad(string, length, character); + } + + /** + * The RPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field rpad(String string, int length) { + return new Rpad(Tools.field(string), Tools.field(length)); + } + + /** + * The RPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field rpad(String string, Field length) { + return new Rpad(Tools.field(string), length); + } + + /** + * The RPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field rpad(Field string, int length) { + return new Rpad(string, Tools.field(length)); + } + + /** + * The RPAD function. + */ + @NotNull + @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + public static Field rpad(Field string, Field length) { + return new Rpad(string, length); + } + /** * The RTRIM function. */ @@ -15579,32 +15795,6 @@ public class DSL { - /** - * Get the rpad(field, length) function. - * - * @see #rpad(Field, Field) - */ - @NotNull - @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) - public static Field rpad(Field field, int length) { - return rpad(Tools.nullSafe(field), Tools.field(length)); - } - - /** - * Get the rpad(field, length) function. - *

- * This renders the rpad function where available: - *

rpad([field], [length])
... or emulates it - * elsewhere using concat, repeat, and length, which may be emulated as - * well, depending on the RDBMS: - *
concat([field], repeat(' ', [length] - length([field])))
- */ - @NotNull - @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) - public static Field rpad(Field field, Field length) { - return new Rpad(Tools.nullSafe(field), Tools.nullSafe(length)); - } - /** * Get the rpad(field, length, character) function. * @@ -15616,61 +15806,6 @@ public class DSL { return rpad(field, length, Character.toString(character)); } - /** - * Get the rpad(field, length, character) function. - * - * @see #rpad(Field, Field, Field) - */ - @NotNull - @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) - public static Field rpad(Field field, int length, String character) { - return rpad(Tools.nullSafe(field), Tools.field(length), Tools.field(character)); - } - - /** - * Get the rpad(field, length, character) function. - *

- * This renders the rpad function where available: - *

rpad([field], [length])
... or emulates it - * elsewhere using concat, repeat, and length, which may be emulated as - * well, depending on the RDBMS: - *
concat([field], repeat([character], [length] - length([field])))
- *

- * In {@link SQLDialect#SQLITE}, this is emulated as such: - *

[field] || replace(replace(substr(quote(zeroblob(([length] + 1) / 2)), 3, ([length] - length([field]))), '\''', ''), '0', [character])
- */ - @NotNull - @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) - public static Field rpad(Field field, Field length, Field character) { - return new Rpad(Tools.nullSafe(field), Tools.nullSafe(length), Tools.nullSafe(character)); - } - - /** - * Get the lpad(field, length) function. - * - * @see #lpad(Field, Field) - */ - @NotNull - @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) - public static Field lpad(Field field, int length) { - return lpad(Tools.nullSafe(field), Tools.field(length)); - } - - /** - * Get the lpad(field, length) function. - *

- * This renders the lpad function where available: - *

lpad([field], [length])
... or emulates it - * elsewhere using concat, repeat, and length, which may be emulated as - * well, depending on the RDBMS: - *
concat(repeat(' ', [length] - length([field])), [field])
- */ - @NotNull - @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) - public static Field lpad(Field field, Field length) { - return new Lpad(Tools.nullSafe(field), Tools.nullSafe(length)); - } - /** * Get the lpad(field, length, character) function. * @@ -15682,35 +15817,6 @@ public class DSL { return lpad(field, length, Character.toString(character)); } - /** - * Get the lpad(field, length, character) function. - * - * @see #lpad(Field, Field, Field) - */ - @NotNull - @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) - public static Field lpad(Field field, int length, String character) { - return lpad(Tools.nullSafe(field), Tools.field(length), Tools.field(character)); - } - - /** - * Get the lpad(field, length, character) function. - *

- * This renders the lpad function where available: - *

lpad([field], [length])
... or emulates it - * elsewhere using concat, repeat, and length, which may be emulated as - * well, depending on the RDBMS: - *
concat(repeat([character], [length] - length([field])), [field])
- *

- * In {@link SQLDialect#SQLITE}, this is emulated as such: - *

replace(replace(substr(quote(zeroblob(([length] + 1) / 2)), 3, ([length] - length([field]))), '\''', ''), '0', [character]) || [field]
- */ - @NotNull - @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) - public static Field lpad(Field field, Field length, Field character) { - return new Lpad(Tools.nullSafe(field), Tools.nullSafe(length), Tools.nullSafe(character)); - } - /** * Get the translate(field, from, to) function. * diff --git a/jOOQ/src/main/java/org/jooq/impl/Lpad.java b/jOOQ/src/main/java/org/jooq/impl/Lpad.java index 6281f08077..091a09644c 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Lpad.java +++ b/jOOQ/src/main/java/org/jooq/impl/Lpad.java @@ -37,45 +37,66 @@ */ package org.jooq.impl; -import static org.jooq.impl.DSL.inline; -import static org.jooq.impl.Internal.isub; -import static org.jooq.impl.Names.N_HEX; -import static org.jooq.impl.Names.N_LEN; -import static org.jooq.impl.Names.N_LENGTH; -import static org.jooq.impl.Names.N_LPAD; -import static org.jooq.impl.Names.N_REPLACE; -import static org.jooq.impl.Names.N_SPACE; -import static org.jooq.impl.Names.N_SUBSTR; -import static org.jooq.impl.Names.N_ZEROBLOB; -import static org.jooq.impl.SQLDataType.VARCHAR; +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 LPAD statement. */ -final class Lpad extends AbstractField { +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class Lpad +extends + AbstractField +{ - /** - * Generated UID - */ - private static final long serialVersionUID = -7273879239726265322L; + private static final long serialVersionUID = 1L; - private final Field field; + private final Field string; private final Field length; private final Field character; - Lpad(Field field, Field length) { - this(field, length, null); + Lpad( + Field string, + Field length + ) { + super(N_LPAD, allNotNull(VARCHAR, string, length)); + + this.string = nullSafeNotNull(string, VARCHAR); + this.length = nullSafeNotNull(length, INTEGER); + this.character = null; } - Lpad(Field field, Field length, Field character) { - super(N_LPAD, VARCHAR); + Lpad( + Field string, + Field length, + Field character + ) { + super(N_LPAD, allNotNull(VARCHAR, string, length, character)); - this.field = field; - this.length = length; - this.character = (character == null ? inline(" ") : character); + this.string = nullSafeNotNull(string, VARCHAR); + this.length = nullSafeNotNull(length, INTEGER); + this.character = nullSafeNotNull(character, VARCHAR); + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + + + private final Field character() { + return character == null ? inline(" ") : character; } @Override @@ -102,14 +123,16 @@ final class Lpad extends AbstractField { .visit(N_HEX).sql('(') .visit(N_ZEROBLOB).sql('(') .visit(length) - .sql(")), '00', ").visit(character) - .sql("), 1, ").visit(length).sql(" - ").visit(N_LENGTH).sql('(').visit(field) - .sql(")) || ").visit(field); + .sql(")), '00', ").visit(character()) + .sql("), 1, ").visit(length).sql(" - ").visit(N_LENGTH).sql('(').visit(string) + .sql(")) || ").visit(string); break; default: - ctx.visit(N_LPAD).sql('(').visit(field).sql(", ").visit(length).sql(", ").visit(character).sql(')'); + ctx.visit(N_LPAD).sql('(').visit(string).sql(", ").visit(length).sql(", ").visit(character()).sql(')'); break; } } + + } diff --git a/jOOQ/src/main/java/org/jooq/impl/Rpad.java b/jOOQ/src/main/java/org/jooq/impl/Rpad.java index 0a83d4fbdc..91bd548638 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Rpad.java +++ b/jOOQ/src/main/java/org/jooq/impl/Rpad.java @@ -37,45 +37,66 @@ */ package org.jooq.impl; -import static org.jooq.impl.DSL.inline; -import static org.jooq.impl.Internal.isub; -import static org.jooq.impl.Names.N_HEX; -import static org.jooq.impl.Names.N_LEN; -import static org.jooq.impl.Names.N_LENGTH; -import static org.jooq.impl.Names.N_REPLACE; -import static org.jooq.impl.Names.N_RPAD; -import static org.jooq.impl.Names.N_SPACE; -import static org.jooq.impl.Names.N_SUBSTR; -import static org.jooq.impl.Names.N_ZEROBLOB; -import static org.jooq.impl.SQLDataType.VARCHAR; +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 RPAD statement. */ -final class Rpad extends AbstractField { +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class Rpad +extends + AbstractField +{ - /** - * Generated UID - */ - private static final long serialVersionUID = -7273879239726265322L; + private static final long serialVersionUID = 1L; - private final Field field; + private final Field string; private final Field length; private final Field character; - Rpad(Field field, Field length) { - this(field, length, null); + Rpad( + Field string, + Field length + ) { + super(N_RPAD, allNotNull(VARCHAR, string, length)); + + this.string = nullSafeNotNull(string, VARCHAR); + this.length = nullSafeNotNull(length, INTEGER); + this.character = null; } - Rpad(Field field, Field length, Field character) { - super(N_RPAD, VARCHAR); + Rpad( + Field string, + Field length, + Field character + ) { + super(N_RPAD, allNotNull(VARCHAR, string, length, character)); - this.field = field; - this.length = length; - this.character = (character == null ? inline(" ") : character); + this.string = nullSafeNotNull(string, VARCHAR); + this.length = nullSafeNotNull(length, INTEGER); + this.character = nullSafeNotNull(character, VARCHAR); + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + + + private final Field character() { + return character == null ? inline(" ") : character; } @Override @@ -97,19 +118,21 @@ final class Rpad extends AbstractField { // This beautiful expression was contributed by "Ludo", here: // http://stackoverflow.com/questions/6576343/how-to-simulate-lpad-rpad-with-sqlite case SQLITE: - ctx.visit(field).sql(" || ").visit(N_SUBSTR).sql('(') + ctx.visit(string).sql(" || ").visit(N_SUBSTR).sql('(') .visit(N_REPLACE).sql('(') .visit(N_HEX).sql('(') .visit(N_ZEROBLOB).sql('(') .visit(length) - .sql(")), '00', ").visit(character) - .sql("), 1, ").visit(length).sql(" - ").visit(N_LENGTH).sql('(').visit(field).sql(')') + .sql(")), '00', ").visit(character()) + .sql("), 1, ").visit(length).sql(" - ").visit(N_LENGTH).sql('(').visit(string).sql(')') .sql(')'); break; default: - ctx.visit(N_RPAD).sql('(').visit(field).sql(", ").visit(length).sql(", ").visit(character).sql(')'); + ctx.visit(N_RPAD).sql('(').visit(string).sql(", ").visit(length).sql(", ").visit(character()).sql(')'); break; } } + + }