diff --git a/src/java/com/samskivert/depot/KeySet.java b/src/java/com/samskivert/depot/KeySet.java index 18a55d8..3399c4f 100644 --- a/src/java/com/samskivert/depot/KeySet.java +++ b/src/java/com/samskivert/depot/KeySet.java @@ -34,13 +34,13 @@ import com.samskivert.util.Logger; import com.samskivert.util.StringUtil; import com.samskivert.depot.clause.WhereClause; +import com.samskivert.depot.operator.In; +import com.samskivert.depot.operator.Or; import com.samskivert.depot.expression.ColumnExp; import com.samskivert.depot.expression.LiteralExp; import com.samskivert.depot.expression.SQLExpression; import com.samskivert.depot.impl.DepotUtil; import com.samskivert.depot.impl.ExpressionVisitor; -import com.samskivert.depot.operator.Conditionals; -import com.samskivert.depot.operator.Logic; /** * Contains a set of primary keys that match a set of persistent records. This is used internally @@ -162,9 +162,9 @@ public abstract class KeySet extends WhereClause public SingleKeySet (Class pClass, Comparable[] keys) { super(pClass); // TODO: remove when we update to 1.6 and change Postgres In handling - if (keys.length > Conditionals.In.MAX_KEYS) { + if (keys.length > In.MAX_KEYS) { throw new IllegalArgumentException("Cannot create where clause for more than " + - Conditionals.In.MAX_KEYS + " at a time."); + In.MAX_KEYS + " at a time."); } _keys = keys; } @@ -172,7 +172,7 @@ public abstract class KeySet extends WhereClause @Override public SQLExpression getWhereExpression () { // Single-column keys result in the compact IN(keyVal1, keyVal2, ...) ColumnExp column = new ColumnExp(_pClass, DepotUtil.getKeyFields(_pClass)[0]); - return new Conditionals.In(column, _keys); + return new In(column, _keys); } // from Iterable> @@ -226,16 +226,16 @@ public abstract class KeySet extends WhereClause for (Comparable[] kvals : _keys) { keyexps[ii++] = new Key.Expression(_pClass, kvals); } - return new Logic.Or(keyexps); + return new Or(keyexps); } // from Iterable> public Iterator> iterator () { - return Iterators.transform( - Iterators.forArray(_keys, 0, _keys.length), new Function[], Key>() { + return Iterators.transform(Iterators.forArray(_keys, 0, _keys.length), + new Function[], Key>() { public Key apply (Comparable[] key) { return new Key(_pClass, key); - } + } }); } diff --git a/src/java/com/samskivert/depot/clause/Join.java b/src/java/com/samskivert/depot/clause/Join.java index 63714d3..79c3f04 100644 --- a/src/java/com/samskivert/depot/clause/Join.java +++ b/src/java/com/samskivert/depot/clause/Join.java @@ -27,7 +27,7 @@ import com.samskivert.depot.expression.ColumnExp; import com.samskivert.depot.expression.SQLExpression; import com.samskivert.depot.impl.DepotUtil; import com.samskivert.depot.impl.ExpressionVisitor; -import com.samskivert.depot.operator.Conditionals.Equals; +import com.samskivert.depot.operator.Equals; /** * Represents a JOIN. diff --git a/src/java/com/samskivert/depot/clause/Where.java b/src/java/com/samskivert/depot/clause/Where.java index abb6e15..17c4f6b 100644 --- a/src/java/com/samskivert/depot/clause/Where.java +++ b/src/java/com/samskivert/depot/clause/Where.java @@ -27,9 +27,9 @@ import com.samskivert.depot.expression.ColumnExp; import com.samskivert.depot.expression.SQLExpression; import com.samskivert.depot.expression.ValueExp; import com.samskivert.depot.impl.ExpressionVisitor; -import com.samskivert.depot.operator.Conditionals.Equals; -import com.samskivert.depot.operator.Conditionals.IsNull; -import com.samskivert.depot.operator.Logic.And; +import com.samskivert.depot.operator.And; +import com.samskivert.depot.operator.Equals; +import com.samskivert.depot.operator.IsNull; /** * Represents a where clause: the condition can be any comparison operator or logical combination diff --git a/src/java/com/samskivert/depot/impl/BuildVisitor.java b/src/java/com/samskivert/depot/impl/BuildVisitor.java index 646c0bf..433fb3a 100644 --- a/src/java/com/samskivert/depot/impl/BuildVisitor.java +++ b/src/java/com/samskivert/depot/impl/BuildVisitor.java @@ -44,22 +44,22 @@ import com.samskivert.depot.clause.GroupBy; import com.samskivert.depot.clause.InsertClause; import com.samskivert.depot.clause.Join; import com.samskivert.depot.clause.Limit; +import com.samskivert.depot.clause.OrderBy.Order; import com.samskivert.depot.clause.OrderBy; import com.samskivert.depot.clause.SelectClause; import com.samskivert.depot.clause.WhereClause; -import com.samskivert.depot.clause.OrderBy.Order; import com.samskivert.depot.expression.ColumnExp; import com.samskivert.depot.expression.EpochSeconds; import com.samskivert.depot.expression.FunctionExp; import com.samskivert.depot.expression.LiteralExp; import com.samskivert.depot.expression.SQLExpression; import com.samskivert.depot.expression.ValueExp; -import com.samskivert.depot.operator.Conditionals.Case; -import com.samskivert.depot.operator.Conditionals.Exists; -import com.samskivert.depot.operator.Conditionals.FullText; -import com.samskivert.depot.operator.Conditionals.In; -import com.samskivert.depot.operator.Conditionals.IsNull; -import com.samskivert.depot.operator.Logic.Not; +import com.samskivert.depot.operator.Case; +import com.samskivert.depot.operator.Exists; +import com.samskivert.depot.operator.FullText; +import com.samskivert.depot.operator.In; +import com.samskivert.depot.operator.IsNull; +import com.samskivert.depot.operator.Not; import com.samskivert.depot.operator.SQLOperator.BinaryOperator; import com.samskivert.depot.operator.SQLOperator.MultiOperator; diff --git a/src/java/com/samskivert/depot/impl/ExpressionEvaluator.java b/src/java/com/samskivert/depot/impl/ExpressionEvaluator.java index 5baac37..7df0ae7 100644 --- a/src/java/com/samskivert/depot/impl/ExpressionEvaluator.java +++ b/src/java/com/samskivert/depot/impl/ExpressionEvaluator.java @@ -45,12 +45,12 @@ import com.samskivert.depot.expression.SQLExpression; import com.samskivert.depot.expression.SQLExpression.NoValue; import com.samskivert.depot.expression.ValueExp; -import com.samskivert.depot.operator.Conditionals.Case; -import com.samskivert.depot.operator.Conditionals.Exists; -import com.samskivert.depot.operator.Conditionals.FullText; -import com.samskivert.depot.operator.Conditionals.In; -import com.samskivert.depot.operator.Conditionals.IsNull; -import com.samskivert.depot.operator.Logic.Not; +import com.samskivert.depot.operator.Case; +import com.samskivert.depot.operator.Exists; +import com.samskivert.depot.operator.FullText; +import com.samskivert.depot.operator.In; +import com.samskivert.depot.operator.IsNull; +import com.samskivert.depot.operator.Not; import com.samskivert.depot.operator.SQLOperator.BinaryOperator; import com.samskivert.depot.operator.SQLOperator.MultiOperator; diff --git a/src/java/com/samskivert/depot/impl/ExpressionVisitor.java b/src/java/com/samskivert/depot/impl/ExpressionVisitor.java index 7f2be6a..9b38e76 100644 --- a/src/java/com/samskivert/depot/impl/ExpressionVisitor.java +++ b/src/java/com/samskivert/depot/impl/ExpressionVisitor.java @@ -40,12 +40,12 @@ import com.samskivert.depot.expression.FunctionExp; import com.samskivert.depot.expression.LiteralExp; import com.samskivert.depot.expression.ValueExp; -import com.samskivert.depot.operator.Conditionals.Case; -import com.samskivert.depot.operator.Conditionals.Exists; -import com.samskivert.depot.operator.Conditionals.FullText; -import com.samskivert.depot.operator.Conditionals.In; -import com.samskivert.depot.operator.Conditionals.IsNull; -import com.samskivert.depot.operator.Logic.Not; +import com.samskivert.depot.operator.Case; +import com.samskivert.depot.operator.Exists; +import com.samskivert.depot.operator.FullText; +import com.samskivert.depot.operator.In; +import com.samskivert.depot.operator.IsNull; +import com.samskivert.depot.operator.Not; import com.samskivert.depot.operator.SQLOperator.BinaryOperator; import com.samskivert.depot.operator.SQLOperator.MultiOperator; diff --git a/src/java/com/samskivert/depot/impl/FindAllQuery.java b/src/java/com/samskivert/depot/impl/FindAllQuery.java index 97eaa04..7f48602 100644 --- a/src/java/com/samskivert/depot/impl/FindAllQuery.java +++ b/src/java/com/samskivert/depot/impl/FindAllQuery.java @@ -38,7 +38,9 @@ import com.google.common.collect.Maps; import com.samskivert.jdbc.DatabaseLiaison; import com.samskivert.jdbc.JDBCUtil; +import com.samskivert.depot.CacheAdapter.CacheCategory; import com.samskivert.depot.DatabaseException; +import com.samskivert.depot.DepotRepository.CacheStrategy; import com.samskivert.depot.DepotRepository; import com.samskivert.depot.Key; import com.samskivert.depot.KeySet; @@ -46,12 +48,10 @@ import com.samskivert.depot.PersistenceContext; import com.samskivert.depot.PersistentRecord; import com.samskivert.depot.SimpleCacheKey; import com.samskivert.depot.Stats; -import com.samskivert.depot.CacheAdapter.CacheCategory; -import com.samskivert.depot.DepotRepository.CacheStrategy; import com.samskivert.depot.clause.FieldOverride; import com.samskivert.depot.clause.QueryClause; import com.samskivert.depot.clause.SelectClause; -import com.samskivert.depot.operator.Conditionals.*; +import com.samskivert.depot.operator.In; import static com.samskivert.depot.Log.log; diff --git a/src/java/com/samskivert/depot/impl/HSQLBuilder.java b/src/java/com/samskivert/depot/impl/HSQLBuilder.java index b0cb684..d321829 100644 --- a/src/java/com/samskivert/depot/impl/HSQLBuilder.java +++ b/src/java/com/samskivert/depot/impl/HSQLBuilder.java @@ -47,11 +47,11 @@ import com.samskivert.depot.expression.ColumnExp; import com.samskivert.depot.expression.EpochSeconds; import com.samskivert.depot.expression.FunctionExp; import com.samskivert.depot.expression.SQLExpression; -import com.samskivert.depot.operator.Arithmetic.BitAnd; -import com.samskivert.depot.operator.Arithmetic.BitOr; -import com.samskivert.depot.operator.Conditionals.FullText; -import com.samskivert.depot.operator.Conditionals.Like; -import com.samskivert.depot.operator.Logic.Or; +import com.samskivert.depot.operator.BitAnd; +import com.samskivert.depot.operator.BitOr; +import com.samskivert.depot.operator.FullText; +import com.samskivert.depot.operator.Like; +import com.samskivert.depot.operator.Or; import com.samskivert.depot.operator.SQLOperator.MultiOperator; import com.samskivert.depot.impl.clause.CreateIndexClause; diff --git a/src/java/com/samskivert/depot/impl/MySQLBuilder.java b/src/java/com/samskivert/depot/impl/MySQLBuilder.java index 07723cd..f42a84f 100644 --- a/src/java/com/samskivert/depot/impl/MySQLBuilder.java +++ b/src/java/com/samskivert/depot/impl/MySQLBuilder.java @@ -39,7 +39,7 @@ import com.samskivert.depot.clause.OrderBy.Order; import com.samskivert.depot.expression.ColumnExp; import com.samskivert.depot.expression.EpochSeconds; import com.samskivert.depot.expression.SQLExpression; -import com.samskivert.depot.operator.Conditionals.FullText; +import com.samskivert.depot.operator.FullText; import com.samskivert.depot.impl.FieldMarshaller.BooleanMarshaller; import com.samskivert.depot.impl.FieldMarshaller.ByteArrayMarshaller; diff --git a/src/java/com/samskivert/depot/impl/PostgreSQL4Builder.java b/src/java/com/samskivert/depot/impl/PostgreSQL4Builder.java index 38b75cb..71cd4ba 100644 --- a/src/java/com/samskivert/depot/impl/PostgreSQL4Builder.java +++ b/src/java/com/samskivert/depot/impl/PostgreSQL4Builder.java @@ -29,7 +29,7 @@ import java.sql.Timestamp; import com.samskivert.depot.ByteEnum; import com.samskivert.depot.DatabaseException; import com.samskivert.depot.expression.ValueExp; -import com.samskivert.depot.operator.Conditionals.In; +import com.samskivert.depot.operator.In; /** * Specializes our PostgreSQL builder for JDBC4. diff --git a/src/java/com/samskivert/depot/impl/PostgreSQLBuilder.java b/src/java/com/samskivert/depot/impl/PostgreSQLBuilder.java index 91f52c5..776e401 100644 --- a/src/java/com/samskivert/depot/impl/PostgreSQLBuilder.java +++ b/src/java/com/samskivert/depot/impl/PostgreSQLBuilder.java @@ -40,7 +40,7 @@ import com.samskivert.depot.PersistentRecord; import com.samskivert.depot.annotation.FullTextIndex.Configuration; import com.samskivert.depot.annotation.FullTextIndex; import com.samskivert.depot.expression.EpochSeconds; -import com.samskivert.depot.operator.Conditionals.FullText; +import com.samskivert.depot.operator.FullText; import static com.samskivert.Log.log; diff --git a/src/java/com/samskivert/depot/operator/Add.java b/src/java/com/samskivert/depot/operator/Add.java new file mode 100644 index 0000000..9ea9cbe --- /dev/null +++ b/src/java/com/samskivert/depot/operator/Add.java @@ -0,0 +1,59 @@ +// +// $Id$ +// +// Depot library - a Java relational persistence library +// Copyright (C) 2006-2009 Michael Bayne and Pär Winzell +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.samskivert.depot.operator; + +import com.samskivert.depot.expression.SQLExpression; + +/** + * The SQL '+' operator. + */ +public class Add extends Arithmetic +{ + public Add (SQLExpression column, Comparable value) + { + super(column, value); + } + + public Add (SQLExpression... values) + { + super(values); + } + + @Override // from Arithmetic + public String operator() + { + return "+"; + } + + @Override // from Arithmetic + public Object evaluate (Object[] operands) + { + return evaluate(operands, "+", new Accumulator() { + public Double accumulate (Double left, Double right) { + return left + right; + } + }, new Accumulator() { + public Long accumulate (Long left, Long right) { + return left + right; + } + }); + } +} diff --git a/src/java/com/samskivert/depot/operator/And.java b/src/java/com/samskivert/depot/operator/And.java new file mode 100644 index 0000000..cb78230 --- /dev/null +++ b/src/java/com/samskivert/depot/operator/And.java @@ -0,0 +1,65 @@ +// +// $Id$ +// +// Depot library - a Java relational persistence library +// Copyright (C) 2006-2009 Michael Bayne and Pär Winzell +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.samskivert.depot.operator; + +import java.util.Collection; + +import com.samskivert.depot.expression.SQLExpression; + +/** + * Represents a condition that is true iff all its subconditions are true. + */ +public class And extends SQLOperator.MultiOperator +{ + public And (Collection conditions) + { + super(conditions.toArray(new SQLExpression[conditions.size()])); + } + + public And (SQLExpression... conditions) + { + super(conditions); + } + + @Override public String operator() + { + return " and "; + } + + @Override + public Object evaluate (Object[] values) + { + // if all operands are true, return true, else if all operands are boolean, return + // false, else return NO_VALUE + boolean allTrue = true; + for (Object value : values) { + if (value instanceof NoValue) { + return value; + } + if (Boolean.FALSE.equals(value)) { + allTrue = false; + } else if (!Boolean.TRUE.equals(value)) { + return new NoValue("Non-boolean operand to AND: " + value); + } + } + return allTrue; + } +} diff --git a/src/java/com/samskivert/depot/operator/Arithmetic.java b/src/java/com/samskivert/depot/operator/Arithmetic.java index 692b38c..c0f2b7d 100644 --- a/src/java/com/samskivert/depot/operator/Arithmetic.java +++ b/src/java/com/samskivert/depot/operator/Arithmetic.java @@ -23,199 +23,12 @@ package com.samskivert.depot.operator; import com.samskivert.depot.expression.SQLExpression; import com.samskivert.depot.expression.ValueExp; import com.samskivert.depot.operator.SQLOperator.MultiOperator; -import com.samskivert.util.StringUtil; /** - * A convenient container for implementations of arithmetic operators. Classes that value brevity - * that feel otherwise will use Arithmetic.Add() and Arithmetic.Sub(). + * A convenient container for implementations of arithmetic operators. */ public abstract class Arithmetic extends MultiOperator { - /** The SQL '+' operator. */ - public static class Add extends Arithmetic - { - public Add (SQLExpression column, Comparable value) - { - super(column, new ValueExp(value)); - } - - public Add (SQLExpression... values) - { - super(values); - } - - @Override public String operator() - { - return "+"; - } - - @Override - public Object evaluate (Object[] operands) - { - return evaluate(operands, "+", new Accumulator() { - public Double accumulate (Double left, Double right) { - return left + right; - }}, new Accumulator() { - public Long accumulate (Long left, Long right) { - return left + right; - }}); - } - } - - /** The SQL '-' operator. */ - public static class Sub extends Arithmetic - { - public Sub (SQLExpression column, Comparable value) - { - super(column, new ValueExp(value)); - } - - public Sub (SQLExpression... values) - { - super(values); - } - - @Override public String operator() - { - return "-"; - } - - @Override - public Object evaluate (Object[] operands) - { - return evaluate(operands, "-", new Accumulator() { - public Double accumulate (Double left, Double right) { - return left - right; - }}, new Accumulator() { - public Long accumulate (Long left, Long right) { - return left - right; - }}); - } - } - - /** The SQL '*' operator. */ - public static class Mul extends Arithmetic - { - public Mul (SQLExpression column, Comparable value) - { - super(column, new ValueExp(value)); - } - - public Mul (SQLExpression... values) - { - super(values); - } - - @Override public String operator() - { - return "*"; - } - - @Override - public Object evaluate (Object[] operands) - { - return evaluate(operands, "*", new Accumulator() { - public Double accumulate (Double left, Double right) { - return left * right; - }}, new Accumulator() { - public Long accumulate (Long left, Long right) { - return left * right; - }}); - } - } - - /** The SQL '/' operator. */ - public static class Div extends Arithmetic - { - public Div (SQLExpression column, Comparable value) - { - super(column, new ValueExp(value)); - } - - public Div (SQLExpression... values) - { - super(values); - } - - @Override public String operator() - { - return " / "; // Pad with spaces to work-around a MySQL bug. - } - - @Override - public Object evaluate (Object[] operands) - { - for (int ii = 1; ii < operands.length; ii ++) { - if (Double.valueOf(0).equals(NUMERICAL.apply(operands[ii]))) { - return new NoValue("Division by zero in: " + StringUtil.toString(operands)); - } - } - return evaluate(operands, "/", new Accumulator() { - public Double accumulate (Double left, Double right) { - return left / right; - }}, new Accumulator() { - public Long accumulate (Long left, Long right) { - return left / right; - }}); - } - } - - /** The SQL '&' operator. */ - public static class BitAnd extends Arithmetic - { - public BitAnd (SQLExpression column, Comparable value) - { - super(column, new ValueExp(value)); - } - - public BitAnd (SQLExpression... values) - { - super(values); - } - - @Override public String operator() - { - return "&"; - } - - @Override - public Object evaluate (Object[] operands) - { - return evaluate(operands, "&", null, new Accumulator() { - public Long accumulate (Long left, Long right) { - return left & right; - }}); - } - } - - /** The SQL '|' operator. */ - public static class BitOr extends Arithmetic - { - public BitOr (SQLExpression column, Comparable value) - { - super(column, new ValueExp(value)); - } - - public BitOr (SQLExpression... values) - { - super(values); - } - - @Override public String operator() - { - return "|"; - } - - @Override - public Object evaluate (Object[] operands) - { - return evaluate(operands, "|", null, new Accumulator() { - public Long accumulate (Long left, Long right) { - return left | right; - }}); - } - } - public Arithmetic (SQLExpression column, Comparable value) { super(column, new ValueExp(value)); diff --git a/src/java/com/samskivert/depot/operator/BitAnd.java b/src/java/com/samskivert/depot/operator/BitAnd.java new file mode 100644 index 0000000..7aff68e --- /dev/null +++ b/src/java/com/samskivert/depot/operator/BitAnd.java @@ -0,0 +1,55 @@ +// +// $Id$ +// +// Depot library - a Java relational persistence library +// Copyright (C) 2006-2009 Michael Bayne and Pär Winzell +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.samskivert.depot.operator; + +import com.samskivert.depot.expression.SQLExpression; + +/** + * The SQL '&' operator. + */ +public class BitAnd extends Arithmetic +{ + public BitAnd (SQLExpression column, Comparable value) + { + super(column, value); + } + + public BitAnd (SQLExpression... values) + { + super(values); + } + + @Override // from Arithmetic + public String operator() + { + return "&"; + } + + @Override // from Arithmetic + public Object evaluate (Object[] operands) + { + return evaluate(operands, "&", null, new Accumulator() { + public Long accumulate (Long left, Long right) { + return left & right; + } + }); + } +} diff --git a/src/java/com/samskivert/depot/operator/BitOr.java b/src/java/com/samskivert/depot/operator/BitOr.java new file mode 100644 index 0000000..86823b5 --- /dev/null +++ b/src/java/com/samskivert/depot/operator/BitOr.java @@ -0,0 +1,55 @@ +// +// $Id$ +// +// Depot library - a Java relational persistence library +// Copyright (C) 2006-2009 Michael Bayne and Pär Winzell +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.samskivert.depot.operator; + +import com.samskivert.depot.expression.SQLExpression; + +/** + * The SQL '|' operator. + */ +public class BitOr extends Arithmetic +{ + public BitOr (SQLExpression column, Comparable value) + { + super(column, value); + } + + public BitOr (SQLExpression... values) + { + super(values); + } + + @Override // from Arithmetic + public String operator() + { + return "|"; + } + + @Override // from Arithmetic + public Object evaluate (Object[] operands) + { + return evaluate(operands, "|", null, new Accumulator() { + public Long accumulate (Long left, Long right) { + return left | right; + } + }); + } +} diff --git a/src/java/com/samskivert/depot/operator/Case.java b/src/java/com/samskivert/depot/operator/Case.java new file mode 100644 index 0000000..ef14bb3 --- /dev/null +++ b/src/java/com/samskivert/depot/operator/Case.java @@ -0,0 +1,93 @@ +// +// $Id$ +// +// Depot library - a Java relational persistence library +// Copyright (C) 2006-2009 Michael Bayne and Pär Winzell +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.samskivert.depot.operator; + +import java.util.Collection; +import java.util.List; + +import com.google.common.collect.Lists; + +import com.samskivert.depot.PersistentRecord; +import com.samskivert.depot.expression.SQLExpression; +import com.samskivert.depot.impl.ExpressionVisitor; +import com.samskivert.util.Tuple; + +/** + * The SQL 'case' operator. + */ +public class Case implements SQLOperator +{ + public Case (SQLExpression... exps) + { + int i = 0; + while (i+1 < exps.length) { + _whenExps.add(Tuple.newTuple(exps[i], exps[i+1])); + i += 2; + } + _elseExp = (i < exps.length) ? exps[i] : null; + } + + public List> getWhenExps () + { + return _whenExps; + } + + public SQLExpression getElseExp () + { + return _elseExp; + } + + // from SQLExpression + public Object accept (ExpressionVisitor builder) + { + return builder.visit(this); + } + + // from SQLExpression + public void addClasses (Collection> classSet) + { + for (Tuple tuple : _whenExps) { + tuple.left.addClasses(classSet); + tuple.right.addClasses(classSet); + } + if (_elseExp != null) { + _elseExp.addClasses(classSet); + } + } + + @Override // from Object + public String toString () + { + StringBuilder builder = new StringBuilder(); + builder.append("Case("); + for (Tuple tuple : _whenExps) { + builder.append(tuple.left.toString()).append("->"); + builder.append(tuple.right.toString()).append(","); + } + if (_elseExp != null) { + builder.append(_elseExp.toString()).append(")"); + } + return builder.toString(); + } + + protected List> _whenExps = Lists.newArrayList(); + protected SQLExpression _elseExp; +} diff --git a/src/java/com/samskivert/depot/operator/Conditionals.java b/src/java/com/samskivert/depot/operator/Conditionals.java deleted file mode 100644 index 0a74abe..0000000 --- a/src/java/com/samskivert/depot/operator/Conditionals.java +++ /dev/null @@ -1,533 +0,0 @@ -// -// $Id$ -// -// Depot library - a Java relational persistence library -// Copyright (C) 2006-2008 Michael Bayne and Pär Winzell -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.samskivert.depot.operator; - -import java.util.Collection; -import java.util.List; - -import com.google.common.collect.Lists; -import com.samskivert.depot.PersistentRecord; -import com.samskivert.depot.clause.SelectClause; -import com.samskivert.depot.expression.ColumnExp; -import com.samskivert.depot.expression.SQLExpression; -import com.samskivert.depot.impl.ExpressionVisitor; -import com.samskivert.util.Tuple; - -import static com.samskivert.Log.log; - -/** - * A convenient container for implementations of conditional operators. Classes that value brevity - * classes that feel otherwise will use Conditionals.Equals() and Conditionals.In(). - */ -public abstract class Conditionals -{ - /** The SQL 'is null' operator. */ - public static class IsNull - implements SQLOperator - { - public IsNull (ColumnExp column) - { - _column = column; - } - - public ColumnExp getColumn() - { - return _column; - } - - // from SQLExpression - public Object accept (ExpressionVisitor builder) - { - return builder.visit(this); - } - - // from SQLExpression - public void addClasses (Collection> classSet) - { - } - - @Override // from Object - public String toString () - { - return "IsNull(" + _column + ")"; - } - - protected ColumnExp _column; - } - - /** The SQL '=' operator. */ - public static class Equals extends SQLOperator.BinaryOperator - { - public Equals (SQLExpression column, Comparable value) - { - super(column, value); - } - - public Equals (SQLExpression column, SQLExpression value) - { - super(column, value); - } - - @Override public String operator() - { - return "="; - } - - @Override - public Object evaluate (Object left, Object right) - { - if (left == null || right == null) { - return new NoValue("Null operand to '=': (" + left + ", " + right + ")"); - } - return left.equals(right); - } - } - - /** The SQL '!=' operator. */ - public static class NotEquals extends SQLOperator.BinaryOperator - { - public NotEquals (SQLExpression column, Comparable value) - { - super(column, value); - } - - public NotEquals (SQLExpression column, SQLExpression value) - { - super(column, value); - } - - @Override public String operator() - { - return "!="; - } - - @Override - public Object evaluate (Object left, Object right) - { - if (left == null || right == null) { - return new NoValue("Null operand to '!=': (" + left + ", " + right + ")"); - } - return !left.equals(right); - } - } - - /** The SQL '<' operator. */ - public static class LessThan extends SQLOperator.BinaryOperator - { - public LessThan (SQLExpression column, Comparable value) - { - super(column, value); - } - - public LessThan (SQLExpression column, SQLExpression value) - { - super(column, value); - } - - @Override public String operator() - { - return "<"; - } - - @Override - public Object evaluate (Object left, Object right) - { - if (all(NUMERICAL, left, right)) { - return NUMERICAL.apply(left) < NUMERICAL.apply(right); - } - if (all(STRING, left, right) || all(DATE, left, right)) { - return compare(STRING, left, right) < 0; - } - return new NoValue("Non-comparable operand to '<': (" + left + ", " + right + ")"); - } - } - - /** The SQL '<=' operator. */ - public static class LessThanEquals extends SQLOperator.BinaryOperator - { - public LessThanEquals (SQLExpression column, Comparable value) - { - super(column, value); - } - - public LessThanEquals (SQLExpression column, SQLExpression value) - { - super(column, value); - } - - @Override public String operator() - { - return "<="; - } - - @Override - public Object evaluate (Object left, Object right) - { - if (all(NUMERICAL, left, right)) { - return NUMERICAL.apply(left) <= NUMERICAL.apply(right); - } - if (all(STRING, left, right) || all(DATE, left, right)) { - return compare(STRING, left, right) <= 0; - } - return new NoValue("Non-comparable operand to '<=': (" + left + ", " + right + ")"); - } -} - - /** The SQL '>' operator. */ - public static class GreaterThan extends SQLOperator.BinaryOperator - { - public GreaterThan (SQLExpression column, Comparable value) - { - super(column, value); - } - - public GreaterThan (SQLExpression column, SQLExpression value) - { - super(column, value); - } - - @Override public String operator() - { - return ">"; - } - - @Override - public Object evaluate (Object left, Object right) - { - if (all(NUMERICAL, left, right)) { - return NUMERICAL.apply(left) > NUMERICAL.apply(right); - } - if (all(STRING, left, right) || all(DATE, left, right)) { - return compare(STRING, left, right) > 0; - } - return new NoValue("Non-comparable operand to '>': (" + left + ", " + right + ")"); - } - } - - /** The SQL '>=' operator. */ - public static class GreaterThanEquals extends SQLOperator.BinaryOperator - { - public GreaterThanEquals (SQLExpression column, Comparable value) - { - super(column, value); - } - - public GreaterThanEquals (SQLExpression column, SQLExpression value) - { - super(column, value); - } - - @Override public String operator() - { - return ">="; - } - - @Override - public Object evaluate (Object left, Object right) - { - if (all(NUMERICAL, left, right)) { - return NUMERICAL.apply(left) >= NUMERICAL.apply(right); - } - if (all(STRING, left, right) || all(DATE, left, right)) { - return compare(STRING, left, right) >= 0; - } - return new NoValue("Non-comparable operand to '>=': (" + left + ", " + right + ")"); - } - } - - /** The SQL 'in (...)' operator. */ - public static class In - implements SQLOperator - { - /** The maximum number of keys allowed in an IN() clause. */ - public static final int MAX_KEYS = Short.MAX_VALUE; - - public In (ColumnExp column, Comparable... values) - { - if (values.length == 0) { - log.warning("Grouchily allowing empty In() operator", "column", column.name, - new Exception()); - } - _column = column; - _values = values; - } - - public In (ColumnExp pColumn, Collection> values) - { - this(pColumn, values.toArray(new Comparable[values.size()])); - } - - public ColumnExp getColumn () - { - return _column; - } - - public Comparable[] getValues () - { - return _values; - } - - // from SQLExpression - public Object accept (ExpressionVisitor builder) - { - return builder.visit(this); - } - - // from SQLExpression - public void addClasses (Collection> classSet) - { - _column.addClasses(classSet); - } - - @Override // from Object - public String toString () - { - StringBuilder builder = new StringBuilder(); - builder.append(_column).append(" in ("); - for (int ii = 0; ii < _values.length; ii++) { - if (ii > 0) { - builder.append(", "); - } - builder.append(_values[ii]); - } - return builder.append(")").toString(); - } - - protected ColumnExp _column; - protected Comparable[] _values; - } - - /** The SQL ' like ' operator. */ - public static class Like extends SQLOperator.BinaryOperator - { - public Like (SQLExpression column, Comparable value) - { - super(column, value); - } - - public Like (SQLExpression column, SQLExpression value) - { - super(column, value); - } - - @Override public String operator() - { - return " like "; - } - - @Override - public Object evaluate (Object left, Object right) - { - return new NoValue("Like operator not implemented"); - } - } - - /** The SQL ' exists' operator. */ - public static class Exists implements SQLOperator - { - public Exists (SelectClause clause) - { - _clause = clause; - } - - public Object accept (ExpressionVisitor builder) - { - return builder.visit(this); - } - - public void addClasses (Collection> classSet) - { - _clause.addClasses(classSet); - } - - public SelectClause getSubClause () - { - return _clause; - } - - @Override // from Object - public String toString () - { - return "Exists(" + _clause + ")"; - } - - protected SelectClause _clause; - } - - public static class Case implements SQLOperator - { - public Case (SQLExpression... exps) - { - int i = 0; - while (i+1 < exps.length) { - _whenExps.add(Tuple.newTuple(exps[i], exps[i+1])); - i += 2; - } - _elseExp = (i < exps.length) ? exps[i] : null; - } - - // from SQLExpression - public Object accept (ExpressionVisitor builder) - { - return builder.visit(this); - } - - // from SQLExpression - public void addClasses (Collection> classSet) - { - for (Tuple tuple : _whenExps) { - tuple.left.addClasses(classSet); - tuple.right.addClasses(classSet); - } - if (_elseExp != null) { - _elseExp.addClasses(classSet); - } - } - - public List> getWhenExps () - { - return _whenExps; - } - - public SQLExpression getElseExp () - { - return _elseExp; - } - - @Override // from Object - public String toString () - { - StringBuilder builder = new StringBuilder(); - builder.append("Case("); - for (Tuple tuple : _whenExps) { - builder.append(tuple.left.toString()).append("->"); - builder.append(tuple.right.toString()).append(","); - } - if (_elseExp != null) { - builder.append(_elseExp.toString()).append(")"); - } - return builder.toString(); - } - - protected List> _whenExps = Lists.newArrayList(); - protected SQLExpression _elseExp; - } - - /** - * An attempt at a dialect-agnostic full-text search condition, such as MySQL's MATCH() and - * PostgreSQL's @@ TO_TSQUERY(...) abilities. - */ - public static class FullText - { - public class Rank - implements SQLOperator - { - // from SQLExpression - public Object accept (ExpressionVisitor builder) - { - return builder.visit(this); - } - - // from SQLExpression - public void addClasses (Collection> classSet) - { - } - - @Override // from Object - public String toString () - { - return FullText.this.toString("Rank"); - } - - public FullText getDefinition () - { - return FullText.this; - } - } - - public class Match - implements SQLOperator - { - // from SQLExpression - public Object accept (ExpressionVisitor builder) - { - return builder.visit(this); - } - - public FullText getDefinition () - { - return FullText.this; - } - - // from SQLExpression - public void addClasses (Collection> classSet) - { - } - - @Override // from Object - public String toString () - { - return FullText.this.toString("Match"); - } - } - - public FullText (Class pClass, String name, String query) - { - _pClass = pClass; - _name = name; - _query = query; - } - - public SQLOperator match () - { - return new Match(); - } - - public SQLOperator rank () - { - return new Rank(); - } - - public Class getPersistentClass () - { - return _pClass; - } - - public String getName () - { - return _name; - } - - public String getQuery () - { - return _query; - } - - protected String toString (String subType) - { - return "FullText." + subType + "(" + _name + "=" + _query + ")"; - } - - protected Class _pClass; - protected String _name; - protected String _query; - } -} diff --git a/src/java/com/samskivert/depot/operator/Div.java b/src/java/com/samskivert/depot/operator/Div.java new file mode 100644 index 0000000..7b1985e --- /dev/null +++ b/src/java/com/samskivert/depot/operator/Div.java @@ -0,0 +1,66 @@ +// +// $Id$ +// +// Depot library - a Java relational persistence library +// Copyright (C) 2006-2009 Michael Bayne and Pär Winzell +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.samskivert.depot.operator; + +import com.samskivert.util.StringUtil; + +import com.samskivert.depot.expression.SQLExpression; + +/** + * The SQL '/' operator. + */ +public class Div extends Arithmetic +{ + public Div (SQLExpression column, Comparable value) + { + super(column, value); + } + + public Div (SQLExpression... values) + { + super(values); + } + + @Override // from Arithmetic + public String operator() + { + return " / "; // Pad with spaces to work-around a MySQL bug. + } + + @Override // from Arithmetic + public Object evaluate (Object[] operands) + { + for (int ii = 1; ii < operands.length; ii ++) { + if (Double.valueOf(0).equals(NUMERICAL.apply(operands[ii]))) { + return new NoValue("Division by zero in: " + StringUtil.toString(operands)); + } + } + return evaluate(operands, "/", new Accumulator() { + public Double accumulate (Double left, Double right) { + return left / right; + } + }, new Accumulator() { + public Long accumulate (Long left, Long right) { + return left / right; + } + }); + } +} diff --git a/src/java/com/samskivert/depot/operator/Equals.java b/src/java/com/samskivert/depot/operator/Equals.java new file mode 100644 index 0000000..7bd3725 --- /dev/null +++ b/src/java/com/samskivert/depot/operator/Equals.java @@ -0,0 +1,54 @@ +// +// $Id$ +// +// Depot library - a Java relational persistence library +// Copyright (C) 2006-2009 Michael Bayne and Pär Winzell +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.samskivert.depot.operator; + +import com.samskivert.depot.expression.SQLExpression; + +/** + * The SQL '=' operator. + */ +public class Equals extends SQLOperator.BinaryOperator +{ + public Equals (SQLExpression column, Comparable value) + { + super(column, value); + } + + public Equals (SQLExpression column, SQLExpression value) + { + super(column, value); + } + + @Override // from SQLOperator.BinaryOperator + public String operator() + { + return "="; + } + + @Override // from SQLOperator.BinaryOperator + public Object evaluate (Object left, Object right) + { + if (left == null || right == null) { + return new NoValue("Null operand to '=': (" + left + ", " + right + ")"); + } + return left.equals(right); + } +} diff --git a/src/java/com/samskivert/depot/operator/Exists.java b/src/java/com/samskivert/depot/operator/Exists.java new file mode 100644 index 0000000..720764d --- /dev/null +++ b/src/java/com/samskivert/depot/operator/Exists.java @@ -0,0 +1,62 @@ +// +// $Id$ +// +// Depot library - a Java relational persistence library +// Copyright (C) 2006-2009 Michael Bayne and Pär Winzell +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.samskivert.depot.operator; + +import java.util.Collection; + +import com.samskivert.depot.PersistentRecord; +import com.samskivert.depot.clause.SelectClause; +import com.samskivert.depot.impl.ExpressionVisitor; + +/** + * The SQL 'exists' operator. + */ +public class Exists + implements SQLOperator +{ + public Exists (SelectClause clause) + { + _clause = clause; + } + + public Object accept (ExpressionVisitor builder) + { + return builder.visit(this); + } + + public void addClasses (Collection> classSet) + { + _clause.addClasses(classSet); + } + + public SelectClause getSubClause () + { + return _clause; + } + + @Override // from Object + public String toString () + { + return "Exists(" + _clause + ")"; + } + + protected SelectClause _clause; +} diff --git a/src/java/com/samskivert/depot/operator/FullText.java b/src/java/com/samskivert/depot/operator/FullText.java new file mode 100644 index 0000000..56a5f3e --- /dev/null +++ b/src/java/com/samskivert/depot/operator/FullText.java @@ -0,0 +1,126 @@ +// +// $Id$ +// +// Depot library - a Java relational persistence library +// Copyright (C) 2006-2009 Michael Bayne and Pär Winzell +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.samskivert.depot.operator; + +import java.util.Collection; + +import com.samskivert.depot.PersistentRecord; +import com.samskivert.depot.impl.ExpressionVisitor; + +/** + * An attempt at a dialect-agnostic full-text search condition, such as MySQL's MATCH() and + * PostgreSQL's @@ TO_TSQUERY(...) abilities. + */ +public class FullText +{ + public class Rank + implements SQLOperator + { + // from SQLExpression + public Object accept (ExpressionVisitor builder) + { + return builder.visit(this); + } + + // from SQLExpression + public void addClasses (Collection> classSet) + { + } + + @Override // from Object + public String toString () + { + return FullText.this.toString("Rank"); + } + + public FullText getDefinition () + { + return FullText.this; + } + } + + public class Match + implements SQLOperator + { + // from SQLExpression + public Object accept (ExpressionVisitor builder) + { + return builder.visit(this); + } + + public FullText getDefinition () + { + return FullText.this; + } + + // from SQLExpression + public void addClasses (Collection> classSet) + { + } + + @Override // from Object + public String toString () + { + return FullText.this.toString("Match"); + } + } + + public FullText (Class pClass, String name, String query) + { + _pClass = pClass; + _name = name; + _query = query; + } + + public SQLOperator match () + { + return new Match(); + } + + public SQLOperator rank () + { + return new Rank(); + } + + public Class getPersistentClass () + { + return _pClass; + } + + public String getName () + { + return _name; + } + + public String getQuery () + { + return _query; + } + + protected String toString (String subType) + { + return "FullText." + subType + "(" + _name + "=" + _query + ")"; + } + + protected Class _pClass; + protected String _name; + protected String _query; +} diff --git a/src/java/com/samskivert/depot/operator/GreaterThan.java b/src/java/com/samskivert/depot/operator/GreaterThan.java new file mode 100644 index 0000000..a5817e1 --- /dev/null +++ b/src/java/com/samskivert/depot/operator/GreaterThan.java @@ -0,0 +1,57 @@ +// +// $Id$ +// +// Depot library - a Java relational persistence library +// Copyright (C) 2006-2009 Michael Bayne and Pär Winzell +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.samskivert.depot.operator; + +import com.samskivert.depot.expression.SQLExpression; + +/** + * The SQL '>' operator. + */ +public class GreaterThan extends SQLOperator.BinaryOperator +{ + public GreaterThan (SQLExpression column, Comparable value) + { + super(column, value); + } + + public GreaterThan (SQLExpression column, SQLExpression value) + { + super(column, value); + } + + @Override // from SQLOperator.BinaryOperator + public String operator() + { + return ">"; + } + + @Override // from SQLOperator.BinaryOperator + public Object evaluate (Object left, Object right) + { + if (all(NUMERICAL, left, right)) { + return NUMERICAL.apply(left) > NUMERICAL.apply(right); + } + if (all(STRING, left, right) || all(DATE, left, right)) { + return compare(STRING, left, right) > 0; + } + return new NoValue("Non-comparable operand to '>': (" + left + ", " + right + ")"); + } +} diff --git a/src/java/com/samskivert/depot/operator/GreaterThanEquals.java b/src/java/com/samskivert/depot/operator/GreaterThanEquals.java new file mode 100644 index 0000000..827f51e --- /dev/null +++ b/src/java/com/samskivert/depot/operator/GreaterThanEquals.java @@ -0,0 +1,57 @@ +// +// $Id$ +// +// Depot library - a Java relational persistence library +// Copyright (C) 2006-2009 Michael Bayne and Pär Winzell +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.samskivert.depot.operator; + +import com.samskivert.depot.expression.SQLExpression; + +/** + * The SQL '>=' operator. + */ +public class GreaterThanEquals extends SQLOperator.BinaryOperator +{ + public GreaterThanEquals (SQLExpression column, Comparable value) + { + super(column, value); + } + + public GreaterThanEquals (SQLExpression column, SQLExpression value) + { + super(column, value); + } + + @Override // from SQLOperator.BinaryOperator + public String operator() + { + return ">="; + } + + @Override // from SQLOperator.BinaryOperator + public Object evaluate (Object left, Object right) + { + if (all(NUMERICAL, left, right)) { + return NUMERICAL.apply(left) >= NUMERICAL.apply(right); + } + if (all(STRING, left, right) || all(DATE, left, right)) { + return compare(STRING, left, right) >= 0; + } + return new NoValue("Non-comparable operand to '>=': (" + left + ", " + right + ")"); + } +} diff --git a/src/java/com/samskivert/depot/operator/In.java b/src/java/com/samskivert/depot/operator/In.java new file mode 100644 index 0000000..1e6cbe1 --- /dev/null +++ b/src/java/com/samskivert/depot/operator/In.java @@ -0,0 +1,93 @@ +// +// $Id$ +// +// Depot library - a Java relational persistence library +// Copyright (C) 2006-2009 Michael Bayne and Pär Winzell +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.samskivert.depot.operator; + +import java.util.Collection; + +import com.samskivert.depot.PersistentRecord; +import com.samskivert.depot.expression.ColumnExp; +import com.samskivert.depot.impl.ExpressionVisitor; + +import static com.samskivert.depot.Log.log; + +/** + * The SQL 'in (...)' operator. + */ +public class In + implements SQLOperator +{ + /** The maximum number of keys allowed in an IN() clause. */ + public static final int MAX_KEYS = Short.MAX_VALUE; + + public In (ColumnExp column, Comparable... values) + { + if (values.length == 0) { + log.warning("Grouchily allowing empty In() operator", "column", column.name, + new Exception()); + } + _column = column; + _values = values; + } + + public In (ColumnExp pColumn, Collection> values) + { + this(pColumn, values.toArray(new Comparable[values.size()])); + } + + public ColumnExp getColumn () + { + return _column; + } + + public Comparable[] getValues () + { + return _values; + } + + // from SQLExpression + public Object accept (ExpressionVisitor builder) + { + return builder.visit(this); + } + + // from SQLExpression + public void addClasses (Collection> classSet) + { + _column.addClasses(classSet); + } + + @Override // from Object + public String toString () + { + StringBuilder builder = new StringBuilder(); + builder.append(_column).append(" in ("); + for (int ii = 0; ii < _values.length; ii++) { + if (ii > 0) { + builder.append(", "); + } + builder.append(_values[ii]); + } + return builder.append(")").toString(); + } + + protected ColumnExp _column; + protected Comparable[] _values; +} diff --git a/src/java/com/samskivert/depot/operator/IsNull.java b/src/java/com/samskivert/depot/operator/IsNull.java new file mode 100644 index 0000000..c824765 --- /dev/null +++ b/src/java/com/samskivert/depot/operator/IsNull.java @@ -0,0 +1,63 @@ +// +// $Id$ +// +// Depot library - a Java relational persistence library +// Copyright (C) 2006-2009 Michael Bayne and Pär Winzell +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.samskivert.depot.operator; + +import java.util.Collection; + +import com.samskivert.depot.PersistentRecord; +import com.samskivert.depot.expression.ColumnExp; +import com.samskivert.depot.impl.ExpressionVisitor; + +/** + * The SQL 'is null' operator. + */ +public class IsNull + implements SQLOperator +{ + public IsNull (ColumnExp column) + { + _column = column; + } + + public ColumnExp getColumn() + { + return _column; + } + + // from SQLExpression + public Object accept (ExpressionVisitor builder) + { + return builder.visit(this); + } + + // from SQLExpression + public void addClasses (Collection> classSet) + { + } + + @Override // from Object + public String toString () + { + return "IsNull(" + _column + ")"; + } + + protected ColumnExp _column; +} diff --git a/src/java/com/samskivert/depot/operator/LessThan.java b/src/java/com/samskivert/depot/operator/LessThan.java new file mode 100644 index 0000000..2636def --- /dev/null +++ b/src/java/com/samskivert/depot/operator/LessThan.java @@ -0,0 +1,57 @@ +// +// $Id$ +// +// Depot library - a Java relational persistence library +// Copyright (C) 2006-2009 Michael Bayne and Pär Winzell +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.samskivert.depot.operator; + +import com.samskivert.depot.expression.SQLExpression; + +/** + * The SQL '<' operator. + */ +public class LessThan extends SQLOperator.BinaryOperator +{ + public LessThan (SQLExpression column, Comparable value) + { + super(column, value); + } + + public LessThan (SQLExpression column, SQLExpression value) + { + super(column, value); + } + + @Override // from SQLOperator.BinaryOperator + public String operator() + { + return "<"; + } + + @Override // from SQLOperator.BinaryOperator + public Object evaluate (Object left, Object right) + { + if (all(NUMERICAL, left, right)) { + return NUMERICAL.apply(left) < NUMERICAL.apply(right); + } + if (all(STRING, left, right) || all(DATE, left, right)) { + return compare(STRING, left, right) < 0; + } + return new NoValue("Non-comparable operand to '<': (" + left + ", " + right + ")"); + } +} diff --git a/src/java/com/samskivert/depot/operator/LessThanEquals.java b/src/java/com/samskivert/depot/operator/LessThanEquals.java new file mode 100644 index 0000000..ee24ab5 --- /dev/null +++ b/src/java/com/samskivert/depot/operator/LessThanEquals.java @@ -0,0 +1,57 @@ +// +// $Id$ +// +// Depot library - a Java relational persistence library +// Copyright (C) 2006-2009 Michael Bayne and Pär Winzell +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.samskivert.depot.operator; + +import com.samskivert.depot.expression.SQLExpression; + +/** + * The SQL '<=' operator. + */ +public class LessThanEquals extends SQLOperator.BinaryOperator +{ + public LessThanEquals (SQLExpression column, Comparable value) + { + super(column, value); + } + + public LessThanEquals (SQLExpression column, SQLExpression value) + { + super(column, value); + } + + @Override // from SQLOperator.BinaryOperator + public String operator() + { + return "<="; + } + + @Override // from SQLOperator.BinaryOperator + public Object evaluate (Object left, Object right) + { + if (all(NUMERICAL, left, right)) { + return NUMERICAL.apply(left) <= NUMERICAL.apply(right); + } + if (all(STRING, left, right) || all(DATE, left, right)) { + return compare(STRING, left, right) <= 0; + } + return new NoValue("Non-comparable operand to '<=': (" + left + ", " + right + ")"); + } +} diff --git a/src/java/com/samskivert/depot/operator/Like.java b/src/java/com/samskivert/depot/operator/Like.java new file mode 100644 index 0000000..053b745 --- /dev/null +++ b/src/java/com/samskivert/depot/operator/Like.java @@ -0,0 +1,51 @@ +// +// $Id$ +// +// Depot library - a Java relational persistence library +// Copyright (C) 2006-2009 Michael Bayne and Pär Winzell +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.samskivert.depot.operator; + +import com.samskivert.depot.expression.SQLExpression; + +/** + * The SQL 'like' operator. + */ +public class Like extends SQLOperator.BinaryOperator +{ + public Like (SQLExpression column, Comparable value) + { + super(column, value); + } + + public Like (SQLExpression column, SQLExpression value) + { + super(column, value); + } + + @Override // from SQLOperator.BinaryOperator + public String operator() + { + return " like "; + } + + @Override // from SQLOperator.BinaryOperator + public Object evaluate (Object left, Object right) + { + return new NoValue("Like operator not implemented"); + } +} diff --git a/src/java/com/samskivert/depot/operator/Logic.java b/src/java/com/samskivert/depot/operator/Logic.java deleted file mode 100644 index c1c485b..0000000 --- a/src/java/com/samskivert/depot/operator/Logic.java +++ /dev/null @@ -1,149 +0,0 @@ -// -// $Id$ -// -// Depot library - a Java relational persistence library -// Copyright (C) 2006-2008 Michael Bayne and Pär Winzell -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.samskivert.depot.operator; - -import java.util.Collection; - -import com.samskivert.depot.PersistentRecord; -import com.samskivert.depot.expression.SQLExpression; -import com.samskivert.depot.impl.ExpressionVisitor; - -/** - * A convenient container for implementations of logical operators. Classes that value brevity - * feel otherwise will use Logic.And() and Logic.Not(). - */ -public abstract class Logic -{ - /** - * Represents a condition that is false iff all its subconditions are false. - */ - public static class Or extends SQLOperator.MultiOperator - { - public Or (Collection conditions) - { - super(conditions.toArray(new SQLExpression[conditions.size()])); - } - - public Or (SQLExpression... conditions) - { - super(conditions); - } - - @Override public String operator() - { - return " or "; - } - - @Override - public Object evaluate (Object[] values) - { - boolean anyTrue = false; - for (Object value : values) { - if (value instanceof NoValue) { - return value; - } - if (Boolean.TRUE.equals(value)) { - anyTrue = true; - } else if (!Boolean.FALSE.equals(value)) { - return new NoValue("Non-boolean operand to OR: " + value); - } - } - return anyTrue; - } - } - - /** - * Represents a condition that is true iff all its subconditions are true. - */ - public static class And extends SQLOperator.MultiOperator - { - public And (Collection conditions) - { - super(conditions.toArray(new SQLExpression[conditions.size()])); - } - - public And (SQLExpression... conditions) - { - super(conditions); - } - - @Override public String operator() - { - return " and "; - } - - @Override - public Object evaluate (Object[] values) - { - // if all operands are true, return true, else if all operands are boolean, return - // false, else return NO_VALUE - boolean allTrue = true; - for (Object value : values) { - if (value instanceof NoValue) { - return value; - } - if (Boolean.FALSE.equals(value)) { - allTrue = false; - } else if (!Boolean.TRUE.equals(value)) { - return new NoValue("Non-boolean operand to AND: " + value); - } - } - return allTrue; - } - } - - /** - * Represents the truth negation of another conditon. - */ - public static class Not - implements SQLOperator - { - public Not (SQLExpression condition) - { - _condition = condition; - } - - public SQLExpression getCondition () - { - return _condition; - } - - // from SQLExpression - public Object accept (ExpressionVisitor builder) - { - return builder.visit(this); - } - - // from SQLExpression - public void addClasses (Collection> classSet) - { - _condition.addClasses(classSet); - } - - @Override // from Object - public String toString () - { - return "Not(" + _condition + ")"; - } - - protected SQLExpression _condition; - } -} diff --git a/src/java/com/samskivert/depot/operator/Mul.java b/src/java/com/samskivert/depot/operator/Mul.java new file mode 100644 index 0000000..4a80aa8 --- /dev/null +++ b/src/java/com/samskivert/depot/operator/Mul.java @@ -0,0 +1,59 @@ +// +// $Id$ +// +// Depot library - a Java relational persistence library +// Copyright (C) 2006-2009 Michael Bayne and Pär Winzell +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.samskivert.depot.operator; + +import com.samskivert.depot.expression.SQLExpression; + +/** + * The SQL '*' operator. + */ +public class Mul extends Arithmetic +{ + public Mul (SQLExpression column, Comparable value) + { + super(column, value); + } + + public Mul (SQLExpression... values) + { + super(values); + } + + @Override // from Arithmetic + public String operator() + { + return "*"; + } + + @Override // from Arithmetic + public Object evaluate (Object[] operands) + { + return evaluate(operands, "*", new Accumulator() { + public Double accumulate (Double left, Double right) { + return left * right; + } + }, new Accumulator() { + public Long accumulate (Long left, Long right) { + return left * right; + } + }); + } +} diff --git a/src/java/com/samskivert/depot/operator/Not.java b/src/java/com/samskivert/depot/operator/Not.java new file mode 100644 index 0000000..735ecd4 --- /dev/null +++ b/src/java/com/samskivert/depot/operator/Not.java @@ -0,0 +1,64 @@ +// +// $Id$ +// +// Depot library - a Java relational persistence library +// Copyright (C) 2006-2009 Michael Bayne and Pär Winzell +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.samskivert.depot.operator; + +import java.util.Collection; + +import com.samskivert.depot.PersistentRecord; +import com.samskivert.depot.expression.SQLExpression; +import com.samskivert.depot.impl.ExpressionVisitor; + +/** + * Represents the truth negation of another conditon. + */ +public class Not + implements SQLOperator +{ + public Not (SQLExpression condition) + { + _condition = condition; + } + + public SQLExpression getCondition () + { + return _condition; + } + + // from SQLExpression + public Object accept (ExpressionVisitor builder) + { + return builder.visit(this); + } + + // from SQLExpression + public void addClasses (Collection> classSet) + { + _condition.addClasses(classSet); + } + + @Override // from Object + public String toString () + { + return "Not(" + _condition + ")"; + } + + protected SQLExpression _condition; +} diff --git a/src/java/com/samskivert/depot/operator/NotEquals.java b/src/java/com/samskivert/depot/operator/NotEquals.java new file mode 100644 index 0000000..3b35b99 --- /dev/null +++ b/src/java/com/samskivert/depot/operator/NotEquals.java @@ -0,0 +1,54 @@ +// +// $Id$ +// +// Depot library - a Java relational persistence library +// Copyright (C) 2006-2009 Michael Bayne and Pär Winzell +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.samskivert.depot.operator; + +import com.samskivert.depot.expression.SQLExpression; + +/** + * The SQL '!=' operator. + */ +public class NotEquals extends SQLOperator.BinaryOperator +{ + public NotEquals (SQLExpression column, Comparable value) + { + super(column, value); + } + + public NotEquals (SQLExpression column, SQLExpression value) + { + super(column, value); + } + + @Override // from SQLOperator.BinaryOperator + public String operator() + { + return "!="; + } + + @Override // from SQLOperator.BinaryOperator + public Object evaluate (Object left, Object right) + { + if (left == null || right == null) { + return new NoValue("Null operand to '!=': (" + left + ", " + right + ")"); + } + return !left.equals(right); + } +} diff --git a/src/java/com/samskivert/depot/operator/Or.java b/src/java/com/samskivert/depot/operator/Or.java new file mode 100644 index 0000000..31f8efd --- /dev/null +++ b/src/java/com/samskivert/depot/operator/Or.java @@ -0,0 +1,63 @@ +// +// $Id$ +// +// Depot library - a Java relational persistence library +// Copyright (C) 2006-2009 Michael Bayne and Pär Winzell +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.samskivert.depot.operator; + +import java.util.Collection; + +import com.samskivert.depot.expression.SQLExpression; + +/** + * Represents a condition that is false iff all its subconditions are false. + */ +public class Or extends SQLOperator.MultiOperator +{ + public Or (Collection conditions) + { + super(conditions.toArray(new SQLExpression[conditions.size()])); + } + + public Or (SQLExpression... conditions) + { + super(conditions); + } + + @Override public String operator() + { + return " or "; + } + + @Override + public Object evaluate (Object[] values) + { + boolean anyTrue = false; + for (Object value : values) { + if (value instanceof NoValue) { + return value; + } + if (Boolean.TRUE.equals(value)) { + anyTrue = true; + } else if (!Boolean.FALSE.equals(value)) { + return new NoValue("Non-boolean operand to OR: " + value); + } + } + return anyTrue; + } +} diff --git a/src/java/com/samskivert/depot/operator/Sub.java b/src/java/com/samskivert/depot/operator/Sub.java new file mode 100644 index 0000000..8dacadb --- /dev/null +++ b/src/java/com/samskivert/depot/operator/Sub.java @@ -0,0 +1,59 @@ +// +// $Id$ +// +// Depot library - a Java relational persistence library +// Copyright (C) 2006-2009 Michael Bayne and Pär Winzell +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.samskivert.depot.operator; + +import com.samskivert.depot.expression.SQLExpression; + +/** + * The SQL '-' operator. + */ +public class Sub extends Arithmetic +{ + public Sub (SQLExpression column, Comparable value) + { + super(column, value); + } + + public Sub (SQLExpression... values) + { + super(values); + } + + @Override // from Arithmetic + public String operator() + { + return "-"; + } + + @Override // from Arithmetic + public Object evaluate (Object[] operands) + { + return evaluate(operands, "-", new Accumulator() { + public Double accumulate (Double left, Double right) { + return left - right; + } + }, new Accumulator() { + public Long accumulate (Long left, Long right) { + return left - right; + } + }); + } +} diff --git a/src/java/com/samskivert/depot/tests/TestRepository.java b/src/java/com/samskivert/depot/tests/TestRepository.java index 02e53ca..64ba73c 100644 --- a/src/java/com/samskivert/depot/tests/TestRepository.java +++ b/src/java/com/samskivert/depot/tests/TestRepository.java @@ -39,7 +39,8 @@ import com.samskivert.depot.SchemaMigration; import com.samskivert.depot.annotation.Computed; import com.samskivert.depot.clause.Where; import com.samskivert.depot.expression.LiteralExp; -import com.samskivert.depot.operator.Conditionals; +import com.samskivert.depot.operator.GreaterThan; +import com.samskivert.depot.operator.LessThan; /** * A test tool for the Depot repository services. @@ -120,7 +121,7 @@ public class TestRepository extends DepotRepository System.out.println("Delete none " + repo.deleteAll(TestRecord.class, none) + "."); // test collection caching - Where where = new Where(new Conditionals.GreaterThan(TestRecord.RECORD_ID, 100)); + Where where = new Where(new GreaterThan(TestRecord.RECORD_ID, 100)); System.out.println("100 and up: " + repo.findAll(TestRecord.class, where).size()); System.out.println("100 and up again: " + repo.findAll(TestRecord.class, where).size()); @@ -131,13 +132,13 @@ public class TestRepository extends DepotRepository System.out.println("Names " + repo.findAll(TestNameRecord.class) + "."); System.out.println("Have " + repo.findAll(TestRecord.class).size() + " records."); - repo.deleteAll(TestRecord.class, new Where(new Conditionals.LessThan( + repo.deleteAll(TestRecord.class, new Where(new LessThan( TestRecord.RECORD_ID, CREATE_RECORDS/2))); System.out.println("Now have " + repo.findAll(TestRecord.class).size() + " records."); repo.deleteAll(TestRecord.class, new Where(new LiteralExp("true"))); // // TODO: try to break our In() clause // Set ids = Sets.newHashSet(); -// for (int ii = 1; ii <= Conditionals.In.MAX_KEYS*2+3; ii++) { +// for (int ii = 1; ii <= In.MAX_KEYS*2+3; ii++) { // ids.add(ii); // } // repo.deleteAll(TestRecord.class, KeySet.newSimpleKeySet(TestRecord.class, ids));