You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pp...@apache.org on 2009/12/02 04:55:10 UTC
svn commit: r886045 -
/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CurrentDate.java
Author: ppoddar
Date: Wed Dec 2 03:55:09 2009
New Revision: 886045
URL: http://svn.apache.org/viewvc?rev=886045&view=rev
Log:
OPENJPA-1409: Missing from TeamCity commit
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CurrentDate.java
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CurrentDate.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CurrentDate.java?rev=886045&r1=886044&r2=886045&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CurrentDate.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CurrentDate.java Wed Dec 2 03:55:09 2009
@@ -18,9 +18,13 @@
*/
package org.apache.openjpa.jdbc.kernel.exps;
+import java.sql.SQLException;
+import java.sql.Time;
+import java.sql.Timestamp;
import java.util.Date;
import org.apache.openjpa.jdbc.meta.JavaSQLTypes;
+import org.apache.openjpa.jdbc.sql.Result;
import org.apache.openjpa.jdbc.sql.SQLBuffer;
import org.apache.openjpa.jdbc.sql.Select;
import org.apache.openjpa.util.InternalException;
@@ -33,38 +37,49 @@
class CurrentDate
extends Const {
- private final int _type;
+ private final Class<? extends Date> _type;
- public CurrentDate(int type) {
+ public CurrentDate(Class<? extends Date> type) {
_type = type;
}
- public Class getType() {
- return Date.class;
+ public Class<? extends Date> getType() {
+ return _type;
}
public void setImplicitType(Class type) {
}
+ public Object load(ExpContext ctx, ExpState state, Result res) throws SQLException {
+ if (Timestamp.class.isAssignableFrom(_type)) {
+ return res.getTimestamp(this, null);
+ } else if (Time.class.isAssignableFrom(_type)) {
+ return res.getTime(this, null);
+ } else if (Date.class.isAssignableFrom(_type)) {
+ return res.getDate(this, null);
+ } else {
+ throw new InternalException();
+ }
+ }
+
public Object getValue(Object[] params) {
- return new Date();
+ try {
+ _type.getConstructor(long.class).newInstance(System.currentTimeMillis());
+ } catch (Exception e) {
+ return new Date();
+ }
+ return null;
}
- public void appendTo(Select sel, ExpContext ctx, ExpState state,
- SQLBuffer sql, int index) {
- switch (_type) {
- case JavaSQLTypes.DATE:
- sql.append(ctx.store.getDBDictionary().currentDateFunction);
- break;
- case JavaSQLTypes.TIME:
- sql.append(ctx.store.getDBDictionary().currentTimeFunction);
- break;
- case JavaSQLTypes.TIMESTAMP:
- sql.append(ctx.store.getDBDictionary().
- currentTimestampFunction);
- break;
- default:
- throw new InternalException();
+ public void appendTo(Select sel, ExpContext ctx, ExpState state, SQLBuffer sql, int index) {
+ if (Timestamp.class.isAssignableFrom(_type)) {
+ sql.append(ctx.store.getDBDictionary().currentTimestampFunction);
+ } else if (Time.class.isAssignableFrom(_type)) {
+ sql.append(ctx.store.getDBDictionary().currentTimeFunction);
+ } else if (Date.class.isAssignableFrom(_type)) {
+ sql.append(ctx.store.getDBDictionary().currentDateFunction);
+ } else {
+ throw new InternalException();
}
}
}