Skip to content

Commit

Permalink
[#5643] Add DSL.currentLocalDate(), currentLocalTime(), currentLocalD…
Browse files Browse the repository at this point in the history
…ateTime(), currentOffsetTime(), currentOffsetDateTime()
  • Loading branch information
lukaseder committed Nov 6, 2016
1 parent 86c2a6e commit c4e067f
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 27 deletions.
15 changes: 7 additions & 8 deletions jOOQ/src/main/java/org/jooq/impl/CurrentDate.java
Expand Up @@ -42,27 +42,26 @@


import static org.jooq.impl.DSL.function; import static org.jooq.impl.DSL.function;


import java.sql.Date;

import org.jooq.Configuration; import org.jooq.Configuration;
import org.jooq.DataType;
import org.jooq.Field; import org.jooq.Field;


/** /**
* @author Lukas Eder * @author Lukas Eder
*/ */
final class CurrentDate extends AbstractFunction<Date> { final class CurrentDate<T> extends AbstractFunction<T> {


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


CurrentDate() { CurrentDate(DataType<T> type) {
super("current_date", SQLDataType.DATE); super("current_date", type);
} }


@Override @Override
final Field<Date> getFunction0(Configuration configuration) { final Field<T> getFunction0(Configuration configuration) {
switch (configuration.family()) { switch (configuration.family()) {




Expand Down Expand Up @@ -92,9 +91,9 @@ final Field<Date> getFunction0(Configuration configuration) {
case HSQLDB: case HSQLDB:
case POSTGRES: case POSTGRES:
case SQLITE: case SQLITE:
return DSL.field("{current_date}", SQLDataType.DATE); return DSL.field("{current_date}", getDataType());
} }


return function("current_date", SQLDataType.DATE); return function("current_date", getDataType());
} }
} }
15 changes: 7 additions & 8 deletions jOOQ/src/main/java/org/jooq/impl/CurrentTime.java
Expand Up @@ -40,27 +40,26 @@
*/ */
package org.jooq.impl; package org.jooq.impl;


import java.sql.Time;

import org.jooq.Configuration; import org.jooq.Configuration;
import org.jooq.DataType;
import org.jooq.Field; import org.jooq.Field;


/** /**
* @author Lukas Eder * @author Lukas Eder
*/ */
final class CurrentTime extends AbstractFunction<Time> { final class CurrentTime<T> extends AbstractFunction<T> {


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


CurrentTime() { CurrentTime(DataType<T> type) {
super("current_time", SQLDataType.TIME); super("current_time", type);
} }


@Override @Override
final Field<Time> getFunction0(Configuration configuration) { final Field<T> getFunction0(Configuration configuration) {
switch (configuration.family()) { switch (configuration.family()) {




Expand All @@ -82,7 +81,7 @@ final Field<Time> getFunction0(Configuration configuration) {
case HSQLDB: case HSQLDB:
case POSTGRES: case POSTGRES:
case SQLITE: case SQLITE:
return DSL.field("{current_time}", SQLDataType.TIME); return DSL.field("{current_time}", getDataType());






Expand All @@ -93,6 +92,6 @@ final Field<Time> getFunction0(Configuration configuration) {


} }


return DSL.function("current_time", SQLDataType.TIME); return DSL.function("current_time", getDataType());
} }
} }
15 changes: 7 additions & 8 deletions jOOQ/src/main/java/org/jooq/impl/CurrentTimestamp.java
Expand Up @@ -42,27 +42,26 @@


import static org.jooq.impl.DSL.function; import static org.jooq.impl.DSL.function;


import java.sql.Timestamp;

import org.jooq.Configuration; import org.jooq.Configuration;
import org.jooq.DataType;
import org.jooq.Field; import org.jooq.Field;


/** /**
* @author Lukas Eder * @author Lukas Eder
*/ */
final class CurrentTimestamp extends AbstractFunction<Timestamp> { final class CurrentTimestamp<T> extends AbstractFunction<T> {


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


CurrentTimestamp() { CurrentTimestamp(DataType<T> type) {
super("current_timestamp", SQLDataType.TIMESTAMP); super("current_timestamp", type);
} }


@Override @Override
final Field<Timestamp> getFunction0(Configuration configuration) { final Field<T> getFunction0(Configuration configuration) {
switch (configuration.family()) { switch (configuration.family()) {




Expand Down Expand Up @@ -92,9 +91,9 @@ final Field<Timestamp> getFunction0(Configuration configuration) {
case HSQLDB: case HSQLDB:
case POSTGRES: case POSTGRES:
case SQLITE: case SQLITE:
return DSL.field("{current_timestamp}", SQLDataType.TIMESTAMP); return DSL.field("{current_timestamp}", getDataType());
} }


return function("current_timestamp", SQLDataType.TIMESTAMP); return function("current_timestamp", getDataType());
} }
} }
58 changes: 55 additions & 3 deletions jOOQ/src/main/java/org/jooq/impl/DSL.java
Expand Up @@ -11499,7 +11499,7 @@ public static Field<String> md5(Field<String> string) {
*/ */
@Support @Support
public static Field<Date> currentDate() { public static Field<Date> currentDate() {
return new CurrentDate(); return new CurrentDate<Date>(SQLDataType.DATE);
} }


/** /**
Expand All @@ -11509,7 +11509,7 @@ public static Field<Date> currentDate() {
*/ */
@Support @Support
public static Field<Time> currentTime() { public static Field<Time> currentTime() {
return new CurrentTime(); return new CurrentTime<Time>(SQLDataType.TIME);
} }


/** /**
Expand All @@ -11519,9 +11519,61 @@ public static Field<Time> currentTime() {
*/ */
@Support @Support
public static Field<Timestamp> currentTimestamp() { public static Field<Timestamp> currentTimestamp() {
return new CurrentTimestamp(); return new CurrentTimestamp<Timestamp>(SQLDataType.TIMESTAMP);
} }



/**
* Get the current_date() function.
* <p>
* This translates into any dialect
*/
@Support
public static Field<LocalDate> currentLocalDate() {
return new CurrentDate<>(SQLDataType.LOCALDATE);
}

/**
* Get the current_time() function.
* <p>
* This translates into any dialect
*/
@Support
public static Field<LocalTime> currentLocalTime() {
return new CurrentTime<>(SQLDataType.LOCALTIME);
}

/**
* Get the current_timestamp() function.
* <p>
* This translates into any dialect
*/
@Support
public static Field<LocalDateTime> currentLocalDateTime() {
return new CurrentTimestamp<>(SQLDataType.LOCALDATETIME);
}

/**
* Get the current_time() function.
* <p>
* This translates into any dialect
*/
@Support
public static Field<OffsetTime> currentOffsetTime() {
return currentTime().cast(SQLDataType.OFFSETTIME);
}

/**
* Get the current_timestamp() function.
* <p>
* This translates into any dialect
*/
@Support
public static Field<OffsetDateTime> currentOffsetDateTime() {
return currentTimestamp().cast(SQLDataType.OFFSETDATETIME);
}


/** /**
* Get the date difference in number of days. * Get the date difference in number of days.
* <p> * <p>
Expand Down

0 comments on commit c4e067f

Please sign in to comment.