The type safety turtles now go all the way down. This tightens up a bit more

fast-and-looseness by propagating types through foo.eq(bar) expressions,
foo.lessThan(bar) expressions and the like.

This means a few things stopped working, like
StringFuncs.length(MyRecord.BYTE_ARRAY_FIELD), but now there's
Funcs.arrayLength() for that. Also Date functions are looser than I'd like
because there's no supertype between sql.Date and sql.Timestamp (to express a
date having type) and sql.Timestamp and sql.Time (to express a time having
type). So you can still do some foot shooting with those methods, but it's
hardly worth crying over since the foot shooting range was fully open for
business prior to this.

MSOY fixes coming presently. ProjectX fixes shortly thereafter.
This commit is contained in:
Michael Bayne
2010-12-09 00:08:58 +00:00
parent 4bb926c238
commit b01eaef2d8
69 changed files with 622 additions and 527 deletions
@@ -20,6 +20,9 @@
package com.samskivert.depot;
import java.sql.Date;
import java.sql.Timestamp;
import com.samskivert.depot.expression.FluentExp;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.impl.expression.DateFun.*;
@@ -32,7 +35,7 @@ public class DateFuncs
/**
* Creates an expression that extracts the date from the given timestamp expression.
*/
public static FluentExp date (SQLExpression exp)
public static FluentExp<Date> date (SQLExpression<Timestamp> exp)
{
return new DateTruncate(exp, DateTruncate.Truncation.DAY);
}
@@ -40,7 +43,7 @@ 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 <T extends Date> FluentExp<Integer> dayOfWeek (SQLExpression<T> exp)
{
return new DatePart(exp, DatePart.Part.DAY_OF_WEEK);
}
@@ -48,7 +51,7 @@ 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 <T extends Date> FluentExp<Integer> dayOfMonth (SQLExpression<T> exp)
{
return new DatePart(exp, DatePart.Part.DAY_OF_MONTH);
}
@@ -56,7 +59,7 @@ 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 <T extends Date> FluentExp<Integer> dayOfYear (SQLExpression<T> exp)
{
return new DatePart(exp, DatePart.Part.DAY_OF_YEAR);
}
@@ -64,7 +67,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<Integer> hour (SQLExpression<Timestamp> exp)
{
return new DatePart(exp, DatePart.Part.HOUR);
}
@@ -72,7 +75,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<Integer> minute (SQLExpression<Timestamp> exp)
{
return new DatePart(exp, DatePart.Part.MINUTE);
}
@@ -80,15 +83,18 @@ 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<Integer> second (SQLExpression<Timestamp> exp)
{
return new DatePart(exp, DatePart.Part.SECOND);
}
// TODO: the below should work on java.sql.Date and java.sql.Timestamp, but annoyingly the only
// supertype shared by those types is java.util.Date
/**
* Creates an expression to extract the week of the the supplied timestamp expression.
*/
public static FluentExp week (SQLExpression exp)
public static FluentExp<Integer> week (SQLExpression<? extends java.util.Date> exp)
{
return new DatePart(exp, DatePart.Part.WEEK);
}
@@ -96,7 +102,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<Integer> month (SQLExpression<? extends java.util.Date> exp)
{
return new DatePart(exp, DatePart.Part.MONTH);
}
@@ -104,7 +110,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<Integer> year (SQLExpression<? extends java.util.Date> exp)
{
return new DatePart(exp, DatePart.Part.YEAR);
}
@@ -113,7 +119,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<Integer> epoch (SQLExpression<? extends java.util.Date> exp)
{
return new DatePart(exp, DatePart.Part.EPOCH);
}
@@ -121,7 +127,7 @@ public class DateFuncs
/**
* Creates an expression for the current timestamp.
*/
public static FluentExp now ()
public static FluentExp<Timestamp> now ()
{
return new Now();
}
@@ -508,7 +508,7 @@ public abstract class DepotRepository
{
// separate the arguments into keys and values
final ColumnExp<?>[] fields = new ColumnExp<?>[updates.size()];
final SQLExpression[] values = new SQLExpression[fields.length];
final SQLExpression<?>[] values = new SQLExpression<?>[fields.length];
int ii = 0;
for (Map.Entry<? extends ColumnExp<?>, ?> entry : updates.entrySet()) {
fields[ii] = entry.getKey();
@@ -545,7 +545,7 @@ public abstract class DepotRepository
{
// separate the updates into keys and values
final ColumnExp<?>[] fields = new ColumnExp<?>[1+more.length/2];
final SQLExpression[] values = new SQLExpression[fields.length];
final SQLExpression<?>[] values = new SQLExpression<?>[fields.length];
fields[0] = field;
values[0] = makeValue(value);
for (int ii = 1, idx = 0; ii < fields.length; ii++) {
@@ -576,7 +576,7 @@ public abstract class DepotRepository
*/
public <T extends PersistentRecord> int updatePartial (
Class<T> type, final WhereClause key, CacheInvalidator invalidator,
ColumnExp<?>[] fields, SQLExpression[] values)
ColumnExp<?>[] fields, SQLExpression<?>[] values)
throws DatabaseException
{
requireNotComputed(type, "updatePartial");
@@ -908,9 +908,14 @@ public abstract class DepotRepository
}
}
protected SQLExpression makeValue (Object value)
protected <T> SQLExpression<T> makeValue (T value)
{
return (value instanceof SQLExpression) ? (SQLExpression)value : new ValueExp(value);
if (value instanceof SQLExpression<?>) {
@SuppressWarnings("unchecked") SQLExpression<T> eval = (SQLExpression<T>)value;
return eval;
} else {
return new ValueExp<T>(value);
}
}
/**
+10 -26
View File
@@ -34,40 +34,24 @@ public class Exps
/**
* Wraps the supplied object in a value expression.
*/
public static FluentExp value (Object value)
public static <T> FluentExp<T> value (T value)
{
return new ValueExp(value);
}
/**
* Creates an expression that evaluates to true.
*/
public static SQLExpression trueLiteral ()
{
return literal("true");
}
/**
* Creates an expression that evaluates to false.
*/
public static SQLExpression falseLiteral ()
{
return literal("false");
return new ValueExp<T>(value);
}
/**
* Creates a literal expression with the supplied SQL snippet. Note: you're probably breaking
* cross platform compatibility by using this construction.
*/
public static SQLExpression literal (String text)
public static <T> SQLExpression<T> literal (String text)
{
return new LiteralExp(text);
return new LiteralExp<T>(text);
}
/**
* Creates an interval for the specified number of years.
*/
public static SQLExpression years (int amount)
public static SQLExpression<Integer> years (int amount)
{
return new IntervalExp(IntervalExp.Unit.YEAR, amount);
}
@@ -75,7 +59,7 @@ public class Exps
/**
* Creates an interval for the specified number of months.
*/
public static SQLExpression months (int amount)
public static SQLExpression<Integer> months (int amount)
{
return new IntervalExp(IntervalExp.Unit.MONTH, amount);
}
@@ -83,7 +67,7 @@ public class Exps
/**
* Creates an interval for the specified number of days.
*/
public static SQLExpression days (int amount)
public static SQLExpression<Integer> days (int amount)
{
return new IntervalExp(IntervalExp.Unit.DAY, amount);
}
@@ -91,7 +75,7 @@ public class Exps
/**
* Creates an interval for the specified number of hours.
*/
public static SQLExpression hours (int amount)
public static SQLExpression<Integer> hours (int amount)
{
return new IntervalExp(IntervalExp.Unit.HOUR, amount);
}
@@ -99,7 +83,7 @@ public class Exps
/**
* Creates an interval for the specified number of minutes.
*/
public static SQLExpression minutes (int amount)
public static SQLExpression<Integer> minutes (int amount)
{
return new IntervalExp(IntervalExp.Unit.MINUTE, amount);
}
@@ -107,7 +91,7 @@ public class Exps
/**
* Creates an interval for the specified number of seconds.
*/
public static SQLExpression seconds (int amount)
public static SQLExpression<Integer> seconds (int amount)
{
return new IntervalExp(IntervalExp.Unit.SECOND, amount);
}
+55 -19
View File
@@ -24,6 +24,7 @@ import com.samskivert.depot.expression.FluentExp;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.impl.expression.AggregateFun.*;
import com.samskivert.depot.impl.expression.ConditionalFun.*;
import com.samskivert.depot.impl.expression.StringFun.*;
/**
* Provides static methods for function construction.
@@ -34,25 +35,25 @@ public class Funcs
* Creates an aggregate expression that averages all values from the supplied expression.
* This would usually be used in a FieldOverride and supplied with a ColumnExp.
*/
public static FluentExp average (SQLExpression expr)
public static <T extends Number> FluentExp<T> average (SQLExpression<T> expr)
{
return new Average(expr);
return new Average<T>(expr);
}
/**
* Creates an expression that averages all distinct values from the supplied expression.
* This would usually be used in a FieldOverride and supplied with a ColumnExp.
*/
public static FluentExp averageDistinct (SQLExpression expr)
public static <T extends Number> FluentExp<T> averageDistinct (SQLExpression<T> expr)
{
return new Average(expr, true);
return new Average<T>(expr, true);
}
/**
* Creates an aggregate expression that counts the number of rows from the supplied
* expression. This would usually be used in a FieldOverride and supplied with a ColumnExp.
*/
public static FluentExp count (SQLExpression expr)
public static FluentExp<Integer> count (SQLExpression<?> expr)
{
return new Count(expr);
}
@@ -62,7 +63,7 @@ public class Funcs
* supplied expression. This would usually be used in a FieldOverride and supplied with a
* ColumnExp.
*/
public static FluentExp countDistinct (SQLExpression expr)
public static FluentExp<Integer> countDistinct (SQLExpression<?> expr)
{
return new Count(expr, true);
}
@@ -72,7 +73,7 @@ public class Funcs
* expression is also true. This would usually be used in a FieldOverride and supplied with
* a ColumnExp.
*/
public static FluentExp every (SQLExpression expr)
public static FluentExp<Boolean> every (SQLExpression<?> expr)
{
return new Every(expr);
}
@@ -82,9 +83,9 @@ public class Funcs
* supplied expression. This would usually be used in a FieldOverride and supplied with
* a ColumnExp.
*/
public static FluentExp max (SQLExpression expr)
public static <T extends Number> FluentExp<T> max (SQLExpression<T> expr)
{
return new Max(expr);
return new Max<T>(expr);
}
/**
@@ -92,41 +93,76 @@ public class Funcs
* supplied expression. This would usually be used in a FieldOverride and supplied with
* a ColumnExp.
*/
public static FluentExp min (SQLExpression expr)
public static <T extends Number> FluentExp<T> min (SQLExpression<T> expr)
{
return new Min(expr);
return new Min<T>(expr);
}
/**
* Creates an aggregate expression that sums all the values from the supplied expression.
* This would usually be used in a FieldOverride and supplied with a ColumnExp.
*/
public static FluentExp sum (SQLExpression expr)
public static <T extends Number> FluentExp<T> sum (SQLExpression<T> expr)
{
return new Sum(expr);
return new Sum<T>(expr);
}
/**
* Creates an expression that evaluates to the first supplied expression that is not null.
*/
public static FluentExp coalesce (SQLExpression... args)
public static <T> FluentExp<T> coalesce (SQLExpression<? extends T> arg1,
SQLExpression<? extends T> arg2)
{
return new Coalesce(args);
return new Coalesce<T>(arg1, arg2);
}
/**
* Creates an expression that evaluates to the first supplied expression that is not null.
*/
public static <T> FluentExp<T> coalesce (SQLExpression<? extends T>... args)
{
return new Coalesce<T>(args);
}
/**
* Creates an expression that evaluates to the largest of the given expressions.
*/
public static FluentExp greatest (SQLExpression... args)
public static <T extends Number> FluentExp<T> greatest (SQLExpression<? extends T> arg1,
SQLExpression<? extends T> arg2)
{
return new Greatest(args);
return new Greatest<T>(arg1, arg2);
}
/**
* Creates an expression that evaluates to the largest of the given expressions.
*/
public static <T extends Number> FluentExp<T> greatest (SQLExpression<? extends T>... args)
{
return new Greatest<T>(args);
}
/**
* Creates an expression that evaluates to the smallest of the given expressions.
*/
public static FluentExp least (SQLExpression... args)
public static <T extends Number> FluentExp<T> least (SQLExpression<? extends T> arg1,
SQLExpression<? extends T> arg2)
{
return new Least(args);
return new Least<T>(arg1, arg2);
}
/**
* Creates an expression that evaluates to the smallest of the given expressions.
*/
public static <T extends Number> FluentExp<T> least (SQLExpression<? extends T>... args)
{
return new Least<T>(args);
}
/**
* Creates an expression that evaluates to the length of the supplied array column.
*/
public static FluentExp<Integer> arrayLength (SQLExpression<?> exp)
{
return new Length(exp);
}
}
+2 -2
View File
@@ -50,7 +50,7 @@ public class Key<T extends PersistentRecord> extends WhereClause
{
/** Handles the matching of the key columns to its bound values. This is needed so that we can
* combine a bunch of keys into a {@link KeySet}. */
public static class Expression implements SQLExpression
public static class Expression implements SQLExpression<Object>
{
public Expression (Class<? extends PersistentRecord> pClass, Comparable<?>[] values) {
_pClass = pClass;
@@ -163,7 +163,7 @@ public class Key<T extends PersistentRecord> extends WhereClause
}
@Override // from WhereClause
public SQLExpression getWhereExpression ()
public SQLExpression<?> getWhereExpression ()
{
return new Expression(_pClass, _values);
}
@@ -127,8 +127,8 @@ public abstract class KeySet<T extends PersistentRecord> extends WhereClause
super(pClass);
}
@Override public SQLExpression getWhereExpression () {
return new LiteralExp("(1 = 0)");
@Override public SQLExpression<?> getWhereExpression () {
return new LiteralExp<Boolean>("false");
}
// from Iterable<Key<T>>
@@ -169,7 +169,7 @@ public abstract class KeySet<T extends PersistentRecord> extends WhereClause
_keys = keys;
}
@Override public SQLExpression getWhereExpression () {
@Override public SQLExpression<?> getWhereExpression () {
// Single-column keys result in the compact IN(keyVal1, keyVal2, ...)
return new In(DepotUtil.getKeyFields(_pClass)[0], _keys);
}
@@ -32,105 +32,106 @@ public class MathFuncs
/**
* Creates an expression that computes the absolute value of the supplied expression.
*/
public static FluentExp abs (SQLExpression expr)
public static <T extends Number> FluentExp<T> abs (SQLExpression<T> expr)
{
return new Abs(expr);
return new Abs<T>(expr);
}
/**
* Creates an expression that computes the integer ceiling of the supplied expression.
*/
public static FluentExp ceil (SQLExpression exp)
public static <T extends Number> FluentExp<T> ceil (SQLExpression<T> exp)
{
return new Ceil(exp);
return new Ceil<T>(exp);
}
/**
* Creates an expression that computes the exponential of the supplied expression.
*/
public static FluentExp exp (SQLExpression exp)
public static <T extends Number> FluentExp<T> exp (SQLExpression<T> exp)
{
return new Exp(exp);
return new Exp<T>(exp);
}
/**
* Creates an expression that computes the integer floor of the supplied expression.
*/
public static FluentExp floor (SQLExpression exp)
public static <T extends Number> FluentExp<T> floor (SQLExpression<T> exp)
{
return new Floor(exp);
return new Floor<T>(exp);
}
/**
* Creates an expression that computes the natural logarithm of the supplied expression.
*/
public static FluentExp ln (SQLExpression exp)
public static <T extends Number> FluentExp<T> ln (SQLExpression<T> exp)
{
return new Ln(exp);
return new Ln<T>(exp);
}
/**
* Creates an expression that computes the base-10 logarithm of the supplied expression.
*/
public static FluentExp log10 (SQLExpression value)
public static <T extends Number> FluentExp<T> log10 (SQLExpression<T> value)
{
return new Log10(value);
return new Log10<T>(value);
}
/**
* Creates an expression that evaluates to the constant PI.
*/
public static FluentExp pi ()
public static <T extends Number> FluentExp<T> pi ()
{
return new Pi();
return new Pi<T>();
}
/**
* Creates an expression that computes the value expression to the given power.
*/
public static FluentExp power (SQLExpression value, SQLExpression power)
public static <R extends Number, P extends Number> FluentExp<R> power (SQLExpression<R> value,
SQLExpression<P> power)
{
return new Power(value, power);
return new Power<R, P>(value, power);
}
/**
* Creates an expression that returns a random number between 0.0 and 1.0.
*/
public static FluentExp random ()
public static <T extends Number> FluentExp<T> random ()
{
return new Random();
return new Random<T>();
}
/**
* Creates an expression that computes the whole number nearest the supplied expression.
*/
public static FluentExp round (SQLExpression exp)
public static <T extends Number> FluentExp<T> round (SQLExpression<T> exp)
{
return new Round(exp);
return new Round<T>(exp);
}
/**
* Creates an expression that computes the sign of the supplied expression.
*/
public static FluentExp sign (SQLExpression exp)
public static <T extends Number> FluentExp<T> sign (SQLExpression<T> exp)
{
return new Sign(exp);
return new Sign<T>(exp);
}
/**
* Creates an expression that computes the square root of the supplied expression.
*/
public static FluentExp sqrt (SQLExpression exp)
public static <T extends Number> FluentExp<T> sqrt (SQLExpression<T> exp)
{
return new Sqrt(exp);
return new Sqrt<T>(exp);
}
/**
* Creates an expression that computes the truncation of the supplied expression,
* i.e. the next closest whole number to zero.
*/
public static FluentExp trunc (SQLExpression exp)
public static <T extends Number> FluentExp<T> trunc (SQLExpression<T> exp)
{
return new Trunc(exp);
return new Trunc<T>(exp);
}
}
@@ -42,7 +42,7 @@ class MultiKeySet<T extends PersistentRecord> extends KeySet<T>
_keyFields = keyFields;
}
@Override public SQLExpression getWhereExpression ()
@Override public SQLExpression<?> getWhereExpression ()
{
Set<Integer> columns = Sets.newHashSet();
for (int ii = 0; ii < _keyFields.length; ii ++) {
@@ -85,10 +85,10 @@ class MultiKeySet<T extends PersistentRecord> extends KeySet<T>
}
// note: this method will destructively modify its arguments
protected SQLExpression rowsToSQLExpression (
protected SQLExpression<?> rowsToSQLExpression (
List<Comparable<?>[]> keys, Set<Integer> columnsLeft)
{
List<SQLExpression> matches = Lists.newArrayList();
List<SQLExpression<?>> matches = Lists.newArrayList();
while (!keys.isEmpty()) {
// go through each column that is still in play, finding the single largest common
@@ -148,7 +148,7 @@ class MultiKeySet<T extends PersistentRecord> extends KeySet<T>
// find all the rows that contain the given chunk value in the given column. delete these
// (destructively modifying the input argument) and replace them with an optimized
// SQLExpression, which is returned
protected SQLExpression extractChunk (List<Comparable<?>[]> rows, Set<Integer> columnsLeft,
protected SQLExpression<?> extractChunk (List<Comparable<?>[]> rows, Set<Integer> columnsLeft,
int column, Comparable<?> value)
{
Iterator<Comparable<?>[]> iterator = rows.iterator();
@@ -165,7 +165,7 @@ class MultiKeySet<T extends PersistentRecord> extends KeySet<T>
Set<Integer> otherColumns = Sets.newHashSet(columnsLeft);
otherColumns.remove(column);
SQLExpression otherCondition;
SQLExpression<?> otherCondition;
if (otherColumns.size() == 1) {
// if there's just two columns, we're doing (A = ? and B in (?, ?, ?, ...))
int otherColumn = otherColumns.iterator().next();
@@ -188,15 +188,15 @@ class MultiKeySet<T extends PersistentRecord> extends KeySet<T>
// given unoptimizable key rows, gather them up into simple SQLExpressions according to
// the naive algorithm
protected List<SQLExpression> gatherDetritus (
protected List<SQLExpression<?>> gatherDetritus (
List<Comparable<?>[]> keys, Set<Integer> columnsLeft)
{
List<SQLExpression> conditions = Lists.newArrayList();
List<SQLExpression<?>> conditions = Lists.newArrayList();
Iterator<Comparable<?>[]> iterator = keys.iterator();
while (iterator.hasNext()) {
Comparable<?>[] row = iterator.next();
List<SQLExpression> bits = Lists.newArrayList();
List<SQLExpression<?>> bits = Lists.newArrayList();
for (int column : columnsLeft) {
bits.add(_keyFields[column].eq(row[column]));
}
+32 -16
View File
@@ -41,7 +41,7 @@ public class Ops
/**
* Creates a NOT expression with the supplied target expression.
*/
public static SQLExpression not (SQLExpression expr)
public static SQLExpression<Boolean> not (SQLExpression<Boolean> expr)
{
return new Not(expr);
}
@@ -49,7 +49,7 @@ public class Ops
/**
* Creates an AND expression with the supplied target expressions.
*/
public static FluentExp and (Iterable<? extends SQLExpression> conditions)
public static FluentExp<Boolean> and (Iterable<? extends SQLExpression<?>> conditions)
{
return and(Iterables.toArray(conditions, SQLExpression.class));
}
@@ -57,9 +57,9 @@ public class Ops
/**
* Creates an AND expression with the supplied target expressions.
*/
public static FluentExp and (SQLExpression... conditions)
public static FluentExp<Boolean> and (SQLExpression<?>... conditions)
{
return new MultiOperator(conditions) {
return new MultiOperator<Boolean>(conditions) {
@Override public String operator() {
return " and ";
}
@@ -86,7 +86,7 @@ public class Ops
/**
* Creates an OR expression with the supplied target expressions.
*/
public static FluentExp or (Iterable<? extends SQLExpression> conditions)
public static FluentExp<Boolean> or (Iterable<? extends SQLExpression<?>> conditions)
{
return or(Iterables.toArray(conditions, SQLExpression.class));
}
@@ -94,9 +94,9 @@ public class Ops
/**
* Creates an OR expression with the supplied target expressions.
*/
public static FluentExp or (SQLExpression... conditions)
public static FluentExp<Boolean> or (SQLExpression<?>... conditions)
{
return new MultiOperator(conditions) {
return new MultiOperator<Boolean>(conditions) {
@Override public String operator() {
return " or ";
}
@@ -121,7 +121,7 @@ public class Ops
/**
* Returns an expression that matches when the source is like the supplied value.
*/
public static FluentExp like (SQLExpression source, Comparable<?> value)
public static FluentExp<Boolean> like (SQLExpression<?> source, Comparable<?> value)
{
return new Like(source, value, true);
}
@@ -129,7 +129,7 @@ public class Ops
/**
* Returns an expression that matches when the source is like the supplied expression.
*/
public static FluentExp like (SQLExpression source, SQLExpression expr)
public static FluentExp<Boolean> like (SQLExpression<?> source, SQLExpression<?> expr)
{
return new Like(source, expr, true);
}
@@ -137,7 +137,7 @@ public class Ops
/**
* Returns an expression that matches when the source is NOT like the supplied value.
*/
public static FluentExp notLike (SQLExpression source, Comparable<?> value)
public static FluentExp<Boolean> notLike (SQLExpression<?> source, Comparable<?> value)
{
return new Like(source, value, false);
}
@@ -145,7 +145,7 @@ public class Ops
/**
* Returns an expression that matches when the source is NOT like the supplied expression.
*/
public static FluentExp notLike (SQLExpression source, SQLExpression expr)
public static FluentExp<Boolean> notLike (SQLExpression<?> source, SQLExpression<?> expr)
{
return new Like(source, expr, false);
}
@@ -153,7 +153,7 @@ public class Ops
/**
* Creates an EXISTS expression with the supplied select clause.
*/
public static SQLExpression exists (SelectClause target)
public static SQLExpression<Boolean> exists (SelectClause target)
{
return new Exists(target);
}
@@ -161,16 +161,32 @@ public class Ops
/**
* Adds the supplied expressions together.
*/
public static FluentExp add (SQLExpression... exprs)
public static <T extends Number> FluentExp<T> add (SQLExpression<T> e1, SQLExpression<T> e2)
{
return new Add(exprs);
return new Add<T>(new SQLExpression<?>[] { e1, e2 });
}
/**
* Adds the supplied expressions together.
*/
public static <T extends Number> FluentExp<T> add (Iterable<SQLExpression<T>> exprs)
{
return new Add<T>(Iterables.toArray(exprs, SQLExpression.class));
}
/**
* Multiplies the supplied expressions together.
*/
public static FluentExp mul (SQLExpression... exprs)
public static <T extends Number> FluentExp<T> mul (SQLExpression<T> e1, SQLExpression<T> e2)
{
return new Mul(exprs);
return new Mul<T>(new SQLExpression<?>[] { e1, e2 });
}
/**
* Multiplies the supplied expressions together.
*/
public static <T extends Number> FluentExp<T> mul (Iterable<SQLExpression<T>> exprs)
{
return new Mul<T>(Iterables.toArray(exprs, SQLExpression.class));
}
}
@@ -85,10 +85,20 @@ public class QueryBuilder<T extends PersistentRecord>
return this;
}
/**
* Configures a {@link Where} clause that matches all rows. For selections, a where clause can
* simply be omitted, but for deletions, this method must be used if you intend to delete all
* rows in the table.
*/
public QueryBuilder<T> whereTrue ()
{
return where(Exps.literal("true"));
}
/**
* Configures a {@link Where} clause that ANDs together all of the supplied expressions.
*/
public QueryBuilder<T> where (SQLExpression... exprs)
public QueryBuilder<T> where (SQLExpression<?>... exprs)
{
return where(Arrays.asList(exprs));
}
@@ -96,11 +106,11 @@ public class QueryBuilder<T extends PersistentRecord>
/**
* Configures a {@link Where} clause that ANDs together all of the supplied expressions.
*/
public QueryBuilder<T> where (Iterable<? extends SQLExpression> exprs)
public QueryBuilder<T> where (Iterable<? extends SQLExpression<?>> exprs)
{
Iterator<? extends SQLExpression> iter = exprs.iterator();
Iterator<? extends SQLExpression<?>> iter = exprs.iterator();
checkArgument(iter.hasNext(), "Must supply at least one expression.");
SQLExpression first = iter.next();
SQLExpression<?> first = iter.next();
return where(iter.hasNext() ? new Where(Ops.and(exprs)) : new Where(first));
}
@@ -146,7 +156,7 @@ public class QueryBuilder<T extends PersistentRecord>
* Adds a {@link Join} clause configured with the join condition.
*/
public QueryBuilder<T> join (Class<? extends PersistentRecord> joinClass,
SQLExpression joinCondition)
SQLExpression<?> joinCondition)
{
return join(new Join(joinClass, joinCondition));
}
@@ -176,7 +186,7 @@ public class QueryBuilder<T extends PersistentRecord>
/**
* Configures a {@link GroupBy} clause on the supplied group expressions.
*/
public QueryBuilder<T> groupBy (SQLExpression... exprs)
public QueryBuilder<T> groupBy (SQLExpression<?>... exprs)
{
checkState(_groupBy == null, "GroupBy clause is already configured.");
_groupBy = new GroupBy(exprs);
@@ -194,7 +204,7 @@ public class QueryBuilder<T extends PersistentRecord>
/**
* Configures an {@link OrderBy} clause that ascends on the supplied expression.
*/
public QueryBuilder<T> ascending (SQLExpression value)
public QueryBuilder<T> ascending (SQLExpression<?> value)
{
return orderBy(OrderBy.ascending(value));
}
@@ -202,7 +212,7 @@ public class QueryBuilder<T extends PersistentRecord>
/**
* Configures an {@link OrderBy} clause that descends on the supplied expression.
*/
public QueryBuilder<T> descending (SQLExpression value)
public QueryBuilder<T> descending (SQLExpression<?> value)
{
return orderBy(OrderBy.descending(value));
}
@@ -275,7 +285,7 @@ public class QueryBuilder<T extends PersistentRecord>
/**
* Adds a {@link FieldDefinition} clause.
*/
public QueryBuilder<T> fieldDef (String field, SQLExpression override)
public QueryBuilder<T> fieldDef (String field, SQLExpression<?> override)
{
return fieldDef(new FieldDefinition(field, override));
}
@@ -283,7 +293,7 @@ public class QueryBuilder<T extends PersistentRecord>
/**
* Adds a {@link FieldDefinition} clause.
*/
public QueryBuilder<T> fieldDef (ColumnExp<?> field, SQLExpression override)
public QueryBuilder<T> fieldDef (ColumnExp<?> field, SQLExpression<?> override)
{
return fieldDef(new FieldDefinition(field, override));
}
@@ -32,7 +32,7 @@ public class StringFuncs
/**
* Creates an expression that evaluates to the string length of the supplied expression.
*/
public static FluentExp length (SQLExpression exp)
public static FluentExp<Integer> length (SQLExpression<String> exp)
{
return new Length(exp);
}
@@ -40,7 +40,7 @@ public class StringFuncs
/**
* Creates an expression that down-cases the supplied expression.
*/
public static FluentExp lower (SQLExpression exp)
public static FluentExp<String> lower (SQLExpression<String> exp)
{
return new Lower(exp);
}
@@ -49,7 +49,8 @@ public class StringFuncs
* Creates an expression that locates the given substring expression within the given
* string expression and returns the index.
*/
public static FluentExp position (SQLExpression substring, SQLExpression string)
public static FluentExp<Integer> position (SQLExpression<String> substring,
SQLExpression<String> string)
{
return new Position(substring, string);
}
@@ -58,8 +59,8 @@ public class StringFuncs
* Creates an expression that evaluates to a substring of the given string expression,
* starting at the given index and of the given length.
*/
public static FluentExp substring (
SQLExpression string, SQLExpression from, SQLExpression count)
public static FluentExp<String> substring (
SQLExpression<String> string, SQLExpression<String> from, SQLExpression<Integer> count)
{
return new Substring(string, from, count);
}
@@ -68,7 +69,7 @@ public class StringFuncs
* Creates an expression that removes whitespace from the beginning and end of the supplied
* string expression.
*/
public static FluentExp trim (SQLExpression exp)
public static FluentExp<String> trim (SQLExpression<String> exp)
{
return new Trim(exp);
}
@@ -76,7 +77,7 @@ public class StringFuncs
/**
* Creates an expression that up-cases the supplied string expression.
*/
public static FluentExp upper (SQLExpression exp)
public static FluentExp<String> upper (SQLExpression<String> exp)
{
return new Upper(exp);
}
@@ -41,7 +41,7 @@ public class FieldDefinition implements QueryClause
{
public FieldDefinition (String field, String str)
{
this(field, new LiteralExp(str));
this(field, new LiteralExp<Object>(str));
}
public FieldDefinition (String field, Class<? extends PersistentRecord> pClass, String pCol)
@@ -49,13 +49,13 @@ public class FieldDefinition implements QueryClause
this(field, new ColumnExp<Object>(pClass, pCol));
}
public FieldDefinition (String field, SQLExpression override)
public FieldDefinition (String field, SQLExpression<?> override)
{
_field = field;
_definition = override;
}
public FieldDefinition (ColumnExp<?> field, SQLExpression override)
public FieldDefinition (ColumnExp<?> field, SQLExpression<?> override)
{
_field = field.name;
_definition = override;
@@ -69,7 +69,7 @@ public class FieldDefinition implements QueryClause
return _field;
}
public SQLExpression getDefinition ()
public SQLExpression<?> getDefinition ()
{
return _definition;
}
@@ -90,6 +90,6 @@ public class FieldDefinition implements QueryClause
protected String _field;
/** The defining expression. */
protected SQLExpression _definition;
protected SQLExpression<?> _definition;
}
@@ -45,12 +45,13 @@ public class FieldOverride extends FieldDefinition
super(field, pClass, pCol);
}
public FieldOverride (String field, SQLExpression override)
public FieldOverride (String field, SQLExpression<?> override)
{
super(field, override);
}
public FieldOverride (ColumnExp<?> field, SQLExpression override)
public FieldOverride (ColumnExp<?> field, SQLExpression<?> override)
{
super(field, override);
}
@@ -31,12 +31,12 @@ import com.samskivert.depot.impl.FragmentVisitor;
*/
public class GroupBy implements QueryClause
{
public GroupBy (SQLExpression... values)
public GroupBy (SQLExpression<?>... values)
{
_values = values;
}
public SQLExpression[] getValues ()
public SQLExpression<?>[] getValues ()
{
return _values;
}
@@ -53,6 +53,6 @@ public class GroupBy implements QueryClause
}
/** The expressions that are generated for the clause. */
protected SQLExpression[] _values;
protected SQLExpression<?>[] _values;
}
@@ -43,7 +43,7 @@ public class Join implements QueryClause
_joinCondition = new Equals(primary, join);
}
public Join (Class<? extends PersistentRecord> joinClass, SQLExpression joinCondition)
public Join (Class<? extends PersistentRecord> joinClass, SQLExpression<?> joinCondition)
{
_joinClass = joinClass;
_joinCondition = joinCondition;
@@ -68,7 +68,7 @@ public class Join implements QueryClause
return _joinClass;
}
public SQLExpression getJoinCondition ()
public SQLExpression<?> getJoinCondition ()
{
return _joinCondition;
}
@@ -99,5 +99,6 @@ public class Join implements QueryClause
protected Class<? extends PersistentRecord> _joinClass;
/** The condition used to join in the new table. */
protected SQLExpression _joinCondition;
protected SQLExpression<?> _joinCondition;
}
@@ -41,32 +41,32 @@ public class OrderBy implements QueryClause
*/
public static OrderBy random ()
{
return ascending(new LiteralExp("rand()"));
return ascending(new LiteralExp<Object>("rand()"));
}
/**
* Creates and returns an ascending order by clause on the supplied expression.
*/
public static OrderBy ascending (SQLExpression value)
public static OrderBy ascending (SQLExpression<?> value)
{
return new OrderBy(new SQLExpression[] { value } , new Order[] { Order.ASC });
return new OrderBy(new SQLExpression<?>[] { value } , new Order[] { Order.ASC });
}
/**
* Creates and returns a descending order by clause on the supplied expression.
*/
public static OrderBy descending (SQLExpression value)
public static OrderBy descending (SQLExpression<?> value)
{
return new OrderBy(new SQLExpression[] { value }, new Order[] { Order.DESC });
return new OrderBy(new SQLExpression<?>[] { value }, new Order[] { Order.DESC });
}
public OrderBy (SQLExpression[] values, Order[] orders)
public OrderBy (SQLExpression<?>[] values, Order[] orders)
{
_values = values;
_orders = orders;
}
public SQLExpression[] getValues ()
public SQLExpression<?>[] getValues ()
{
return _values;
}
@@ -79,7 +79,7 @@ public class OrderBy implements QueryClause
/**
* Concatenates the supplied order expression to this one, returns a new expression.
*/
public OrderBy thenAscending (SQLExpression value)
public OrderBy thenAscending (SQLExpression<?> value)
{
return new OrderBy(ArrayUtil.append(_values, value),
ArrayUtil.append(_orders, Order.ASC));
@@ -88,7 +88,7 @@ public class OrderBy implements QueryClause
/**
* Creates and returns a descending order by clause on the supplied expression.
*/
public OrderBy thenDescending (SQLExpression value)
public OrderBy thenDescending (SQLExpression<?> value)
{
return new OrderBy(ArrayUtil.append(_values, value),
ArrayUtil.append(_orders, Order.DESC));
@@ -103,7 +103,7 @@ public class OrderBy implements QueryClause
// from SQLExpression
public void addClasses (Collection<Class<? extends PersistentRecord>> classSet)
{
for (SQLExpression expression : _values) {
for (SQLExpression<?> expression : _values) {
expression.addClasses(classSet);
}
}
@@ -122,7 +122,7 @@ public class OrderBy implements QueryClause
}
/** The expressions that are generated for the clause. */
protected SQLExpression[] _values;
protected SQLExpression<?>[] _values;
/** Whether the ordering is to be ascending or descending. */
protected Order[] _orders;
@@ -27,7 +27,6 @@ import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.expression.ColumnExp;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.impl.FragmentVisitor;
import com.samskivert.depot.impl.expression.ValueExp;
import com.samskivert.depot.impl.operator.Equals;
import com.samskivert.depot.impl.operator.IsNull;
@@ -63,13 +62,13 @@ public class Where extends WhereClause
this(toCondition(columns, values));
}
public Where (SQLExpression condition)
public Where (SQLExpression<?> condition)
{
_condition = condition;
}
@Override // from WhereClause
public SQLExpression getWhereExpression ()
public SQLExpression<?> getWhereExpression ()
{
return _condition;
}
@@ -92,15 +91,15 @@ public class Where extends WhereClause
return String.valueOf(_condition);
}
protected static SQLExpression toCondition (ColumnExp<?>[] columns, Comparable<?>[] values)
protected static SQLExpression<?> toCondition (ColumnExp<?>[] columns, Comparable<?>[] values)
{
SQLExpression[] comparisons = new SQLExpression[columns.length];
SQLExpression<?>[] comparisons = new SQLExpression[columns.length];
for (int ii = 0; ii < columns.length; ii ++) {
comparisons[ii] = (values[ii] == null) ? new IsNull(columns[ii]) :
new Equals(columns[ii], new ValueExp(values[ii]));
new Equals(columns[ii], values[ii]);
}
return Ops.and(comparisons);
}
protected SQLExpression _condition;
protected SQLExpression<?> _condition;
}
@@ -32,7 +32,7 @@ public abstract class WhereClause implements QueryClause
/**
* Returns the condition associated with this where clause.
*/
public abstract SQLExpression getWhereExpression ();
public abstract SQLExpression<?> getWhereExpression ();
/**
* Validates that the supplied persistent record type is the type matched by this where clause.
@@ -30,7 +30,7 @@ import com.samskivert.depot.impl.FragmentVisitor;
* An expression that unambiguously identifies a field of a class, for example
* <code>GameRecord.itemId</code>.
*/
public class ColumnExp<T> extends FluentExp
public class ColumnExp<T> extends FluentExp<T>
{
/** The name of the column we reference. */
public final String name;
@@ -40,29 +40,29 @@ import com.samskivert.depot.impl.operator.Sub;
/**
* Provides a fluent API for creating most SQL expressions like and, or, equal, not equal, etc.
*/
public abstract class FluentExp
implements SQLExpression
public abstract class FluentExp<T>
implements SQLExpression<T>
{
/** Returns an {@link Equals} with this expression and the supplied target. */
public FluentExp eq (Comparable<?> value)
public FluentExp<Boolean> eq (Comparable<?> value)
{
return new Equals(this, value);
}
/** Returns an {@link Equals} with this expression and the supplied target. */
public FluentExp eq (SQLExpression expr)
public FluentExp<Boolean> eq (SQLExpression<?> expr)
{
return new Equals(this, expr);
}
/** Returns a {@link NotEquals} with this expression and the supplied target. */
public FluentExp notEq (Comparable<?> value)
public FluentExp<Boolean> notEq (Comparable<?> value)
{
return new NotEquals(this, value);
}
/** Returns a {@link NotEquals} with this expression and the supplied target. */
public FluentExp notEq (SQLExpression expr)
public FluentExp<Boolean> notEq (SQLExpression<?> expr)
{
return new NotEquals(this, expr);
}
@@ -86,158 +86,172 @@ public abstract class FluentExp
}
/** Returns a {@link GreaterThan} with this expression and the supplied target. */
public FluentExp greaterThan (Comparable<?> value)
public FluentExp<Boolean> greaterThan (Comparable<?> value)
{
return new GreaterThan(this, value);
}
/** Returns a {@link GreaterThan} with this expression and the supplied target. */
public FluentExp greaterThan (SQLExpression expr)
public FluentExp<Boolean> greaterThan (SQLExpression<?> expr)
{
return new GreaterThan(this, expr);
}
/** Returns a {@link LessThan} with this expression and the supplied target. */
public FluentExp lessThan (Comparable<?> value)
public FluentExp<Boolean> lessThan (Comparable<?> value)
{
return new LessThan(this, value);
}
/** Returns a {@link LessThan} with this expression and the supplied target. */
public FluentExp lessThan (SQLExpression expr)
public FluentExp<Boolean> lessThan (SQLExpression<?> expr)
{
return new LessThan(this, expr);
}
/** Returns a {@link GreaterThanEquals} with this expression and the supplied target. */
public FluentExp greaterEq (Comparable<?> value)
public FluentExp<Boolean> greaterEq (Comparable<?> value)
{
return new GreaterThanEquals(this, value);
}
/** Returns a {@link GreaterThanEquals} with this expression and the supplied target. */
public FluentExp greaterEq (SQLExpression expr)
public FluentExp<Boolean> greaterEq (SQLExpression<?> expr)
{
return new GreaterThanEquals(this, expr);
}
/** Returns a {@link LessThanEquals} with this expression and the supplied target. */
public FluentExp lessEq (Comparable<?> value)
public FluentExp<Boolean> lessEq (Comparable<?> value)
{
return new LessThanEquals(this, value);
}
/** Returns a {@link LessThanEquals} with this expression and the supplied target. */
public FluentExp lessEq (SQLExpression expr)
public FluentExp<Boolean> lessEq (SQLExpression<?> expr)
{
return new LessThanEquals(this, expr);
}
/** Returns a boolean and of this expression and the supplied target. */
public FluentExp and (SQLExpression expr)
public FluentExp<Boolean> and (SQLExpression<Boolean> expr)
{
return Ops.and(this, expr);
}
/** Returns a boolean or of this expression and the supplied target. */
public FluentExp or (SQLExpression expr)
public FluentExp<Boolean> or (SQLExpression<Boolean> expr)
{
return Ops.or(this, expr);
}
/** Returns a bitwise and of this expression and the supplied target. */
public FluentExp bitAnd (Comparable<?> value)
public <V extends Number> FluentExp<V> bitAnd (V value)
{
return new BitAnd(this, value);
return new BitAnd<V>(this, value);
}
/** Returns a bitwise and of this expression and the supplied target. */
public FluentExp bitAnd (SQLExpression expr)
public <V extends Number> FluentExp<V> bitAnd (SQLExpression<V> expr)
{
return new BitAnd(this, expr);
return new BitAnd<V>(this, expr);
}
/** Returns a bitwise or of this expression and the supplied target. */
public FluentExp bitOr (Comparable<?> value)
public <V extends Number> FluentExp<V> bitOr (V value)
{
return new BitOr(this, value);
return new BitOr<V>(this, value);
}
/** Returns a bitwise or of this expression and the supplied target. */
public FluentExp bitOr (SQLExpression expr)
public <V extends Number> FluentExp<V> bitOr (SQLExpression<V> expr)
{
return new BitOr(this, expr);
return new BitOr<V>(this, expr);
}
/** Returns the sum of this expression and the supplied target. */
public FluentExp plus (Comparable<?> value)
public <V extends Number> FluentExp<V> plus (V value)
{
return new Add(this, value);
return new Add<V>(this, value);
}
/** Returns the sum of this expression and the supplied target. */
public FluentExp plus (SQLExpression expr)
public <V extends Number> FluentExp<V> plus (SQLExpression<V> expr)
{
return new Add(this, expr);
return new Add<V>(this, expr);
}
/** Returns this expression minus the supplied target. */
public FluentExp minus (Comparable<?> value)
public <V extends Number> FluentExp<V> minus (V value)
{
return new Sub(this, value);
return new Sub<V>(this, value);
}
/** Returns this expression minus the supplied target. */
public FluentExp minus (SQLExpression expr)
public <V extends Number> FluentExp<V> minus (SQLExpression<V> expr)
{
return new Sub(this, expr);
return new Sub<V>(this, expr);
}
/** Returns this expression times the supplied target. */
public FluentExp times (Comparable<?> value)
public <V extends Number> FluentExp<V> times (V value)
{
return new Mul(this, value);
return new Mul<V>(this, value);
}
/** Returns this expression times the supplied target. */
public FluentExp times (SQLExpression expr)
public <V extends Number> FluentExp<V> times (SQLExpression<V> expr)
{
return new Mul(this, expr);
return new Mul<V>(this, expr);
}
/** Returns this expression divided by the supplied target. */
public FluentExp div (Comparable<?> value)
public <V extends Number> FluentExp<V> div (V value)
{
return new Div(this, value);
return new Div<V>(this, value);
}
/** Returns this expression divided by the supplied target. */
public FluentExp div (SQLExpression expr)
public <V extends Number> FluentExp<V> div (SQLExpression<V> expr)
{
return new Div(this, expr);
return new Div<V>(this, expr);
}
/** Returns a {@link Like} on this column and the supplied target. */
public FluentExp like (Comparable<?> value)
public FluentExp<Boolean> like (Comparable<?> value)
{
return new Like(this, value, true);
}
/** Returns a {@link Like} on this column and the supplied target. */
public FluentExp like (SQLExpression expr)
public FluentExp<Boolean> like (SQLExpression<?> expr)
{
return new Like(this, expr, true);
}
/** Returns a negated {@link Like} on this column and the supplied target. */
public FluentExp notLike (Comparable<?> value)
public FluentExp<Boolean> notLike (Comparable<?> value)
{
return new Like(this, value, false);
}
/** Returns a negated {@link Like} on this column and the supplied target. */
public FluentExp notLike (SQLExpression expr)
public FluentExp<Boolean> notLike (SQLExpression<?> expr)
{
return new Like(this, expr, false);
}
/** Returns this expression minus the supplied target, assuming this and the target represent
* Date values. Because date arithmetic is database specific, you're on your own with types. */
public FluentExp<Number> dateSub (SQLExpression<?> expr)
{
return new Sub<Number>(this, expr);
}
/** Returns this expression plus the supplied target, assuming this and the target represent
* Date values. Because date arithmetic is database specific, you're on your own with types. */
public FluentExp<Number> dateAdd (SQLExpression<?> expr)
{
return new Add<Number>(this, expr);
}
}
@@ -25,7 +25,7 @@ import com.samskivert.depot.SQLFragment;
/**
* Represents an SQL expression, e.g. column name, function, or constant.
*/
public interface SQLExpression extends SQLFragment
public interface SQLExpression<T> extends SQLFragment
{
/** Used internally to represent the lack of a value. */
public static final class NoValue
@@ -33,6 +33,7 @@ import com.google.common.collect.Maps;
import com.samskivert.util.ByteEnum;
import com.samskivert.util.Tuple;
import com.samskivert.depot.Exps;
import com.samskivert.depot.Key;
import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.annotation.Computed;
@@ -170,9 +171,9 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
return null;
}
public Void visit (MultiOperator multiOperator)
public Void visit (MultiOperator<?> multiOperator)
{
SQLExpression[] conditions = multiOperator.getArgs();
SQLExpression<?>[] conditions = multiOperator.getArgs();
for (int ii = 0; ii < conditions.length; ii++) {
if (ii > 0) {
_builder.append(" ").append(multiOperator.operator()).append(" ");
@@ -184,7 +185,7 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
return null;
}
public Void visit (BinaryOperator binaryOperator)
public Void visit (BinaryOperator<?> binaryOperator)
{
_builder.append('(');
binaryOperator.getLeftHandSide().accept(this);
@@ -205,7 +206,7 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
{
// if the In() expression is empty, replace it with a 'false'
if (in.getValues().length == 0) {
new ValueExp(false).accept(this);
Exps.value(false).accept(this);
return null;
}
in.getExpression().accept(this);
@@ -224,16 +225,16 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
public abstract Void visit (FullText.Match match);
public abstract Void visit (FullText.Rank rank);
public Void visit (Case caseExp)
public Void visit (Case<?> caseExp)
{
_builder.append("(case ");
for (Tuple<SQLExpression, SQLExpression> tuple : caseExp.getWhenExps()) {
for (Tuple<SQLExpression<?>, SQLExpression<?>> tuple : caseExp.getWhenExps()) {
_builder.append(" when ");
tuple.left.accept(this);
_builder.append(" then ");
tuple.right.accept(this);
}
SQLExpression elseExp = caseExp.getElseExp();
SQLExpression<?> elseExp = caseExp.getElseExp();
if (elseExp != null) {
_builder.append(" else ");
elseExp.accept(this);
@@ -260,7 +261,7 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
{
_builder.append(" group by ");
SQLExpression[] values = groupBy.getValues();
SQLExpression<?>[] values = groupBy.getValues();
for (int ii = 0; ii < values.length; ii++) {
if (ii > 0) {
_builder.append(", ");
@@ -280,7 +281,7 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
{
_builder.append(" order by ");
SQLExpression[] values = orderBy.getValues();
SQLExpression<?>[] values = orderBy.getValues();
OrderBy.Order[] orders = orderBy.getOrders();
for (int ii = 0; ii < values.length; ii++) {
if (ii > 0) {
@@ -320,13 +321,13 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
return null;
}
public Void visit (LiteralExp literalExp)
public Void visit (LiteralExp<?> literalExp)
{
_builder.append(literalExp.getText());
return null;
}
public Void visit (ValueExp valueExp)
public Void visit (ValueExp<?> valueExp)
{
bindValue(valueExp.getValue());
return null;
@@ -456,7 +457,7 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
ColumnExp<?>[] fields = updateClause.getFields();
Object pojo = updateClause.getPojo();
SQLExpression[] values = updateClause.getValues();
SQLExpression<?>[] values = updateClause.getValues();
for (int ii = 0; ii < fields.length; ii ++) {
if (ii > 0) {
_builder.append(", ");
@@ -499,7 +500,7 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
public Void visit (CreateIndexClause createIndexClause)
{
if (!_allowComplexIndices) {
for (Tuple<SQLExpression, Order> field : createIndexClause.getFields()) {
for (Tuple<SQLExpression<?>, Order> field : createIndexClause.getFields()) {
if (!(field.left instanceof ColumnExp<?>)) {
log.warning("This database can't handle complex indexes. Aborting creation.",
"ixName", createIndexClause.getName());
@@ -520,7 +521,7 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
// turn off table abbreviations here
_defaultType = createIndexClause.getPersistentClass();
boolean comma = false;
for (Tuple<SQLExpression, Order> field : createIndexClause.getFields()) {
for (Tuple<SQLExpression<?>, Order> field : createIndexClause.getFields()) {
if (comma) {
_builder.append(", ");
}
@@ -558,67 +559,67 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
//
// NUMERICAL FUNCTIONS
public Void visit (Abs exp)
public Void visit (Abs<?> exp)
{
return appendFunctionCall("abs", exp.getArg());
}
public Void visit (Ceil exp)
public Void visit (Ceil<?> exp)
{
return appendFunctionCall("ceil", exp.getArg());
}
public Void visit (Exp exp)
public Void visit (Exp<?> exp)
{
return appendFunctionCall("exp", exp.getArg());
}
public Void visit (Floor exp)
public Void visit (Floor<?> exp)
{
return appendFunctionCall("floor", exp.getArg());
}
public Void visit (Ln exp)
public Void visit (Ln<?> exp)
{
return appendFunctionCall("ln", exp.getArg());
}
public Void visit (Log10 exp)
public Void visit (Log10<?> exp)
{
return appendFunctionCall("log", exp.getArg());
}
public Void visit (Pi exp)
public Void visit (Pi<?> exp)
{
return appendFunctionCall("PI");
}
public Void visit (Power exp)
public Void visit (Power<?,?> exp)
{
return appendFunctionCall("power", exp.getPower(), exp.getValue());
}
public Void visit (Random exp)
public Void visit (Random<?> exp)
{
return appendFunctionCall("random");
}
public Void visit (Round exp)
public Void visit (Round<?> exp)
{
return appendFunctionCall("round", exp.getArg());
}
public Void visit (Sign exp)
public Void visit (Sign<?> exp)
{
return appendFunctionCall("sign", exp.getArg());
}
public Void visit (Sqrt exp)
public Void visit (Sqrt<?> exp)
{
return appendFunctionCall("sqrt", exp.getArg());
}
public Void visit (Trunc exp)
public Void visit (Trunc<?> exp)
{
return appendFunctionCall("trunc", exp.getArg());
}
@@ -668,7 +669,7 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
return null;
}
public Void visit (Average exp)
public Void visit (Average<?> exp)
{
return appendAggregateFunctionCall("average", exp);
}
@@ -683,17 +684,17 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
return appendAggregateFunctionCall("every", exp);
}
public Void visit (Max exp)
public Void visit (Max<?> exp)
{
return appendAggregateFunctionCall("max", exp);
}
public Void visit (Min exp)
public Void visit (Min<?> exp)
{
return appendAggregateFunctionCall("min", exp);
}
public Void visit (Sum exp)
public Void visit (Sum<?> exp)
{
return appendAggregateFunctionCall("sum", exp);
}
@@ -701,22 +702,22 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
//
// CONDITIONAL FUNCTIONS
public Void visit (Coalesce exp)
public Void visit (Coalesce<?> exp)
{
return appendFunctionCall("coalesce", exp.getArgs());
}
public Void visit (Greatest exp)
public Void visit (Greatest<?> exp)
{
return appendFunctionCall("greatest", exp.getArgs());
}
public Void visit (Least exp)
public Void visit (Least<?> exp)
{
return appendFunctionCall("least", exp.getArgs());
}
protected Void appendAggregateFunctionCall (String function, AggregateFun exp)
protected Void appendAggregateFunctionCall (String function, AggregateFun<?> exp)
{
_builder.append(" ").append(function).append("(");
if (exp.isDistinct()) {
@@ -727,7 +728,7 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
return null;
}
protected Void appendFunctionCall (String function, SQLExpression... args)
protected Void appendFunctionCall (String function, SQLExpression<?>... args)
{
_builder.append(" ").append(function).append("(");
appendArguments(args);
@@ -735,7 +736,7 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
return null;
}
protected Void appendArguments (SQLExpression... args)
protected Void appendArguments (SQLExpression<?>... args)
{
for (int ii = 0; ii < args.length; ii ++) {
if (ii > 0) {
@@ -955,9 +956,9 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
if (value instanceof ByteEnum) {
// byte enums require special conversion
stmt.setByte(argIx, ((ByteEnum)value).toByte());
} else if (value instanceof Enum) {
} else if (value instanceof Enum<?>) {
// enums are converted to strings
stmt.setString(argIx, ((Enum)value).name());
stmt.setString(argIx, ((Enum<?>)value).name());
} else if (value instanceof int[]) {
// int arrays require conversion to byte arrays
int[] data = (int[])value;
@@ -34,7 +34,6 @@ import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
@@ -121,9 +120,9 @@ public class DepotMarshaller<T extends PersistentRecord> implements QueryMarshal
// introspect on the class and create marshallers and indices for persistent fields
List<ColumnExp<?>> fields = Lists.newArrayList();
ListMultimap<String, Tuple<SQLExpression, Order>> namedFieldIndices =
ListMultimap<String, Tuple<SQLExpression<?>, Order>> namedFieldIndices =
ArrayListMultimap.create();
ListMultimap<String, Tuple<SQLExpression, Order>> uniqueNamedFieldIndices =
ListMultimap<String, Tuple<SQLExpression<?>, Order>> uniqueNamedFieldIndices =
ArrayListMultimap.create();
for (Field field : _pClass.getFields()) {
int mods = field.getModifiers();
@@ -203,8 +202,8 @@ public class DepotMarshaller<T extends PersistentRecord> implements QueryMarshal
Index index = field.getAnnotation(Index.class);
if (index != null) {
String name = index.name().equals("") ? field.getName() + "Index" : index.name();
Tuple<SQLExpression, Order> entry =
new Tuple<SQLExpression, Order>(fieldColumn, Order.ASC);
Tuple<SQLExpression<?>, Order> entry =
new Tuple<SQLExpression<?>, Order>(fieldColumn, Order.ASC);
if (index.unique()) {
checkArgument(!namedFieldIndices.containsKey(index.name()),
"All @Index for a particular name must be unique or non-unique");
@@ -955,22 +954,22 @@ public class DepotMarshaller<T extends PersistentRecord> implements QueryMarshal
protected CreateIndexClause buildIndex (String name, boolean unique, Object config)
{
List<Tuple<SQLExpression, Order>> definition = Lists.newArrayList();
List<Tuple<SQLExpression<?>, Order>> definition = Lists.newArrayList();
if (config instanceof ColumnExp<?>) {
definition.add(new Tuple<SQLExpression, Order>((ColumnExp<?>)config, Order.ASC));
definition.add(new Tuple<SQLExpression<?>, Order>((ColumnExp<?>)config, Order.ASC));
} else if (config instanceof ColumnExp<?>[]) {
for (ColumnExp<?> column : (ColumnExp<?>[])config) {
definition.add(new Tuple<SQLExpression, Order>(column, Order.ASC));
definition.add(new Tuple<SQLExpression<?>, Order>(column, Order.ASC));
}
} else if (config instanceof SQLExpression) {
definition.add(new Tuple<SQLExpression, Order>((SQLExpression)config, Order.ASC));
definition.add(new Tuple<SQLExpression<?>, Order>((SQLExpression<?>)config, Order.ASC));
} else if (config instanceof Tuple<?,?>) {
@SuppressWarnings("unchecked") Tuple<SQLExpression, Order> tuple =
(Tuple<SQLExpression, Order>)config;
@SuppressWarnings("unchecked") Tuple<SQLExpression<?>, Order> tuple =
(Tuple<SQLExpression<?>, Order>)config;
definition.add(tuple);
} else if (config instanceof List<?>) {
@SuppressWarnings("unchecked") List<Tuple<SQLExpression, Order>> defs =
(List<Tuple<SQLExpression, Order>>)config;
@SuppressWarnings("unchecked") List<Tuple<SQLExpression<?>, Order>> defs =
(List<Tuple<SQLExpression<?>, Order>>)config;
definition.addAll(defs);
} else {
throw new IllegalArgumentException(
@@ -107,9 +107,9 @@ public class ExpressionEvaluator
_pRec = pRec;
}
public Object visit (MultiOperator multiOperator)
public Object visit (MultiOperator<?> multiOperator)
{
SQLExpression[] operands = multiOperator.getArgs();
SQLExpression<?>[] operands = multiOperator.getArgs();
Object[] values = new Object[operands.length];
for (int ii = 0; ii < operands.length; ii ++) {
values[ii] = operands[ii].accept(this);
@@ -121,7 +121,7 @@ public class ExpressionEvaluator
return multiOperator.evaluate(values);
}
public Object visit (BinaryOperator binaryOperator)
public Object visit (BinaryOperator<?> binaryOperator)
{
Object left = binaryOperator.getLeftHandSide().accept(this);
Object right = binaryOperator.getRightHandSide().accept(this);
@@ -157,9 +157,9 @@ public class ExpressionEvaluator
return new NoValue("Full Text Match not implemented");
}
public Object visit (Case caseExp)
public Object visit (Case<?> caseExp)
{
for (Tuple<SQLExpression, SQLExpression> exp : caseExp.getWhenExps()) {
for (Tuple<SQLExpression<?>, SQLExpression<?>> exp : caseExp.getWhenExps()) {
Object result = exp.left.accept(this);
if (result instanceof NoValue || !(result instanceof Boolean)) {
return new NoValue("Failed to evaluate case: " + exp.left + " -> " + result);
@@ -168,7 +168,7 @@ public class ExpressionEvaluator
return exp.right.accept(this);
}
}
SQLExpression elseExp = caseExp.getElseExp();
SQLExpression<?> elseExp = caseExp.getElseExp();
if (elseExp != null) {
return elseExp.accept(this);
}
@@ -209,12 +209,12 @@ public class ExpressionEvaluator
return new NoValue("Boolean negation of non-boolean value: " + result);
}
public Object visit (LiteralExp literalExp)
public Object visit (LiteralExp<?> literalExp)
{
return new NoValue("Cannot evaluate LiteralExp: " + literalExp);
}
public Object visit (ValueExp valueExp)
public Object visit (ValueExp<?> valueExp)
{
return valueExp.getValue();
}
@@ -336,67 +336,67 @@ public class ExpressionEvaluator
//
// NUMERICAL FUNCTIONS
public Void visit (Abs exp)
public Void visit (Abs<?> exp)
{
throw new IllegalArgumentException("Can't evaluate expression: " + exp);
}
public Void visit (Ceil exp)
public Void visit (Ceil<?> exp)
{
throw new IllegalArgumentException("Can't evaluate expression: " + exp);
}
public Void visit (Exp exp)
public Void visit (Exp<?> exp)
{
throw new IllegalArgumentException("Can't evaluate expression: " + exp);
}
public Void visit (Floor exp)
public Void visit (Floor<?> exp)
{
throw new IllegalArgumentException("Can't evaluate expression: " + exp);
}
public Void visit (Ln exp)
public Void visit (Ln<?> exp)
{
throw new IllegalArgumentException("Can't evaluate expression: " + exp);
}
public Void visit (Log10 exp)
public Void visit (Log10<?> exp)
{
throw new IllegalArgumentException("Can't evaluate expression: " + exp);
}
public Void visit (Pi exp)
public Void visit (Pi<?> exp)
{
throw new IllegalArgumentException("Can't evaluate expression: " + exp);
}
public Void visit (Power exp)
public Void visit (Power<?,?> exp)
{
throw new IllegalArgumentException("Can't evaluate expression: " + exp);
}
public Void visit (Random exp)
public Void visit (Random<?> exp)
{
throw new IllegalArgumentException("Can't evaluate expression: " + exp);
}
public Void visit (Round exp)
public Void visit (Round<?> exp)
{
throw new IllegalArgumentException("Can't evaluate expression: " + exp);
}
public Void visit (Sign exp)
public Void visit (Sign<?> exp)
{
throw new IllegalArgumentException("Can't evaluate expression: " + exp);
}
public Void visit (Sqrt exp)
public Void visit (Sqrt<?> exp)
{
throw new IllegalArgumentException("Can't evaluate expression: " + exp);
}
public Void visit (Trunc exp)
public Void visit (Trunc<?> exp)
{
throw new IllegalArgumentException("Can't evaluate expression: " + exp);
}
@@ -449,7 +449,7 @@ public class ExpressionEvaluator
throw new IllegalArgumentException("Can't evaluate expression: " + exp);
}
public Void visit (Average exp)
public Void visit (Average<?> exp)
{
throw new IllegalArgumentException("Can't evaluate expression: " + exp);
}
@@ -464,17 +464,17 @@ public class ExpressionEvaluator
throw new IllegalArgumentException("Can't evaluate expression: " + exp);
}
public Void visit (Max exp)
public Void visit (Max<?> exp)
{
throw new IllegalArgumentException("Can't evaluate expression: " + exp);
}
public Void visit (Min exp)
public Void visit (Min<?> exp)
{
throw new IllegalArgumentException("Can't evaluate expression: " + exp);
}
public Void visit (Sum exp)
public Void visit (Sum<?> exp)
{
throw new IllegalArgumentException("Can't evaluate expression: " + exp);
}
@@ -482,17 +482,17 @@ public class ExpressionEvaluator
//
// CONDITIONAL FUNCTIONS
public Void visit (Coalesce exp)
public Void visit (Coalesce<?> exp)
{
throw new IllegalArgumentException("Can't evaluate expression: " + exp);
}
public Void visit (Greatest exp)
public Void visit (Greatest<?> exp)
{
throw new IllegalArgumentException("Can't evaluate expression: " + exp);
}
public Void visit (Least exp)
public Void visit (Least<?> exp)
{
throw new IllegalArgumentException("Can't evaluate expression: " + exp);
}
@@ -89,8 +89,8 @@ public interface FragmentVisitor<T>
{
public T visit (FieldDefinition fieldOverride);
public T visit (FromOverride fromOverride);
public T visit (MultiOperator multiOperator);
public T visit (BinaryOperator binaryOperator);
public T visit (MultiOperator<?> multiOperator);
public T visit (BinaryOperator<?> binaryOperator);
public T visit (IsNull isNull);
public T visit (In in);
public T visit (FullText.Match match);
@@ -102,8 +102,8 @@ public interface FragmentVisitor<T>
public T visit (OrderBy orderBy);
public T visit (Join join);
public T visit (Limit limit);
public T visit (LiteralExp literal);
public T visit (ValueExp value);
public T visit (LiteralExp<?> literal);
public T visit (ValueExp<?> value);
public T visit (IntervalExp interval);
public T visit (WhereClause where);
public T visit (Key.Expression key);
@@ -114,22 +114,22 @@ public interface FragmentVisitor<T>
public T visit (InsertClause insertClause);
public T visit (CreateIndexClause createIndexClause);
public T visit (DropIndexClause dropIndexClause);
public T visit (Case caseExp);
public T visit (Case<?> caseExp);
// Numerical
public T visit (Abs exp);
public T visit (Ceil exp);
public T visit (Exp exp);
public T visit (Floor exp);
public T visit (Ln exp);
public T visit (Log10 exp);
public T visit (Pi exp);
public T visit (Power exp);
public T visit (Random exp);
public T visit (Round exp);
public T visit (Sign exp);
public T visit (Sqrt exp);
public T visit (Trunc exp);
public T visit (Abs<?> exp);
public T visit (Ceil<?> exp);
public T visit (Exp<?> exp);
public T visit (Floor<?> exp);
public T visit (Ln<?> exp);
public T visit (Log10<?> exp);
public T visit (Pi<?> exp);
public T visit (Power<?,?> exp);
public T visit (Random<?> exp);
public T visit (Round<?> exp);
public T visit (Sign<?> exp);
public T visit (Sqrt<?> exp);
public T visit (Trunc<?> exp);
// String
public T visit (Length exp);
@@ -145,15 +145,15 @@ public interface FragmentVisitor<T>
public T visit (Now exp);
// Aggregation
public T visit (Average exp);
public T visit (Average<?> exp);
public T visit (Count exp);
public T visit (Every exp);
public T visit (Max exp);
public T visit (Min exp);
public T visit (Sum exp);
public T visit (Max<?> exp);
public T visit (Min<?> exp);
public T visit (Sum<?> exp);
// Conditional
public T visit (Coalesce exp);
public T visit (Greatest exp);
public T visit (Least exp);
public T visit (Coalesce<?> exp);
public T visit (Greatest<?> exp);
public T visit (Least<?> exp);
}
@@ -71,12 +71,12 @@ public class HSQLBuilder
}
// now iterate over the cartesian product of the query words & the fields
List<SQLExpression> bits = Lists.newArrayList();
List<SQLExpression<?>> bits = Lists.newArrayList();
for (String field : fields) {
for (String ftsWord : ftsWords) {
// build comparisons between each word and column
bits.add(new Like(new Lower(
new ColumnExp<Object>(pClass, field)), "%"+ftsWord+"%", true));
bits.add(new Like(new Lower(new ColumnExp<String>(pClass, field)),
"%"+ftsWord+"%", true));
}
}
// then just OR them all together and we have our query
@@ -93,7 +93,7 @@ public class HSQLBuilder
}
@Override
public Void visit (MultiOperator operator)
public Void visit (MultiOperator<?> operator)
{
// HSQL doesn't handle & and | operators
if (operator instanceof BitAnd) {
@@ -225,7 +225,7 @@ public class HSQLBuilder
}
/** Holds the Full Text Seach condition between build and bind phases. */
protected SQLExpression _ftsCondition;
protected SQLExpression<?> _ftsCondition;
protected static final FieldMarshaller.ColumnTyper TYPER = new FieldMarshaller.ColumnTyper() {
public String getBooleanType (int length) {
@@ -72,7 +72,7 @@ public class MySQLBuilder
return null;
}
@Override public Void visit (Trunc exp)
@Override public Void visit (Trunc<?> exp)
{
return appendFunctionCall("truncate", exp.getArg());
}
@@ -28,7 +28,7 @@ import java.sql.SQLException;
import java.sql.Timestamp;
import com.samskivert.depot.DatabaseException;
import com.samskivert.depot.impl.expression.ValueExp;
import com.samskivert.depot.Exps;
import com.samskivert.depot.impl.operator.In;
import com.samskivert.util.ByteEnum;
@@ -43,7 +43,7 @@ public class PostgreSQL4Builder extends PostgreSQLBuilder
// if the In() expression is empty, replace it with a 'false'
final Comparable<?>[] values = in.getValues();
if (values.length == 0) {
new ValueExp(false).accept(this);
Exps.value(false).accept(this);
return null;
}
in.getExpression().accept(this);
@@ -43,7 +43,7 @@ public class CreateIndexClause
* database.
*/
public CreateIndexClause (Class<? extends PersistentRecord> pClass, String name, boolean unique,
List<Tuple<SQLExpression, Order>> fields)
List<Tuple<SQLExpression<?>, Order>> fields)
{
_pClass = pClass;
_name = name;
@@ -66,7 +66,7 @@ public class CreateIndexClause
return _unique;
}
public List<Tuple<SQLExpression,Order>> getFields ()
public List<Tuple<SQLExpression<?>,Order>> getFields ()
{
return _fields;
}
@@ -88,5 +88,5 @@ public class CreateIndexClause
protected boolean _unique;
/** The components of the index, e.g. columns or functions of columns. */
protected List<Tuple<SQLExpression,Order>> _fields;
protected List<Tuple<SQLExpression<?>,Order>> _fields;
}
@@ -47,7 +47,7 @@ public class UpdateClause
}
public UpdateClause (Class<? extends PersistentRecord> pClass, WhereClause where,
ColumnExp<?>[] fields, SQLExpression[] values)
ColumnExp<?>[] fields, SQLExpression<?>[] values)
{
_pClass = pClass;
_fields = fields;
@@ -66,7 +66,7 @@ public class UpdateClause
return _fields;
}
public SQLExpression[] getValues ()
public SQLExpression<?>[] getValues ()
{
return _values;
}
@@ -111,7 +111,7 @@ public class UpdateClause
protected ColumnExp<?>[] _fields;
/** The field values, or null. */
protected SQLExpression[] _values;
protected SQLExpression<?>[] _values;
/** The object from which to fetch values, or null. */
protected PersistentRecord _pojo;
@@ -24,13 +24,13 @@ import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.impl.FragmentVisitor;
import com.samskivert.depot.impl.expression.Function.OneArgFun;
public abstract class AggregateFun extends OneArgFun
public abstract class AggregateFun<T> extends OneArgFun<T>
{
public static class Average extends AggregateFun {
public Average (SQLExpression argument) {
public static class Average<T extends Number> extends AggregateFun<T> {
public Average (SQLExpression<T> argument) {
this(argument, false);
}
public Average (SQLExpression argument, boolean distinct) {
public Average (SQLExpression<T> argument, boolean distinct) {
super(argument, distinct);
}
public Object accept (FragmentVisitor<?> visitor) {
@@ -41,11 +41,11 @@ public abstract class AggregateFun extends OneArgFun
}
}
public static class Count extends AggregateFun {
public Count (SQLExpression argument) {
public static class Count extends AggregateFun<Integer> {
public Count (SQLExpression<?> argument) {
this(argument, false);
}
public Count (SQLExpression argument, boolean distinct) {
public Count (SQLExpression<?> argument, boolean distinct) {
super(argument, distinct);
}
public Object accept (FragmentVisitor<?> visitor) {
@@ -56,11 +56,11 @@ public abstract class AggregateFun extends OneArgFun
}
}
public static class Every extends AggregateFun {
public Every (SQLExpression argument) {
public static class Every extends AggregateFun<Boolean> {
public Every (SQLExpression<?> argument) {
this(argument, false);
}
public Every (SQLExpression argument, boolean distinct) {
public Every (SQLExpression<?> argument, boolean distinct) {
super(argument, distinct);
}
public Object accept (FragmentVisitor<?> visitor) {
@@ -71,11 +71,11 @@ public abstract class AggregateFun extends OneArgFun
}
}
public static class Max extends AggregateFun {
public Max (SQLExpression argument) {
public static class Max<T extends Number> extends AggregateFun<T> {
public Max (SQLExpression<T> argument) {
this(argument, false);
}
public Max (SQLExpression argument, boolean distinct) {
public Max (SQLExpression<T> argument, boolean distinct) {
super(argument, distinct);
}
public Object accept (FragmentVisitor<?> visitor) {
@@ -86,11 +86,11 @@ public abstract class AggregateFun extends OneArgFun
}
}
public static class Min extends AggregateFun {
public Min (SQLExpression argument) {
public static class Min<T extends Number> extends AggregateFun<T> {
public Min (SQLExpression<T> argument) {
this(argument, false);
}
public Min (SQLExpression argument, boolean distinct) {
public Min (SQLExpression<T> argument, boolean distinct) {
super(argument, distinct);
}
public Object accept (FragmentVisitor<?> visitor) {
@@ -101,11 +101,11 @@ public abstract class AggregateFun extends OneArgFun
}
}
public static class Sum extends AggregateFun {
public Sum (SQLExpression argument) {
public static class Sum<T extends Number> extends AggregateFun<T> {
public Sum (SQLExpression<T> argument) {
this(argument, false);
}
public Sum (SQLExpression argument, boolean distinct) {
public Sum (SQLExpression<T> argument, boolean distinct) {
super(argument, distinct);
}
public Object accept (FragmentVisitor<?> visitor) {
@@ -116,7 +116,7 @@ public abstract class AggregateFun extends OneArgFun
}
}
public AggregateFun (SQLExpression argument, boolean distinct)
public AggregateFun (SQLExpression<?> argument, boolean distinct)
{
super(argument);
_distinct = distinct;
@@ -26,24 +26,24 @@ import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.expression.FluentExp;
import com.samskivert.depot.expression.SQLExpression;
public abstract class ArgumentExp extends FluentExp
public abstract class ArgumentExp<T> extends FluentExp<T>
{
protected ArgumentExp (SQLExpression... args)
protected ArgumentExp (SQLExpression<?>... args)
{
_args = args;
}
public void addClasses (Collection<Class<? extends PersistentRecord>> classSet)
{
for (SQLExpression arg : _args) {
for (SQLExpression<?> arg : _args) {
arg.addClasses(classSet);
}
}
public SQLExpression[] getArgs ()
public SQLExpression<?>[] getArgs ()
{
return _args;
}
protected SQLExpression[] _args;
protected SQLExpression<?>[] _args;
}
@@ -26,10 +26,13 @@ import com.samskivert.depot.impl.expression.Function.ManyArgFun;
public abstract class ConditionalFun
{
public static class Coalesce extends ManyArgFun {
public Coalesce (SQLExpression... args) {
public static class Coalesce<T> extends ManyArgFun<T> {
public Coalesce (SQLExpression<? extends T>... args) {
super(args);
}
public Coalesce (SQLExpression<? extends T> arg1, SQLExpression<? extends T> arg2) {
super(arg1, arg2);
}
public Object accept (FragmentVisitor<?> visitor) {
return visitor.visit(this);
}
@@ -38,10 +41,13 @@ public abstract class ConditionalFun
}
}
public static class Greatest extends ManyArgFun {
public Greatest (SQLExpression... args) {
public static class Greatest<T extends Number> extends ManyArgFun<T> {
public Greatest (SQLExpression<? extends T>... args) {
super(args);
}
public Greatest (SQLExpression<? extends T> arg1, SQLExpression<? extends T> arg2) {
super(arg1, arg2);
}
public Object accept (FragmentVisitor<?> visitor) {
return visitor.visit(this);
}
@@ -50,10 +56,13 @@ public abstract class ConditionalFun
}
}
public static class Least extends ManyArgFun {
public Least (SQLExpression... args) {
public static class Least<T extends Number> extends ManyArgFun<T> {
public Least (SQLExpression<? extends T>... args) {
super(args);
}
public Least (SQLExpression<? extends T> arg1, SQLExpression<? extends T> arg2) {
super(arg1, arg2);
}
public Object accept (FragmentVisitor<?> visitor) {
return visitor.visit(this);
}
@@ -20,6 +20,9 @@
package com.samskivert.depot.impl.expression;
import java.sql.Date;
import java.sql.Timestamp;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.impl.FragmentVisitor;
import com.samskivert.depot.impl.expression.Function.NoArgFun;
@@ -27,12 +30,12 @@ import com.samskivert.depot.impl.expression.Function.OneArgFun;
public abstract class DateFun
{
public static class DatePart extends OneArgFun {
public static class DatePart extends OneArgFun<Integer> {
public enum Part {
DAY_OF_MONTH, DAY_OF_WEEK, DAY_OF_YEAR, HOUR, MINUTE, MONTH,
SECOND, WEEK, YEAR, EPOCH
}
public DatePart (SQLExpression date, Part part) {
public DatePart (SQLExpression<?> date, Part part) {
super(date);
_part = part;
}
@@ -48,7 +51,7 @@ public abstract class DateFun
protected Part _part;
}
public static class DateTruncate extends OneArgFun {
public static class DateTruncate extends OneArgFun<Date> {
/**
* The degree of truncation to perform, in time units. Currently only DAY, due to lacking
* MySQL support, but we hope for future versions to match PostgreSQL.
@@ -60,7 +63,7 @@ public abstract class DateFun
* Truncate a SQL timestamp value, currently only to the nearest day (Truncation.DAY) due
* to lacking MySQL support, but we hope for future versions to match PostgreSQL.
*/
public DateTruncate (SQLExpression date, Truncation truncation) {
public DateTruncate (SQLExpression<?> date, Truncation truncation) {
super(date);
_truncation= truncation;
}
@@ -76,7 +79,7 @@ public abstract class DateFun
protected Truncation _truncation;
}
public static class Now extends NoArgFun {
public static class Now extends NoArgFun<Timestamp> {
public Object accept (FragmentVisitor<?> visitor) {
return visitor.visit(this);
}
@@ -31,7 +31,7 @@ public interface Function
{
String getCanonicalFunctionName ();
public static abstract class NoArgFun extends FluentExp implements Function
public static abstract class NoArgFun<T> extends FluentExp<T> implements Function
{
public void addClasses (Collection<Class<? extends PersistentRecord>> classSet)
{
@@ -39,9 +39,9 @@ public interface Function
}
}
public static abstract class OneArgFun extends FluentExp implements Function
public static abstract class OneArgFun<T> extends FluentExp<T> implements Function
{
protected OneArgFun (SQLExpression argument)
protected OneArgFun (SQLExpression<?> argument)
{
_arg = argument;
}
@@ -51,7 +51,7 @@ public interface Function
_arg.addClasses(classSet);
}
public SQLExpression getArg ()
public SQLExpression<?> getArg ()
{
return _arg;
}
@@ -62,12 +62,12 @@ public interface Function
return getCanonicalFunctionName() + "(" + _arg + ")";
}
protected SQLExpression _arg;
protected SQLExpression<?> _arg;
}
public static abstract class TwoArgFun extends FluentExp implements Function
public static abstract class TwoArgFun<T> extends FluentExp<T> implements Function
{
protected TwoArgFun (SQLExpression arg1, SQLExpression arg2)
protected TwoArgFun (SQLExpression<?> arg1, SQLExpression<?> arg2)
{
_arg1 = arg1;
_arg2 = arg2;
@@ -85,16 +85,25 @@ public interface Function
return getCanonicalFunctionName() + "(" + _arg1 + ", " + _arg2 + ")";
}
protected SQLExpression _arg1, _arg2;
protected SQLExpression<?> _arg1, _arg2;
}
public static abstract class ManyArgFun extends ArgumentExp implements Function
public static abstract class ManyArgFun<T> extends ArgumentExp<T> implements Function
{
protected ManyArgFun (SQLExpression... args)
protected ManyArgFun (SQLExpression<?>... args)
{
super(args);
}
// we specialize for arity two to allow subtypes who require proper generic types to
// provide arity two constructors for use in 99% of the cases where you don't need
// arbitrary arguments and don't want to have to suppress the annoying use-site generic
// varargs array creation warning
protected ManyArgFun (SQLExpression<?> arg1, SQLExpression<?> arg2)
{
super(arg1, arg2);
}
@Override
public String toString ()
{
@@ -30,7 +30,7 @@ import com.samskivert.depot.impl.FragmentVisitor;
* A code for representing a date interval.
*/
public class IntervalExp
implements SQLExpression
implements SQLExpression<Integer>
{
/** The units that can be used for an interval. */
public enum Unit { YEAR, MONTH, DAY, HOUR, MINUTE, SECOND }
@@ -29,8 +29,8 @@ import com.samskivert.depot.impl.FragmentVisitor;
/**
* An expression for things we don't support natively, e.g. COUNT(*).
*/
public class LiteralExp
implements SQLExpression
public class LiteralExp<T>
implements SQLExpression<T>
{
public LiteralExp (String text)
{
@@ -28,8 +28,8 @@ import com.samskivert.depot.impl.expression.Function.TwoArgFun;
public abstract class NumericalFun
{
public static class Abs extends OneArgFun {
public Abs (SQLExpression argument) {
public static class Abs<T extends Number> extends OneArgFun<T> {
public Abs (SQLExpression<T> argument) {
super(argument);
}
public Object accept (FragmentVisitor<?> visitor) {
@@ -40,8 +40,8 @@ public abstract class NumericalFun
}
}
public static class Ceil extends OneArgFun {
public Ceil (SQLExpression argument) {
public static class Ceil<T extends Number> extends OneArgFun<T> {
public Ceil (SQLExpression<T> argument) {
super(argument);
}
public Object accept (FragmentVisitor<?> visitor) {
@@ -52,8 +52,8 @@ public abstract class NumericalFun
}
}
public static class Exp extends OneArgFun {
public Exp (SQLExpression argument) {
public static class Exp<T extends Number> extends OneArgFun<T> {
public Exp (SQLExpression<T> argument) {
super(argument);
}
public Object accept (FragmentVisitor<?> visitor) {
@@ -64,8 +64,8 @@ public abstract class NumericalFun
}
}
public static class Floor extends OneArgFun {
public Floor (SQLExpression argument) {
public static class Floor<T extends Number> extends OneArgFun<T> {
public Floor (SQLExpression<T> argument) {
super(argument);
}
public Object accept (FragmentVisitor<?> visitor) {
@@ -76,8 +76,8 @@ public abstract class NumericalFun
}
}
public static class Ln extends OneArgFun {
public Ln (SQLExpression argument) {
public static class Ln<T extends Number> extends OneArgFun<T> {
public Ln (SQLExpression<T> argument) {
super(argument);
}
public Object accept (FragmentVisitor<?> visitor) {
@@ -88,8 +88,8 @@ public abstract class NumericalFun
}
}
public static class Log10 extends OneArgFun {
public Log10 (SQLExpression value) {
public static class Log10<T extends Number> extends OneArgFun<T> {
public Log10 (SQLExpression<T> value) {
super(value);
}
public Object accept (FragmentVisitor<?> visitor) {
@@ -100,7 +100,7 @@ public abstract class NumericalFun
}
}
public static class Pi extends NoArgFun {
public static class Pi<T extends Number> extends NoArgFun<T> {
public Object accept (FragmentVisitor<?> visitor) {
return visitor.visit(this);
}
@@ -109,8 +109,8 @@ public abstract class NumericalFun
}
}
public static class Power extends TwoArgFun {
public Power (SQLExpression value, SQLExpression power) {
public static class Power<R extends Number,P extends Number> extends TwoArgFun<R> {
public Power (SQLExpression<R> value, SQLExpression<P> power) {
super(value, power);
}
public Object accept (FragmentVisitor<?> visitor) {
@@ -119,15 +119,15 @@ public abstract class NumericalFun
public String getCanonicalFunctionName () {
return "Power";
}
public SQLExpression getValue () {
public SQLExpression<?> getValue () {
return _arg1;
}
public SQLExpression getPower () {
public SQLExpression<?> getPower () {
return _arg2;
}
}
public static class Random extends NoArgFun {
public static class Random<T extends Number> extends NoArgFun<T> {
public Object accept (FragmentVisitor<?> visitor) {
return visitor.visit(this);
}
@@ -136,8 +136,8 @@ public abstract class NumericalFun
}
}
public static class Round extends OneArgFun {
public Round (SQLExpression argument) {
public static class Round<T extends Number> extends OneArgFun<T> {
public Round (SQLExpression<T> argument) {
super(argument);
}
public Object accept (FragmentVisitor<?> visitor) {
@@ -148,8 +148,8 @@ public abstract class NumericalFun
}
}
public static class Sign extends OneArgFun {
public Sign (SQLExpression argument) {
public static class Sign<T extends Number> extends OneArgFun<T> {
public Sign (SQLExpression<T> argument) {
super(argument);
}
public Object accept (FragmentVisitor<?> visitor) {
@@ -160,8 +160,8 @@ public abstract class NumericalFun
}
}
public static class Sqrt extends OneArgFun {
public Sqrt (SQLExpression argument) {
public static class Sqrt<T extends Number> extends OneArgFun<T> {
public Sqrt (SQLExpression<T> argument) {
super(argument);
}
public Object accept (FragmentVisitor<?> visitor) {
@@ -172,8 +172,8 @@ public abstract class NumericalFun
}
}
public static class Trunc extends OneArgFun {
public Trunc (SQLExpression argument) {
public static class Trunc<T extends Number> extends OneArgFun<T> {
public Trunc (SQLExpression<T> argument) {
super(argument);
}
public Object accept (FragmentVisitor<?> visitor) {
@@ -28,8 +28,9 @@ import com.samskivert.depot.impl.expression.Function.TwoArgFun;
public abstract class StringFun
{
public static class Length extends OneArgFun {
public Length (SQLExpression argument) {
public static class Length extends OneArgFun<Integer> {
// can take both String or array types (anything that turns into byte[])
public Length (SQLExpression<?> argument) {
super(argument);
}
public Object accept (FragmentVisitor<?> visitor) {
@@ -40,8 +41,8 @@ public abstract class StringFun
}
}
public static class Lower extends OneArgFun {
public Lower (SQLExpression argument) {
public static class Lower extends OneArgFun<String> {
public Lower (SQLExpression<String> argument) {
super(argument);
}
public Object accept (FragmentVisitor<?> visitor) {
@@ -52,8 +53,8 @@ public abstract class StringFun
}
}
public static class Position extends TwoArgFun {
public Position (SQLExpression substring, SQLExpression string) {
public static class Position extends TwoArgFun<Integer> {
public Position (SQLExpression<String> substring, SQLExpression<String> string) {
super(substring, string);
}
public Object accept (FragmentVisitor<?> visitor) {
@@ -62,16 +63,17 @@ public abstract class StringFun
public String getCanonicalFunctionName () {
return "position";
}
public SQLExpression getSubString () {
public SQLExpression<?> getSubString () {
return _arg1;
}
public SQLExpression getString () {
public SQLExpression<?> getString () {
return _arg2;
}
}
public static class Substring extends ManyArgFun {
public Substring (SQLExpression string, SQLExpression from, SQLExpression count) {
public static class Substring extends ManyArgFun<String> {
public Substring (SQLExpression<String> string, SQLExpression<String> from,
SQLExpression<Integer> count) {
super(string, from, count);
}
public Object accept (FragmentVisitor<?> visitor) {
@@ -82,8 +84,8 @@ public abstract class StringFun
}
}
public static class Trim extends OneArgFun {
public Trim (SQLExpression argument) {
public static class Trim extends OneArgFun<String> {
public Trim (SQLExpression<String> argument) {
super(argument);
}
public Object accept (FragmentVisitor<?> visitor) {
@@ -94,8 +96,8 @@ public abstract class StringFun
}
}
public static class Upper extends OneArgFun {
public Upper (SQLExpression argument) {
public static class Upper extends OneArgFun<String> {
public Upper (SQLExpression<String> argument) {
super(argument);
}
public Object accept (FragmentVisitor<?> visitor) {
@@ -29,9 +29,9 @@ import com.samskivert.depot.impl.FragmentVisitor;
/**
* A Java value that is bound as a parameter to the query, e.g. 1 or 'abc'.
*/
public class ValueExp extends FluentExp
public class ValueExp<T> extends FluentExp<T>
{
public ValueExp (Object value)
public ValueExp (T value)
{
_value = value;
}
@@ -47,7 +47,7 @@ public class ValueExp extends FluentExp
{
}
public Object getValue ()
public T getValue ()
{
return _value;
}
@@ -59,5 +59,5 @@ public class ValueExp extends FluentExp
}
/** The value to be bound to the SQL parameters. */
protected Object _value;
protected T _value;
}
@@ -25,14 +25,14 @@ import com.samskivert.depot.expression.SQLExpression;
/**
* The SQL '+' operator.
*/
public class Add extends Arithmetic
public class Add<T extends Number> extends Arithmetic<T>
{
public Add (SQLExpression column, Comparable<?> value)
public Add (SQLExpression<?> column, T value)
{
super(column, value);
}
public Add (SQLExpression... values)
public Add (SQLExpression<?>... values)
{
super(values);
}
@@ -26,14 +26,14 @@ import com.samskivert.depot.impl.expression.ValueExp;
/**
* A convenient container for implementations of arithmetic operators.
*/
public abstract class Arithmetic extends MultiOperator
public abstract class Arithmetic<T extends Number> extends MultiOperator<T>
{
public Arithmetic (SQLExpression column, Comparable<?> value)
public Arithmetic (SQLExpression<?> column, T value)
{
super(column, new ValueExp(value));
super(column, new ValueExp<T>(value));
}
public Arithmetic (SQLExpression... values)
public Arithmetic (SQLExpression<?>... values)
{
super(values);
}
@@ -15,7 +15,7 @@ import com.samskivert.depot.impl.expression.ArgumentExp;
/**
* A base class for all operators.
*/
public abstract class BaseOperator extends ArgumentExp
public abstract class BaseOperator<T> extends ArgumentExp<T>
{
public static Function<Object, Long> INTEGRAL = new Function<Object, Long>() {
public Long apply (Object o) {
@@ -60,7 +60,7 @@ public abstract class BaseOperator extends ArgumentExp
return v;
}
protected BaseOperator (SQLExpression... operands)
protected BaseOperator (SQLExpression<?>... operands)
{
super(operands);
}
@@ -3,23 +3,23 @@
package com.samskivert.depot.impl.operator;
import com.samskivert.depot.Exps;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.impl.FragmentVisitor;
import com.samskivert.depot.impl.expression.ValueExp;
/**
* Does the real work for simple binary operators such as Equals.
*/
public abstract class BinaryOperator extends BaseOperator
public abstract class BinaryOperator<T> extends BaseOperator<T>
{
public BinaryOperator (SQLExpression lhs, SQLExpression rhs)
public BinaryOperator (SQLExpression<?> lhs, SQLExpression<?> rhs)
{
super(lhs, rhs);
}
public BinaryOperator (SQLExpression lhs, Comparable<?> rhs)
public BinaryOperator (SQLExpression<?> lhs, Comparable<?> rhs)
{
this(lhs, new ValueExp(rhs));
this(lhs, Exps.value(rhs));
}
/**
@@ -38,12 +38,12 @@ public abstract class BinaryOperator extends BaseOperator
return builder.visit(this);
}
public SQLExpression getLeftHandSide ()
public SQLExpression<?> getLeftHandSide ()
{
return _args[0];
}
public SQLExpression getRightHandSide ()
public SQLExpression<?> getRightHandSide ()
{
return _args[1];
}
@@ -25,14 +25,14 @@ import com.samskivert.depot.expression.SQLExpression;
/**
* The SQL '&' operator.
*/
public class BitAnd extends Arithmetic
public class BitAnd<T extends Number> extends Arithmetic<T>
{
public BitAnd (SQLExpression column, Comparable<?> value)
public BitAnd (SQLExpression<?> column, T value)
{
super(column, value);
}
public BitAnd (SQLExpression... values)
public BitAnd (SQLExpression<?>... values)
{
super(values);
}
@@ -25,14 +25,14 @@ import com.samskivert.depot.expression.SQLExpression;
/**
* The SQL '|' operator.
*/
public class BitOr extends Arithmetic
public class BitOr<T extends Number> extends Arithmetic<T>
{
public BitOr (SQLExpression column, Comparable<?> value)
public BitOr (SQLExpression<?> column, T value)
{
super(column, value);
}
public BitOr (SQLExpression... values)
public BitOr (SQLExpression<?>... values)
{
super(values);
}
@@ -27,14 +27,14 @@ import com.samskivert.depot.expression.SQLExpression;
/**
* The SQL '/' operator.
*/
public class Div extends Arithmetic
public class Div<T extends Number> extends Arithmetic<T>
{
public Div (SQLExpression column, Comparable<?> value)
public Div (SQLExpression<?> column, T value)
{
super(column, value);
}
public Div (SQLExpression... values)
public Div (SQLExpression<?>... values)
{
super(values);
}
@@ -25,14 +25,14 @@ import com.samskivert.depot.expression.SQLExpression;
/**
* The SQL '=' operator.
*/
public class Equals extends BinaryOperator
public class Equals extends BinaryOperator<Boolean>
{
public Equals (SQLExpression column, Comparable<?> value)
public Equals (SQLExpression<?> column, Comparable<?> value)
{
super(column, value);
}
public Equals (SQLExpression column, SQLExpression value)
public Equals (SQLExpression<?> column, SQLExpression<?> value)
{
super(column, value);
}
@@ -31,7 +31,7 @@ import com.samskivert.depot.impl.FragmentVisitor;
* The SQL 'exists' operator.
*/
public class Exists
implements SQLExpression
implements SQLExpression<Boolean>
{
public Exists (SelectClause clause)
{
@@ -25,14 +25,14 @@ import com.samskivert.depot.expression.SQLExpression;
/**
* The SQL '>' operator.
*/
public class GreaterThan extends BinaryOperator
public class GreaterThan extends BinaryOperator<Boolean>
{
public GreaterThan (SQLExpression column, Comparable<?> value)
public GreaterThan (SQLExpression<?> column, Comparable<?> value)
{
super(column, value);
}
public GreaterThan (SQLExpression column, SQLExpression value)
public GreaterThan (SQLExpression<?> column, SQLExpression<?> value)
{
super(column, value);
}
@@ -25,14 +25,14 @@ import com.samskivert.depot.expression.SQLExpression;
/**
* The SQL '>=' operator.
*/
public class GreaterThanEquals extends BinaryOperator
public class GreaterThanEquals extends BinaryOperator<Boolean>
{
public GreaterThanEquals (SQLExpression column, Comparable<?> value)
public GreaterThanEquals (SQLExpression<?> column, Comparable<?> value)
{
super(column, value);
}
public GreaterThanEquals (SQLExpression column, SQLExpression value)
public GreaterThanEquals (SQLExpression<?> column, SQLExpression<?> value)
{
super(column, value);
}
@@ -31,23 +31,23 @@ import com.samskivert.depot.impl.FragmentVisitor;
* The SQL 'in (...)' operator.
*/
public class In
implements SQLExpression
implements SQLExpression<Boolean>
{
/** The maximum number of keys allowed in an IN() clause. */
public static final int MAX_KEYS = Short.MAX_VALUE;
public In (SQLExpression expression, Comparable<?>... values)
public In (SQLExpression<?> expression, Comparable<?>... values)
{
_expression = expression;
_values = values;
}
public In (SQLExpression pColumn, Iterable<? extends Comparable<?>> values)
public In (SQLExpression<?> pColumn, Iterable<? extends Comparable<?>> values)
{
this(pColumn, Iterables.toArray(values, Comparable.class));
}
public SQLExpression getExpression ()
public SQLExpression<?> getExpression ()
{
return _expression;
}
@@ -84,6 +84,6 @@ public class In
return builder.append(")").toString();
}
protected SQLExpression _expression;
protected SQLExpression<?> _expression;
protected Comparable<?>[] _values;
}
@@ -30,14 +30,14 @@ import com.samskivert.depot.impl.FragmentVisitor;
* The SQL 'is null' operator.
*/
public class IsNull
implements SQLExpression
implements SQLExpression<Boolean>
{
public IsNull (SQLExpression expression)
public IsNull (SQLExpression<?> expression)
{
_expression = expression;
}
public SQLExpression getExpression ()
public SQLExpression<?> getExpression ()
{
return _expression;
}
@@ -59,5 +59,5 @@ public class IsNull
return "IsNull(" + _expression + ")";
}
protected SQLExpression _expression;
protected SQLExpression<?> _expression;
}
@@ -25,14 +25,14 @@ import com.samskivert.depot.expression.SQLExpression;
/**
* The SQL '<' operator.
*/
public class LessThan extends BinaryOperator
public class LessThan extends BinaryOperator<Boolean>
{
public LessThan (SQLExpression column, Comparable<?> value)
public LessThan (SQLExpression<?> column, Comparable<?> value)
{
super(column, value);
}
public LessThan (SQLExpression column, SQLExpression value)
public LessThan (SQLExpression<?> column, SQLExpression<?> value)
{
super(column, value);
}
@@ -25,14 +25,14 @@ import com.samskivert.depot.expression.SQLExpression;
/**
* The SQL '<=' operator.
*/
public class LessThanEquals extends BinaryOperator
public class LessThanEquals extends BinaryOperator<Boolean>
{
public LessThanEquals (SQLExpression column, Comparable<?> value)
public LessThanEquals (SQLExpression<?> column, Comparable<?> value)
{
super(column, value);
}
public LessThanEquals (SQLExpression column, SQLExpression value)
public LessThanEquals (SQLExpression<?> column, SQLExpression<?> value)
{
super(column, value);
}
@@ -25,15 +25,15 @@ import com.samskivert.depot.expression.SQLExpression;
/**
* The SQL 'like' (and 'not like') operator.
*/
public class Like extends BinaryOperator
public class Like extends BinaryOperator<Boolean>
{
public Like (SQLExpression column, Comparable<?> value, boolean like)
public Like (SQLExpression<?> column, Comparable<?> value, boolean like)
{
super(column, value);
_like = like;
}
public Like (SQLExpression column, SQLExpression value, boolean like)
public Like (SQLExpression<?> column, SQLExpression<?> value, boolean like)
{
super(column, value);
_like = like;
@@ -25,14 +25,14 @@ import com.samskivert.depot.expression.SQLExpression;
/**
* The SQL '*' operator.
*/
public class Mul extends Arithmetic
public class Mul<T extends Number> extends Arithmetic<T>
{
public Mul (SQLExpression column, Comparable<?> value)
public Mul (SQLExpression<?> column, T value)
{
super(column, value);
}
public Mul (SQLExpression... values)
public Mul (SQLExpression<?>... values)
{
super(values);
}
@@ -12,9 +12,9 @@ import com.samskivert.depot.impl.FragmentVisitor;
/**
* Represents an operator with any number of operands.
*/
public abstract class MultiOperator extends BaseOperator
public abstract class MultiOperator<T> extends BaseOperator<T>
{
public MultiOperator (SQLExpression ... operands)
public MultiOperator (SQLExpression<?>... operands)
{
super(operands);
}
@@ -38,7 +38,7 @@ public abstract class MultiOperator extends BaseOperator
@Override // from SQLFragment
public void addClasses (Collection<Class<? extends PersistentRecord>> classSet)
{
for (SQLExpression operand : _args) {
for (SQLExpression<?> operand : _args) {
operand.addClasses(classSet);
}
}
@@ -47,7 +47,7 @@ public abstract class MultiOperator extends BaseOperator
public String toString ()
{
StringBuilder builder = new StringBuilder("(");
for (SQLExpression operand : _args) {
for (SQLExpression<?> operand : _args) {
if (builder.length() > 1) {
builder.append(operator());
}
@@ -30,14 +30,14 @@ import com.samskivert.depot.impl.FragmentVisitor;
* Represents the truth negation of another conditon.
*/
public class Not
implements SQLExpression
implements SQLExpression<Boolean>
{
public Not (SQLExpression condition)
public Not (SQLExpression<Boolean> condition)
{
_condition = condition;
}
public SQLExpression getCondition ()
public SQLExpression<Boolean> getCondition ()
{
return _condition;
}
@@ -60,5 +60,5 @@ public class Not
return "Not(" + _condition + ")";
}
protected SQLExpression _condition;
protected SQLExpression<Boolean> _condition;
}
@@ -25,14 +25,14 @@ import com.samskivert.depot.expression.SQLExpression;
/**
* The SQL '!=' operator.
*/
public class NotEquals extends BinaryOperator
public class NotEquals extends BinaryOperator<Boolean>
{
public NotEquals (SQLExpression column, Comparable<?> value)
public NotEquals (SQLExpression<?> column, Comparable<?> value)
{
super(column, value);
}
public NotEquals (SQLExpression column, SQLExpression value)
public NotEquals (SQLExpression<?> column, SQLExpression<?> value)
{
super(column, value);
}
@@ -25,14 +25,14 @@ import com.samskivert.depot.expression.SQLExpression;
/**
* The SQL '-' operator.
*/
public class Sub extends Arithmetic
public class Sub<T extends Number> extends Arithmetic<T>
{
public Sub (SQLExpression column, Comparable<?> value)
public Sub (SQLExpression<?> column, T value)
{
super(column, value);
}
public Sub (SQLExpression... values)
public Sub (SQLExpression<?>... values)
{
super(values);
}
@@ -33,10 +33,10 @@ import com.samskivert.util.Tuple;
/**
* The SQL 'case' operator.
*/
public class Case
implements SQLExpression
public class Case<T>
implements SQLExpression<T>
{
public Case (SQLExpression... exps)
public Case (SQLExpression<?>... exps)
{
int i = 0;
while (i+1 < exps.length) {
@@ -46,12 +46,12 @@ public class Case
_elseExp = (i < exps.length) ? exps[i] : null;
}
public List<Tuple<SQLExpression, SQLExpression>> getWhenExps ()
public List<Tuple<SQLExpression<?>, SQLExpression<?>>> getWhenExps ()
{
return _whenExps;
}
public SQLExpression getElseExp ()
public SQLExpression<?> getElseExp ()
{
return _elseExp;
}
@@ -65,7 +65,7 @@ public class Case
// from SQLExpression
public void addClasses (Collection<Class<? extends PersistentRecord>> classSet)
{
for (Tuple<SQLExpression, SQLExpression> tuple : _whenExps) {
for (Tuple<SQLExpression<?>, SQLExpression<?>> tuple : _whenExps) {
tuple.left.addClasses(classSet);
tuple.right.addClasses(classSet);
}
@@ -79,7 +79,7 @@ public class Case
{
StringBuilder builder = new StringBuilder();
builder.append("Case(");
for (Tuple<SQLExpression, SQLExpression> tuple : _whenExps) {
for (Tuple<SQLExpression<?>, SQLExpression<?>> tuple : _whenExps) {
builder.append(tuple.left.toString()).append("->");
builder.append(tuple.right.toString()).append(",");
}
@@ -89,6 +89,6 @@ public class Case
return builder.toString();
}
protected List<Tuple<SQLExpression, SQLExpression>> _whenExps = Lists.newArrayList();
protected SQLExpression _elseExp;
protected List<Tuple<SQLExpression<?>, SQLExpression<?>>> _whenExps = Lists.newArrayList();
protected SQLExpression<?> _elseExp;
}
@@ -32,7 +32,7 @@ import com.samskivert.depot.impl.FragmentVisitor;
*/
public class FullText
{
public class Rank extends FluentExp
public class Rank extends FluentExp<Number>
{
// from SQLExpression
public Object accept (FragmentVisitor<?> builder)
@@ -57,7 +57,7 @@ public class FullText
}
}
public class Match extends FluentExp
public class Match extends FluentExp<Boolean>
{
// from SQLExpression
public Object accept (FragmentVisitor<?> builder)
@@ -20,7 +20,6 @@
package com.samskivert.depot;
import java.util.List;
import java.util.Set;
import org.junit.Test;
@@ -23,8 +23,6 @@ package com.samskivert.depot;
import org.junit.Test;
import static org.junit.Assert.*;
import com.samskivert.depot.clause.Where;
/**
* Tests row counting.
*/
@@ -41,7 +39,7 @@ public class CountTest extends TestBase
assertEquals(49, _repo.from(TestRecord.class).
where(TestRecord.RECORD_ID.lessThan(50)).selectCount());
_repo.deleteAll(TestRecord.class, new Where(Exps.trueLiteral()));
_repo.from(TestRecord.class).whereTrue().delete();
assertEquals(0, _repo.from(TestRecord.class).
where(TestRecord.RECORD_ID.lessThan(50)).selectCount());
@@ -39,7 +39,7 @@ public class KeyTest extends TestBase
Key<MonkeyRecord> key = MonkeyRecord.getKey(species, monkeyId);
// make sure that the arguments we passed in got assigned in the right positions
ColumnExp[] kfs = DepotUtil.getKeyFields(MonkeyRecord.class);
ColumnExp<?>[] kfs = DepotUtil.getKeyFields(MonkeyRecord.class);
int kspecies = 0, kmonkeyId = 0;
for (int ii = 0; ii < kfs.length; ii++) {
if (MonkeyRecord.SPECIES.equals(kfs[ii])) {
@@ -58,7 +58,7 @@ public class KeyTest extends TestBase
Key<TestRecord> key = TestRecord.getKey(recordId);
// make sure that the arguments we passed in got assigned in the right positions
ColumnExp[] kfs = DepotUtil.getKeyFields(TestRecord.class);
ColumnExp<?>[] kfs = DepotUtil.getKeyFields(TestRecord.class);
int krecordId = 0;
for (int ii = 0; ii < kfs.length; ii++) {
if (TestRecord.RECORD_ID.equals(kfs[ii])) {
@@ -82,7 +82,7 @@ public class KeyTest extends TestBase
assertEquals("beee", _repo.loadEnum(EnumKeyRecord.Type.B).name);
_repo.from(EnumKeyRecord.class).where(Exps.trueLiteral()).delete();
_repo.from(EnumKeyRecord.class).whereTrue().delete();
}
// the HSQL in-memory database persists for the lifetime of the VM, which means we have to
@@ -30,7 +30,6 @@ import static org.junit.Assert.*;
import com.samskivert.depot.annotation.Computed;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.clause.Where;
/**
* Tests queries.
@@ -64,7 +63,7 @@ public class QueryTest extends TestBase
assertEquals(0, _repo.deleteAll(TestRecord.class, none));
// test collection caching (TODO: check that the records are ==)
SQLExpression where = TestRecord.RECORD_ID.greaterThan(CREATE_RECORDS-50);
SQLExpression<Boolean> where = TestRecord.RECORD_ID.greaterThan(CREATE_RECORDS-50);
assertEquals(50, _repo.from(TestRecord.class).where(where).select().size());
assertEquals(50, _repo.from(TestRecord.class).where(where).select().size());
@@ -79,10 +78,10 @@ public class QueryTest extends TestBase
}
assertEquals(CREATE_RECORDS, _repo.findAll(TestRecord.class).size());
_repo.deleteAll(TestRecord.class, new Where(TestRecord.RECORD_ID.lessEq(CREATE_RECORDS/2)));
_repo.from(TestRecord.class).where(TestRecord.RECORD_ID.lessEq(CREATE_RECORDS/2)).delete();
assertEquals(CREATE_RECORDS/2, _repo.findAll(TestRecord.class).size());
_repo.deleteAll(TestRecord.class, new Where(Exps.trueLiteral()));
_repo.from(TestRecord.class).whereTrue().delete();
assertEquals(0, _repo.findAll(TestRecord.class).size());
// // TODO: try to break our In() clause
@@ -53,8 +53,10 @@ public class SelectFieldsTest extends TestBase
List<Tuple2<Integer,String>> data = _repo.from(TestRecord.class).where(
TestRecord.RECORD_ID.greaterThan(7)).select(TestRecord.RECORD_ID, TestRecord.NAME);
assertEquals(data, Lists.newArrayList(Tuple2.newTuple(8, "Elvis"),
Tuple2.newTuple(9, "Elvis")));
List<Tuple2<Integer,String>> want = Lists.newArrayList();
want.add(Tuple2.newTuple(8, "Elvis"));
want.add(Tuple2.newTuple(9, "Elvis"));
assertEquals(data, want);
// test a basic join
List<Tuple2<Integer,EnumKeyRecord.Type>> jdata = _repo.from(TestRecord.class).join(
@@ -62,8 +64,8 @@ public class SelectFieldsTest extends TestBase
System.out.println(jdata);
// finally clean up after ourselves
_repo.from(TestRecord.class).where(Exps.trueLiteral()).delete();
_repo.from(EnumKeyRecord.class).where(Exps.trueLiteral()).delete();
_repo.from(TestRecord.class).whereTrue().delete();
_repo.from(EnumKeyRecord.class).whereTrue().delete();
}
// the HSQL in-memory database persists for the lifetime of the VM, which means we have to
@@ -134,13 +134,13 @@ public class TransformTest extends TestBase
{
// AUTO-GENERATED: FIELDS START
public static final Class<TransformRecord> _R = TransformRecord.class;
public static final ColumnExp RECORD_ID = colexp(_R, "recordId");
public static final ColumnExp STRINGS = colexp(_R, "strings");
public static final ColumnExp STRING_LIST = colexp(_R, "stringList");
public static final ColumnExp STRING_SET = colexp(_R, "stringSet");
public static final ColumnExp CUSTOM = colexp(_R, "custom");
public static final ColumnExp ORDINAL = colexp(_R, "ordinal");
public static final ColumnExp BOBS = colexp(_R, "bobs");
public static final ColumnExp<Integer> RECORD_ID = colexp(_R, "recordId");
public static final ColumnExp<String[]> STRINGS = colexp(_R, "strings");
public static final ColumnExp<List<String>> STRING_LIST = colexp(_R, "stringList");
public static final ColumnExp<Set<String>> STRING_SET = colexp(_R, "stringSet");
public static final ColumnExp<CustomType> CUSTOM = colexp(_R, "custom");
public static final ColumnExp<Ordinal> ORDINAL = colexp(_R, "ordinal");
public static final ColumnExp<Set<ExtraOrdinal>> BOBS = colexp(_R, "bobs");
// AUTO-GENERATED: FIELDS END
public static final int SCHEMA_VERSION = 1;