*/
public interface EvalContext
{
- public TemporalConfig getTemporalConfig();
-
public Value.Type getResultType();
+ public TemporalConfig getTemporalConfig();
+
public SimpleDateFormat createDateFormat(String formatStr);
public Value getThisColumnValue();
public String getAsString();
- public Date getAsDateTime();
+ public Date getAsDateTime(EvalContext ctx);
public Long getAsLong();
import java.util.Date;
import com.healthmarketscience.jackcess.impl.ColumnImpl;
+import com.healthmarketscience.jackcess.expr.EvalContext;
/**
*
return _fmt.format(_val);
}
+ @Override
+ public Date getAsDateTime(EvalContext ctx) {
+ return _val;
+ }
+
@Override
public Long getAsLong() {
return getNumber().longValue();
import java.math.BigDecimal;
import java.util.Date;
+import com.healthmarketscience.jackcess.expr.EvalContext;
import com.healthmarketscience.jackcess.expr.Value;
/**
return getDelegate().getAsString();
}
- public Date getAsDateTime() {
- return getDelegate().getAsDateTime();
+ public Date getAsDateTime(EvalContext ctx) {
+ return getDelegate().getAsDateTime(ctx);
}
public Long getAsLong() {
package com.healthmarketscience.jackcess.impl.expr;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import com.healthmarketscience.jackcess.expr.EvalContext;
+import com.healthmarketscience.jackcess.impl.ColumnImpl;
/**
*
return getNumber().doubleValue();
}
+ @Override
+ public Date getAsDateTime(EvalContext ctx) {
+ double d = getNumber().doubleValue();
+
+ SimpleDateFormat sdf = ctx.createDateFormat(
+ ctx.getTemporalConfig().getDefaultDateTimeFormat());
+ return new Date(ColumnImpl.fromDateDouble(d, sdf.getCalendar()));
+ }
+
protected abstract Number getNumber();
}
import java.util.Date;
import com.healthmarketscience.jackcess.expr.Value;
+import com.healthmarketscience.jackcess.expr.EvalContext;
/**
*
throw invalidConversion(Value.Type.STRING);
}
- public Date getAsDateTime() {
+ public Date getAsDateTime(EvalContext ctx) {
throw invalidConversion(Value.Type.DATE_TIME);
}
return NULL_VAL;
}
+ // FIXME, string will convert to number if one is number and one is a string parseable as a number!!!
+
Value.Type mathType = getGeneralMathTypePrecedence(param1, param2);
switch(mathType) {
return ((t1.compareTo(t2) > 0) ? t1 : t2);
}
- private static boolean isIntegral(double d) {
+ static boolean isIntegral(double d) {
return ((d == Math.rint(d)) && !Double.isInfinite(d) && !Double.isNaN(d));
}
return null;
}
- // FIXME, booleans seem to go to -1 (true),0 (false) ...?
-
- return val.get();
+ // FIXME possibly do some type coercion. are there conversions here which don't work elsewhere? (string -> date, string -> number)?
+ switch(ctx.getResultType()) {
+ case STRING:
+ return val.getAsString();
+ case DATE:
+ case TIME:
+ case DATE_TIME:
+ return val.getAsDateTime(ctx);
+ case LONG:
+ return val.getAsLong();
+ case DOUBLE:
+ return val.getAsDouble();
+ case BIG_DEC:
+ return val.getAsBigDecimal();
+ default:
+ throw new IllegalStateException("unexpected result type " +
+ ctx.getResultType());
+ }
}
private Boolean evalCondition(EvalContext ctx) {