Patches from Jamie:

1. DateFuncs.dayOfWeek and dayOfMonth can now be used on Timestamp. +FromDate
variants exist for using on Date.

2. hour, minute, second, etc. are now typed Number to cope with differing
opinions on the part of the underlying SQL drivers as to whether to return
Double, Long, Integer or something else.
This commit is contained in:
Michael Bayne
2011-02-15 22:20:53 +00:00
parent 51aa221606
commit 6603fb7d81
2 changed files with 35 additions and 11 deletions
@@ -43,7 +43,15 @@ public class DateFuncs
/**
* Creates an expression to extract the day-of-week from the the supplied timestamp expression.
*/
public static <T extends Date> FluentExp<Integer> dayOfWeek (SQLExpression<T> exp)
public static FluentExp<Number> dayOfWeek (SQLExpression<Timestamp> exp)
{
return new DatePart(exp, DatePart.Part.DAY_OF_WEEK);
}
/**
* Creates an expression to extract the day-of-week from the the supplied date expression.
*/
public static FluentExp<Number> dayOfWeekFromDate (SQLExpression<Date> exp)
{
return new DatePart(exp, DatePart.Part.DAY_OF_WEEK);
}
@@ -51,7 +59,15 @@ public class DateFuncs
/**
* Creates an expression to extract the day-of-month from the the supplied timestamp expression.
*/
public static <T extends Date> FluentExp<Integer> dayOfMonth (SQLExpression<T> exp)
public static FluentExp<Number> dayOfMonth (SQLExpression<Timestamp> exp)
{
return new DatePart(exp, DatePart.Part.DAY_OF_MONTH);
}
/**
* Creates an expression to extract the day-of-month from the the supplied date expression.
*/
public static FluentExp<Number> dayOfMonthFromDate (SQLExpression<Date> exp)
{
return new DatePart(exp, DatePart.Part.DAY_OF_MONTH);
}
@@ -59,7 +75,15 @@ public class DateFuncs
/**
* Creates an expression to extract the day-of-year from the the supplied timestamp expression.
*/
public static <T extends Date> FluentExp<Integer> dayOfYear (SQLExpression<T> exp)
public static FluentExp<Number> dayOfYear (SQLExpression<Timestamp> exp)
{
return new DatePart(exp, DatePart.Part.DAY_OF_YEAR);
}
/**
* Creates an expression to extract the day-of-year from the the supplied data expression.
*/
public static FluentExp<Number> dayOfYearFromDate (SQLExpression<Date> exp)
{
return new DatePart(exp, DatePart.Part.DAY_OF_YEAR);
}
@@ -67,7 +91,7 @@ public class DateFuncs
/**
* Creates an expression to extract the hour of the the supplied timestamp expression.
*/
public static FluentExp<Integer> hour (SQLExpression<Timestamp> exp)
public static FluentExp<Number> hour (SQLExpression<Timestamp> exp)
{
return new DatePart(exp, DatePart.Part.HOUR);
}
@@ -75,7 +99,7 @@ public class DateFuncs
/**
* Creates an expression to extract the minute of the the supplied timestamp expression.
*/
public static FluentExp<Integer> minute (SQLExpression<Timestamp> exp)
public static FluentExp<Number> minute (SQLExpression<Timestamp> exp)
{
return new DatePart(exp, DatePart.Part.MINUTE);
}
@@ -83,7 +107,7 @@ public class DateFuncs
/**
* Creates an expression to extract the second of the the supplied timestamp expression.
*/
public static FluentExp<Integer> second (SQLExpression<Timestamp> exp)
public static FluentExp<Number> second (SQLExpression<Timestamp> exp)
{
return new DatePart(exp, DatePart.Part.SECOND);
}
@@ -94,7 +118,7 @@ public class DateFuncs
/**
* Creates an expression to extract the week of the the supplied timestamp expression.
*/
public static FluentExp<Integer> week (SQLExpression<? extends java.util.Date> exp)
public static FluentExp<Number> week (SQLExpression<? extends java.util.Date> exp)
{
return new DatePart(exp, DatePart.Part.WEEK);
}
@@ -102,7 +126,7 @@ public class DateFuncs
/**
* Creates an expression to extract the month of the the supplied timestamp expression.
*/
public static FluentExp<Integer> month (SQLExpression<? extends java.util.Date> exp)
public static FluentExp<Number> month (SQLExpression<? extends java.util.Date> exp)
{
return new DatePart(exp, DatePart.Part.MONTH);
}
@@ -110,7 +134,7 @@ public class DateFuncs
/**
* Creates an expression to extract the year of the the supplied timestamp expression.
*/
public static FluentExp<Integer> year (SQLExpression<? extends java.util.Date> exp)
public static FluentExp<Number> year (SQLExpression<? extends java.util.Date> exp)
{
return new DatePart(exp, DatePart.Part.YEAR);
}
@@ -119,7 +143,7 @@ public class DateFuncs
* Creates an expression to extract the epoch (aka unix timestamp, aka seconds passed since
* 1970-01-01) of the the supplied timestamp expression.
*/
public static FluentExp<Integer> epoch (SQLExpression<? extends java.util.Date> exp)
public static FluentExp<Number> epoch (SQLExpression<? extends java.util.Date> exp)
{
return new DatePart(exp, DatePart.Part.EPOCH);
}
@@ -30,7 +30,7 @@ import com.samskivert.depot.impl.expression.Function.OneArgFun;
public abstract class DateFun
{
public static class DatePart extends OneArgFun<Integer> {
public static class DatePart extends OneArgFun<Number> {
public enum Part {
DAY_OF_MONTH, DAY_OF_WEEK, DAY_OF_YEAR, HOUR, MINUTE, MONTH,
SECOND, WEEK, YEAR, EPOCH