From 6603fb7d81412bcdea12c3e2ffa6acbfbf045bb3 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 15 Feb 2011 22:20:53 +0000 Subject: [PATCH] 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. --- .../java/com/samskivert/depot/DateFuncs.java | 44 ++++++++++++++----- .../depot/impl/expression/DateFun.java | 2 +- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/samskivert/depot/DateFuncs.java b/src/main/java/com/samskivert/depot/DateFuncs.java index b942673..1862275 100644 --- a/src/main/java/com/samskivert/depot/DateFuncs.java +++ b/src/main/java/com/samskivert/depot/DateFuncs.java @@ -43,7 +43,15 @@ public class DateFuncs /** * Creates an expression to extract the day-of-week from the the supplied timestamp expression. */ - public static FluentExp dayOfWeek (SQLExpression exp) + public static FluentExp dayOfWeek (SQLExpression 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 dayOfWeekFromDate (SQLExpression 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 FluentExp dayOfMonth (SQLExpression exp) + public static FluentExp dayOfMonth (SQLExpression 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 dayOfMonthFromDate (SQLExpression 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 FluentExp dayOfYear (SQLExpression exp) + public static FluentExp dayOfYear (SQLExpression 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 dayOfYearFromDate (SQLExpression 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 hour (SQLExpression exp) + public static FluentExp hour (SQLExpression 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 minute (SQLExpression exp) + public static FluentExp minute (SQLExpression 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 second (SQLExpression exp) + public static FluentExp second (SQLExpression 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 week (SQLExpression exp) + public static FluentExp week (SQLExpression 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 month (SQLExpression exp) + public static FluentExp month (SQLExpression 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 year (SQLExpression exp) + public static FluentExp year (SQLExpression 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 epoch (SQLExpression exp) + public static FluentExp epoch (SQLExpression exp) { return new DatePart(exp, DatePart.Part.EPOCH); } diff --git a/src/main/java/com/samskivert/depot/impl/expression/DateFun.java b/src/main/java/com/samskivert/depot/impl/expression/DateFun.java index 29e641f..f2ea6a8 100644 --- a/src/main/java/com/samskivert/depot/impl/expression/DateFun.java +++ b/src/main/java/com/samskivert/depot/impl/expression/DateFun.java @@ -30,7 +30,7 @@ import com.samskivert.depot.impl.expression.Function.OneArgFun; public abstract class DateFun { - public static class DatePart extends OneArgFun { + public static class DatePart extends OneArgFun { public enum Part { DAY_OF_MONTH, DAY_OF_WEEK, DAY_OF_YEAR, HOUR, MINUTE, MONTH, SECOND, WEEK, YEAR, EPOCH