Well, OK. We're going to take the pain and break binary compatibility and use

thsi opportunity to move a whole heap of stuff into impl that doesn't really
need to be visible to external parties. We're changing the return value of all
expression creating factory classes to SQLExpression or FluentExp because those
expose all the functionality one might need on the returned values and there's
otherwise no value to be had getting an And() or a LiteralExp() and a downside
of preventing us from replacing the implementation of those expressions without
breaking binary compatibility.

I hemmed a bit about everything in depot.operator. In theory everything there
is available via a combination of Exps and FluentExp but in practice Whirled
uses a ton of those classes directly (whre a ton is defined as 64 imports of
classes in depot.operator). Perhaps I'll go on a cleanup jihad there and then
move all that to impl as well.

The rabbit holes, they always go deep.
This commit is contained in:
Michael Bayne
2009-09-10 02:18:38 +00:00
parent cf49fbbc9a
commit a5face282b
33 changed files with 194 additions and 451 deletions
@@ -44,7 +44,6 @@ import com.samskivert.depot.clause.QueryClause;
import com.samskivert.depot.clause.WhereClause;
import com.samskivert.depot.expression.ColumnExp;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.expression.ValueExp;
import com.samskivert.depot.impl.DepotMarshaller;
import com.samskivert.depot.impl.DepotMigrationHistoryRecord;
@@ -57,6 +56,7 @@ import com.samskivert.depot.impl.Modifier;
import com.samskivert.depot.impl.SQLBuilder;
import com.samskivert.depot.impl.clause.DeleteClause;
import com.samskivert.depot.impl.clause.UpdateClause;
import com.samskivert.depot.impl.expression.ValueExp;
import static com.samskivert.depot.Log.log;
@@ -517,7 +517,7 @@ public abstract class DepotRepository
* @param key the key for the persistent objects to be modified.
* @param field the first field to be updated.
* @param value the value to assign to the first field. This may be a primitive (Integer,
* String, etc.) which will be wrapped in ValueExp or a SQLExpression instance.
* String, etc.) which will be wrapped in value expression or a SQLExpression instance.
* @param more additional (field, value) pairs to be updated.
*
* @return the number of rows modified by this action.
@@ -538,7 +538,7 @@ public abstract class DepotRepository
*
* @param key the key for the persistent objects to be modified.
* @param updates a mapping from field to value for all values to be changed. The values may be
* primitives (Integer, String, etc.) which will be wrapped in ValueExp instances or
* primitives (Integer, String, etc.) which will be wrapped in value expression instances or
* SQLExpression instances defining the value.
*
* @return the number of rows modified by this action.
@@ -564,7 +564,7 @@ public abstract class DepotRepository
* @param invalidator a cache invalidator that will be run prior to the update to flush the
* relevant persistent objects from the cache, or null if no invalidation is needed.
* @param updates a mapping from field to value for all values to be changed. The values may be
* primitives (Integer, String, etc.) which will be wrapped in ValueExp instances or
* primitives (Integer, String, etc.) which will be wrapped in value expression instances or
* SQLExpression instances defining the value.
*
* @return the number of rows modified by this action.
@@ -601,7 +601,7 @@ public abstract class DepotRepository
* relevant persistent objects from the cache, or null if no invalidation is needed.
* @param field the first field to be updated.
* @param value the value to assign to the first field. This may be a primitive (Integer,
* String, etc.) which will be wrapped in ValueExp or a SQLExpression instance.
* String, etc.) which will be wrapped in value expression or a SQLExpression instance.
* @param more additional (field, value) pairs to be updated.
*
* @return the number of rows modified by this action.
+13 -58
View File
@@ -21,6 +21,9 @@
package com.samskivert.depot;
import com.samskivert.depot.expression.*;
import com.samskivert.depot.impl.expression.IntervalExp;
import com.samskivert.depot.impl.expression.LiteralExp;
import com.samskivert.depot.impl.expression.ValueExp;
/**
* Provides static methods for expression construction. For example: {@link #literal}, {@link
@@ -29,18 +32,18 @@ import com.samskivert.depot.expression.*;
public class Exps
{
/**
* Wraps the supplied object in a {@link ValueExp}.
* Wraps the supplied object in a value expression.
*/
public static ValueExp value (Object value)
public static FluentExp value (Object value)
{
return new ValueExp(value);
}
/**
* Creates a {@link LiteralExp} with the supplied SQL snippet. Note: you're probably breaking
* Creates a literal expression with the supplied SQL snippet. Note: you're probably breaking
* cross platform compatibility by using this construction.
*/
public static LiteralExp literal (String text)
public static SQLExpression literal (String text)
{
return new LiteralExp(text);
}
@@ -48,7 +51,7 @@ public class Exps
/**
* Creates an interval for the specified number of years.
*/
public static IntervalExp years (int amount)
public static SQLExpression years (int amount)
{
return new IntervalExp(IntervalExp.Unit.YEAR, amount);
}
@@ -56,7 +59,7 @@ public class Exps
/**
* Creates an interval for the specified number of months.
*/
public static IntervalExp months (int amount)
public static SQLExpression months (int amount)
{
return new IntervalExp(IntervalExp.Unit.MONTH, amount);
}
@@ -64,7 +67,7 @@ public class Exps
/**
* Creates an interval for the specified number of days.
*/
public static IntervalExp days (int amount)
public static SQLExpression days (int amount)
{
return new IntervalExp(IntervalExp.Unit.DAY, amount);
}
@@ -72,7 +75,7 @@ public class Exps
/**
* Creates an interval for the specified number of hours.
*/
public static IntervalExp hours (int amount)
public static SQLExpression hours (int amount)
{
return new IntervalExp(IntervalExp.Unit.HOUR, amount);
}
@@ -80,7 +83,7 @@ public class Exps
/**
* Creates an interval for the specified number of minutes.
*/
public static IntervalExp minutes (int amount)
public static SQLExpression minutes (int amount)
{
return new IntervalExp(IntervalExp.Unit.MINUTE, amount);
}
@@ -88,56 +91,8 @@ public class Exps
/**
* Creates an interval for the specified number of seconds.
*/
public static IntervalExp seconds (int amount)
public static SQLExpression seconds (int amount)
{
return new IntervalExp(IntervalExp.Unit.SECOND, amount);
}
/**
* Creates an expression that converts the supplied expression into seconds since the epoch.
*/
@SuppressWarnings("deprecation")
public static EpochSeconds epochSeconds (SQLExpression expr)
{
return new EpochSeconds(expr);
}
/**
* Creates an expression that computes the sum of the supplied expression. This would usually
* be used in a FieldOverride and supplied with a ColumnExp.
*/
@Deprecated
public static FunctionExp sum (SQLExpression expr)
{
return new FunctionExp("sum", expr);
}
/**
* Creates an expression that computes the absolute value of the supplied expression.
*/
@Deprecated
public static FunctionExp abs (SQLExpression expr)
{
return new FunctionExp("abs", expr);
}
/**
* Creates an expression that counts the number of rows that match the supplied expression.
* This would usually be used in a FieldOverride and supplied with a ColumnExp.
*/
@Deprecated
public static FunctionExp count (SQLExpression expr)
{
return new FunctionExp("count", expr);
}
/**
* Creates an expression that counts the number of distinct values that match the supplied
* expression. This would usually be used in a FieldOverride and supplied with a ColumnExp.
*/
@Deprecated
public static FunctionExp countDistinct (SQLExpression expr)
{
return new FunctionExp("count", "distinct", expr);
}
}
+7 -7
View File
@@ -22,13 +22,13 @@ package com.samskivert.depot;
import com.samskivert.depot.expression.FluentExp;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.function.AggregateFun.*;
import com.samskivert.depot.function.ConditionalFun.*;
import com.samskivert.depot.function.DateFun.*;
import com.samskivert.depot.function.DateFun.DatePart.Part;
import com.samskivert.depot.function.DateFun.DateTruncate.Truncation;
import com.samskivert.depot.function.NumericalFun.*;
import com.samskivert.depot.function.StringFun.*;
import com.samskivert.depot.impl.expression.AggregateFun.*;
import com.samskivert.depot.impl.expression.ConditionalFun.*;
import com.samskivert.depot.impl.expression.DateFun.*;
import com.samskivert.depot.impl.expression.DateFun.DatePart.Part;
import com.samskivert.depot.impl.expression.DateFun.DateTruncate.Truncation;
import com.samskivert.depot.impl.expression.NumericalFun.*;
import com.samskivert.depot.impl.expression.StringFun.*;
/**
* Provides static methods for function construction. For example: {@link #round}, {@link
+1 -1
View File
@@ -35,10 +35,10 @@ import com.samskivert.util.StringUtil;
import com.samskivert.depot.clause.WhereClause;
import com.samskivert.depot.expression.ColumnExp;
import com.samskivert.depot.expression.LiteralExp;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.impl.DepotUtil;
import com.samskivert.depot.impl.ExpressionVisitor;
import com.samskivert.depot.impl.expression.LiteralExp;
import com.samskivert.depot.operator.In;
import com.samskivert.depot.operator.Or;
@@ -24,9 +24,9 @@ import java.util.Collection;
import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.expression.ColumnExp;
import com.samskivert.depot.expression.LiteralExp;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.impl.ExpressionVisitor;
import com.samskivert.depot.impl.expression.LiteralExp;
/**
* Supplies a definition for a computed field of the persistent object we're creating.
@@ -22,8 +22,8 @@ package com.samskivert.depot.clause;
import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.expression.ColumnExp;
import com.samskivert.depot.expression.LiteralExp;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.impl.expression.LiteralExp;
/**
* Redirects one field of the persistent object we're creating from its default associated column
@@ -24,9 +24,9 @@ import java.util.Collection;
import com.samskivert.depot.PersistentRecord;
import com.samskivert.util.ArrayUtil;
import com.samskivert.depot.expression.LiteralExp;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.impl.ExpressionVisitor;
import com.samskivert.depot.impl.expression.LiteralExp;
/**
* Represents an ORDER BY clause.
@@ -25,8 +25,8 @@ import java.util.Collection;
import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.expression.ColumnExp;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.expression.ValueExp;
import com.samskivert.depot.impl.ExpressionVisitor;
import com.samskivert.depot.impl.expression.ValueExp;
import com.samskivert.depot.operator.And;
import com.samskivert.depot.operator.Equals;
import com.samskivert.depot.operator.IsNull;
@@ -1,67 +0,0 @@
//
// $Id$
//
// Depot library - a Java relational persistence library
// Copyright (C) 2006-2008 Michael Bayne and Pär Winzell
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.samskivert.depot.expression;
import java.util.Collection;
import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.impl.ExpressionVisitor;
/**
* An expression for extracting the seconds since the epoch from a date expression.
*/
@Deprecated
public class EpochSeconds extends FluentExp
{
/**
* Create a new EpochSeconds with the given argument.
*/
public EpochSeconds (SQLExpression arg)
{
_arg = arg;
}
// from SQLExpression
public Object accept (ExpressionVisitor<?> builder)
{
return builder.visit(this);
}
// from SQLExpression
public void addClasses (Collection<Class<? extends PersistentRecord>> classSet)
{
_arg.addClasses(classSet);
}
public SQLExpression getArgument ()
{
return _arg;
}
@Override // from Object
public String toString ()
{
return "Epoch(" + _arg + ")";
}
/** The argument. */
protected SQLExpression _arg;
}
@@ -43,157 +43,157 @@ public abstract class FluentExp
implements SQLExpression
{
/** Returns an {@link Equals} with this expression and the supplied target. */
public Equals eq (Comparable<?> value)
public FluentExp eq (Comparable<?> value)
{
return new Equals(this, value);
}
/** Returns an {@link Equals} with this expression and the supplied target. */
public Equals eq (SQLExpression expr)
public FluentExp eq (SQLExpression expr)
{
return new Equals(this, expr);
}
/** Returns a {@link NotEquals} with this expression and the supplied target. */
public NotEquals notEq (Comparable<?> value)
public FluentExp notEq (Comparable<?> value)
{
return new NotEquals(this, value);
}
/** Returns a {@link NotEquals} with this expression and the supplied target. */
public NotEquals notEq (SQLExpression expr)
public FluentExp notEq (SQLExpression expr)
{
return new NotEquals(this, expr);
}
/** Returns a {@link GreaterThan} with this expression and the supplied target. */
public GreaterThan greaterThan (Comparable<?> value)
public FluentExp greaterThan (Comparable<?> value)
{
return new GreaterThan(this, value);
}
/** Returns a {@link GreaterThan} with this expression and the supplied target. */
public GreaterThan greaterThan (SQLExpression expr)
public FluentExp greaterThan (SQLExpression expr)
{
return new GreaterThan(this, expr);
}
/** Returns a {@link LessThan} with this expression and the supplied target. */
public LessThan lessThan (Comparable<?> value)
public FluentExp lessThan (Comparable<?> value)
{
return new LessThan(this, value);
}
/** Returns a {@link LessThan} with this expression and the supplied target. */
public LessThan lessThan (SQLExpression expr)
public FluentExp lessThan (SQLExpression expr)
{
return new LessThan(this, expr);
}
/** Returns a {@link GreaterThanEquals} with this expression and the supplied target. */
public GreaterThanEquals greaterEq (Comparable<?> value)
public FluentExp greaterEq (Comparable<?> value)
{
return new GreaterThanEquals(this, value);
}
/** Returns a {@link GreaterThanEquals} with this expression and the supplied target. */
public GreaterThanEquals greaterEq (SQLExpression expr)
public FluentExp greaterEq (SQLExpression expr)
{
return new GreaterThanEquals(this, expr);
}
/** Returns a {@link LessThanEquals} with this expression and the supplied target. */
public LessThanEquals lessEq (Comparable<?> value)
public FluentExp lessEq (Comparable<?> value)
{
return new LessThanEquals(this, value);
}
/** Returns a {@link LessThanEquals} with this expression and the supplied target. */
public LessThanEquals lessEq (SQLExpression expr)
public FluentExp lessEq (SQLExpression expr)
{
return new LessThanEquals(this, expr);
}
/** Returns an {@link And} with this expression and the supplied target. */
public And and (SQLExpression expr)
public FluentExp and (SQLExpression expr)
{
return new And(this, expr);
}
/** Returns an {@link Or} with this expression and the supplied target. */
public Or or (SQLExpression expr)
public FluentExp or (SQLExpression expr)
{
return new Or(this, expr);
}
/** Returns an {@link BitAnd} with this expression and the supplied target. */
public BitAnd bitAnd (Comparable<?> value)
public FluentExp bitAnd (Comparable<?> value)
{
return new BitAnd(this, value);
}
/** Returns an {@link BitAnd} with this expression and the supplied target. */
public BitAnd bitAnd (SQLExpression expr)
public FluentExp bitAnd (SQLExpression expr)
{
return new BitAnd(this, expr);
}
/** Returns an {@link BitOr} with this expression and the supplied target. */
public BitOr bitOr (Comparable<?> value)
public FluentExp bitOr (Comparable<?> value)
{
return new BitOr(this, value);
}
/** Returns an {@link BitOr} with this expression and the supplied target. */
public BitOr bitOr (SQLExpression expr)
public FluentExp bitOr (SQLExpression expr)
{
return new BitOr(this, expr);
}
/** Returns an {@link Add} with this expression and the supplied target. */
public Add plus (Comparable<?> value)
public FluentExp plus (Comparable<?> value)
{
return new Add(this, value);
}
/** Returns an {@link Add} with this expression and the supplied target. */
public Add plus (SQLExpression expr)
public FluentExp plus (SQLExpression expr)
{
return new Add(this, expr);
}
/** Returns a {@link Sub} with this expression and the supplied target. */
public Sub minus (Comparable<?> value)
public FluentExp minus (Comparable<?> value)
{
return new Sub(this, value);
}
/** Returns a {@link Sub} with this expression and the supplied target. */
public Sub minus (SQLExpression expr)
public FluentExp minus (SQLExpression expr)
{
return new Sub(this, expr);
}
/** Returns a {@link Mul} with this expression and the supplied target. */
public Mul times (Comparable<?> value)
public FluentExp times (Comparable<?> value)
{
return new Mul(this, value);
}
/** Returns a {@link Mul} with this expression and the supplied target. */
public Mul times (SQLExpression expr)
public FluentExp times (SQLExpression expr)
{
return new Mul(this, expr);
}
/** Returns a {@link Div} with this expression and the supplied target. */
public Div div (Comparable<?> value)
public FluentExp div (Comparable<?> value)
{
return new Div(this, value);
}
/** Returns a {@link Div} with this expression and the supplied target. */
public Div div (SQLExpression expr)
public FluentExp div (SQLExpression expr)
{
return new Div(this, expr);
}
@@ -1,99 +0,0 @@
//
// $Id$
//
// Depot library - a Java relational persistence library
// Copyright (C) 2006-2008 Michael Bayne and Pär Winzell
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.samskivert.depot.expression;
import java.util.Collection;
import com.samskivert.util.StringUtil;
import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.impl.ExpressionVisitor;
/**
* An expression for a function, e.g. FLOOR(blah).
*/
@Deprecated
public class FunctionExp extends FluentExp
{
/**
* Create a new FunctionExp with the given function and arguments.
*/
public FunctionExp (String function, SQLExpression... arguments)
{
this(function, null, arguments);
_arguments = arguments;
}
/**
* Create a new FunctionExp with the given function, expression annotation and arguments.
*/
public FunctionExp (String function, String annotation, SQLExpression... arguments)
{
_function = function;
_annotation = annotation;
_arguments = arguments;
}
// from SQLExpression
public Object accept (ExpressionVisitor<?> builder)
{
return builder.visit(this);
}
// from SQLExpression
public void addClasses (Collection<Class<? extends PersistentRecord>> classSet)
{
for (SQLExpression _argument : _arguments) {
_argument.addClasses(classSet);
}
}
public String getFunction ()
{
return _function;
}
public String getAnnotation ()
{
return _annotation;
}
public SQLExpression[] getArguments ()
{
return _arguments;
}
@Override
public String toString ()
{
return _function + "(" + (_annotation == null ? "" : (_annotation + " ")) +
StringUtil.join(_arguments, ", ") + ")";
}
/** The literal name of this function, e.g. FLOOR */
protected String _function;
/** An annotation that goes on the function's expression (only used for count(distinct X)) */
protected String _annotation;
/** The arguments to this function */
protected SQLExpression[] _arguments;
}
@@ -49,39 +49,6 @@ import com.samskivert.depot.clause.OrderBy;
import com.samskivert.depot.clause.SelectClause;
import com.samskivert.depot.clause.WhereClause;
import com.samskivert.depot.expression.*;
import com.samskivert.depot.function.AggregateFun;
import com.samskivert.depot.function.AggregateFun.Average;
import com.samskivert.depot.function.AggregateFun.Count;
import com.samskivert.depot.function.AggregateFun.Every;
import com.samskivert.depot.function.AggregateFun.Max;
import com.samskivert.depot.function.AggregateFun.Min;
import com.samskivert.depot.function.AggregateFun.Sum;
import com.samskivert.depot.function.ConditionalFun.Coalesce;
import com.samskivert.depot.function.ConditionalFun.Greatest;
import com.samskivert.depot.function.ConditionalFun.Least;
import com.samskivert.depot.function.DateFun.DatePart;
import com.samskivert.depot.function.DateFun.DateTruncate;
import com.samskivert.depot.function.DateFun.Now;
import com.samskivert.depot.function.DateFun.DatePart.Part;
import com.samskivert.depot.function.NumericalFun.Abs;
import com.samskivert.depot.function.NumericalFun.Ceil;
import com.samskivert.depot.function.NumericalFun.Exp;
import com.samskivert.depot.function.NumericalFun.Floor;
import com.samskivert.depot.function.NumericalFun.Ln;
import com.samskivert.depot.function.NumericalFun.Log10;
import com.samskivert.depot.function.NumericalFun.Pi;
import com.samskivert.depot.function.NumericalFun.Power;
import com.samskivert.depot.function.NumericalFun.Random;
import com.samskivert.depot.function.NumericalFun.Round;
import com.samskivert.depot.function.NumericalFun.Sign;
import com.samskivert.depot.function.NumericalFun.Sqrt;
import com.samskivert.depot.function.NumericalFun.Trunc;
import com.samskivert.depot.function.StringFun.Length;
import com.samskivert.depot.function.StringFun.Lower;
import com.samskivert.depot.function.StringFun.Position;
import com.samskivert.depot.function.StringFun.Substring;
import com.samskivert.depot.function.StringFun.Trim;
import com.samskivert.depot.function.StringFun.Upper;
import com.samskivert.depot.operator.Case;
import com.samskivert.depot.operator.Exists;
import com.samskivert.depot.operator.FullText;
@@ -95,6 +62,41 @@ import com.samskivert.depot.impl.clause.CreateIndexClause;
import com.samskivert.depot.impl.clause.DeleteClause;
import com.samskivert.depot.impl.clause.DropIndexClause;
import com.samskivert.depot.impl.clause.UpdateClause;
import com.samskivert.depot.impl.expression.AggregateFun;
import com.samskivert.depot.impl.expression.IntervalExp;
import com.samskivert.depot.impl.expression.LiteralExp;
import com.samskivert.depot.impl.expression.ValueExp;
import com.samskivert.depot.impl.expression.AggregateFun.Average;
import com.samskivert.depot.impl.expression.AggregateFun.Count;
import com.samskivert.depot.impl.expression.AggregateFun.Every;
import com.samskivert.depot.impl.expression.AggregateFun.Max;
import com.samskivert.depot.impl.expression.AggregateFun.Min;
import com.samskivert.depot.impl.expression.AggregateFun.Sum;
import com.samskivert.depot.impl.expression.ConditionalFun.Coalesce;
import com.samskivert.depot.impl.expression.ConditionalFun.Greatest;
import com.samskivert.depot.impl.expression.ConditionalFun.Least;
import com.samskivert.depot.impl.expression.DateFun.DatePart;
import com.samskivert.depot.impl.expression.DateFun.DateTruncate;
import com.samskivert.depot.impl.expression.DateFun.Now;
import com.samskivert.depot.impl.expression.NumericalFun.Abs;
import com.samskivert.depot.impl.expression.NumericalFun.Ceil;
import com.samskivert.depot.impl.expression.NumericalFun.Exp;
import com.samskivert.depot.impl.expression.NumericalFun.Floor;
import com.samskivert.depot.impl.expression.NumericalFun.Ln;
import com.samskivert.depot.impl.expression.NumericalFun.Log10;
import com.samskivert.depot.impl.expression.NumericalFun.Pi;
import com.samskivert.depot.impl.expression.NumericalFun.Power;
import com.samskivert.depot.impl.expression.NumericalFun.Random;
import com.samskivert.depot.impl.expression.NumericalFun.Round;
import com.samskivert.depot.impl.expression.NumericalFun.Sign;
import com.samskivert.depot.impl.expression.NumericalFun.Sqrt;
import com.samskivert.depot.impl.expression.NumericalFun.Trunc;
import com.samskivert.depot.impl.expression.StringFun.Length;
import com.samskivert.depot.impl.expression.StringFun.Lower;
import com.samskivert.depot.impl.expression.StringFun.Position;
import com.samskivert.depot.impl.expression.StringFun.Substring;
import com.samskivert.depot.impl.expression.StringFun.Trim;
import com.samskivert.depot.impl.expression.StringFun.Upper;
/**
* Implements the base functionality of the SQL-building pass of {@link SQLBuilder}. Dialectal
@@ -169,18 +171,6 @@ public abstract class BuildVisitor implements ExpressionVisitor<Void>
return null;
}
@SuppressWarnings("deprecation")
public Void visit (FunctionExp functionExp)
{
_builder.append(functionExp.getFunction()).append("(");
if (functionExp.getAnnotation() != null) {
_builder.append(functionExp.getAnnotation()).append(" ");
}
appendArguments(functionExp.getArguments());
_builder.append(")");
return null;
}
public Void visit (MultiOperator multiOperator)
{
SQLExpression[] conditions = multiOperator.getArgs();
@@ -232,11 +222,6 @@ public abstract class BuildVisitor implements ExpressionVisitor<Void>
return null;
}
@SuppressWarnings("deprecation")
public Void visit (EpochSeconds epochSeconds) {
return visit(new DatePart(epochSeconds.getArgument(), Part.EPOCH));
}
public abstract Void visit (FullText.Match match);
public abstract Void visit (FullText.Rank rank);
@@ -21,7 +21,6 @@
package com.samskivert.depot.impl;
import java.lang.reflect.Field;
import java.util.Date;
import com.samskivert.depot.Key;
import com.samskivert.depot.PersistentRecord;
@@ -40,37 +39,6 @@ import com.samskivert.depot.clause.WhereClause;
import com.samskivert.depot.expression.*;
import com.samskivert.depot.expression.SQLExpression.NoValue;
import com.samskivert.depot.function.AggregateFun.Average;
import com.samskivert.depot.function.AggregateFun.Count;
import com.samskivert.depot.function.AggregateFun.Every;
import com.samskivert.depot.function.AggregateFun.Max;
import com.samskivert.depot.function.AggregateFun.Min;
import com.samskivert.depot.function.AggregateFun.Sum;
import com.samskivert.depot.function.ConditionalFun.Coalesce;
import com.samskivert.depot.function.ConditionalFun.Greatest;
import com.samskivert.depot.function.ConditionalFun.Least;
import com.samskivert.depot.function.DateFun.DatePart;
import com.samskivert.depot.function.DateFun.DateTruncate;
import com.samskivert.depot.function.DateFun.Now;
import com.samskivert.depot.function.NumericalFun.Abs;
import com.samskivert.depot.function.NumericalFun.Ceil;
import com.samskivert.depot.function.NumericalFun.Exp;
import com.samskivert.depot.function.NumericalFun.Floor;
import com.samskivert.depot.function.NumericalFun.Ln;
import com.samskivert.depot.function.NumericalFun.Log10;
import com.samskivert.depot.function.NumericalFun.Pi;
import com.samskivert.depot.function.NumericalFun.Power;
import com.samskivert.depot.function.NumericalFun.Random;
import com.samskivert.depot.function.NumericalFun.Round;
import com.samskivert.depot.function.NumericalFun.Sign;
import com.samskivert.depot.function.NumericalFun.Sqrt;
import com.samskivert.depot.function.NumericalFun.Trunc;
import com.samskivert.depot.function.StringFun.Length;
import com.samskivert.depot.function.StringFun.Lower;
import com.samskivert.depot.function.StringFun.Position;
import com.samskivert.depot.function.StringFun.Substring;
import com.samskivert.depot.function.StringFun.Trim;
import com.samskivert.depot.function.StringFun.Upper;
import com.samskivert.depot.operator.Case;
import com.samskivert.depot.operator.Exists;
@@ -85,6 +53,40 @@ import com.samskivert.depot.impl.clause.CreateIndexClause;
import com.samskivert.depot.impl.clause.DeleteClause;
import com.samskivert.depot.impl.clause.DropIndexClause;
import com.samskivert.depot.impl.clause.UpdateClause;
import com.samskivert.depot.impl.expression.IntervalExp;
import com.samskivert.depot.impl.expression.LiteralExp;
import com.samskivert.depot.impl.expression.ValueExp;
import com.samskivert.depot.impl.expression.AggregateFun.Average;
import com.samskivert.depot.impl.expression.AggregateFun.Count;
import com.samskivert.depot.impl.expression.AggregateFun.Every;
import com.samskivert.depot.impl.expression.AggregateFun.Max;
import com.samskivert.depot.impl.expression.AggregateFun.Min;
import com.samskivert.depot.impl.expression.AggregateFun.Sum;
import com.samskivert.depot.impl.expression.ConditionalFun.Coalesce;
import com.samskivert.depot.impl.expression.ConditionalFun.Greatest;
import com.samskivert.depot.impl.expression.ConditionalFun.Least;
import com.samskivert.depot.impl.expression.DateFun.DatePart;
import com.samskivert.depot.impl.expression.DateFun.DateTruncate;
import com.samskivert.depot.impl.expression.DateFun.Now;
import com.samskivert.depot.impl.expression.NumericalFun.Abs;
import com.samskivert.depot.impl.expression.NumericalFun.Ceil;
import com.samskivert.depot.impl.expression.NumericalFun.Exp;
import com.samskivert.depot.impl.expression.NumericalFun.Floor;
import com.samskivert.depot.impl.expression.NumericalFun.Ln;
import com.samskivert.depot.impl.expression.NumericalFun.Log10;
import com.samskivert.depot.impl.expression.NumericalFun.Pi;
import com.samskivert.depot.impl.expression.NumericalFun.Power;
import com.samskivert.depot.impl.expression.NumericalFun.Random;
import com.samskivert.depot.impl.expression.NumericalFun.Round;
import com.samskivert.depot.impl.expression.NumericalFun.Sign;
import com.samskivert.depot.impl.expression.NumericalFun.Sqrt;
import com.samskivert.depot.impl.expression.NumericalFun.Trunc;
import com.samskivert.depot.impl.expression.StringFun.Length;
import com.samskivert.depot.impl.expression.StringFun.Lower;
import com.samskivert.depot.impl.expression.StringFun.Position;
import com.samskivert.depot.impl.expression.StringFun.Substring;
import com.samskivert.depot.impl.expression.StringFun.Trim;
import com.samskivert.depot.impl.expression.StringFun.Upper;
import com.samskivert.util.ArrayUtil;
import com.samskivert.util.Tuple;
@@ -106,35 +108,6 @@ public class ExpressionEvaluator
_pRec = pRec;
}
@SuppressWarnings("deprecation")
public Object visit (FunctionExp functionExp)
{
SQLExpression[] arguments = functionExp.getArguments();
Object[] values = new Object[functionExp.getArguments().length];
for (int ii = 0; ii < values.length; ii ++) {
values[ii] = arguments[ii].accept(this);
if (values[ii] instanceof NoValue) {
return values[ii];
}
}
if ("lower".equalsIgnoreCase(functionExp.getFunction())) {
if (values.length == 1 && values[0] instanceof String) {
return ((String) values[0]).toLowerCase();
}
}
return new NoValue("Bad Function: " + functionExp);
}
@SuppressWarnings("deprecation")
public Object visit (EpochSeconds epochSeconds)
{
Object result = epochSeconds.getArgument().accept(this);
if (result instanceof Date) {
return ((Date) result).getTime();
}
return new NoValue("Bad EpochSeconds: " + epochSeconds);
}
public Object visit (MultiOperator multiOperator)
{
SQLExpression[] operands = multiOperator.getArgs();
@@ -34,37 +34,6 @@ import com.samskivert.depot.clause.SelectClause;
import com.samskivert.depot.clause.WhereClause;
import com.samskivert.depot.expression.*;
import com.samskivert.depot.function.AggregateFun.Average;
import com.samskivert.depot.function.AggregateFun.Count;
import com.samskivert.depot.function.AggregateFun.Every;
import com.samskivert.depot.function.AggregateFun.Max;
import com.samskivert.depot.function.AggregateFun.Min;
import com.samskivert.depot.function.AggregateFun.Sum;
import com.samskivert.depot.function.ConditionalFun.Coalesce;
import com.samskivert.depot.function.ConditionalFun.Greatest;
import com.samskivert.depot.function.ConditionalFun.Least;
import com.samskivert.depot.function.DateFun.DatePart;
import com.samskivert.depot.function.DateFun.DateTruncate;
import com.samskivert.depot.function.DateFun.Now;
import com.samskivert.depot.function.NumericalFun.Abs;
import com.samskivert.depot.function.NumericalFun.Ceil;
import com.samskivert.depot.function.NumericalFun.Exp;
import com.samskivert.depot.function.NumericalFun.Floor;
import com.samskivert.depot.function.NumericalFun.Ln;
import com.samskivert.depot.function.NumericalFun.Log10;
import com.samskivert.depot.function.NumericalFun.Pi;
import com.samskivert.depot.function.NumericalFun.Power;
import com.samskivert.depot.function.NumericalFun.Random;
import com.samskivert.depot.function.NumericalFun.Round;
import com.samskivert.depot.function.NumericalFun.Sign;
import com.samskivert.depot.function.NumericalFun.Sqrt;
import com.samskivert.depot.function.NumericalFun.Trunc;
import com.samskivert.depot.function.StringFun.Length;
import com.samskivert.depot.function.StringFun.Lower;
import com.samskivert.depot.function.StringFun.Position;
import com.samskivert.depot.function.StringFun.Substring;
import com.samskivert.depot.function.StringFun.Trim;
import com.samskivert.depot.function.StringFun.Upper;
import com.samskivert.depot.operator.Case;
import com.samskivert.depot.operator.Exists;
import com.samskivert.depot.operator.FullText;
@@ -78,6 +47,40 @@ import com.samskivert.depot.impl.clause.CreateIndexClause;
import com.samskivert.depot.impl.clause.DeleteClause;
import com.samskivert.depot.impl.clause.DropIndexClause;
import com.samskivert.depot.impl.clause.UpdateClause;
import com.samskivert.depot.impl.expression.IntervalExp;
import com.samskivert.depot.impl.expression.LiteralExp;
import com.samskivert.depot.impl.expression.ValueExp;
import com.samskivert.depot.impl.expression.AggregateFun.Average;
import com.samskivert.depot.impl.expression.AggregateFun.Count;
import com.samskivert.depot.impl.expression.AggregateFun.Every;
import com.samskivert.depot.impl.expression.AggregateFun.Max;
import com.samskivert.depot.impl.expression.AggregateFun.Min;
import com.samskivert.depot.impl.expression.AggregateFun.Sum;
import com.samskivert.depot.impl.expression.ConditionalFun.Coalesce;
import com.samskivert.depot.impl.expression.ConditionalFun.Greatest;
import com.samskivert.depot.impl.expression.ConditionalFun.Least;
import com.samskivert.depot.impl.expression.DateFun.DatePart;
import com.samskivert.depot.impl.expression.DateFun.DateTruncate;
import com.samskivert.depot.impl.expression.DateFun.Now;
import com.samskivert.depot.impl.expression.NumericalFun.Abs;
import com.samskivert.depot.impl.expression.NumericalFun.Ceil;
import com.samskivert.depot.impl.expression.NumericalFun.Exp;
import com.samskivert.depot.impl.expression.NumericalFun.Floor;
import com.samskivert.depot.impl.expression.NumericalFun.Ln;
import com.samskivert.depot.impl.expression.NumericalFun.Log10;
import com.samskivert.depot.impl.expression.NumericalFun.Pi;
import com.samskivert.depot.impl.expression.NumericalFun.Power;
import com.samskivert.depot.impl.expression.NumericalFun.Random;
import com.samskivert.depot.impl.expression.NumericalFun.Round;
import com.samskivert.depot.impl.expression.NumericalFun.Sign;
import com.samskivert.depot.impl.expression.NumericalFun.Sqrt;
import com.samskivert.depot.impl.expression.NumericalFun.Trunc;
import com.samskivert.depot.impl.expression.StringFun.Length;
import com.samskivert.depot.impl.expression.StringFun.Lower;
import com.samskivert.depot.impl.expression.StringFun.Position;
import com.samskivert.depot.impl.expression.StringFun.Substring;
import com.samskivert.depot.impl.expression.StringFun.Trim;
import com.samskivert.depot.impl.expression.StringFun.Upper;
/**
* Enumerates visitation methods for every possible SQL expression type.
@@ -85,10 +88,6 @@ import com.samskivert.depot.impl.clause.UpdateClause;
public interface ExpressionVisitor<T>
{
public T visit (FieldDefinition fieldOverride);
@SuppressWarnings("deprecation")
public T visit (FunctionExp functionExp);
@SuppressWarnings("deprecation")
public T visit (EpochSeconds epochSeconds);
public T visit (FromOverride fromOverride);
public T visit (MultiOperator multiOperator);
public T visit (BinaryOperator binaryOperator);
@@ -44,10 +44,6 @@ import com.samskivert.depot.annotation.FullTextIndex;
import com.samskivert.depot.annotation.GeneratedValue;
import com.samskivert.depot.clause.OrderBy.Order;
import com.samskivert.depot.expression.*;
import com.samskivert.depot.function.DateFun.DatePart;
import com.samskivert.depot.function.DateFun.DateTruncate;
import com.samskivert.depot.function.DateFun.DatePart.Part;
import com.samskivert.depot.function.StringFun.Lower;
import com.samskivert.depot.operator.BitAnd;
import com.samskivert.depot.operator.BitOr;
import com.samskivert.depot.operator.FullText;
@@ -56,6 +52,10 @@ import com.samskivert.depot.operator.Or;
import com.samskivert.depot.operator.SQLOperator.MultiOperator;
import com.samskivert.depot.impl.clause.CreateIndexClause;
import com.samskivert.depot.impl.expression.DateFun.DatePart;
import com.samskivert.depot.impl.expression.DateFun.DateTruncate;
import com.samskivert.depot.impl.expression.DateFun.DatePart.Part;
import com.samskivert.depot.impl.expression.StringFun.Lower;
public class HSQLBuilder
extends SQLBuilder
@@ -86,7 +86,7 @@ public class HSQLBuilder
for (String field : fields) {
for (String ftsWord : ftsWords) {
// build comparisons between each word and column
bits.add(new Like(new Lower(new ColumnExp(pClass, field)), "%" + ftsWord + "%"));
bits.add(new Like(new Lower(new ColumnExp(pClass, field)), "%"+ftsWord+"%"));
}
}
// then just OR them all together and we have our query
@@ -115,12 +115,6 @@ public class HSQLBuilder
return super.visit(operator);
}
@Override @SuppressWarnings("deprecation")
public Void visit (EpochSeconds epochSeconds)
{
return visit (new DatePart(epochSeconds.getArgument(), Part.EPOCH));
}
@Override public Void visit (DatePart exp) {
if (exp.getPart() == Part.EPOCH) {
@@ -36,10 +36,6 @@ import com.samskivert.depot.annotation.FullTextIndex;
import com.samskivert.depot.clause.OrderBy.Order;
import com.samskivert.depot.expression.ColumnExp;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.function.DateFun.DatePart;
import com.samskivert.depot.function.DateFun.DateTruncate;
import com.samskivert.depot.function.DateFun.DatePart.Part;
import com.samskivert.depot.function.NumericalFun.Trunc;
import com.samskivert.depot.operator.FullText;
import com.samskivert.depot.impl.FieldMarshaller.BooleanMarshaller;
@@ -56,6 +52,10 @@ import com.samskivert.depot.impl.FieldMarshaller.ShortMarshaller;
import com.samskivert.depot.impl.clause.CreateIndexClause;
import com.samskivert.depot.impl.clause.DeleteClause;
import com.samskivert.depot.impl.clause.DropIndexClause;
import com.samskivert.depot.impl.expression.DateFun.DatePart;
import com.samskivert.depot.impl.expression.DateFun.DateTruncate;
import com.samskivert.depot.impl.expression.DateFun.DatePart.Part;
import com.samskivert.depot.impl.expression.NumericalFun.Trunc;
import static com.samskivert.Log.log;
@@ -27,7 +27,7 @@ import java.sql.SQLException;
import java.sql.Timestamp;
import com.samskivert.depot.DatabaseException;
import com.samskivert.depot.expression.ValueExp;
import com.samskivert.depot.impl.expression.ValueExp;
import com.samskivert.depot.operator.In;
import com.samskivert.util.ByteEnum;
@@ -39,10 +39,10 @@ import com.samskivert.depot.Exps;
import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.annotation.FullTextIndex.Configuration;
import com.samskivert.depot.annotation.FullTextIndex;
import com.samskivert.depot.expression.IntervalExp;
import com.samskivert.depot.function.DateFun.DatePart;
import com.samskivert.depot.function.DateFun.DateTruncate;
import com.samskivert.depot.function.DateFun.DatePart.Part;
import com.samskivert.depot.impl.expression.IntervalExp;
import com.samskivert.depot.impl.expression.DateFun.DatePart;
import com.samskivert.depot.impl.expression.DateFun.DateTruncate;
import com.samskivert.depot.impl.expression.DateFun.DatePart.Part;
import com.samskivert.depot.operator.FullText;
import static com.samskivert.Log.log;
@@ -18,7 +18,7 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.samskivert.depot.function;
package com.samskivert.depot.impl.expression;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.impl.ExpressionVisitor;
@@ -18,11 +18,13 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.samskivert.depot.expression;
package com.samskivert.depot.impl.expression;
import java.util.Collection;
import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.expression.FluentExp;
import com.samskivert.depot.expression.SQLExpression;
public abstract class ArgumentExp extends FluentExp
{
@@ -18,9 +18,8 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.samskivert.depot.function;
package com.samskivert.depot.impl.expression;
import com.samskivert.depot.expression.ArgumentExp;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.impl.ExpressionVisitor;
@@ -18,7 +18,7 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.samskivert.depot.function;
package com.samskivert.depot.impl.expression;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.impl.ExpressionVisitor;
@@ -18,11 +18,12 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.samskivert.depot.expression;
package com.samskivert.depot.impl.expression;
import java.util.Collection;
import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.impl.ExpressionVisitor;
/**
@@ -18,11 +18,12 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.samskivert.depot.expression;
package com.samskivert.depot.impl.expression;
import java.util.Collection;
import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.impl.ExpressionVisitor;
/**
@@ -18,7 +18,7 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.samskivert.depot.function;
package com.samskivert.depot.impl.expression;
import java.util.Collection;
@@ -18,7 +18,7 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.samskivert.depot.function;
package com.samskivert.depot.impl.expression;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.impl.ExpressionVisitor;
@@ -18,7 +18,7 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.samskivert.depot.function;
package com.samskivert.depot.impl.expression;
import java.util.Collection;
@@ -18,9 +18,8 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.samskivert.depot.function;
package com.samskivert.depot.impl.expression;
import com.samskivert.depot.expression.ArgumentExp;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.impl.ExpressionVisitor;
@@ -18,7 +18,7 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.samskivert.depot.function;
package com.samskivert.depot.impl.expression;
import java.util.Collection;
@@ -18,11 +18,12 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.samskivert.depot.expression;
package com.samskivert.depot.impl.expression;
import java.util.Collection;
import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.expression.FluentExp;
import com.samskivert.depot.impl.ExpressionVisitor;
/**
@@ -21,7 +21,7 @@
package com.samskivert.depot.operator;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.expression.ValueExp;
import com.samskivert.depot.impl.expression.ValueExp;
import com.samskivert.depot.operator.SQLOperator.MultiOperator;
/**
@@ -28,10 +28,10 @@ import com.google.common.base.Function;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.expression.ArgumentExp;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.expression.ValueExp;
import com.samskivert.depot.impl.ExpressionVisitor;
import com.samskivert.depot.impl.expression.ArgumentExp;
import com.samskivert.depot.impl.expression.ValueExp;
/**
* A common interface for operator hierarchies in SQL. The main purpose of breaking this out from
@@ -39,7 +39,7 @@ import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.SchemaMigration;
import com.samskivert.depot.annotation.Computed;
import com.samskivert.depot.clause.Where;
import com.samskivert.depot.expression.LiteralExp;
import com.samskivert.depot.impl.expression.LiteralExp;
import com.samskivert.depot.operator.GreaterThan;
import com.samskivert.depot.operator.LessThan;