Skip to content

Commit

Permalink
[#11061] [#11070] [#11091] WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaseder committed Dec 4, 2020
1 parent e137636 commit 5b1e7eb
Show file tree
Hide file tree
Showing 13 changed files with 364 additions and 112 deletions.
108 changes: 108 additions & 0 deletions jOOQ/src/main/java/org/jooq/impl/BitLength.java
@@ -0,0 +1,108 @@
/*
* 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
*
* http://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: http://www.jooq.org/licenses
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
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 org.jooq.Context;
import org.jooq.Field;

/**
* @author Lukas Eder
*/
final class BitLength extends AbstractField<Integer> {

/**
* Generated UID
*/
private static final long serialVersionUID = 1484652553287331042L;

private final Field<String> field;

BitLength(Field<String> field) {
super(N_BIT_LENGTH, INTEGER.nullable(field == null || field.getDataType().nullable()));

this.field = nullSafeNotNull(field, VARCHAR);
}

@Override
public void accept(Context<?> ctx) {
switch (ctx.family()) {






















case DERBY:
case SQLITE:
ctx.visit(inline(8).times(function(N_LENGTH, getDataType(), field)));
break;

default:
ctx.visit(function(N_BIT_LENGTH, getDataType(), field));
break;
}
}
}
97 changes: 97 additions & 0 deletions jOOQ/src/main/java/org/jooq/impl/CharLength.java
@@ -0,0 +1,97 @@
/*
* 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
*
* http://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: http://www.jooq.org/licenses
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
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 org.jooq.Context;
import org.jooq.Field;

/**
* @author Lukas Eder
*/
final class CharLength extends AbstractField<Integer> {

/**
* Generated UID
*/
private static final long serialVersionUID = 1484652553287331042L;

private final Field<String> field;

CharLength(Field<String> field) {
super(N_CHAR_LENGTH, INTEGER.nullable(field == null || field.getDataType().nullable()));

this.field = nullSafeNotNull(field, VARCHAR);
}

@Override
public void accept(Context<?> ctx) {
switch (ctx.family()) {














case DERBY:
case SQLITE:
ctx.visit(function(N_LENGTH, getDataType(), field));
break;

default:
ctx.visit(function(N_CHAR_LENGTH, getDataType(), field));
break;
}
}
}
26 changes: 13 additions & 13 deletions jOOQ/src/main/java/org/jooq/impl/DSL.java
Expand Up @@ -15224,7 +15224,7 @@ public static Field<String> repeat(String field, int count) {
@NotNull
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
public static Field<String> repeat(String field, Field<? extends Number> count) {
return repeat(Tools.field(field), Tools.nullSafe(count));
return repeat(Tools.field(field), count);
}

/**
Expand All @@ -15235,7 +15235,7 @@ public static Field<String> repeat(String field, Field<? extends Number> count)
@NotNull
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
public static Field<String> repeat(Field<String> field, int count) {
return repeat(Tools.nullSafe(field), Tools.field(count));
return repeat(field, Tools.field(count));
}

/**
Expand All @@ -15254,7 +15254,7 @@ public static Field<String> repeat(Field<String> field, int count) {
@NotNull
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
public static Field<String> repeat(Field<String> field, Field<? extends Number> count) {
return new Repeat(Tools.nullSafe(field), Tools.nullSafe(count));
return new Repeat(field, count);
}

/**
Expand All @@ -15269,7 +15269,7 @@ public static Field<String> repeat(Field<String> field, Field<? extends Number>
@NotNull
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
public static Field<String> space(int value) {
return space(val(value));
return space(Tools.field(value));
}

/**
Expand All @@ -15284,7 +15284,7 @@ public static Field<String> space(int value) {
@NotNull
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
public static Field<String> space(Field<Integer> value) {
return new Space(Tools.nullSafe(value));
return new Space(value);
}

/**
Expand All @@ -15302,7 +15302,7 @@ public static Field<String> reverse(String value) {
@NotNull
@Support({ CUBRID, HSQLDB, MARIADB, MYSQL, POSTGRES })
public static Field<String> reverse(Field<String> field) {
return new Reverse(Tools.nullSafe(field));
return new Reverse(field);
}

/**
Expand Down Expand Up @@ -15821,7 +15821,7 @@ public static Field<String> left(String field, int length) {
@NotNull
@Support
public static Field<String> left(String field, Field<? extends Number> length) {
return left(Tools.field(field), Tools.nullSafe(length));
return left(Tools.field(field), length);
}

/**
Expand All @@ -15835,7 +15835,7 @@ public static Field<String> left(String field, Field<? extends Number> length) {
@NotNull
@Support
public static Field<String> left(Field<String> field, int length) {
return left(Tools.nullSafe(field), Tools.field(length));
return left(field, Tools.field(length));
}

/**
Expand Down Expand Up @@ -15877,7 +15877,7 @@ public static Field<String> right(String field, int length) {
@NotNull
@Support
public static Field<String> right(String field, Field<? extends Number> length) {
return right(Tools.field(field), Tools.nullSafe(length));
return right(Tools.field(field), length);
}

/**
Expand All @@ -15891,7 +15891,7 @@ public static Field<String> right(String field, Field<? extends Number> length)
@NotNull
@Support
public static Field<String> right(Field<String> field, int length) {
return right(Tools.nullSafe(field), Tools.field(length));
return right(field, Tools.field(length));
}

/**
Expand Down Expand Up @@ -15951,7 +15951,7 @@ public static Field<Integer> charLength(String value) {
@NotNull
@Support
public static Field<Integer> charLength(Field<String> field) {
return new DefaultAggregateFunction<>(Term.CHAR_LENGTH, INTEGER.nullable(Tools.nullSafeDataType(field).nullable()), Tools.nullSafe(field));
return new CharLength(field);
}

/**
Expand All @@ -15973,7 +15973,7 @@ public static Field<Integer> bitLength(String value) {
@NotNull
@Support
public static Field<Integer> bitLength(Field<String> field) {
return new DefaultAggregateFunction<>(Term.BIT_LENGTH, INTEGER.nullable(Tools.nullSafeDataType(field).nullable()), Tools.nullSafe(field));
return new BitLength(field);
}

/**
Expand All @@ -15995,7 +15995,7 @@ public static Field<Integer> octetLength(String value) {
@NotNull
@Support
public static Field<Integer> octetLength(Field<String> field) {
return new DefaultAggregateFunction<>(Term.OCTET_LENGTH, INTEGER.nullable(Tools.nullSafeDataType(field).nullable()), Tools.nullSafe(field));
return new OctetLength(field);
}

// ------------------------------------------------------------------------
Expand Down
6 changes: 4 additions & 2 deletions jOOQ/src/main/java/org/jooq/impl/Left.java
Expand Up @@ -39,8 +39,10 @@

import static org.jooq.impl.DSL.inline;
import static org.jooq.impl.Names.N_LEFT;
import static org.jooq.impl.SQLDataType.INTEGER;
import static org.jooq.impl.SQLDataType.VARCHAR;
import static org.jooq.impl.Tools.allNotNull;
import static org.jooq.impl.Tools.nullSafeNotNull;

import org.jooq.Context;
import org.jooq.Field;
Expand All @@ -61,8 +63,8 @@ final class Left extends AbstractField<String> {
Left(Field<String> field, Field<? extends Number> length) {
super(N_LEFT, allNotNull(VARCHAR, field, length));

this.field = field;
this.length = length;
this.field = nullSafeNotNull(field, VARCHAR);
this.length = nullSafeNotNull(length, INTEGER);
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions jOOQ/src/main/java/org/jooq/impl/Names.java
Expand Up @@ -68,13 +68,15 @@ final class Names {
static final Name N_ATAN = unquotedName("atan");
static final Name N_ATN = unquotedName("atn");
static final Name N_BIT_COUNT = unquotedName("bit_count");
static final Name N_BIT_LENGTH = unquotedName("bit_length");
static final Name N_BOOL_AND = unquotedName("bool_and");
static final Name N_BOOL_OR = unquotedName("bool_or");
static final Name N_CARDINALITY = unquotedName("cardinality");
static final Name N_CASE = unquotedName("case");
static final Name N_CAST = unquotedName("cast");
static final Name N_CEIL = unquotedName("ceil");
static final Name N_CEILING = unquotedName("ceiling");
static final Name N_CHAR_LENGTH = unquotedName("char_length");
static final Name N_CHARINDEX = unquotedName("charindex");
static final Name N_CHOOSE = unquotedName("choose");
static final Name N_CLNG = unquotedName("clng");
Expand All @@ -96,6 +98,7 @@ final class Names {
static final Name N_CURRENT_USER = unquotedName("current_user");
static final Name N_CURRENTUSER = unquotedName("currentuser");
static final Name N_CURRVAL = unquotedName("currval");
static final Name N_DATALENGTH = unquotedName("datalength");
static final Name N_DATE_ADD = unquotedName("date_add");
static final Name N_DATE_DIFF = unquotedName("date_diff");
static final Name N_DATE_TRUNC = unquotedName("date_trunc");
Expand Down Expand Up @@ -157,6 +160,7 @@ final class Names {
static final Name N_LEFT = unquotedName("left");
static final Name N_LEN = unquotedName("len");
static final Name N_LENGTH = unquotedName("length");
static final Name N_LENGTHB = unquotedName("lengthb");
static final Name N_LIST = unquotedName("list");
static final Name N_LISTAGG = unquotedName("listagg");
static final Name N_LN = unquotedName("ln");
Expand All @@ -178,6 +182,7 @@ final class Names {
static final Name N_NUMTODSINTERVAL = unquotedName("numtodsinterval");
static final Name N_NVL = unquotedName("nvl");
static final Name N_NVL2 = unquotedName("nvl2");
static final Name N_OCTET_LENGTH = unquotedName("octet_length");
static final Name N_OPENJSON = unquotedName("openjson");
static final Name N_OPENXML = unquotedName("openxml");
static final Name N_OVERLAY = unquotedName("overlay");
Expand Down

0 comments on commit 5b1e7eb

Please sign in to comment.