diff --git a/src/java/com/samskivert/depot/Exps.java b/src/java/com/samskivert/depot/Exps.java new file mode 100644 index 0000000..23d687b --- /dev/null +++ b/src/java/com/samskivert/depot/Exps.java @@ -0,0 +1,107 @@ +// +// $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; + +import com.samskivert.depot.expression.EpochSeconds; +import com.samskivert.depot.expression.IntervalExp; +import com.samskivert.depot.expression.LiteralExp; +import com.samskivert.depot.expression.SQLExpression; +import com.samskivert.depot.expression.ValueExp; + +/** + * Provides static methods for expression construction. For example: {@link #literal}, {@link + * #value} and {@link #years}. + */ +public class Exps +{ + /** + * Wraps the supplied object in a {@link ValueExp}. + */ + public ValueExp value (Object value) + { + return new ValueExp(value); + } + + /** + * Creates a {@link LiteralExp} with the supplied SQL snippet. Note: you're probably breaking + * cross platform compatibility by using this construction. + */ + public LiteralExp literal (String text) + { + return new LiteralExp(text); + } + + /** + * Creates an interval for the specified number of years. + */ + public static IntervalExp years (int amount) + { + return new IntervalExp(IntervalExp.Unit.YEAR, amount); + } + + /** + * Creates an interval for the specified number of months. + */ + public static IntervalExp months (int amount) + { + return new IntervalExp(IntervalExp.Unit.MONTH, amount); + } + + /** + * Creates an interval for the specified number of days. + */ + public static IntervalExp days (int amount) + { + return new IntervalExp(IntervalExp.Unit.DAY, amount); + } + + /** + * Creates an interval for the specified number of hours. + */ + public static IntervalExp hours (int amount) + { + return new IntervalExp(IntervalExp.Unit.HOUR, amount); + } + + /** + * Creates an interval for the specified number of minutes. + */ + public static IntervalExp minutes (int amount) + { + return new IntervalExp(IntervalExp.Unit.MINUTE, amount); + } + + /** + * Creates an interval for the specified number of seconds. + */ + public static IntervalExp seconds (int amount) + { + return new IntervalExp(IntervalExp.Unit.SECOND, amount); + } + + /** + * Creates an expression that converts the supplied expression into seconds since the epoch. + */ + public static EpochSeconds epochSeconds (SQLExpression expr) + { + return new EpochSeconds(expr); + } +} diff --git a/src/java/com/samskivert/depot/Ops.java b/src/java/com/samskivert/depot/Ops.java new file mode 100644 index 0000000..c7cdaf2 --- /dev/null +++ b/src/java/com/samskivert/depot/Ops.java @@ -0,0 +1,60 @@ +// +// $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; + +import java.util.Collection; + +import com.samskivert.depot.expression.SQLExpression; +import com.samskivert.depot.operator.And; +import com.samskivert.depot.operator.Not; +import com.samskivert.depot.operator.Or; + +/** + * Provides static methods for operator construction that don't fit nicely into the fluent style. + * For example: Ops.and(), Ops.or() and Ops.not(). + */ +public class Ops +{ + public static Not not (SQLExpression expr) + { + return new Not(expr); + } + + public static And and (Collection conditions) + { + return new And(conditions); + } + + public static And and (SQLExpression... conditions) + { + return new And(conditions); + } + + public static Or or (Collection conditions) + { + return new Or(conditions); + } + + public static Or or (SQLExpression... conditions) + { + return new Or(conditions); + } +} diff --git a/src/java/com/samskivert/depot/expression/IntervalExp.java b/src/java/com/samskivert/depot/expression/IntervalExp.java index 9d850e0..85820ae 100644 --- a/src/java/com/samskivert/depot/expression/IntervalExp.java +++ b/src/java/com/samskivert/depot/expression/IntervalExp.java @@ -40,54 +40,6 @@ public class IntervalExp /** The number of units for this interval. */ public final int amount; - /** - * Creates an interval for the specified number of years. - */ - public static IntervalExp years (int amount) - { - return new IntervalExp(Unit.YEAR, amount); - } - - /** - * Creates an interval for the specified number of months. - */ - public static IntervalExp months (int amount) - { - return new IntervalExp(Unit.MONTH, amount); - } - - /** - * Creates an interval for the specified number of days. - */ - public static IntervalExp days (int amount) - { - return new IntervalExp(Unit.DAY, amount); - } - - /** - * Creates an interval for the specified number of hours. - */ - public static IntervalExp hours (int amount) - { - return new IntervalExp(Unit.HOUR, amount); - } - - /** - * Creates an interval for the specified number of minutes. - */ - public static IntervalExp minutes (int amount) - { - return new IntervalExp(Unit.MINUTE, amount); - } - - /** - * Creates an interval for the specified number of seconds. - */ - public static IntervalExp seconds (int amount) - { - return new IntervalExp(Unit.SECOND, amount); - } - public IntervalExp (Unit unit, int amount) { this.unit = unit;