[jOOQ/jOOQ#7900] Added Derby support

This commit is contained in:
Lukas Eder 2020-06-05 15:40:29 +02:00
parent b56e93585b
commit 81aab8f263
3 changed files with 57 additions and 11 deletions

View File

@ -15325,7 +15325,7 @@ public class DSL {
* despite there being less than 2 years between the two days. The behaviour
* replicates that of SQL Server.
*/
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
@Support({ DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
public static Field<Integer> dateDiff(DatePart part, Date startDate, Date endDate) {
return dateDiff(part, Tools.field(startDate), Tools.field(endDate));
}
@ -15338,7 +15338,7 @@ public class DSL {
* despite there being less than 2 years between the two days. The behaviour
* replicates that of SQL Server.
*/
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
@Support({ DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
public static Field<Integer> dateDiff(DatePart part, Field<Date> startDate, Date endDate) {
return dateDiff(part, nullSafe(startDate), Tools.field(endDate));
}
@ -15351,7 +15351,7 @@ public class DSL {
* despite there being less than 2 years between the two days. The behaviour
* replicates that of SQL Server.
*/
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
@Support({ DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
public static Field<Integer> dateDiff(DatePart part, Date startDate, Field<Date> endDate) {
return dateDiff(part, Tools.field(startDate), nullSafe(endDate));
}
@ -15364,7 +15364,7 @@ public class DSL {
* despite there being less than 2 years between the two days. The behaviour
* replicates that of SQL Server.
*/
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
@Support({ DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
public static Field<Integer> dateDiff(DatePart part, Field<Date> startDate, Field<Date> endDate) {
return new DateDiff<>(part, nullSafe(startDate), nullSafe(endDate));
}
@ -15731,7 +15731,7 @@ public class DSL {
* despite there being less than 2 years between the two days. The behaviour
* replicates that of SQL Server.
*/
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
@Support({ DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
public static Field<Integer> localDateDiff(DatePart part, LocalDate startDate, LocalDate endDate) {
return localDateDiff(part, Tools.field(startDate), Tools.field(endDate));
}
@ -15744,7 +15744,7 @@ public class DSL {
* despite there being less than 2 years between the two days. The behaviour
* replicates that of SQL Server.
*/
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
@Support({ DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
public static Field<Integer> localDateDiff(DatePart part, Field<LocalDate> startDate, LocalDate endDate) {
return localDateDiff(part, nullSafe(startDate), Tools.field(endDate));
}
@ -15757,7 +15757,7 @@ public class DSL {
* despite there being less than 2 years between the two days. The behaviour
* replicates that of SQL Server.
*/
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
@Support({ DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
public static Field<Integer> localDateDiff(DatePart part, LocalDate startDate, Field<LocalDate> endDate) {
return localDateDiff(part, Tools.field(startDate), nullSafe(endDate));
}
@ -15770,7 +15770,7 @@ public class DSL {
* despite there being less than 2 years between the two days. The behaviour
* replicates that of SQL Server.
*/
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
@Support({ DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
public static Field<Integer> localDateDiff(DatePart part, Field<LocalDate> startDate, Field<LocalDate> endDate) {
return new DateDiff<>(part, nullSafe(startDate), nullSafe(endDate));
}

View File

@ -42,16 +42,21 @@ import static org.jooq.DatePart.EPOCH;
import static org.jooq.DatePart.HOUR;
import static org.jooq.DatePart.MICROSECOND;
import static org.jooq.DatePart.MILLISECOND;
import static org.jooq.DatePart.NANOSECOND;
import static org.jooq.DatePart.QUARTER;
import static org.jooq.DatePart.YEAR;
import static org.jooq.SQLDialect.FIREBIRD;
import static org.jooq.SQLDialect.HSQLDB;
import static org.jooq.impl.DSL.function;
import static org.jooq.impl.DSL.inline;
import static org.jooq.impl.DSL.keyword;
import static org.jooq.impl.Names.N_DATEDIFF;
import static org.jooq.impl.Names.N_DAYS;
import static org.jooq.impl.Names.N_DAYS_BETWEEN;
import static org.jooq.impl.Names.N_SQL_TSI_DAY;
import static org.jooq.impl.Names.N_SQL_TSI_FRAC_SECOND;
import static org.jooq.impl.Names.N_SQL_TSI_HOUR;
import static org.jooq.impl.Names.N_SQL_TSI_MINUTE;
import static org.jooq.impl.Names.N_SQL_TSI_SECOND;
import static org.jooq.impl.Names.N_STRFTIME;
import static org.jooq.impl.Names.N_TIMESTAMPDIFF;
import static org.jooq.impl.SQLDataType.TIMESTAMP;
@ -60,6 +65,7 @@ import static org.jooq.impl.Tools.castIfNeeded;
import org.jooq.Context;
import org.jooq.DatePart;
import org.jooq.Field;
import org.jooq.Name;
/**
* @author Lukas Eder
@ -123,9 +129,40 @@ final class DateDiff<T> extends AbstractField<Integer> {
ctx.visit(N_TIMESTAMPDIFF).sql('(').visit(p.toName()).sql(", ").visit(startDate).sql(", ").visit(endDate).sql(')');
return;
case DERBY:
ctx.sql("{fn ").visit(N_TIMESTAMPDIFF).sql('(').visit(keyword("sql_tsi_day")).sql(", ").visit(startDate).sql(", ").visit(endDate).sql(") }");
case DERBY: {
Name name = N_SQL_TSI_DAY;
switch (p) {
case MILLENNIUM:
case CENTURY:
case DECADE:
case YEAR:
ctx.visit(partDiff(p));
return;
case QUARTER:
case MONTH:
ctx.visit(monthDiff(p));
return;
case DAY: name = N_SQL_TSI_DAY; break;
case HOUR: name = N_SQL_TSI_HOUR; break;
case MINUTE: name = N_SQL_TSI_MINUTE; break;
case SECOND: name = N_SQL_TSI_SECOND; break;
case NANOSECOND: name = N_SQL_TSI_FRAC_SECOND; break;
case MILLISECOND:
ctx.visit(new DateDiff<>(NANOSECOND, startDate, endDate).div(inline(1000000L)));
return;
case MICROSECOND:
ctx.visit(new DateDiff<>(NANOSECOND, startDate, endDate).div(inline(1000L)));
return;
}
ctx.sql("{fn ").visit(N_TIMESTAMPDIFF).sql('(').visit(name).sql(", ").visit(startDate).sql(", ").visit(endDate).sql(") }");
return;
}

View File

@ -205,6 +205,15 @@ final class Names {
static final Name N_SIGN = unquotedName("sign");
static final Name N_SINH = unquotedName("sinh");
static final Name N_SPACE = unquotedName("space");
static final Name N_SQL_TSI_DAY = unquotedName("sql_tsi_day");
static final Name N_SQL_TSI_FRAC_SECOND = unquotedName("sql_tsi_frac_second");
static final Name N_SQL_TSI_HOUR = unquotedName("sql_tsi_hour");
static final Name N_SQL_TSI_MINUTE = unquotedName("sql_tsi_minute");
static final Name N_SQL_TSI_MONTH = unquotedName("sql_tsi_month");
static final Name N_SQL_TSI_QUARTER = unquotedName("sql_tsi_quarter");
static final Name N_SQL_TSI_SECOND = unquotedName("sql_tsi_second");
static final Name N_SQL_TSI_WEEK = unquotedName("sql_tsi_week");
static final Name N_SQL_TSI_YEAR = unquotedName("sql_tsi_year");
static final Name N_SQR = unquotedName("sqr");
static final Name N_SQRT = unquotedName("sqrt");
static final Name N_STANDARD_HASH = unquotedName("standard_hash");