diff --git a/src/main/java/com/samskivert/depot/DateFuncs.java b/src/main/java/com/samskivert/depot/DateFuncs.java index fe0114d..b942673 100644 --- a/src/main/java/com/samskivert/depot/DateFuncs.java +++ b/src/main/java/com/samskivert/depot/DateFuncs.java @@ -20,6 +20,9 @@ package com.samskivert.depot; +import java.sql.Date; +import java.sql.Timestamp; + import com.samskivert.depot.expression.FluentExp; import com.samskivert.depot.expression.SQLExpression; import com.samskivert.depot.impl.expression.DateFun.*; @@ -32,7 +35,7 @@ public class DateFuncs /** * Creates an expression that extracts the date from the given timestamp expression. */ - public static FluentExp date (SQLExpression exp) + public static FluentExp date (SQLExpression exp) { return new DateTruncate(exp, DateTruncate.Truncation.DAY); } @@ -40,7 +43,7 @@ public class DateFuncs /** * Creates an expression to extract the day-of-week from the the supplied timestamp expression. */ - public static FluentExp dayOfWeek (SQLExpression exp) + public static FluentExp dayOfWeek (SQLExpression exp) { return new DatePart(exp, DatePart.Part.DAY_OF_WEEK); } @@ -48,7 +51,7 @@ public class DateFuncs /** * Creates an expression to extract the day-of-month from the the supplied timestamp expression. */ - public static FluentExp dayOfMonth (SQLExpression exp) + public static FluentExp dayOfMonth (SQLExpression exp) { return new DatePart(exp, DatePart.Part.DAY_OF_MONTH); } @@ -56,7 +59,7 @@ public class DateFuncs /** * Creates an expression to extract the day-of-year from the the supplied timestamp expression. */ - public static FluentExp dayOfYear (SQLExpression exp) + public static FluentExp dayOfYear (SQLExpression exp) { return new DatePart(exp, DatePart.Part.DAY_OF_YEAR); } @@ -64,7 +67,7 @@ public class DateFuncs /** * Creates an expression to extract the hour of the the supplied timestamp expression. */ - public static FluentExp hour (SQLExpression exp) + public static FluentExp hour (SQLExpression exp) { return new DatePart(exp, DatePart.Part.HOUR); } @@ -72,7 +75,7 @@ public class DateFuncs /** * Creates an expression to extract the minute of the the supplied timestamp expression. */ - public static FluentExp minute (SQLExpression exp) + public static FluentExp minute (SQLExpression exp) { return new DatePart(exp, DatePart.Part.MINUTE); } @@ -80,15 +83,18 @@ public class DateFuncs /** * Creates an expression to extract the second of the the supplied timestamp expression. */ - public static FluentExp second (SQLExpression exp) + public static FluentExp second (SQLExpression exp) { return new DatePart(exp, DatePart.Part.SECOND); } + // TODO: the below should work on java.sql.Date and java.sql.Timestamp, but annoyingly the only + // supertype shared by those types is java.util.Date + /** * Creates an expression to extract the week of the the supplied timestamp expression. */ - public static FluentExp week (SQLExpression exp) + public static FluentExp week (SQLExpression exp) { return new DatePart(exp, DatePart.Part.WEEK); } @@ -96,7 +102,7 @@ public class DateFuncs /** * Creates an expression to extract the month of the the supplied timestamp expression. */ - public static FluentExp month (SQLExpression exp) + public static FluentExp month (SQLExpression exp) { return new DatePart(exp, DatePart.Part.MONTH); } @@ -104,7 +110,7 @@ public class DateFuncs /** * Creates an expression to extract the year of the the supplied timestamp expression. */ - public static FluentExp year (SQLExpression exp) + public static FluentExp year (SQLExpression exp) { return new DatePart(exp, DatePart.Part.YEAR); } @@ -113,7 +119,7 @@ public class DateFuncs * Creates an expression to extract the epoch (aka unix timestamp, aka seconds passed since * 1970-01-01) of the the supplied timestamp expression. */ - public static FluentExp epoch (SQLExpression exp) + public static FluentExp epoch (SQLExpression exp) { return new DatePart(exp, DatePart.Part.EPOCH); } @@ -121,7 +127,7 @@ public class DateFuncs /** * Creates an expression for the current timestamp. */ - public static FluentExp now () + public static FluentExp now () { return new Now(); } diff --git a/src/main/java/com/samskivert/depot/DepotRepository.java b/src/main/java/com/samskivert/depot/DepotRepository.java index 6028d4a..d124b77 100644 --- a/src/main/java/com/samskivert/depot/DepotRepository.java +++ b/src/main/java/com/samskivert/depot/DepotRepository.java @@ -508,7 +508,7 @@ public abstract class DepotRepository { // separate the arguments into keys and values final ColumnExp[] fields = new ColumnExp[updates.size()]; - final SQLExpression[] values = new SQLExpression[fields.length]; + final SQLExpression[] values = new SQLExpression[fields.length]; int ii = 0; for (Map.Entry, ?> entry : updates.entrySet()) { fields[ii] = entry.getKey(); @@ -545,7 +545,7 @@ public abstract class DepotRepository { // separate the updates into keys and values final ColumnExp[] fields = new ColumnExp[1+more.length/2]; - final SQLExpression[] values = new SQLExpression[fields.length]; + final SQLExpression[] values = new SQLExpression[fields.length]; fields[0] = field; values[0] = makeValue(value); for (int ii = 1, idx = 0; ii < fields.length; ii++) { @@ -576,7 +576,7 @@ public abstract class DepotRepository */ public int updatePartial ( Class type, final WhereClause key, CacheInvalidator invalidator, - ColumnExp[] fields, SQLExpression[] values) + ColumnExp[] fields, SQLExpression[] values) throws DatabaseException { requireNotComputed(type, "updatePartial"); @@ -908,9 +908,14 @@ public abstract class DepotRepository } } - protected SQLExpression makeValue (Object value) + protected SQLExpression makeValue (T value) { - return (value instanceof SQLExpression) ? (SQLExpression)value : new ValueExp(value); + if (value instanceof SQLExpression) { + @SuppressWarnings("unchecked") SQLExpression eval = (SQLExpression)value; + return eval; + } else { + return new ValueExp(value); + } } /** diff --git a/src/main/java/com/samskivert/depot/Exps.java b/src/main/java/com/samskivert/depot/Exps.java index 7d29aee..add1f89 100644 --- a/src/main/java/com/samskivert/depot/Exps.java +++ b/src/main/java/com/samskivert/depot/Exps.java @@ -34,40 +34,24 @@ public class Exps /** * Wraps the supplied object in a value expression. */ - public static FluentExp value (Object value) + public static FluentExp value (T value) { - return new ValueExp(value); - } - - /** - * Creates an expression that evaluates to true. - */ - public static SQLExpression trueLiteral () - { - return literal("true"); - } - - /** - * Creates an expression that evaluates to false. - */ - public static SQLExpression falseLiteral () - { - return literal("false"); + return new ValueExp(value); } /** * Creates a literal expression with the supplied SQL snippet. Note: you're probably breaking * cross platform compatibility by using this construction. */ - public static SQLExpression literal (String text) + public static SQLExpression literal (String text) { - return new LiteralExp(text); + return new LiteralExp(text); } /** * Creates an interval for the specified number of years. */ - public static SQLExpression years (int amount) + public static SQLExpression years (int amount) { return new IntervalExp(IntervalExp.Unit.YEAR, amount); } @@ -75,7 +59,7 @@ public class Exps /** * Creates an interval for the specified number of months. */ - public static SQLExpression months (int amount) + public static SQLExpression months (int amount) { return new IntervalExp(IntervalExp.Unit.MONTH, amount); } @@ -83,7 +67,7 @@ public class Exps /** * Creates an interval for the specified number of days. */ - public static SQLExpression days (int amount) + public static SQLExpression days (int amount) { return new IntervalExp(IntervalExp.Unit.DAY, amount); } @@ -91,7 +75,7 @@ public class Exps /** * Creates an interval for the specified number of hours. */ - public static SQLExpression hours (int amount) + public static SQLExpression hours (int amount) { return new IntervalExp(IntervalExp.Unit.HOUR, amount); } @@ -99,7 +83,7 @@ public class Exps /** * Creates an interval for the specified number of minutes. */ - public static SQLExpression minutes (int amount) + public static SQLExpression minutes (int amount) { return new IntervalExp(IntervalExp.Unit.MINUTE, amount); } @@ -107,7 +91,7 @@ public class Exps /** * Creates an interval for the specified number of seconds. */ - public static SQLExpression seconds (int amount) + public static SQLExpression seconds (int amount) { return new IntervalExp(IntervalExp.Unit.SECOND, amount); } diff --git a/src/main/java/com/samskivert/depot/Funcs.java b/src/main/java/com/samskivert/depot/Funcs.java index 084e702..1333318 100644 --- a/src/main/java/com/samskivert/depot/Funcs.java +++ b/src/main/java/com/samskivert/depot/Funcs.java @@ -24,6 +24,7 @@ import com.samskivert.depot.expression.FluentExp; import com.samskivert.depot.expression.SQLExpression; import com.samskivert.depot.impl.expression.AggregateFun.*; import com.samskivert.depot.impl.expression.ConditionalFun.*; +import com.samskivert.depot.impl.expression.StringFun.*; /** * Provides static methods for function construction. @@ -34,25 +35,25 @@ public class Funcs * Creates an aggregate expression that averages all values from the supplied expression. * This would usually be used in a FieldOverride and supplied with a ColumnExp. */ - public static FluentExp average (SQLExpression expr) + public static FluentExp average (SQLExpression expr) { - return new Average(expr); + return new Average(expr); } /** * Creates an expression that averages all distinct values from the supplied expression. * This would usually be used in a FieldOverride and supplied with a ColumnExp. */ - public static FluentExp averageDistinct (SQLExpression expr) + public static FluentExp averageDistinct (SQLExpression expr) { - return new Average(expr, true); + return new Average(expr, true); } /** * Creates an aggregate expression that counts the number of rows from the supplied * expression. This would usually be used in a FieldOverride and supplied with a ColumnExp. */ - public static FluentExp count (SQLExpression expr) + public static FluentExp count (SQLExpression expr) { return new Count(expr); } @@ -62,7 +63,7 @@ public class Funcs * supplied expression. This would usually be used in a FieldOverride and supplied with a * ColumnExp. */ - public static FluentExp countDistinct (SQLExpression expr) + public static FluentExp countDistinct (SQLExpression expr) { return new Count(expr, true); } @@ -72,7 +73,7 @@ public class Funcs * expression is also true. This would usually be used in a FieldOverride and supplied with * a ColumnExp. */ - public static FluentExp every (SQLExpression expr) + public static FluentExp every (SQLExpression expr) { return new Every(expr); } @@ -82,9 +83,9 @@ public class Funcs * supplied expression. This would usually be used in a FieldOverride and supplied with * a ColumnExp. */ - public static FluentExp max (SQLExpression expr) + public static FluentExp max (SQLExpression expr) { - return new Max(expr); + return new Max(expr); } /** @@ -92,41 +93,76 @@ public class Funcs * supplied expression. This would usually be used in a FieldOverride and supplied with * a ColumnExp. */ - public static FluentExp min (SQLExpression expr) + public static FluentExp min (SQLExpression expr) { - return new Min(expr); + return new Min(expr); } /** * Creates an aggregate expression that sums all the values from the supplied expression. * This would usually be used in a FieldOverride and supplied with a ColumnExp. */ - public static FluentExp sum (SQLExpression expr) + public static FluentExp sum (SQLExpression expr) { - return new Sum(expr); + return new Sum(expr); } /** * Creates an expression that evaluates to the first supplied expression that is not null. */ - public static FluentExp coalesce (SQLExpression... args) + public static FluentExp coalesce (SQLExpression arg1, + SQLExpression arg2) { - return new Coalesce(args); + return new Coalesce(arg1, arg2); + } + + /** + * Creates an expression that evaluates to the first supplied expression that is not null. + */ + public static FluentExp coalesce (SQLExpression... args) + { + return new Coalesce(args); } /** * Creates an expression that evaluates to the largest of the given expressions. */ - public static FluentExp greatest (SQLExpression... args) + public static FluentExp greatest (SQLExpression arg1, + SQLExpression arg2) { - return new Greatest(args); + return new Greatest(arg1, arg2); + } + + /** + * Creates an expression that evaluates to the largest of the given expressions. + */ + public static FluentExp greatest (SQLExpression... args) + { + return new Greatest(args); } /** * Creates an expression that evaluates to the smallest of the given expressions. */ - public static FluentExp least (SQLExpression... args) + public static FluentExp least (SQLExpression arg1, + SQLExpression arg2) { - return new Least(args); + return new Least(arg1, arg2); + } + + /** + * Creates an expression that evaluates to the smallest of the given expressions. + */ + public static FluentExp least (SQLExpression... args) + { + return new Least(args); + } + + /** + * Creates an expression that evaluates to the length of the supplied array column. + */ + public static FluentExp arrayLength (SQLExpression exp) + { + return new Length(exp); } } diff --git a/src/main/java/com/samskivert/depot/Key.java b/src/main/java/com/samskivert/depot/Key.java index 957f2fa..71fbfe8 100644 --- a/src/main/java/com/samskivert/depot/Key.java +++ b/src/main/java/com/samskivert/depot/Key.java @@ -50,7 +50,7 @@ public class Key extends WhereClause { /** Handles the matching of the key columns to its bound values. This is needed so that we can * combine a bunch of keys into a {@link KeySet}. */ - public static class Expression implements SQLExpression + public static class Expression implements SQLExpression { public Expression (Class pClass, Comparable[] values) { _pClass = pClass; @@ -163,7 +163,7 @@ public class Key extends WhereClause } @Override // from WhereClause - public SQLExpression getWhereExpression () + public SQLExpression getWhereExpression () { return new Expression(_pClass, _values); } diff --git a/src/main/java/com/samskivert/depot/KeySet.java b/src/main/java/com/samskivert/depot/KeySet.java index be305cf..3d7cc0c 100644 --- a/src/main/java/com/samskivert/depot/KeySet.java +++ b/src/main/java/com/samskivert/depot/KeySet.java @@ -127,8 +127,8 @@ public abstract class KeySet extends WhereClause super(pClass); } - @Override public SQLExpression getWhereExpression () { - return new LiteralExp("(1 = 0)"); + @Override public SQLExpression getWhereExpression () { + return new LiteralExp("false"); } // from Iterable> @@ -169,7 +169,7 @@ public abstract class KeySet extends WhereClause _keys = keys; } - @Override public SQLExpression getWhereExpression () { + @Override public SQLExpression getWhereExpression () { // Single-column keys result in the compact IN(keyVal1, keyVal2, ...) return new In(DepotUtil.getKeyFields(_pClass)[0], _keys); } diff --git a/src/main/java/com/samskivert/depot/MathFuncs.java b/src/main/java/com/samskivert/depot/MathFuncs.java index e892269..7e8c0d3 100644 --- a/src/main/java/com/samskivert/depot/MathFuncs.java +++ b/src/main/java/com/samskivert/depot/MathFuncs.java @@ -32,105 +32,106 @@ public class MathFuncs /** * Creates an expression that computes the absolute value of the supplied expression. */ - public static FluentExp abs (SQLExpression expr) + public static FluentExp abs (SQLExpression expr) { - return new Abs(expr); + return new Abs(expr); } /** * Creates an expression that computes the integer ceiling of the supplied expression. */ - public static FluentExp ceil (SQLExpression exp) + public static FluentExp ceil (SQLExpression exp) { - return new Ceil(exp); + return new Ceil(exp); } /** * Creates an expression that computes the exponential of the supplied expression. */ - public static FluentExp exp (SQLExpression exp) + public static FluentExp exp (SQLExpression exp) { - return new Exp(exp); + return new Exp(exp); } /** * Creates an expression that computes the integer floor of the supplied expression. */ - public static FluentExp floor (SQLExpression exp) + public static FluentExp floor (SQLExpression exp) { - return new Floor(exp); + return new Floor(exp); } /** * Creates an expression that computes the natural logarithm of the supplied expression. */ - public static FluentExp ln (SQLExpression exp) + public static FluentExp ln (SQLExpression exp) { - return new Ln(exp); + return new Ln(exp); } /** * Creates an expression that computes the base-10 logarithm of the supplied expression. */ - public static FluentExp log10 (SQLExpression value) + public static FluentExp log10 (SQLExpression value) { - return new Log10(value); + return new Log10(value); } /** * Creates an expression that evaluates to the constant PI. */ - public static FluentExp pi () + public static FluentExp pi () { - return new Pi(); + return new Pi(); } /** * Creates an expression that computes the value expression to the given power. */ - public static FluentExp power (SQLExpression value, SQLExpression power) + public static FluentExp power (SQLExpression value, + SQLExpression

