From 7a350474f5d88944f40dc7e0521149bab66d4814 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 10 Sep 2009 02:56:21 +0000 Subject: [PATCH] Added exists() as well as a static add() and mul() for times when it seems weird to use those fluently. Might also add div() and sub() but I'm currently wondering why those have varags constructors Div(SQLExpression... values). What does foo / bar / baz mean exactly? That's a rhetorical question, division is left associative, but it's still weird and too non-obvious IMO. foo - bar - baz is also wonky. --- src/java/com/samskivert/depot/Ops.java | 46 ++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/src/java/com/samskivert/depot/Ops.java b/src/java/com/samskivert/depot/Ops.java index 79e03a7..61f1e53 100644 --- a/src/java/com/samskivert/depot/Ops.java +++ b/src/java/com/samskivert/depot/Ops.java @@ -22,10 +22,14 @@ package com.samskivert.depot; import java.util.Collection; +import com.samskivert.depot.clause.SelectClause; import com.samskivert.depot.expression.FluentExp; import com.samskivert.depot.expression.SQLExpression; +import com.samskivert.depot.operator.Add; import com.samskivert.depot.operator.And; +import com.samskivert.depot.operator.Exists; import com.samskivert.depot.operator.Like; +import com.samskivert.depot.operator.Mul; import com.samskivert.depot.operator.Not; import com.samskivert.depot.operator.Or; @@ -36,7 +40,7 @@ import com.samskivert.depot.operator.Or; public class Ops { /** - * Creates a {@link Not} with the supplied target expression. + * Creates a NOT expression with the supplied target expression. */ public static SQLExpression not (SQLExpression expr) { @@ -44,7 +48,7 @@ public class Ops } /** - * Creates an {@link And} with the supplied target expressions. + * Creates an AND expression with the supplied target expressions. */ public static FluentExp and (Collection conditions) { @@ -52,7 +56,7 @@ public class Ops } /** - * Creates an {@link And} with the supplied target expressions. + * Creates an AND expression with the supplied target expressions. */ public static FluentExp and (SQLExpression... conditions) { @@ -60,7 +64,7 @@ public class Ops } /** - * Creates an {@link Or} with the supplied target expressions. + * Creates an OR expression with the supplied target expressions. */ public static FluentExp or (Collection conditions) { @@ -68,22 +72,50 @@ public class Ops } /** - * Creates an {@link Or} with the supplied target expressions. + * Creates an OR expression with the supplied target expressions. */ public static FluentExp or (SQLExpression... conditions) { return new Or(conditions); } - /** Returns an expression that matches when the source is like the supplied value. */ + /** + * Returns an expression that matches when the source is like the supplied value. + */ public static FluentExp like (SQLExpression source, Comparable value) { return new Like(source, value); } - /** Returns an expression that matches when the source is like the supplied expression. */ + /** + * Returns an expression that matches when the source is like the supplied expression. + */ public static FluentExp like (SQLExpression source, SQLExpression expr) { return new Like(source, expr); } + + /** + * Creates an EXISTS expression with the supplied select clause. + */ + public static SQLExpression exists (SelectClause target) + { + return new Exists(target); + } + + /** + * Adds the supplied expressions together. + */ + public static FluentExp add (SQLExpression... exprs) + { + return new Add(exprs); + } + + /** + * Multiplies the supplied expressions together. + */ + public static FluentExp mul (SQLExpression... exprs) + { + return new Mul(exprs); + } }