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