power) { - return new Power(value, power); + return new Power(value, power); } /** * Creates an expression that returns a random number between 0.0 and 1.0. */ - public static FluentExp random () + public static FluentExp random () { - return new Random(); + return new Random(); } /** * Creates an expression that computes the whole number nearest the supplied expression. */ - public static FluentExp round (SQLExpression exp) + public static FluentExp round (SQLExpression exp) { - return new Round(exp); + return new Round(exp); } /** * Creates an expression that computes the sign of the supplied expression. */ - public static FluentExp sign (SQLExpression exp) + public static FluentExp sign (SQLExpression exp) { - return new Sign(exp); + return new Sign(exp); } /** * Creates an expression that computes the square root of the supplied expression. */ - public static FluentExp sqrt (SQLExpression exp) + public static FluentExp sqrt (SQLExpression exp) { - return new Sqrt(exp); + return new Sqrt(exp); } /** * Creates an expression that computes the truncation of the supplied expression, * i.e. the next closest whole number to zero. */ - public static FluentExp trunc (SQLExpression exp) + public static FluentExp trunc (SQLExpression exp) { - return new Trunc(exp); + return new Trunc(exp); } } diff --git a/src/main/java/com/samskivert/depot/MultiKeySet.java b/src/main/java/com/samskivert/depot/MultiKeySet.java index 91730cf..0553dc7 100644 --- a/src/main/java/com/samskivert/depot/MultiKeySet.java +++ b/src/main/java/com/samskivert/depot/MultiKeySet.java @@ -42,7 +42,7 @@ class MultiKeySet extends KeySet _keyFields = keyFields; } - @Override public SQLExpression getWhereExpression () + @Override public SQLExpression getWhereExpression () { Set columns = Sets.newHashSet(); for (int ii = 0; ii < _keyFields.length; ii ++) { @@ -85,10 +85,10 @@ class MultiKeySet extends KeySet } // note: this method will destructively modify its arguments - protected SQLExpression rowsToSQLExpression ( + protected SQLExpression rowsToSQLExpression ( List[]> keys, Set columnsLeft) { - List matches = Lists.newArrayList(); + List> matches = Lists.newArrayList(); while (!keys.isEmpty()) { // go through each column that is still in play, finding the single largest common @@ -148,7 +148,7 @@ class MultiKeySet extends KeySet // find all the rows that contain the given chunk value in the given column. delete these // (destructively modifying the input argument) and replace them with an optimized // SQLExpression, which is returned - protected SQLExpression extractChunk (List[]> rows, Set columnsLeft, + protected SQLExpression extractChunk (List[]> rows, Set columnsLeft, int column, Comparable value) { Iterator[]> iterator = rows.iterator(); @@ -165,7 +165,7 @@ class MultiKeySet extends KeySet Set otherColumns = Sets.newHashSet(columnsLeft); otherColumns.remove(column); - SQLExpression otherCondition; + SQLExpression otherCondition; if (otherColumns.size() == 1) { // if there's just two columns, we're doing (A = ? and B in (?, ?, ?, ...)) int otherColumn = otherColumns.iterator().next(); @@ -188,15 +188,15 @@ class MultiKeySet extends KeySet // given unoptimizable key rows, gather them up into simple SQLExpressions according to // the naive algorithm - protected List gatherDetritus ( + protected List> gatherDetritus ( List[]> keys, Set columnsLeft) { - List conditions = Lists.newArrayList(); + List> conditions = Lists.newArrayList(); Iterator[]> iterator = keys.iterator(); while (iterator.hasNext()) { Comparable[] row = iterator.next(); - List bits = Lists.newArrayList(); + List> bits = Lists.newArrayList(); for (int column : columnsLeft) { bits.add(_keyFields[column].eq(row[column])); } diff --git a/src/main/java/com/samskivert/depot/Ops.java b/src/main/java/com/samskivert/depot/Ops.java index fa5ebd5..6ef9b1c 100644 --- a/src/main/java/com/samskivert/depot/Ops.java +++ b/src/main/java/com/samskivert/depot/Ops.java @@ -41,7 +41,7 @@ public class Ops /** * Creates a NOT expression with the supplied target expression. */ - public static SQLExpression not (SQLExpression expr) + public static SQLExpression not (SQLExpression expr) { return new Not(expr); } @@ -49,7 +49,7 @@ public class Ops /** * Creates an AND expression with the supplied target expressions. */ - public static FluentExp and (Iterable conditions) + public static FluentExp and (Iterable> conditions) { return and(Iterables.toArray(conditions, SQLExpression.class)); } @@ -57,9 +57,9 @@ public class Ops /** * Creates an AND expression with the supplied target expressions. */ - public static FluentExp and (SQLExpression... conditions) + public static FluentExp and (SQLExpression... conditions) { - return new MultiOperator(conditions) { + return new MultiOperator(conditions) { @Override public String operator() { return " and "; } @@ -86,7 +86,7 @@ public class Ops /** * Creates an OR expression with the supplied target expressions. */ - public static FluentExp or (Iterable conditions) + public static FluentExp or (Iterable> conditions) { return or(Iterables.toArray(conditions, SQLExpression.class)); } @@ -94,9 +94,9 @@ public class Ops /** * Creates an OR expression with the supplied target expressions. */ - public static FluentExp or (SQLExpression... conditions) + public static FluentExp or (SQLExpression... conditions) { - return new MultiOperator(conditions) { + return new MultiOperator(conditions) { @Override public String operator() { return " or "; } @@ -121,7 +121,7 @@ public class Ops /** * Returns an expression that matches when the source is like the supplied value. */ - public static FluentExp like (SQLExpression source, Comparable value) + public static FluentExp like (SQLExpression source, Comparable value) { return new Like(source, value, true); } @@ -129,7 +129,7 @@ public class Ops /** * Returns an expression that matches when the source is like the supplied expression. */ - public static FluentExp like (SQLExpression source, SQLExpression expr) + public static FluentExp like (SQLExpression source, SQLExpression expr) { return new Like(source, expr, true); } @@ -137,7 +137,7 @@ public class Ops /** * Returns an expression that matches when the source is NOT like the supplied value. */ - public static FluentExp notLike (SQLExpression source, Comparable value) + public static FluentExp notLike (SQLExpression source, Comparable value) { return new Like(source, value, false); } @@ -145,7 +145,7 @@ public class Ops /** * Returns an expression that matches when the source is NOT like the supplied expression. */ - public static FluentExp notLike (SQLExpression source, SQLExpression expr) + public static FluentExp notLike (SQLExpression source, SQLExpression expr) { return new Like(source, expr, false); } @@ -153,7 +153,7 @@ public class Ops /** * Creates an EXISTS expression with the supplied select clause. */ - public static SQLExpression exists (SelectClause target) + public static SQLExpression exists (SelectClause target) { return new Exists(target); } @@ -161,16 +161,32 @@ public class Ops /** * Adds the supplied expressions together. */ - public static FluentExp add (SQLExpression... exprs) + public static FluentExp add (SQLExpression e1, SQLExpression e2) { - return new Add(exprs); + return new Add(new SQLExpression[] { e1, e2 }); + } + + /** + * Adds the supplied expressions together. + */ + public static FluentExp add (Iterable> exprs) + { + return new Add(Iterables.toArray(exprs, SQLExpression.class)); } /** * Multiplies the supplied expressions together. */ - public static FluentExp mul (SQLExpression... exprs) + public static FluentExp mul (SQLExpression e1, SQLExpression e2) { - return new Mul(exprs); + return new Mul(new SQLExpression[] { e1, e2 }); + } + + /** + * Multiplies the supplied expressions together. + */ + public static FluentExp mul (Iterable> exprs) + { + return new Mul(Iterables.toArray(exprs, SQLExpression.class)); } } diff --git a/src/main/java/com/samskivert/depot/QueryBuilder.java b/src/main/java/com/samskivert/depot/QueryBuilder.java index 26599c5..b3fd6ae 100644 --- a/src/main/java/com/samskivert/depot/QueryBuilder.java +++ b/src/main/java/com/samskivert/depot/QueryBuilder.java @@ -85,10 +85,20 @@ public class QueryBuilder 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 whereTrue () + { + return where(Exps.literal("true")); + } + /** * Configures a {@link Where} clause that ANDs together all of the supplied expressions. */ - public QueryBuilder where (SQLExpression... exprs) + public QueryBuilder where (SQLExpression... exprs) { return where(Arrays.asList(exprs)); } @@ -96,11 +106,11 @@ public class QueryBuilder /** * Configures a {@link Where} clause that ANDs together all of the supplied expressions. */ - public QueryBuilder where (Iterable exprs) + public QueryBuilder where (Iterable> exprs) { - Iterator iter = exprs.iterator(); + Iterator> iter = exprs.iterator(); checkArgument(iter.hasNext(), "Must supply at least one expression."); - SQLExpression first = iter.next(); + SQLExpression first = iter.next(); return where(iter.hasNext() ? new Where(Ops.and(exprs)) : new Where(first)); } @@ -146,7 +156,7 @@ public class QueryBuilder * Adds a {@link Join} clause configured with the join condition. */ public QueryBuilder join (Class joinClass, - SQLExpression joinCondition) + SQLExpression joinCondition) { return join(new Join(joinClass, joinCondition)); } @@ -176,7 +186,7 @@ public class QueryBuilder /** * Configures a {@link GroupBy} clause on the supplied group expressions. */ - public QueryBuilder groupBy (SQLExpression... exprs) + public QueryBuilder groupBy (SQLExpression... exprs) { checkState(_groupBy == null, "GroupBy clause is already configured."); _groupBy = new GroupBy(exprs); @@ -194,7 +204,7 @@ public class QueryBuilder /** * Configures an {@link OrderBy} clause that ascends on the supplied expression. */ - public QueryBuilder ascending (SQLExpression value) + public QueryBuilder ascending (SQLExpression value) { return orderBy(OrderBy.ascending(value)); } @@ -202,7 +212,7 @@ public class QueryBuilder /** * Configures an {@link OrderBy} clause that descends on the supplied expression. */ - public QueryBuilder descending (SQLExpression value) + public QueryBuilder descending (SQLExpression value) { return orderBy(OrderBy.descending(value)); } @@ -275,7 +285,7 @@ public class QueryBuilder /** * Adds a {@link FieldDefinition} clause. */ - public QueryBuilder fieldDef (String field, SQLExpression override) + public QueryBuilder fieldDef (String field, SQLExpression override) { return fieldDef(new FieldDefinition(field, override)); } @@ -283,7 +293,7 @@ public class QueryBuilder /** * Adds a {@link FieldDefinition} clause. */ - public QueryBuilder fieldDef (ColumnExp field, SQLExpression override) + public QueryBuilder fieldDef (ColumnExp field, SQLExpression override) { return fieldDef(new FieldDefinition(field, override)); } diff --git a/src/main/java/com/samskivert/depot/StringFuncs.java b/src/main/java/com/samskivert/depot/StringFuncs.java index 6d8ae84..38348c3 100644 --- a/src/main/java/com/samskivert/depot/StringFuncs.java +++ b/src/main/java/com/samskivert/depot/StringFuncs.java @@ -32,7 +32,7 @@ public class StringFuncs /** * Creates an expression that evaluates to the string length of the supplied expression. */ - public static FluentExp length (SQLExpression exp) + public static FluentExp length (SQLExpression exp) { return new Length(exp); } @@ -40,7 +40,7 @@ public class StringFuncs /** * Creates an expression that down-cases the supplied expression. */ - public static FluentExp lower (SQLExpression exp) + public static FluentExp lower (SQLExpression exp) { return new Lower(exp); } @@ -49,7 +49,8 @@ public class StringFuncs * Creates an expression that locates the given substring expression within the given * string expression and returns the index. */ - public static FluentExp position (SQLExpression substring, SQLExpression string) + public static FluentExp position (SQLExpression substring, + SQLExpression string) { return new Position(substring, string); } @@ -58,8 +59,8 @@ public class StringFuncs * Creates an expression that evaluates to a substring of the given string expression, * starting at the given index and of the given length. */ - public static FluentExp substring ( - SQLExpression string, SQLExpression from, SQLExpression count) + public static FluentExp substring ( + SQLExpression string, SQLExpression from, SQLExpression count) { return new Substring(string, from, count); } @@ -68,7 +69,7 @@ public class StringFuncs * Creates an expression that removes whitespace from the beginning and end of the supplied * string expression. */ - public static FluentExp trim (SQLExpression exp) + public static FluentExp trim (SQLExpression exp) { return new Trim(exp); } @@ -76,7 +77,7 @@ public class StringFuncs /** * Creates an expression that up-cases the supplied string expression. */ - public static FluentExp upper (SQLExpression exp) + public static FluentExp upper (SQLExpression exp) { return new Upper(exp); } diff --git a/src/main/java/com/samskivert/depot/clause/FieldDefinition.java b/src/main/java/com/samskivert/depot/clause/FieldDefinition.java index 0814b76..3853ae6 100644 --- a/src/main/java/com/samskivert/depot/clause/FieldDefinition.java +++ b/src/main/java/com/samskivert/depot/clause/FieldDefinition.java @@ -41,7 +41,7 @@ public class FieldDefinition implements QueryClause { public FieldDefinition (String field, String str) { - this(field, new LiteralExp(str)); + this(field, new LiteralExp(str)); } public FieldDefinition (String field, Class pClass, String pCol) @@ -49,13 +49,13 @@ public class FieldDefinition implements QueryClause this(field, new ColumnExp(pClass, pCol)); } - public FieldDefinition (String field, SQLExpression override) + public FieldDefinition (String field, SQLExpression override) { _field = field; _definition = override; } - public FieldDefinition (ColumnExp field, SQLExpression override) + public FieldDefinition (ColumnExp field, SQLExpression override) { _field = field.name; _definition = override; @@ -69,7 +69,7 @@ public class FieldDefinition implements QueryClause return _field; } - public SQLExpression getDefinition () + public SQLExpression getDefinition () { return _definition; } @@ -90,6 +90,6 @@ public class FieldDefinition implements QueryClause protected String _field; /** The defining expression. */ - protected SQLExpression _definition; + protected SQLExpression _definition; } diff --git a/src/main/java/com/samskivert/depot/clause/FieldOverride.java b/src/main/java/com/samskivert/depot/clause/FieldOverride.java index a453c4f..d6613ea 100644 --- a/src/main/java/com/samskivert/depot/clause/FieldOverride.java +++ b/src/main/java/com/samskivert/depot/clause/FieldOverride.java @@ -45,12 +45,13 @@ public class FieldOverride extends FieldDefinition super(field, pClass, pCol); } - public FieldOverride (String field, SQLExpression override) + public FieldOverride (String field, SQLExpression override) { super(field, override); } - public FieldOverride (ColumnExp field, SQLExpression override) + + public FieldOverride (ColumnExp field, SQLExpression override) { super(field, override); } diff --git a/src/main/java/com/samskivert/depot/clause/GroupBy.java b/src/main/java/com/samskivert/depot/clause/GroupBy.java index 4e5db84..707641e 100644 --- a/src/main/java/com/samskivert/depot/clause/GroupBy.java +++ b/src/main/java/com/samskivert/depot/clause/GroupBy.java @@ -31,12 +31,12 @@ import com.samskivert.depot.impl.FragmentVisitor; */ public class GroupBy implements QueryClause { - public GroupBy (SQLExpression... values) + public GroupBy (SQLExpression... values) { _values = values; } - public SQLExpression[] getValues () + public SQLExpression[] getValues () { return _values; } @@ -53,6 +53,6 @@ public class GroupBy implements QueryClause } /** The expressions that are generated for the clause. */ - protected SQLExpression[] _values; + protected SQLExpression[] _values; } diff --git a/src/main/java/com/samskivert/depot/clause/Join.java b/src/main/java/com/samskivert/depot/clause/Join.java index 39f0223..eb94bb3 100644 --- a/src/main/java/com/samskivert/depot/clause/Join.java +++ b/src/main/java/com/samskivert/depot/clause/Join.java @@ -43,7 +43,7 @@ public class Join implements QueryClause _joinCondition = new Equals(primary, join); } - public Join (Class joinClass, SQLExpression joinCondition) + public Join (Class joinClass, SQLExpression joinCondition) { _joinClass = joinClass; _joinCondition = joinCondition; @@ -68,7 +68,7 @@ public class Join implements QueryClause return _joinClass; } - public SQLExpression getJoinCondition () + public SQLExpression getJoinCondition () { return _joinCondition; } @@ -99,5 +99,6 @@ public class Join implements QueryClause protected Class _joinClass; /** The condition used to join in the new table. */ - protected SQLExpression _joinCondition; + + protected SQLExpression _joinCondition; } diff --git a/src/main/java/com/samskivert/depot/clause/OrderBy.java b/src/main/java/com/samskivert/depot/clause/OrderBy.java index 8200a3f..88c71c5 100644 --- a/src/main/java/com/samskivert/depot/clause/OrderBy.java +++ b/src/main/java/com/samskivert/depot/clause/OrderBy.java @@ -41,32 +41,32 @@ public class OrderBy implements QueryClause */ public static OrderBy random () { - return ascending(new LiteralExp("rand()")); + return ascending(new LiteralExp("rand()")); } /** * Creates and returns an ascending order by clause on the supplied expression. */ - public static OrderBy ascending (SQLExpression value) + public static OrderBy ascending (SQLExpression value) { - return new OrderBy(new SQLExpression[] { value } , new Order[] { Order.ASC }); + return new OrderBy(new SQLExpression[] { value } , new Order[] { Order.ASC }); } /** * Creates and returns a descending order by clause on the supplied expression. */ - public static OrderBy descending (SQLExpression value) + public static OrderBy descending (SQLExpression value) { - return new OrderBy(new SQLExpression[] { value }, new Order[] { Order.DESC }); + return new OrderBy(new SQLExpression[] { value }, new Order[] { Order.DESC }); } - public OrderBy (SQLExpression[] values, Order[] orders) + public OrderBy (SQLExpression[] values, Order[] orders) { _values = values; _orders = orders; } - public SQLExpression[] getValues () + public SQLExpression[] getValues () { return _values; } @@ -79,7 +79,7 @@ public class OrderBy implements QueryClause /** * Concatenates the supplied order expression to this one, returns a new expression. */ - public OrderBy thenAscending (SQLExpression value) + public OrderBy thenAscending (SQLExpression value) { return new OrderBy(ArrayUtil.append(_values, value), ArrayUtil.append(_orders, Order.ASC)); @@ -88,7 +88,7 @@ public class OrderBy implements QueryClause /** * Creates and returns a descending order by clause on the supplied expression. */ - public OrderBy thenDescending (SQLExpression value) + public OrderBy thenDescending (SQLExpression value) { return new OrderBy(ArrayUtil.append(_values, value), ArrayUtil.append(_orders, Order.DESC)); @@ -103,7 +103,7 @@ public class OrderBy implements QueryClause // from SQLExpression public void addClasses (Collection> classSet) { - for (SQLExpression expression : _values) { + for (SQLExpression expression : _values) { expression.addClasses(classSet); } } @@ -122,7 +122,7 @@ public class OrderBy implements QueryClause } /** The expressions that are generated for the clause. */ - protected SQLExpression[] _values; + protected SQLExpression[] _values; /** Whether the ordering is to be ascending or descending. */ protected Order[] _orders; diff --git a/src/main/java/com/samskivert/depot/clause/Where.java b/src/main/java/com/samskivert/depot/clause/Where.java index eeb0078..b4b270b 100644 --- a/src/main/java/com/samskivert/depot/clause/Where.java +++ b/src/main/java/com/samskivert/depot/clause/Where.java @@ -27,7 +27,6 @@ import com.samskivert.depot.PersistentRecord; import com.samskivert.depot.expression.ColumnExp; import com.samskivert.depot.expression.SQLExpression; import com.samskivert.depot.impl.FragmentVisitor; -import com.samskivert.depot.impl.expression.ValueExp; import com.samskivert.depot.impl.operator.Equals; import com.samskivert.depot.impl.operator.IsNull; @@ -63,13 +62,13 @@ public class Where extends WhereClause this(toCondition(columns, values)); } - public Where (SQLExpression condition) + public Where (SQLExpression condition) { _condition = condition; } @Override // from WhereClause - public SQLExpression getWhereExpression () + public SQLExpression getWhereExpression () { return _condition; } @@ -92,15 +91,15 @@ public class Where extends WhereClause return String.valueOf(_condition); } - protected static SQLExpression toCondition (ColumnExp[] columns, Comparable[] values) + protected static SQLExpression toCondition (ColumnExp[] columns, Comparable[] values) { - SQLExpression[] comparisons = new SQLExpression[columns.length]; + SQLExpression[] comparisons = new SQLExpression[columns.length]; for (int ii = 0; ii < columns.length; ii ++) { comparisons[ii] = (values[ii] == null) ? new IsNull(columns[ii]) : - new Equals(columns[ii], new ValueExp(values[ii])); + new Equals(columns[ii], values[ii]); } return Ops.and(comparisons); } - protected SQLExpression _condition; + protected SQLExpression _condition; } diff --git a/src/main/java/com/samskivert/depot/clause/WhereClause.java b/src/main/java/com/samskivert/depot/clause/WhereClause.java index 2f16994..6db0619 100644 --- a/src/main/java/com/samskivert/depot/clause/WhereClause.java +++ b/src/main/java/com/samskivert/depot/clause/WhereClause.java @@ -32,7 +32,7 @@ public abstract class WhereClause implements QueryClause /** * Returns the condition associated with this where clause. */ - public abstract SQLExpression getWhereExpression (); + public abstract SQLExpression getWhereExpression (); /** * Validates that the supplied persistent record type is the type matched by this where clause. diff --git a/src/main/java/com/samskivert/depot/expression/ColumnExp.java b/src/main/java/com/samskivert/depot/expression/ColumnExp.java index 0385262..55a2084 100644 --- a/src/main/java/com/samskivert/depot/expression/ColumnExp.java +++ b/src/main/java/com/samskivert/depot/expression/ColumnExp.java @@ -30,7 +30,7 @@ import com.samskivert.depot.impl.FragmentVisitor; * An expression that unambiguously identifies a field of a class, for example * GameRecord.itemId. */ -public class ColumnExp extends FluentExp +public class ColumnExp extends FluentExp { /** The name of the column we reference. */ public final String name; diff --git a/src/main/java/com/samskivert/depot/expression/FluentExp.java b/src/main/java/com/samskivert/depot/expression/FluentExp.java index a179c52..ef02b2d 100644 --- a/src/main/java/com/samskivert/depot/expression/FluentExp.java +++ b/src/main/java/com/samskivert/depot/expression/FluentExp.java @@ -40,29 +40,29 @@ import com.samskivert.depot.impl.operator.Sub; /** * Provides a fluent API for creating most SQL expressions like and, or, equal, not equal, etc. */ -public abstract class FluentExp - implements SQLExpression +public abstract class FluentExp + implements SQLExpression { /** Returns an {@link Equals} with this expression and the supplied target. */ - public FluentExp eq (Comparable value) + public FluentExp eq (Comparable value) { return new Equals(this, value); } /** Returns an {@link Equals} with this expression and the supplied target. */ - public FluentExp eq (SQLExpression expr) + public FluentExp eq (SQLExpression expr) { return new Equals(this, expr); } /** Returns a {@link NotEquals} with this expression and the supplied target. */ - public FluentExp notEq (Comparable value) + public FluentExp notEq (Comparable value) { return new NotEquals(this, value); } /** Returns a {@link NotEquals} with this expression and the supplied target. */ - public FluentExp notEq (SQLExpression expr) + public FluentExp notEq (SQLExpression expr) { return new NotEquals(this, expr); } @@ -86,158 +86,172 @@ public abstract class FluentExp } /** Returns a {@link GreaterThan} with this expression and the supplied target. */ - public FluentExp greaterThan (Comparable value) + public FluentExp greaterThan (Comparable value) { return new GreaterThan(this, value); } /** Returns a {@link GreaterThan} with this expression and the supplied target. */ - public FluentExp greaterThan (SQLExpression expr) + public FluentExp greaterThan (SQLExpression expr) { return new GreaterThan(this, expr); } /** Returns a {@link LessThan} with this expression and the supplied target. */ - public FluentExp lessThan (Comparable value) + public FluentExp lessThan (Comparable value) { return new LessThan(this, value); } /** Returns a {@link LessThan} with this expression and the supplied target. */ - public FluentExp lessThan (SQLExpression expr) + public FluentExp lessThan (SQLExpression expr) { return new LessThan(this, expr); } /** Returns a {@link GreaterThanEquals} with this expression and the supplied target. */ - public FluentExp greaterEq (Comparable value) + public FluentExp greaterEq (Comparable value) { return new GreaterThanEquals(this, value); } /** Returns a {@link GreaterThanEquals} with this expression and the supplied target. */ - public FluentExp greaterEq (SQLExpression expr) + public FluentExp greaterEq (SQLExpression expr) { return new GreaterThanEquals(this, expr); } /** Returns a {@link LessThanEquals} with this expression and the supplied target. */ - public FluentExp lessEq (Comparable value) + public FluentExp lessEq (Comparable value) { return new LessThanEquals(this, value); } /** Returns a {@link LessThanEquals} with this expression and the supplied target. */ - public FluentExp lessEq (SQLExpression expr) + public FluentExp lessEq (SQLExpression expr) { return new LessThanEquals(this, expr); } /** Returns a boolean and of this expression and the supplied target. */ - public FluentExp and (SQLExpression expr) + public FluentExp and (SQLExpression expr) { return Ops.and(this, expr); } /** Returns a boolean or of this expression and the supplied target. */ - public FluentExp or (SQLExpression expr) + public FluentExp or (SQLExpression expr) { return Ops.or(this, expr); } /** Returns a bitwise and of this expression and the supplied target. */ - public FluentExp bitAnd (Comparable value) + public FluentExp bitAnd (V value) { - return new BitAnd(this, value); + return new BitAnd(this, value); } /** Returns a bitwise and of this expression and the supplied target. */ - public FluentExp bitAnd (SQLExpression expr) + public FluentExp bitAnd (SQLExpression expr) { - return new BitAnd(this, expr); + return new BitAnd(this, expr); } /** Returns a bitwise or of this expression and the supplied target. */ - public FluentExp bitOr (Comparable value) + public FluentExp bitOr (V value) { - return new BitOr(this, value); + return new BitOr(this, value); } /** Returns a bitwise or of this expression and the supplied target. */ - public FluentExp bitOr (SQLExpression expr) + public FluentExp bitOr (SQLExpression expr) { - return new BitOr(this, expr); + return new BitOr(this, expr); } /** Returns the sum of this expression and the supplied target. */ - public FluentExp plus (Comparable value) + public FluentExp plus (V value) { - return new Add(this, value); + return new Add(this, value); } /** Returns the sum of this expression and the supplied target. */ - public FluentExp plus (SQLExpression expr) + public FluentExp plus (SQLExpression expr) { - return new Add(this, expr); + return new Add(this, expr); } /** Returns this expression minus the supplied target. */ - public FluentExp minus (Comparable value) + public FluentExp minus (V value) { - return new Sub(this, value); + return new Sub(this, value); } /** Returns this expression minus the supplied target. */ - public FluentExp minus (SQLExpression expr) + public FluentExp minus (SQLExpression expr) { - return new Sub(this, expr); + return new Sub(this, expr); } /** Returns this expression times the supplied target. */ - public FluentExp times (Comparable value) + public FluentExp times (V value) { - return new Mul(this, value); + return new Mul(this, value); } /** Returns this expression times the supplied target. */ - public FluentExp times (SQLExpression expr) + public FluentExp times (SQLExpression expr) { - return new Mul(this, expr); + return new Mul(this, expr); } /** Returns this expression divided by the supplied target. */ - public FluentExp div (Comparable value) + public FluentExp div (V value) { - return new Div(this, value); + return new Div(this, value); } /** Returns this expression divided by the supplied target. */ - public FluentExp div (SQLExpression expr) + public FluentExp div (SQLExpression expr) { - return new Div(this, expr); + return new Div(this, expr); } /** Returns a {@link Like} on this column and the supplied target. */ - public FluentExp like (Comparable value) + public FluentExp like (Comparable value) { return new Like(this, value, true); } /** Returns a {@link Like} on this column and the supplied target. */ - public FluentExp like (SQLExpression expr) + public FluentExp like (SQLExpression expr) { return new Like(this, expr, true); } /** Returns a negated {@link Like} on this column and the supplied target. */ - public FluentExp notLike (Comparable value) + public FluentExp notLike (Comparable value) { return new Like(this, value, false); } /** Returns a negated {@link Like} on this column and the supplied target. */ - public FluentExp notLike (SQLExpression expr) + public FluentExp notLike (SQLExpression expr) { return new Like(this, expr, false); } + + /** Returns this expression minus the supplied target, assuming this and the target represent + * Date values. Because date arithmetic is database specific, you're on your own with types. */ + public FluentExp dateSub (SQLExpression expr) + { + return new Sub(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 dateAdd (SQLExpression expr) + { + return new Add(this, expr); + } } diff --git a/src/main/java/com/samskivert/depot/expression/SQLExpression.java b/src/main/java/com/samskivert/depot/expression/SQLExpression.java index 6968cb6..db25448 100644 --- a/src/main/java/com/samskivert/depot/expression/SQLExpression.java +++ b/src/main/java/com/samskivert/depot/expression/SQLExpression.java @@ -25,7 +25,7 @@ import com.samskivert.depot.SQLFragment; /** * Represents an SQL expression, e.g. column name, function, or constant. */ -public interface SQLExpression extends SQLFragment +public interface SQLExpression extends SQLFragment { /** Used internally to represent the lack of a value. */ public static final class NoValue diff --git a/src/main/java/com/samskivert/depot/impl/BuildVisitor.java b/src/main/java/com/samskivert/depot/impl/BuildVisitor.java index 4e6d510..b5f0b3e 100644 --- a/src/main/java/com/samskivert/depot/impl/BuildVisitor.java +++ b/src/main/java/com/samskivert/depot/impl/BuildVisitor.java @@ -33,6 +33,7 @@ import com.google.common.collect.Maps; import com.samskivert.util.ByteEnum; import com.samskivert.util.Tuple; +import com.samskivert.depot.Exps; import com.samskivert.depot.Key; import com.samskivert.depot.PersistentRecord; import com.samskivert.depot.annotation.Computed; @@ -170,9 +171,9 @@ public abstract class BuildVisitor implements FragmentVisitor return null; } - public Void visit (MultiOperator multiOperator) + public Void visit (MultiOperator multiOperator) { - SQLExpression[] conditions = multiOperator.getArgs(); + SQLExpression[] conditions = multiOperator.getArgs(); for (int ii = 0; ii < conditions.length; ii++) { if (ii > 0) { _builder.append(" ").append(multiOperator.operator()).append(" "); @@ -184,7 +185,7 @@ public abstract class BuildVisitor implements FragmentVisitor return null; } - public Void visit (BinaryOperator binaryOperator) + public Void visit (BinaryOperator binaryOperator) { _builder.append('('); binaryOperator.getLeftHandSide().accept(this); @@ -205,7 +206,7 @@ public abstract class BuildVisitor implements FragmentVisitor { // if the In() expression is empty, replace it with a 'false' if (in.getValues().length == 0) { - new ValueExp(false).accept(this); + Exps.value(false).accept(this); return null; } in.getExpression().accept(this); @@ -224,16 +225,16 @@ public abstract class BuildVisitor implements FragmentVisitor public abstract Void visit (FullText.Match match); public abstract Void visit (FullText.Rank rank); - public Void visit (Case caseExp) + public Void visit (Case caseExp) { _builder.append("(case "); - for (Tuple tuple : caseExp.getWhenExps()) { + for (Tuple, SQLExpression> tuple : caseExp.getWhenExps()) { _builder.append(" when "); tuple.left.accept(this); _builder.append(" then "); tuple.right.accept(this); } - SQLExpression elseExp = caseExp.getElseExp(); + SQLExpression elseExp = caseExp.getElseExp(); if (elseExp != null) { _builder.append(" else "); elseExp.accept(this); @@ -260,7 +261,7 @@ public abstract class BuildVisitor implements FragmentVisitor { _builder.append(" group by "); - SQLExpression[] values = groupBy.getValues(); + SQLExpression[] values = groupBy.getValues(); for (int ii = 0; ii < values.length; ii++) { if (ii > 0) { _builder.append(", "); @@ -280,7 +281,7 @@ public abstract class BuildVisitor implements FragmentVisitor { _builder.append(" order by "); - SQLExpression[] values = orderBy.getValues(); + SQLExpression[] values = orderBy.getValues(); OrderBy.Order[] orders = orderBy.getOrders(); for (int ii = 0; ii < values.length; ii++) { if (ii > 0) { @@ -320,13 +321,13 @@ public abstract class BuildVisitor implements FragmentVisitor return null; } - public Void visit (LiteralExp literalExp) + public Void visit (LiteralExp literalExp) { _builder.append(literalExp.getText()); return null; } - public Void visit (ValueExp valueExp) + public Void visit (ValueExp valueExp) { bindValue(valueExp.getValue()); return null; @@ -456,7 +457,7 @@ public abstract class BuildVisitor implements FragmentVisitor ColumnExp[] fields = updateClause.getFields(); Object pojo = updateClause.getPojo(); - SQLExpression[] values = updateClause.getValues(); + SQLExpression[] values = updateClause.getValues(); for (int ii = 0; ii < fields.length; ii ++) { if (ii > 0) { _builder.append(", "); @@ -499,7 +500,7 @@ public abstract class BuildVisitor implements FragmentVisitor public Void visit (CreateIndexClause createIndexClause) { if (!_allowComplexIndices) { - for (Tuple field : createIndexClause.getFields()) { + for (Tuple, Order> field : createIndexClause.getFields()) { if (!(field.left instanceof ColumnExp)) { log.warning("This database can't handle complex indexes. Aborting creation.", "ixName", createIndexClause.getName()); @@ -520,7 +521,7 @@ public abstract class BuildVisitor implements FragmentVisitor // turn off table abbreviations here _defaultType = createIndexClause.getPersistentClass(); boolean comma = false; - for (Tuple field : createIndexClause.getFields()) { + for (Tuple, Order> field : createIndexClause.getFields()) { if (comma) { _builder.append(", "); } @@ -558,67 +559,67 @@ public abstract class BuildVisitor implements FragmentVisitor // // NUMERICAL FUNCTIONS - public Void visit (Abs exp) + public Void visit (Abs exp) { return appendFunctionCall("abs", exp.getArg()); } - public Void visit (Ceil exp) + public Void visit (Ceil exp) { return appendFunctionCall("ceil", exp.getArg()); } - public Void visit (Exp exp) + public Void visit (Exp exp) { return appendFunctionCall("exp", exp.getArg()); } - public Void visit (Floor exp) + public Void visit (Floor exp) { return appendFunctionCall("floor", exp.getArg()); } - public Void visit (Ln exp) + public Void visit (Ln exp) { return appendFunctionCall("ln", exp.getArg()); } - public Void visit (Log10 exp) + public Void visit (Log10 exp) { return appendFunctionCall("log", exp.getArg()); } - public Void visit (Pi exp) + public Void visit (Pi exp) { return appendFunctionCall("PI"); } - public Void visit (Power exp) + public Void visit (Power exp) { return appendFunctionCall("power", exp.getPower(), exp.getValue()); } - public Void visit (Random exp) + public Void visit (Random exp) { return appendFunctionCall("random"); } - public Void visit (Round exp) + public Void visit (Round exp) { return appendFunctionCall("round", exp.getArg()); } - public Void visit (Sign exp) + public Void visit (Sign exp) { return appendFunctionCall("sign", exp.getArg()); } - public Void visit (Sqrt exp) + public Void visit (Sqrt exp) { return appendFunctionCall("sqrt", exp.getArg()); } - public Void visit (Trunc exp) + public Void visit (Trunc exp) { return appendFunctionCall("trunc", exp.getArg()); } @@ -668,7 +669,7 @@ public abstract class BuildVisitor implements FragmentVisitor return null; } - public Void visit (Average exp) + public Void visit (Average exp) { return appendAggregateFunctionCall("average", exp); } @@ -683,17 +684,17 @@ public abstract class BuildVisitor implements FragmentVisitor return appendAggregateFunctionCall("every", exp); } - public Void visit (Max exp) + public Void visit (Max exp) { return appendAggregateFunctionCall("max", exp); } - public Void visit (Min exp) + public Void visit (Min exp) { return appendAggregateFunctionCall("min", exp); } - public Void visit (Sum exp) + public Void visit (Sum exp) { return appendAggregateFunctionCall("sum", exp); } @@ -701,22 +702,22 @@ public abstract class BuildVisitor implements FragmentVisitor // // CONDITIONAL FUNCTIONS - public Void visit (Coalesce exp) + public Void visit (Coalesce exp) { return appendFunctionCall("coalesce", exp.getArgs()); } - public Void visit (Greatest exp) + public Void visit (Greatest exp) { return appendFunctionCall("greatest", exp.getArgs()); } - public Void visit (Least exp) + public Void visit (Least exp) { return appendFunctionCall("least", exp.getArgs()); } - protected Void appendAggregateFunctionCall (String function, AggregateFun exp) + protected Void appendAggregateFunctionCall (String function, AggregateFun exp) { _builder.append(" ").append(function).append("("); if (exp.isDistinct()) { @@ -727,7 +728,7 @@ public abstract class BuildVisitor implements FragmentVisitor return null; } - protected Void appendFunctionCall (String function, SQLExpression... args) + protected Void appendFunctionCall (String function, SQLExpression... args) { _builder.append(" ").append(function).append("("); appendArguments(args); @@ -735,7 +736,7 @@ public abstract class BuildVisitor implements FragmentVisitor return null; } - protected Void appendArguments (SQLExpression... args) + protected Void appendArguments (SQLExpression... args) { for (int ii = 0; ii < args.length; ii ++) { if (ii > 0) { @@ -955,9 +956,9 @@ public abstract class BuildVisitor implements FragmentVisitor if (value instanceof ByteEnum) { // byte enums require special conversion stmt.setByte(argIx, ((ByteEnum)value).toByte()); - } else if (value instanceof Enum) { + } else if (value instanceof Enum) { // enums are converted to strings - stmt.setString(argIx, ((Enum)value).name()); + stmt.setString(argIx, ((Enum)value).name()); } else if (value instanceof int[]) { // int arrays require conversion to byte arrays int[] data = (int[])value; diff --git a/src/main/java/com/samskivert/depot/impl/DepotMarshaller.java b/src/main/java/com/samskivert/depot/impl/DepotMarshaller.java index 049c33f..ad5d885 100644 --- a/src/main/java/com/samskivert/depot/impl/DepotMarshaller.java +++ b/src/main/java/com/samskivert/depot/impl/DepotMarshaller.java @@ -34,7 +34,6 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; import com.google.common.base.Function; -import com.google.common.base.Preconditions; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ListMultimap; import com.google.common.collect.Lists; @@ -121,9 +120,9 @@ public class DepotMarshaller implements QueryMarshal // introspect on the class and create marshallers and indices for persistent fields List> fields = Lists.newArrayList(); - ListMultimap> namedFieldIndices = + ListMultimap, Order>> namedFieldIndices = ArrayListMultimap.create(); - ListMultimap> uniqueNamedFieldIndices = + ListMultimap, Order>> uniqueNamedFieldIndices = ArrayListMultimap.create(); for (Field field : _pClass.getFields()) { int mods = field.getModifiers(); @@ -203,8 +202,8 @@ public class DepotMarshaller implements QueryMarshal Index index = field.getAnnotation(Index.class); if (index != null) { String name = index.name().equals("") ? field.getName() + "Index" : index.name(); - Tuple entry = - new Tuple(fieldColumn, Order.ASC); + Tuple, Order> entry = + new Tuple, Order>(fieldColumn, Order.ASC); if (index.unique()) { checkArgument(!namedFieldIndices.containsKey(index.name()), "All @Index for a particular name must be unique or non-unique"); @@ -955,22 +954,22 @@ public class DepotMarshaller implements QueryMarshal protected CreateIndexClause buildIndex (String name, boolean unique, Object config) { - List> definition = Lists.newArrayList(); + List, Order>> definition = Lists.newArrayList(); if (config instanceof ColumnExp) { - definition.add(new Tuple((ColumnExp)config, Order.ASC)); + definition.add(new Tuple, Order>((ColumnExp)config, Order.ASC)); } else if (config instanceof ColumnExp[]) { for (ColumnExp column : (ColumnExp[])config) { - definition.add(new Tuple(column, Order.ASC)); + definition.add(new Tuple, Order>(column, Order.ASC)); } } else if (config instanceof SQLExpression) { - definition.add(new Tuple((SQLExpression)config, Order.ASC)); + definition.add(new Tuple, Order>((SQLExpression)config, Order.ASC)); } else if (config instanceof Tuple) { - @SuppressWarnings("unchecked") Tuple tuple = - (Tuple)config; + @SuppressWarnings("unchecked") Tuple, Order> tuple = + (Tuple, Order>)config; definition.add(tuple); } else if (config instanceof List) { - @SuppressWarnings("unchecked") List> defs = - (List>)config; + @SuppressWarnings("unchecked") List, Order>> defs = + (List, Order>>)config; definition.addAll(defs); } else { throw new IllegalArgumentException( diff --git a/src/main/java/com/samskivert/depot/impl/ExpressionEvaluator.java b/src/main/java/com/samskivert/depot/impl/ExpressionEvaluator.java index d9556b3..96744b9 100644 --- a/src/main/java/com/samskivert/depot/impl/ExpressionEvaluator.java +++ b/src/main/java/com/samskivert/depot/impl/ExpressionEvaluator.java @@ -107,9 +107,9 @@ public class ExpressionEvaluator _pRec = pRec; } - public Object visit (MultiOperator multiOperator) + public Object visit (MultiOperator multiOperator) { - SQLExpression[] operands = multiOperator.getArgs(); + SQLExpression[] operands = multiOperator.getArgs(); Object[] values = new Object[operands.length]; for (int ii = 0; ii < operands.length; ii ++) { values[ii] = operands[ii].accept(this); @@ -121,7 +121,7 @@ public class ExpressionEvaluator return multiOperator.evaluate(values); } - public Object visit (BinaryOperator binaryOperator) + public Object visit (BinaryOperator binaryOperator) { Object left = binaryOperator.getLeftHandSide().accept(this); Object right = binaryOperator.getRightHandSide().accept(this); @@ -157,9 +157,9 @@ public class ExpressionEvaluator return new NoValue("Full Text Match not implemented"); } - public Object visit (Case caseExp) + public Object visit (Case caseExp) { - for (Tuple exp : caseExp.getWhenExps()) { + for (Tuple, SQLExpression> exp : caseExp.getWhenExps()) { Object result = exp.left.accept(this); if (result instanceof NoValue || !(result instanceof Boolean)) { return new NoValue("Failed to evaluate case: " + exp.left + " -> " + result); @@ -168,7 +168,7 @@ public class ExpressionEvaluator return exp.right.accept(this); } } - SQLExpression elseExp = caseExp.getElseExp(); + SQLExpression elseExp = caseExp.getElseExp(); if (elseExp != null) { return elseExp.accept(this); } @@ -209,12 +209,12 @@ public class ExpressionEvaluator return new NoValue("Boolean negation of non-boolean value: " + result); } - public Object visit (LiteralExp literalExp) + public Object visit (LiteralExp literalExp) { return new NoValue("Cannot evaluate LiteralExp: " + literalExp); } - public Object visit (ValueExp valueExp) + public Object visit (ValueExp valueExp) { return valueExp.getValue(); } @@ -336,67 +336,67 @@ public class ExpressionEvaluator // // NUMERICAL FUNCTIONS - public Void visit (Abs exp) + public Void visit (Abs exp) { throw new IllegalArgumentException("Can't evaluate expression: " + exp); } - public Void visit (Ceil exp) + public Void visit (Ceil exp) { throw new IllegalArgumentException("Can't evaluate expression: " + exp); } - public Void visit (Exp exp) + public Void visit (Exp exp) { throw new IllegalArgumentException("Can't evaluate expression: " + exp); } - public Void visit (Floor exp) + public Void visit (Floor exp) { throw new IllegalArgumentException("Can't evaluate expression: " + exp); } - public Void visit (Ln exp) + public Void visit (Ln exp) { throw new IllegalArgumentException("Can't evaluate expression: " + exp); } - public Void visit (Log10 exp) + public Void visit (Log10 exp) { throw new IllegalArgumentException("Can't evaluate expression: " + exp); } - public Void visit (Pi exp) + public Void visit (Pi exp) { throw new IllegalArgumentException("Can't evaluate expression: " + exp); } - public Void visit (Power exp) + public Void visit (Power exp) { throw new IllegalArgumentException("Can't evaluate expression: " + exp); } - public Void visit (Random exp) + public Void visit (Random exp) { throw new IllegalArgumentException("Can't evaluate expression: " + exp); } - public Void visit (Round exp) + public Void visit (Round exp) { throw new IllegalArgumentException("Can't evaluate expression: " + exp); } - public Void visit (Sign exp) + public Void visit (Sign exp) { throw new IllegalArgumentException("Can't evaluate expression: " + exp); } - public Void visit (Sqrt exp) + public Void visit (Sqrt exp) { throw new IllegalArgumentException("Can't evaluate expression: " + exp); } - public Void visit (Trunc exp) + public Void visit (Trunc exp) { throw new IllegalArgumentException("Can't evaluate expression: " + exp); } @@ -449,7 +449,7 @@ public class ExpressionEvaluator throw new IllegalArgumentException("Can't evaluate expression: " + exp); } - public Void visit (Average exp) + public Void visit (Average exp) { throw new IllegalArgumentException("Can't evaluate expression: " + exp); } @@ -464,17 +464,17 @@ public class ExpressionEvaluator throw new IllegalArgumentException("Can't evaluate expression: " + exp); } - public Void visit (Max exp) + public Void visit (Max exp) { throw new IllegalArgumentException("Can't evaluate expression: " + exp); } - public Void visit (Min exp) + public Void visit (Min exp) { throw new IllegalArgumentException("Can't evaluate expression: " + exp); } - public Void visit (Sum exp) + public Void visit (Sum exp) { throw new IllegalArgumentException("Can't evaluate expression: " + exp); } @@ -482,17 +482,17 @@ public class ExpressionEvaluator // // CONDITIONAL FUNCTIONS - public Void visit (Coalesce exp) + public Void visit (Coalesce exp) { throw new IllegalArgumentException("Can't evaluate expression: " + exp); } - public Void visit (Greatest exp) + public Void visit (Greatest exp) { throw new IllegalArgumentException("Can't evaluate expression: " + exp); } - public Void visit (Least exp) + public Void visit (Least exp) { throw new IllegalArgumentException("Can't evaluate expression: " + exp); } diff --git a/src/main/java/com/samskivert/depot/impl/FragmentVisitor.java b/src/main/java/com/samskivert/depot/impl/FragmentVisitor.java index 66d2d65..67ffa95 100644 --- a/src/main/java/com/samskivert/depot/impl/FragmentVisitor.java +++ b/src/main/java/com/samskivert/depot/impl/FragmentVisitor.java @@ -89,8 +89,8 @@ public interface FragmentVisitor { public T visit (FieldDefinition fieldOverride); public T visit (FromOverride fromOverride); - public T visit (MultiOperator multiOperator); - public T visit (BinaryOperator binaryOperator); + public T visit (MultiOperator multiOperator); + public T visit (BinaryOperator binaryOperator); public T visit (IsNull isNull); public T visit (In in); public T visit (FullText.Match match); @@ -102,8 +102,8 @@ public interface FragmentVisitor public T visit (OrderBy orderBy); public T visit (Join join); public T visit (Limit limit); - public T visit (LiteralExp literal); - public T visit (ValueExp value); + public T visit (LiteralExp literal); + public T visit (ValueExp value); public T visit (IntervalExp interval); public T visit (WhereClause where); public T visit (Key.Expression key); @@ -114,22 +114,22 @@ public interface FragmentVisitor public T visit (InsertClause insertClause); public T visit (CreateIndexClause createIndexClause); public T visit (DropIndexClause dropIndexClause); - public T visit (Case caseExp); + public T visit (Case caseExp); // Numerical - public T visit (Abs exp); - public T visit (Ceil exp); - public T visit (Exp exp); - public T visit (Floor exp); - public T visit (Ln exp); - public T visit (Log10 exp); - public T visit (Pi exp); - public T visit (Power exp); - public T visit (Random exp); - public T visit (Round exp); - public T visit (Sign exp); - public T visit (Sqrt exp); - public T visit (Trunc exp); + public T visit (Abs exp); + public T visit (Ceil exp); + public T visit (Exp exp); + public T visit (Floor exp); + public T visit (Ln exp); + public T visit (Log10 exp); + public T visit (Pi exp); + public T visit (Power exp); + public T visit (Random exp); + public T visit (Round exp); + public T visit (Sign exp); + public T visit (Sqrt exp); + public T visit (Trunc exp); // String public T visit (Length exp); @@ -145,15 +145,15 @@ public interface FragmentVisitor public T visit (Now exp); // Aggregation - public T visit (Average exp); + public T visit (Average exp); public T visit (Count exp); public T visit (Every exp); - public T visit (Max exp); - public T visit (Min exp); - public T visit (Sum exp); + public T visit (Max exp); + public T visit (Min exp); + public T visit (Sum exp); // Conditional - public T visit (Coalesce exp); - public T visit (Greatest exp); - public T visit (Least exp); + public T visit (Coalesce exp); + public T visit (Greatest exp); + public T visit (Least exp); } diff --git a/src/main/java/com/samskivert/depot/impl/HSQLBuilder.java b/src/main/java/com/samskivert/depot/impl/HSQLBuilder.java index daf70a9..dc9c23e 100644 --- a/src/main/java/com/samskivert/depot/impl/HSQLBuilder.java +++ b/src/main/java/com/samskivert/depot/impl/HSQLBuilder.java @@ -71,12 +71,12 @@ public class HSQLBuilder } // now iterate over the cartesian product of the query words & the fields - List bits = Lists.newArrayList(); + List> bits = Lists.newArrayList(); for (String field : fields) { for (String ftsWord : ftsWords) { // build comparisons between each word and column - bits.add(new Like(new Lower( - new ColumnExp(pClass, field)), "%"+ftsWord+"%", true)); + bits.add(new Like(new Lower(new ColumnExp(pClass, field)), + "%"+ftsWord+"%", true)); } } // then just OR them all together and we have our query @@ -93,7 +93,7 @@ public class HSQLBuilder } @Override - public Void visit (MultiOperator operator) + public Void visit (MultiOperator operator) { // HSQL doesn't handle & and | operators if (operator instanceof BitAnd) { @@ -225,7 +225,7 @@ public class HSQLBuilder } /** Holds the Full Text Seach condition between build and bind phases. */ - protected SQLExpression _ftsCondition; + protected SQLExpression _ftsCondition; protected static final FieldMarshaller.ColumnTyper TYPER = new FieldMarshaller.ColumnTyper() { public String getBooleanType (int length) { diff --git a/src/main/java/com/samskivert/depot/impl/MySQLBuilder.java b/src/main/java/com/samskivert/depot/impl/MySQLBuilder.java index 2199cea..cf89169 100644 --- a/src/main/java/com/samskivert/depot/impl/MySQLBuilder.java +++ b/src/main/java/com/samskivert/depot/impl/MySQLBuilder.java @@ -72,7 +72,7 @@ public class MySQLBuilder return null; } - @Override public Void visit (Trunc exp) + @Override public Void visit (Trunc exp) { return appendFunctionCall("truncate", exp.getArg()); } diff --git a/src/main/java/com/samskivert/depot/impl/PostgreSQL4Builder.java b/src/main/java/com/samskivert/depot/impl/PostgreSQL4Builder.java index 1432b50..90c9f4b 100644 --- a/src/main/java/com/samskivert/depot/impl/PostgreSQL4Builder.java +++ b/src/main/java/com/samskivert/depot/impl/PostgreSQL4Builder.java @@ -28,7 +28,7 @@ import java.sql.SQLException; import java.sql.Timestamp; import com.samskivert.depot.DatabaseException; -import com.samskivert.depot.impl.expression.ValueExp; +import com.samskivert.depot.Exps; import com.samskivert.depot.impl.operator.In; import com.samskivert.util.ByteEnum; @@ -43,7 +43,7 @@ public class PostgreSQL4Builder extends PostgreSQLBuilder // if the In() expression is empty, replace it with a 'false' final Comparable[] values = in.getValues(); if (values.length == 0) { - new ValueExp(false).accept(this); + Exps.value(false).accept(this); return null; } in.getExpression().accept(this); diff --git a/src/main/java/com/samskivert/depot/impl/clause/CreateIndexClause.java b/src/main/java/com/samskivert/depot/impl/clause/CreateIndexClause.java index f0f241e..3795387 100644 --- a/src/main/java/com/samskivert/depot/impl/clause/CreateIndexClause.java +++ b/src/main/java/com/samskivert/depot/impl/clause/CreateIndexClause.java @@ -43,7 +43,7 @@ public class CreateIndexClause * database. */ public CreateIndexClause (Class pClass, String name, boolean unique, - List> fields) + List, Order>> fields) { _pClass = pClass; _name = name; @@ -66,7 +66,7 @@ public class CreateIndexClause return _unique; } - public List> getFields () + public List,Order>> getFields () { return _fields; } @@ -88,5 +88,5 @@ public class CreateIndexClause protected boolean _unique; /** The components of the index, e.g. columns or functions of columns. */ - protected List> _fields; + protected List,Order>> _fields; } diff --git a/src/main/java/com/samskivert/depot/impl/clause/UpdateClause.java b/src/main/java/com/samskivert/depot/impl/clause/UpdateClause.java index 8f4fbba..48c20d9 100644 --- a/src/main/java/com/samskivert/depot/impl/clause/UpdateClause.java +++ b/src/main/java/com/samskivert/depot/impl/clause/UpdateClause.java @@ -47,7 +47,7 @@ public class UpdateClause } public UpdateClause (Class pClass, WhereClause where, - ColumnExp[] fields, SQLExpression[] values) + ColumnExp[] fields, SQLExpression[] values) { _pClass = pClass; _fields = fields; @@ -66,7 +66,7 @@ public class UpdateClause return _fields; } - public SQLExpression[] getValues () + public SQLExpression[] getValues () { return _values; } @@ -111,7 +111,7 @@ public class UpdateClause protected ColumnExp[] _fields; /** The field values, or null. */ - protected SQLExpression[] _values; + protected SQLExpression[] _values; /** The object from which to fetch values, or null. */ protected PersistentRecord _pojo; diff --git a/src/main/java/com/samskivert/depot/impl/expression/AggregateFun.java b/src/main/java/com/samskivert/depot/impl/expression/AggregateFun.java index 5868cec..4838123 100644 --- a/src/main/java/com/samskivert/depot/impl/expression/AggregateFun.java +++ b/src/main/java/com/samskivert/depot/impl/expression/AggregateFun.java @@ -24,13 +24,13 @@ import com.samskivert.depot.expression.SQLExpression; import com.samskivert.depot.impl.FragmentVisitor; import com.samskivert.depot.impl.expression.Function.OneArgFun; -public abstract class AggregateFun extends OneArgFun +public abstract class AggregateFun extends OneArgFun { - public static class Average extends AggregateFun { - public Average (SQLExpression argument) { + public static class Average extends AggregateFun { + public Average (SQLExpression argument) { this(argument, false); } - public Average (SQLExpression argument, boolean distinct) { + public Average (SQLExpression argument, boolean distinct) { super(argument, distinct); } public Object accept (FragmentVisitor visitor) { @@ -41,11 +41,11 @@ public abstract class AggregateFun extends OneArgFun } } - public static class Count extends AggregateFun { - public Count (SQLExpression argument) { + public static class Count extends AggregateFun { + public Count (SQLExpression argument) { this(argument, false); } - public Count (SQLExpression argument, boolean distinct) { + public Count (SQLExpression argument, boolean distinct) { super(argument, distinct); } public Object accept (FragmentVisitor visitor) { @@ -56,11 +56,11 @@ public abstract class AggregateFun extends OneArgFun } } - public static class Every extends AggregateFun { - public Every (SQLExpression argument) { + public static class Every extends AggregateFun { + public Every (SQLExpression argument) { this(argument, false); } - public Every (SQLExpression argument, boolean distinct) { + public Every (SQLExpression argument, boolean distinct) { super(argument, distinct); } public Object accept (FragmentVisitor visitor) { @@ -71,11 +71,11 @@ public abstract class AggregateFun extends OneArgFun } } - public static class Max extends AggregateFun { - public Max (SQLExpression argument) { + public static class Max extends AggregateFun { + public Max (SQLExpression argument) { this(argument, false); } - public Max (SQLExpression argument, boolean distinct) { + public Max (SQLExpression argument, boolean distinct) { super(argument, distinct); } public Object accept (FragmentVisitor visitor) { @@ -86,11 +86,11 @@ public abstract class AggregateFun extends OneArgFun } } - public static class Min extends AggregateFun { - public Min (SQLExpression argument) { + public static class Min extends AggregateFun { + public Min (SQLExpression argument) { this(argument, false); } - public Min (SQLExpression argument, boolean distinct) { + public Min (SQLExpression argument, boolean distinct) { super(argument, distinct); } public Object accept (FragmentVisitor visitor) { @@ -101,11 +101,11 @@ public abstract class AggregateFun extends OneArgFun } } - public static class Sum extends AggregateFun { - public Sum (SQLExpression argument) { + public static class Sum extends AggregateFun { + public Sum (SQLExpression argument) { this(argument, false); } - public Sum (SQLExpression argument, boolean distinct) { + public Sum (SQLExpression argument, boolean distinct) { super(argument, distinct); } public Object accept (FragmentVisitor visitor) { @@ -116,7 +116,7 @@ public abstract class AggregateFun extends OneArgFun } } - public AggregateFun (SQLExpression argument, boolean distinct) + public AggregateFun (SQLExpression argument, boolean distinct) { super(argument); _distinct = distinct; diff --git a/src/main/java/com/samskivert/depot/impl/expression/ArgumentExp.java b/src/main/java/com/samskivert/depot/impl/expression/ArgumentExp.java index 549f453..1011e9f 100644 --- a/src/main/java/com/samskivert/depot/impl/expression/ArgumentExp.java +++ b/src/main/java/com/samskivert/depot/impl/expression/ArgumentExp.java @@ -26,24 +26,24 @@ import com.samskivert.depot.PersistentRecord; import com.samskivert.depot.expression.FluentExp; import com.samskivert.depot.expression.SQLExpression; -public abstract class ArgumentExp extends FluentExp +public abstract class ArgumentExp extends FluentExp { - protected ArgumentExp (SQLExpression... args) + protected ArgumentExp (SQLExpression... args) { _args = args; } public void addClasses (Collection> classSet) { - for (SQLExpression arg : _args) { + for (SQLExpression arg : _args) { arg.addClasses(classSet); } } - public SQLExpression[] getArgs () + public SQLExpression[] getArgs () { return _args; } - protected SQLExpression[] _args; + protected SQLExpression[] _args; } diff --git a/src/main/java/com/samskivert/depot/impl/expression/ConditionalFun.java b/src/main/java/com/samskivert/depot/impl/expression/ConditionalFun.java index f082330..580ff31 100644 --- a/src/main/java/com/samskivert/depot/impl/expression/ConditionalFun.java +++ b/src/main/java/com/samskivert/depot/impl/expression/ConditionalFun.java @@ -26,10 +26,13 @@ import com.samskivert.depot.impl.expression.Function.ManyArgFun; public abstract class ConditionalFun { - public static class Coalesce extends ManyArgFun { - public Coalesce (SQLExpression... args) { + public static class Coalesce extends ManyArgFun { + public Coalesce (SQLExpression... args) { super(args); } + public Coalesce (SQLExpression arg1, SQLExpression arg2) { + super(arg1, arg2); + } public Object accept (FragmentVisitor visitor) { return visitor.visit(this); } @@ -38,10 +41,13 @@ public abstract class ConditionalFun } } - public static class Greatest extends ManyArgFun { - public Greatest (SQLExpression... args) { + public static class Greatest extends ManyArgFun { + public Greatest (SQLExpression... args) { super(args); } + public Greatest (SQLExpression arg1, SQLExpression arg2) { + super(arg1, arg2); + } public Object accept (FragmentVisitor visitor) { return visitor.visit(this); } @@ -50,10 +56,13 @@ public abstract class ConditionalFun } } - public static class Least extends ManyArgFun { - public Least (SQLExpression... args) { + public static class Least extends ManyArgFun { + public Least (SQLExpression... args) { super(args); } + public Least (SQLExpression arg1, SQLExpression arg2) { + super(arg1, arg2); + } public Object accept (FragmentVisitor visitor) { return visitor.visit(this); } diff --git a/src/main/java/com/samskivert/depot/impl/expression/DateFun.java b/src/main/java/com/samskivert/depot/impl/expression/DateFun.java index c87635b..29e641f 100644 --- a/src/main/java/com/samskivert/depot/impl/expression/DateFun.java +++ b/src/main/java/com/samskivert/depot/impl/expression/DateFun.java @@ -20,6 +20,9 @@ package com.samskivert.depot.impl.expression; +import java.sql.Date; +import java.sql.Timestamp; + import com.samskivert.depot.expression.SQLExpression; import com.samskivert.depot.impl.FragmentVisitor; import com.samskivert.depot.impl.expression.Function.NoArgFun; @@ -27,12 +30,12 @@ import com.samskivert.depot.impl.expression.Function.OneArgFun; public abstract class DateFun { - public static class DatePart extends OneArgFun { + public static class DatePart extends OneArgFun { public enum Part { DAY_OF_MONTH, DAY_OF_WEEK, DAY_OF_YEAR, HOUR, MINUTE, MONTH, SECOND, WEEK, YEAR, EPOCH } - public DatePart (SQLExpression date, Part part) { + public DatePart (SQLExpression date, Part part) { super(date); _part = part; } @@ -48,7 +51,7 @@ public abstract class DateFun protected Part _part; } - public static class DateTruncate extends OneArgFun { + public static class DateTruncate extends OneArgFun { /** * The degree of truncation to perform, in time units. Currently only DAY, due to lacking * MySQL support, but we hope for future versions to match PostgreSQL. @@ -60,7 +63,7 @@ public abstract class DateFun * Truncate a SQL timestamp value, currently only to the nearest day (Truncation.DAY) due * to lacking MySQL support, but we hope for future versions to match PostgreSQL. */ - public DateTruncate (SQLExpression date, Truncation truncation) { + public DateTruncate (SQLExpression date, Truncation truncation) { super(date); _truncation= truncation; } @@ -76,7 +79,7 @@ public abstract class DateFun protected Truncation _truncation; } - public static class Now extends NoArgFun { + public static class Now extends NoArgFun { public Object accept (FragmentVisitor visitor) { return visitor.visit(this); } diff --git a/src/main/java/com/samskivert/depot/impl/expression/Function.java b/src/main/java/com/samskivert/depot/impl/expression/Function.java index 71a39f8..2d9acf1 100644 --- a/src/main/java/com/samskivert/depot/impl/expression/Function.java +++ b/src/main/java/com/samskivert/depot/impl/expression/Function.java @@ -31,7 +31,7 @@ public interface Function { String getCanonicalFunctionName (); - public static abstract class NoArgFun extends FluentExp implements Function + public static abstract class NoArgFun extends FluentExp implements Function { public void addClasses (Collection> classSet) { @@ -39,9 +39,9 @@ public interface Function } } - public static abstract class OneArgFun extends FluentExp implements Function + public static abstract class OneArgFun extends FluentExp implements Function { - protected OneArgFun (SQLExpression argument) + protected OneArgFun (SQLExpression argument) { _arg = argument; } @@ -51,7 +51,7 @@ public interface Function _arg.addClasses(classSet); } - public SQLExpression getArg () + public SQLExpression getArg () { return _arg; } @@ -62,12 +62,12 @@ public interface Function return getCanonicalFunctionName() + "(" + _arg + ")"; } - protected SQLExpression _arg; + protected SQLExpression _arg; } - public static abstract class TwoArgFun extends FluentExp implements Function + public static abstract class TwoArgFun extends FluentExp implements Function { - protected TwoArgFun (SQLExpression arg1, SQLExpression arg2) + protected TwoArgFun (SQLExpression arg1, SQLExpression arg2) { _arg1 = arg1; _arg2 = arg2; @@ -85,16 +85,25 @@ public interface Function return getCanonicalFunctionName() + "(" + _arg1 + ", " + _arg2 + ")"; } - protected SQLExpression _arg1, _arg2; + protected SQLExpression _arg1, _arg2; } - public static abstract class ManyArgFun extends ArgumentExp implements Function + public static abstract class ManyArgFun extends ArgumentExp implements Function { - protected ManyArgFun (SQLExpression... args) + protected ManyArgFun (SQLExpression... args) { super(args); } + // we specialize for arity two to allow subtypes who require proper generic types to + // provide arity two constructors for use in 99% of the cases where you don't need + // arbitrary arguments and don't want to have to suppress the annoying use-site generic + // varargs array creation warning + protected ManyArgFun (SQLExpression arg1, SQLExpression arg2) + { + super(arg1, arg2); + } + @Override public String toString () { diff --git a/src/main/java/com/samskivert/depot/impl/expression/IntervalExp.java b/src/main/java/com/samskivert/depot/impl/expression/IntervalExp.java index 6dcd069..66d472d 100644 --- a/src/main/java/com/samskivert/depot/impl/expression/IntervalExp.java +++ b/src/main/java/com/samskivert/depot/impl/expression/IntervalExp.java @@ -30,7 +30,7 @@ import com.samskivert.depot.impl.FragmentVisitor; * A code for representing a date interval. */ public class IntervalExp - implements SQLExpression + implements SQLExpression { /** The units that can be used for an interval. */ public enum Unit { YEAR, MONTH, DAY, HOUR, MINUTE, SECOND } diff --git a/src/main/java/com/samskivert/depot/impl/expression/LiteralExp.java b/src/main/java/com/samskivert/depot/impl/expression/LiteralExp.java index ce0532e..21ee426 100644 --- a/src/main/java/com/samskivert/depot/impl/expression/LiteralExp.java +++ b/src/main/java/com/samskivert/depot/impl/expression/LiteralExp.java @@ -29,8 +29,8 @@ import com.samskivert.depot.impl.FragmentVisitor; /** * An expression for things we don't support natively, e.g. COUNT(*). */ -public class LiteralExp - implements SQLExpression +public class LiteralExp + implements SQLExpression { public LiteralExp (String text) { diff --git a/src/main/java/com/samskivert/depot/impl/expression/NumericalFun.java b/src/main/java/com/samskivert/depot/impl/expression/NumericalFun.java index 3cd602c..8997c7c 100644 --- a/src/main/java/com/samskivert/depot/impl/expression/NumericalFun.java +++ b/src/main/java/com/samskivert/depot/impl/expression/NumericalFun.java @@ -28,8 +28,8 @@ import com.samskivert.depot.impl.expression.Function.TwoArgFun; public abstract class NumericalFun { - public static class Abs extends OneArgFun { - public Abs (SQLExpression argument) { + public static class Abs extends OneArgFun { + public Abs (SQLExpression argument) { super(argument); } public Object accept (FragmentVisitor visitor) { @@ -40,8 +40,8 @@ public abstract class NumericalFun } } - public static class Ceil extends OneArgFun { - public Ceil (SQLExpression argument) { + public static class Ceil extends OneArgFun { + public Ceil (SQLExpression argument) { super(argument); } public Object accept (FragmentVisitor visitor) { @@ -52,8 +52,8 @@ public abstract class NumericalFun } } - public static class Exp extends OneArgFun { - public Exp (SQLExpression argument) { + public static class Exp extends OneArgFun { + public Exp (SQLExpression argument) { super(argument); } public Object accept (FragmentVisitor visitor) { @@ -64,8 +64,8 @@ public abstract class NumericalFun } } - public static class Floor extends OneArgFun { - public Floor (SQLExpression argument) { + public static class Floor extends OneArgFun { + public Floor (SQLExpression argument) { super(argument); } public Object accept (FragmentVisitor visitor) { @@ -76,8 +76,8 @@ public abstract class NumericalFun } } - public static class Ln extends OneArgFun { - public Ln (SQLExpression argument) { + public static class Ln extends OneArgFun { + public Ln (SQLExpression argument) { super(argument); } public Object accept (FragmentVisitor visitor) { @@ -88,8 +88,8 @@ public abstract class NumericalFun } } - public static class Log10 extends OneArgFun { - public Log10 (SQLExpression value) { + public static class Log10 extends OneArgFun { + public Log10 (SQLExpression value) { super(value); } public Object accept (FragmentVisitor visitor) { @@ -100,7 +100,7 @@ public abstract class NumericalFun } } - public static class Pi extends NoArgFun { + public static class Pi extends NoArgFun { public Object accept (FragmentVisitor visitor) { return visitor.visit(this); } @@ -109,8 +109,8 @@ public abstract class NumericalFun } } - public static class Power extends TwoArgFun { - public Power (SQLExpression value, SQLExpression power) { + public static class Power extends TwoArgFun { + public Power (SQLExpression value, SQLExpression

power) { super(value, power); } public Object accept (FragmentVisitor visitor) { @@ -119,15 +119,15 @@ public abstract class NumericalFun public String getCanonicalFunctionName () { return "Power"; } - public SQLExpression getValue () { + public SQLExpression getValue () { return _arg1; } - public SQLExpression getPower () { + public SQLExpression getPower () { return _arg2; } } - public static class Random extends NoArgFun { + public static class Random extends NoArgFun { public Object accept (FragmentVisitor visitor) { return visitor.visit(this); } @@ -136,8 +136,8 @@ public abstract class NumericalFun } } - public static class Round extends OneArgFun { - public Round (SQLExpression argument) { + public static class Round extends OneArgFun { + public Round (SQLExpression argument) { super(argument); } public Object accept (FragmentVisitor visitor) { @@ -148,8 +148,8 @@ public abstract class NumericalFun } } - public static class Sign extends OneArgFun { - public Sign (SQLExpression argument) { + public static class Sign extends OneArgFun { + public Sign (SQLExpression argument) { super(argument); } public Object accept (FragmentVisitor visitor) { @@ -160,8 +160,8 @@ public abstract class NumericalFun } } - public static class Sqrt extends OneArgFun { - public Sqrt (SQLExpression argument) { + public static class Sqrt extends OneArgFun { + public Sqrt (SQLExpression argument) { super(argument); } public Object accept (FragmentVisitor visitor) { @@ -172,8 +172,8 @@ public abstract class NumericalFun } } - public static class Trunc extends OneArgFun { - public Trunc (SQLExpression argument) { + public static class Trunc extends OneArgFun { + public Trunc (SQLExpression argument) { super(argument); } public Object accept (FragmentVisitor visitor) { diff --git a/src/main/java/com/samskivert/depot/impl/expression/StringFun.java b/src/main/java/com/samskivert/depot/impl/expression/StringFun.java index 64c0227..cbf48b8 100644 --- a/src/main/java/com/samskivert/depot/impl/expression/StringFun.java +++ b/src/main/java/com/samskivert/depot/impl/expression/StringFun.java @@ -28,8 +28,9 @@ import com.samskivert.depot.impl.expression.Function.TwoArgFun; public abstract class StringFun { - public static class Length extends OneArgFun { - public Length (SQLExpression argument) { + public static class Length extends OneArgFun { + // can take both String or array types (anything that turns into byte[]) + public Length (SQLExpression argument) { super(argument); } public Object accept (FragmentVisitor visitor) { @@ -40,8 +41,8 @@ public abstract class StringFun } } - public static class Lower extends OneArgFun { - public Lower (SQLExpression argument) { + public static class Lower extends OneArgFun { + public Lower (SQLExpression argument) { super(argument); } public Object accept (FragmentVisitor visitor) { @@ -52,8 +53,8 @@ public abstract class StringFun } } - public static class Position extends TwoArgFun { - public Position (SQLExpression substring, SQLExpression string) { + public static class Position extends TwoArgFun { + public Position (SQLExpression substring, SQLExpression string) { super(substring, string); } public Object accept (FragmentVisitor visitor) { @@ -62,16 +63,17 @@ public abstract class StringFun public String getCanonicalFunctionName () { return "position"; } - public SQLExpression getSubString () { + public SQLExpression getSubString () { return _arg1; } - public SQLExpression getString () { + public SQLExpression getString () { return _arg2; } } - public static class Substring extends ManyArgFun { - public Substring (SQLExpression string, SQLExpression from, SQLExpression count) { + public static class Substring extends ManyArgFun { + public Substring (SQLExpression string, SQLExpression from, + SQLExpression count) { super(string, from, count); } public Object accept (FragmentVisitor visitor) { @@ -82,8 +84,8 @@ public abstract class StringFun } } - public static class Trim extends OneArgFun { - public Trim (SQLExpression argument) { + public static class Trim extends OneArgFun { + public Trim (SQLExpression argument) { super(argument); } public Object accept (FragmentVisitor visitor) { @@ -94,8 +96,8 @@ public abstract class StringFun } } - public static class Upper extends OneArgFun { - public Upper (SQLExpression argument) { + public static class Upper extends OneArgFun { + public Upper (SQLExpression argument) { super(argument); } public Object accept (FragmentVisitor visitor) { diff --git a/src/main/java/com/samskivert/depot/impl/expression/ValueExp.java b/src/main/java/com/samskivert/depot/impl/expression/ValueExp.java index 47bdd5d..3698fd8 100644 --- a/src/main/java/com/samskivert/depot/impl/expression/ValueExp.java +++ b/src/main/java/com/samskivert/depot/impl/expression/ValueExp.java @@ -29,9 +29,9 @@ import com.samskivert.depot.impl.FragmentVisitor; /** * A Java value that is bound as a parameter to the query, e.g. 1 or 'abc'. */ -public class ValueExp extends FluentExp +public class ValueExp extends FluentExp { - public ValueExp (Object value) + public ValueExp (T value) { _value = value; } @@ -47,7 +47,7 @@ public class ValueExp extends FluentExp { } - public Object getValue () + public T getValue () { return _value; } @@ -59,5 +59,5 @@ public class ValueExp extends FluentExp } /** The value to be bound to the SQL parameters. */ - protected Object _value; + protected T _value; } diff --git a/src/main/java/com/samskivert/depot/impl/operator/Add.java b/src/main/java/com/samskivert/depot/impl/operator/Add.java index 20f8914..d6c4728 100644 --- a/src/main/java/com/samskivert/depot/impl/operator/Add.java +++ b/src/main/java/com/samskivert/depot/impl/operator/Add.java @@ -25,14 +25,14 @@ import com.samskivert.depot.expression.SQLExpression; /** * The SQL '+' operator. */ -public class Add extends Arithmetic +public class Add extends Arithmetic { - public Add (SQLExpression column, Comparable value) + public Add (SQLExpression column, T value) { super(column, value); } - public Add (SQLExpression... values) + public Add (SQLExpression... values) { super(values); } diff --git a/src/main/java/com/samskivert/depot/impl/operator/Arithmetic.java b/src/main/java/com/samskivert/depot/impl/operator/Arithmetic.java index 3810bda..9d3d478 100644 --- a/src/main/java/com/samskivert/depot/impl/operator/Arithmetic.java +++ b/src/main/java/com/samskivert/depot/impl/operator/Arithmetic.java @@ -26,14 +26,14 @@ import com.samskivert.depot.impl.expression.ValueExp; /** * A convenient container for implementations of arithmetic operators. */ -public abstract class Arithmetic extends MultiOperator +public abstract class Arithmetic extends MultiOperator { - public Arithmetic (SQLExpression column, Comparable value) + public Arithmetic (SQLExpression column, T value) { - super(column, new ValueExp(value)); + super(column, new ValueExp(value)); } - public Arithmetic (SQLExpression... values) + public Arithmetic (SQLExpression... values) { super(values); } diff --git a/src/main/java/com/samskivert/depot/impl/operator/BaseOperator.java b/src/main/java/com/samskivert/depot/impl/operator/BaseOperator.java index 99dbd31..e075269 100644 --- a/src/main/java/com/samskivert/depot/impl/operator/BaseOperator.java +++ b/src/main/java/com/samskivert/depot/impl/operator/BaseOperator.java @@ -15,7 +15,7 @@ import com.samskivert.depot.impl.expression.ArgumentExp; /** * A base class for all operators. */ -public abstract class BaseOperator extends ArgumentExp +public abstract class BaseOperator extends ArgumentExp { public static Function INTEGRAL = new Function() { public Long apply (Object o) { @@ -60,7 +60,7 @@ public abstract class BaseOperator extends ArgumentExp return v; } - protected BaseOperator (SQLExpression... operands) + protected BaseOperator (SQLExpression... operands) { super(operands); } diff --git a/src/main/java/com/samskivert/depot/impl/operator/BinaryOperator.java b/src/main/java/com/samskivert/depot/impl/operator/BinaryOperator.java index b55153f..0977982 100644 --- a/src/main/java/com/samskivert/depot/impl/operator/BinaryOperator.java +++ b/src/main/java/com/samskivert/depot/impl/operator/BinaryOperator.java @@ -3,23 +3,23 @@ package com.samskivert.depot.impl.operator; +import com.samskivert.depot.Exps; import com.samskivert.depot.expression.SQLExpression; import com.samskivert.depot.impl.FragmentVisitor; -import com.samskivert.depot.impl.expression.ValueExp; /** * Does the real work for simple binary operators such as Equals. */ -public abstract class BinaryOperator extends BaseOperator +public abstract class BinaryOperator extends BaseOperator { - public BinaryOperator (SQLExpression lhs, SQLExpression rhs) + public BinaryOperator (SQLExpression lhs, SQLExpression rhs) { super(lhs, rhs); } - public BinaryOperator (SQLExpression lhs, Comparable rhs) + public BinaryOperator (SQLExpression lhs, Comparable rhs) { - this(lhs, new ValueExp(rhs)); + this(lhs, Exps.value(rhs)); } /** @@ -38,12 +38,12 @@ public abstract class BinaryOperator extends BaseOperator return builder.visit(this); } - public SQLExpression getLeftHandSide () + public SQLExpression getLeftHandSide () { return _args[0]; } - public SQLExpression getRightHandSide () + public SQLExpression getRightHandSide () { return _args[1]; } diff --git a/src/main/java/com/samskivert/depot/impl/operator/BitAnd.java b/src/main/java/com/samskivert/depot/impl/operator/BitAnd.java index 8358ddd..de0a087 100644 --- a/src/main/java/com/samskivert/depot/impl/operator/BitAnd.java +++ b/src/main/java/com/samskivert/depot/impl/operator/BitAnd.java @@ -25,14 +25,14 @@ import com.samskivert.depot.expression.SQLExpression; /** * The SQL '&' operator. */ -public class BitAnd extends Arithmetic +public class BitAnd extends Arithmetic { - public BitAnd (SQLExpression column, Comparable value) + public BitAnd (SQLExpression column, T value) { super(column, value); } - public BitAnd (SQLExpression... values) + public BitAnd (SQLExpression... values) { super(values); } diff --git a/src/main/java/com/samskivert/depot/impl/operator/BitOr.java b/src/main/java/com/samskivert/depot/impl/operator/BitOr.java index bdf9360..b29eff5 100644 --- a/src/main/java/com/samskivert/depot/impl/operator/BitOr.java +++ b/src/main/java/com/samskivert/depot/impl/operator/BitOr.java @@ -25,14 +25,14 @@ import com.samskivert.depot.expression.SQLExpression; /** * The SQL '|' operator. */ -public class BitOr extends Arithmetic +public class BitOr extends Arithmetic { - public BitOr (SQLExpression column, Comparable value) + public BitOr (SQLExpression column, T value) { super(column, value); } - public BitOr (SQLExpression... values) + public BitOr (SQLExpression... values) { super(values); } diff --git a/src/main/java/com/samskivert/depot/impl/operator/Div.java b/src/main/java/com/samskivert/depot/impl/operator/Div.java index d48ebb6..231100c 100644 --- a/src/main/java/com/samskivert/depot/impl/operator/Div.java +++ b/src/main/java/com/samskivert/depot/impl/operator/Div.java @@ -27,14 +27,14 @@ import com.samskivert.depot.expression.SQLExpression; /** * The SQL '/' operator. */ -public class Div extends Arithmetic +public class Div extends Arithmetic { - public Div (SQLExpression column, Comparable value) + public Div (SQLExpression column, T value) { super(column, value); } - public Div (SQLExpression... values) + public Div (SQLExpression... values) { super(values); } diff --git a/src/main/java/com/samskivert/depot/impl/operator/Equals.java b/src/main/java/com/samskivert/depot/impl/operator/Equals.java index 2b5478c..3fbf93c 100644 --- a/src/main/java/com/samskivert/depot/impl/operator/Equals.java +++ b/src/main/java/com/samskivert/depot/impl/operator/Equals.java @@ -25,14 +25,14 @@ import com.samskivert.depot.expression.SQLExpression; /** * The SQL '=' operator. */ -public class Equals extends BinaryOperator +public class Equals extends BinaryOperator { - public Equals (SQLExpression column, Comparable value) + public Equals (SQLExpression column, Comparable value) { super(column, value); } - public Equals (SQLExpression column, SQLExpression value) + public Equals (SQLExpression column, SQLExpression value) { super(column, value); } diff --git a/src/main/java/com/samskivert/depot/impl/operator/Exists.java b/src/main/java/com/samskivert/depot/impl/operator/Exists.java index 1c3bae9..51a3a99 100644 --- a/src/main/java/com/samskivert/depot/impl/operator/Exists.java +++ b/src/main/java/com/samskivert/depot/impl/operator/Exists.java @@ -31,7 +31,7 @@ import com.samskivert.depot.impl.FragmentVisitor; * The SQL 'exists' operator. */ public class Exists - implements SQLExpression + implements SQLExpression { public Exists (SelectClause clause) { diff --git a/src/main/java/com/samskivert/depot/impl/operator/GreaterThan.java b/src/main/java/com/samskivert/depot/impl/operator/GreaterThan.java index a72241e..509ac86 100644 --- a/src/main/java/com/samskivert/depot/impl/operator/GreaterThan.java +++ b/src/main/java/com/samskivert/depot/impl/operator/GreaterThan.java @@ -25,14 +25,14 @@ import com.samskivert.depot.expression.SQLExpression; /** * The SQL '>' operator. */ -public class GreaterThan extends BinaryOperator +public class GreaterThan extends BinaryOperator { - public GreaterThan (SQLExpression column, Comparable value) + public GreaterThan (SQLExpression column, Comparable value) { super(column, value); } - public GreaterThan (SQLExpression column, SQLExpression value) + public GreaterThan (SQLExpression column, SQLExpression value) { super(column, value); } diff --git a/src/main/java/com/samskivert/depot/impl/operator/GreaterThanEquals.java b/src/main/java/com/samskivert/depot/impl/operator/GreaterThanEquals.java index e6e0e66..7f07b70 100644 --- a/src/main/java/com/samskivert/depot/impl/operator/GreaterThanEquals.java +++ b/src/main/java/com/samskivert/depot/impl/operator/GreaterThanEquals.java @@ -25,14 +25,14 @@ import com.samskivert.depot.expression.SQLExpression; /** * The SQL '>=' operator. */ -public class GreaterThanEquals extends BinaryOperator +public class GreaterThanEquals extends BinaryOperator { - public GreaterThanEquals (SQLExpression column, Comparable value) + public GreaterThanEquals (SQLExpression column, Comparable value) { super(column, value); } - public GreaterThanEquals (SQLExpression column, SQLExpression value) + public GreaterThanEquals (SQLExpression column, SQLExpression value) { super(column, value); } diff --git a/src/main/java/com/samskivert/depot/impl/operator/In.java b/src/main/java/com/samskivert/depot/impl/operator/In.java index 756b140..2bd071d 100644 --- a/src/main/java/com/samskivert/depot/impl/operator/In.java +++ b/src/main/java/com/samskivert/depot/impl/operator/In.java @@ -31,23 +31,23 @@ import com.samskivert.depot.impl.FragmentVisitor; * The SQL 'in (...)' operator. */ public class In - implements SQLExpression + implements SQLExpression { /** The maximum number of keys allowed in an IN() clause. */ public static final int MAX_KEYS = Short.MAX_VALUE; - public In (SQLExpression expression, Comparable... values) + public In (SQLExpression expression, Comparable... values) { _expression = expression; _values = values; } - public In (SQLExpression pColumn, Iterable> values) + public In (SQLExpression pColumn, Iterable> values) { this(pColumn, Iterables.toArray(values, Comparable.class)); } - public SQLExpression getExpression () + public SQLExpression getExpression () { return _expression; } @@ -84,6 +84,6 @@ public class In return builder.append(")").toString(); } - protected SQLExpression _expression; + protected SQLExpression _expression; protected Comparable[] _values; } diff --git a/src/main/java/com/samskivert/depot/impl/operator/IsNull.java b/src/main/java/com/samskivert/depot/impl/operator/IsNull.java index 9f7f42a..069709e 100644 --- a/src/main/java/com/samskivert/depot/impl/operator/IsNull.java +++ b/src/main/java/com/samskivert/depot/impl/operator/IsNull.java @@ -30,14 +30,14 @@ import com.samskivert.depot.impl.FragmentVisitor; * The SQL 'is null' operator. */ public class IsNull - implements SQLExpression + implements SQLExpression { - public IsNull (SQLExpression expression) + public IsNull (SQLExpression expression) { _expression = expression; } - public SQLExpression getExpression () + public SQLExpression getExpression () { return _expression; } @@ -59,5 +59,5 @@ public class IsNull return "IsNull(" + _expression + ")"; } - protected SQLExpression _expression; + protected SQLExpression _expression; } diff --git a/src/main/java/com/samskivert/depot/impl/operator/LessThan.java b/src/main/java/com/samskivert/depot/impl/operator/LessThan.java index 8646f29..1b58953 100644 --- a/src/main/java/com/samskivert/depot/impl/operator/LessThan.java +++ b/src/main/java/com/samskivert/depot/impl/operator/LessThan.java @@ -25,14 +25,14 @@ import com.samskivert.depot.expression.SQLExpression; /** * The SQL '<' operator. */ -public class LessThan extends BinaryOperator +public class LessThan extends BinaryOperator { - public LessThan (SQLExpression column, Comparable value) + public LessThan (SQLExpression column, Comparable value) { super(column, value); } - public LessThan (SQLExpression column, SQLExpression value) + public LessThan (SQLExpression column, SQLExpression value) { super(column, value); } diff --git a/src/main/java/com/samskivert/depot/impl/operator/LessThanEquals.java b/src/main/java/com/samskivert/depot/impl/operator/LessThanEquals.java index 1e574af..7e77ac6 100644 --- a/src/main/java/com/samskivert/depot/impl/operator/LessThanEquals.java +++ b/src/main/java/com/samskivert/depot/impl/operator/LessThanEquals.java @@ -25,14 +25,14 @@ import com.samskivert.depot.expression.SQLExpression; /** * The SQL '<=' operator. */ -public class LessThanEquals extends BinaryOperator +public class LessThanEquals extends BinaryOperator { - public LessThanEquals (SQLExpression column, Comparable value) + public LessThanEquals (SQLExpression column, Comparable value) { super(column, value); } - public LessThanEquals (SQLExpression column, SQLExpression value) + public LessThanEquals (SQLExpression column, SQLExpression value) { super(column, value); } diff --git a/src/main/java/com/samskivert/depot/impl/operator/Like.java b/src/main/java/com/samskivert/depot/impl/operator/Like.java index 4fd328a..fc17f93 100644 --- a/src/main/java/com/samskivert/depot/impl/operator/Like.java +++ b/src/main/java/com/samskivert/depot/impl/operator/Like.java @@ -25,15 +25,15 @@ import com.samskivert.depot.expression.SQLExpression; /** * The SQL 'like' (and 'not like') operator. */ -public class Like extends BinaryOperator +public class Like extends BinaryOperator { - public Like (SQLExpression column, Comparable value, boolean like) + public Like (SQLExpression column, Comparable value, boolean like) { super(column, value); _like = like; } - public Like (SQLExpression column, SQLExpression value, boolean like) + public Like (SQLExpression column, SQLExpression value, boolean like) { super(column, value); _like = like; diff --git a/src/main/java/com/samskivert/depot/impl/operator/Mul.java b/src/main/java/com/samskivert/depot/impl/operator/Mul.java index a727b4e..9012eca 100644 --- a/src/main/java/com/samskivert/depot/impl/operator/Mul.java +++ b/src/main/java/com/samskivert/depot/impl/operator/Mul.java @@ -25,14 +25,14 @@ import com.samskivert.depot.expression.SQLExpression; /** * The SQL '*' operator. */ -public class Mul extends Arithmetic +public class Mul extends Arithmetic { - public Mul (SQLExpression column, Comparable value) + public Mul (SQLExpression column, T value) { super(column, value); } - public Mul (SQLExpression... values) + public Mul (SQLExpression... values) { super(values); } diff --git a/src/main/java/com/samskivert/depot/impl/operator/MultiOperator.java b/src/main/java/com/samskivert/depot/impl/operator/MultiOperator.java index 571050a..928974a 100644 --- a/src/main/java/com/samskivert/depot/impl/operator/MultiOperator.java +++ b/src/main/java/com/samskivert/depot/impl/operator/MultiOperator.java @@ -12,9 +12,9 @@ import com.samskivert.depot.impl.FragmentVisitor; /** * Represents an operator with any number of operands. */ -public abstract class MultiOperator extends BaseOperator +public abstract class MultiOperator extends BaseOperator { - public MultiOperator (SQLExpression ... operands) + public MultiOperator (SQLExpression... operands) { super(operands); } @@ -38,7 +38,7 @@ public abstract class MultiOperator extends BaseOperator @Override // from SQLFragment public void addClasses (Collection> classSet) { - for (SQLExpression operand : _args) { + for (SQLExpression operand : _args) { operand.addClasses(classSet); } } @@ -47,7 +47,7 @@ public abstract class MultiOperator extends BaseOperator public String toString () { StringBuilder builder = new StringBuilder("("); - for (SQLExpression operand : _args) { + for (SQLExpression operand : _args) { if (builder.length() > 1) { builder.append(operator()); } diff --git a/src/main/java/com/samskivert/depot/impl/operator/Not.java b/src/main/java/com/samskivert/depot/impl/operator/Not.java index e364298..557b3b1 100644 --- a/src/main/java/com/samskivert/depot/impl/operator/Not.java +++ b/src/main/java/com/samskivert/depot/impl/operator/Not.java @@ -30,14 +30,14 @@ import com.samskivert.depot.impl.FragmentVisitor; * Represents the truth negation of another conditon. */ public class Not - implements SQLExpression + implements SQLExpression { - public Not (SQLExpression condition) + public Not (SQLExpression condition) { _condition = condition; } - public SQLExpression getCondition () + public SQLExpression getCondition () { return _condition; } @@ -60,5 +60,5 @@ public class Not return "Not(" + _condition + ")"; } - protected SQLExpression _condition; + protected SQLExpression _condition; } diff --git a/src/main/java/com/samskivert/depot/impl/operator/NotEquals.java b/src/main/java/com/samskivert/depot/impl/operator/NotEquals.java index 13cfcc1..a954b6c 100644 --- a/src/main/java/com/samskivert/depot/impl/operator/NotEquals.java +++ b/src/main/java/com/samskivert/depot/impl/operator/NotEquals.java @@ -25,14 +25,14 @@ import com.samskivert.depot.expression.SQLExpression; /** * The SQL '!=' operator. */ -public class NotEquals extends BinaryOperator +public class NotEquals extends BinaryOperator { - public NotEquals (SQLExpression column, Comparable value) + public NotEquals (SQLExpression column, Comparable value) { super(column, value); } - public NotEquals (SQLExpression column, SQLExpression value) + public NotEquals (SQLExpression column, SQLExpression value) { super(column, value); } diff --git a/src/main/java/com/samskivert/depot/impl/operator/Sub.java b/src/main/java/com/samskivert/depot/impl/operator/Sub.java index 9328174..82ec0d9 100644 --- a/src/main/java/com/samskivert/depot/impl/operator/Sub.java +++ b/src/main/java/com/samskivert/depot/impl/operator/Sub.java @@ -25,14 +25,14 @@ import com.samskivert.depot.expression.SQLExpression; /** * The SQL '-' operator. */ -public class Sub extends Arithmetic +public class Sub extends Arithmetic { - public Sub (SQLExpression column, Comparable value) + public Sub (SQLExpression column, T value) { super(column, value); } - public Sub (SQLExpression... values) + public Sub (SQLExpression... values) { super(values); } diff --git a/src/main/java/com/samskivert/depot/operator/Case.java b/src/main/java/com/samskivert/depot/operator/Case.java index fad06e6..89ba24f 100644 --- a/src/main/java/com/samskivert/depot/operator/Case.java +++ b/src/main/java/com/samskivert/depot/operator/Case.java @@ -33,10 +33,10 @@ import com.samskivert.util.Tuple; /** * The SQL 'case' operator. */ -public class Case - implements SQLExpression +public class Case + implements SQLExpression { - public Case (SQLExpression... exps) + public Case (SQLExpression... exps) { int i = 0; while (i+1 < exps.length) { @@ -46,12 +46,12 @@ public class Case _elseExp = (i < exps.length) ? exps[i] : null; } - public List> getWhenExps () + public List, SQLExpression>> getWhenExps () { return _whenExps; } - public SQLExpression getElseExp () + public SQLExpression getElseExp () { return _elseExp; } @@ -65,7 +65,7 @@ public class Case // from SQLExpression public void addClasses (Collection> classSet) { - for (Tuple tuple : _whenExps) { + for (Tuple, SQLExpression> tuple : _whenExps) { tuple.left.addClasses(classSet); tuple.right.addClasses(classSet); } @@ -79,7 +79,7 @@ public class Case { StringBuilder builder = new StringBuilder(); builder.append("Case("); - for (Tuple tuple : _whenExps) { + for (Tuple, SQLExpression> tuple : _whenExps) { builder.append(tuple.left.toString()).append("->"); builder.append(tuple.right.toString()).append(","); } @@ -89,6 +89,6 @@ public class Case return builder.toString(); } - protected List> _whenExps = Lists.newArrayList(); - protected SQLExpression _elseExp; + protected List, SQLExpression>> _whenExps = Lists.newArrayList(); + protected SQLExpression _elseExp; } diff --git a/src/main/java/com/samskivert/depot/operator/FullText.java b/src/main/java/com/samskivert/depot/operator/FullText.java index f686875..5798756 100644 --- a/src/main/java/com/samskivert/depot/operator/FullText.java +++ b/src/main/java/com/samskivert/depot/operator/FullText.java @@ -32,7 +32,7 @@ import com.samskivert.depot.impl.FragmentVisitor; */ public class FullText { - public class Rank extends FluentExp + public class Rank extends FluentExp { // from SQLExpression public Object accept (FragmentVisitor builder) @@ -57,7 +57,7 @@ public class FullText } } - public class Match extends FluentExp + public class Match extends FluentExp { // from SQLExpression public Object accept (FragmentVisitor builder) diff --git a/src/test/java/com/samskivert/depot/AllTypesTest.java b/src/test/java/com/samskivert/depot/AllTypesTest.java index 53bfb62..509a216 100644 --- a/src/test/java/com/samskivert/depot/AllTypesTest.java +++ b/src/test/java/com/samskivert/depot/AllTypesTest.java @@ -20,7 +20,6 @@ package com.samskivert.depot; -import java.util.List; import java.util.Set; import org.junit.Test; diff --git a/src/test/java/com/samskivert/depot/CountTest.java b/src/test/java/com/samskivert/depot/CountTest.java index f9ada52..427602a 100644 --- a/src/test/java/com/samskivert/depot/CountTest.java +++ b/src/test/java/com/samskivert/depot/CountTest.java @@ -23,8 +23,6 @@ package com.samskivert.depot; import org.junit.Test; import static org.junit.Assert.*; -import com.samskivert.depot.clause.Where; - /** * Tests row counting. */ @@ -41,7 +39,7 @@ public class CountTest extends TestBase assertEquals(49, _repo.from(TestRecord.class). where(TestRecord.RECORD_ID.lessThan(50)).selectCount()); - _repo.deleteAll(TestRecord.class, new Where(Exps.trueLiteral())); + _repo.from(TestRecord.class).whereTrue().delete(); assertEquals(0, _repo.from(TestRecord.class). where(TestRecord.RECORD_ID.lessThan(50)).selectCount()); diff --git a/src/test/java/com/samskivert/depot/KeyTest.java b/src/test/java/com/samskivert/depot/KeyTest.java index 082d3ab..c21d81c 100644 --- a/src/test/java/com/samskivert/depot/KeyTest.java +++ b/src/test/java/com/samskivert/depot/KeyTest.java @@ -39,7 +39,7 @@ public class KeyTest extends TestBase Key key = MonkeyRecord.getKey(species, monkeyId); // make sure that the arguments we passed in got assigned in the right positions - ColumnExp[] kfs = DepotUtil.getKeyFields(MonkeyRecord.class); + ColumnExp[] kfs = DepotUtil.getKeyFields(MonkeyRecord.class); int kspecies = 0, kmonkeyId = 0; for (int ii = 0; ii < kfs.length; ii++) { if (MonkeyRecord.SPECIES.equals(kfs[ii])) { @@ -58,7 +58,7 @@ public class KeyTest extends TestBase Key key = TestRecord.getKey(recordId); // make sure that the arguments we passed in got assigned in the right positions - ColumnExp[] kfs = DepotUtil.getKeyFields(TestRecord.class); + ColumnExp[] kfs = DepotUtil.getKeyFields(TestRecord.class); int krecordId = 0; for (int ii = 0; ii < kfs.length; ii++) { if (TestRecord.RECORD_ID.equals(kfs[ii])) { @@ -82,7 +82,7 @@ public class KeyTest extends TestBase assertEquals("beee", _repo.loadEnum(EnumKeyRecord.Type.B).name); - _repo.from(EnumKeyRecord.class).where(Exps.trueLiteral()).delete(); + _repo.from(EnumKeyRecord.class).whereTrue().delete(); } // the HSQL in-memory database persists for the lifetime of the VM, which means we have to diff --git a/src/test/java/com/samskivert/depot/QueryTest.java b/src/test/java/com/samskivert/depot/QueryTest.java index 8fdaec7..f462cad 100644 --- a/src/test/java/com/samskivert/depot/QueryTest.java +++ b/src/test/java/com/samskivert/depot/QueryTest.java @@ -30,7 +30,6 @@ import static org.junit.Assert.*; import com.samskivert.depot.annotation.Computed; import com.samskivert.depot.expression.SQLExpression; -import com.samskivert.depot.clause.Where; /** * Tests queries. @@ -64,7 +63,7 @@ public class QueryTest extends TestBase assertEquals(0, _repo.deleteAll(TestRecord.class, none)); // test collection caching (TODO: check that the records are ==) - SQLExpression where = TestRecord.RECORD_ID.greaterThan(CREATE_RECORDS-50); + SQLExpression where = TestRecord.RECORD_ID.greaterThan(CREATE_RECORDS-50); assertEquals(50, _repo.from(TestRecord.class).where(where).select().size()); assertEquals(50, _repo.from(TestRecord.class).where(where).select().size()); @@ -79,10 +78,10 @@ public class QueryTest extends TestBase } assertEquals(CREATE_RECORDS, _repo.findAll(TestRecord.class).size()); - _repo.deleteAll(TestRecord.class, new Where(TestRecord.RECORD_ID.lessEq(CREATE_RECORDS/2))); + _repo.from(TestRecord.class).where(TestRecord.RECORD_ID.lessEq(CREATE_RECORDS/2)).delete(); assertEquals(CREATE_RECORDS/2, _repo.findAll(TestRecord.class).size()); - _repo.deleteAll(TestRecord.class, new Where(Exps.trueLiteral())); + _repo.from(TestRecord.class).whereTrue().delete(); assertEquals(0, _repo.findAll(TestRecord.class).size()); // // TODO: try to break our In() clause diff --git a/src/test/java/com/samskivert/depot/SelectFieldsTest.java b/src/test/java/com/samskivert/depot/SelectFieldsTest.java index f314bcf..8f0717a 100644 --- a/src/test/java/com/samskivert/depot/SelectFieldsTest.java +++ b/src/test/java/com/samskivert/depot/SelectFieldsTest.java @@ -53,8 +53,10 @@ public class SelectFieldsTest extends TestBase List> data = _repo.from(TestRecord.class).where( TestRecord.RECORD_ID.greaterThan(7)).select(TestRecord.RECORD_ID, TestRecord.NAME); - assertEquals(data, Lists.newArrayList(Tuple2.newTuple(8, "Elvis"), - Tuple2.newTuple(9, "Elvis"))); + List> want = Lists.newArrayList(); + want.add(Tuple2.newTuple(8, "Elvis")); + want.add(Tuple2.newTuple(9, "Elvis")); + assertEquals(data, want); // test a basic join List> jdata = _repo.from(TestRecord.class).join( @@ -62,8 +64,8 @@ public class SelectFieldsTest extends TestBase System.out.println(jdata); // finally clean up after ourselves - _repo.from(TestRecord.class).where(Exps.trueLiteral()).delete(); - _repo.from(EnumKeyRecord.class).where(Exps.trueLiteral()).delete(); + _repo.from(TestRecord.class).whereTrue().delete(); + _repo.from(EnumKeyRecord.class).whereTrue().delete(); } // the HSQL in-memory database persists for the lifetime of the VM, which means we have to diff --git a/src/test/java/com/samskivert/depot/TransformTest.java b/src/test/java/com/samskivert/depot/TransformTest.java index 8edbb10..18ea0b1 100644 --- a/src/test/java/com/samskivert/depot/TransformTest.java +++ b/src/test/java/com/samskivert/depot/TransformTest.java @@ -134,13 +134,13 @@ public class TransformTest extends TestBase { // AUTO-GENERATED: FIELDS START public static final Class _R = TransformRecord.class; - public static final ColumnExp RECORD_ID = colexp(_R, "recordId"); - public static final ColumnExp STRINGS = colexp(_R, "strings"); - public static final ColumnExp STRING_LIST = colexp(_R, "stringList"); - public static final ColumnExp STRING_SET = colexp(_R, "stringSet"); - public static final ColumnExp CUSTOM = colexp(_R, "custom"); - public static final ColumnExp ORDINAL = colexp(_R, "ordinal"); - public static final ColumnExp BOBS = colexp(_R, "bobs"); + public static final ColumnExp RECORD_ID = colexp(_R, "recordId"); + public static final ColumnExp STRINGS = colexp(_R, "strings"); + public static final ColumnExp> STRING_LIST = colexp(_R, "stringList"); + public static final ColumnExp> STRING_SET = colexp(_R, "stringSet"); + public static final ColumnExp CUSTOM = colexp(_R, "custom"); + public static final ColumnExp ORDINAL = colexp(_R, "ordinal"); + public static final ColumnExp> BOBS = colexp(_R, "bobs"); // AUTO-GENERATED: FIELDS END public static final int SCHEMA_VERSION = 1;