Don't freak out on empty In()'s, just scold the developer.

This commit is contained in:
Par Winzell
2009-04-10 18:11:13 +00:00
parent a4dc9860de
commit 03ca344984
2 changed files with 19 additions and 12 deletions
@@ -220,6 +220,11 @@ public abstract class BuildVisitor implements ExpressionVisitor
public void visit (In in) public void visit (In in)
{ {
// if the In() expression is empty, replace it with a 'false'
if (in.getValues().length == 0) {
new ValueExp(false).accept(this);
return;
}
in.getColumn().accept(this); in.getColumn().accept(this);
_builder.append(" in ("); _builder.append(" in (");
Comparable<?>[] values = in.getValues(); Comparable<?>[] values = in.getValues();
@@ -3,7 +3,7 @@
// //
// Depot library - a Java relational persistence library // Depot library - a Java relational persistence library
// Copyright (C) 2006-2008 Michael Bayne and Pär Winzell // Copyright (C) 2006-2008 Michael Bayne and Pär Winzell
// //
// This library is free software; you can redistribute it and/or modify it // 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 // 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 // by the Free Software Foundation; either version 2.1 of the License, or
@@ -31,6 +31,8 @@ import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.impl.ExpressionVisitor; import com.samskivert.depot.impl.ExpressionVisitor;
import com.samskivert.util.Tuple; import com.samskivert.util.Tuple;
import static com.samskivert.Log.log;
/** /**
* A convenient container for implementations of conditional operators. Classes that value brevity * A convenient container for implementations of conditional operators. Classes that value brevity
* classes that feel otherwise will use Conditionals.Equals() and Conditionals.In(). * classes that feel otherwise will use Conditionals.Equals() and Conditionals.In().
@@ -70,7 +72,7 @@ public abstract class Conditionals
protected ColumnExp _column; protected ColumnExp _column;
} }
/** The SQL '=' operator. */ /** The SQL '=' operator. */
public static class Equals extends SQLOperator.BinaryOperator public static class Equals extends SQLOperator.BinaryOperator
{ {
@@ -195,7 +197,7 @@ public abstract class Conditionals
public In (ColumnExp column, Comparable<?>... values) public In (ColumnExp column, Comparable<?>... values)
{ {
if (values.length == 0) { if (values.length == 0) {
throw new IllegalArgumentException("In() condition needs at least one value."); log.warning("Grouchily allowing empty In() operator", "column", column.name);
} }
_column = column; _column = column;
_values = values; _values = values;
@@ -298,7 +300,7 @@ public abstract class Conditionals
protected SelectClause<T> _clause; protected SelectClause<T> _clause;
} }
public static class Case implements SQLOperator public static class Case implements SQLOperator
{ {
public Case (SQLExpression... exps) public Case (SQLExpression... exps)
@@ -310,7 +312,7 @@ public abstract class Conditionals
} }
_elseExp = (i < exps.length) ? exps[i] : null; _elseExp = (i < exps.length) ? exps[i] : null;
} }
// from SQLExpression // from SQLExpression
public void accept (ExpressionVisitor builder) public void accept (ExpressionVisitor builder)
{ {
@@ -328,7 +330,7 @@ public abstract class Conditionals
_elseExp.addClasses(classSet); _elseExp.addClasses(classSet);
} }
} }
public List<Tuple<SQLExpression, SQLExpression>> getWhenExps () public List<Tuple<SQLExpression, SQLExpression>> getWhenExps ()
{ {
return _whenExps; return _whenExps;
@@ -338,7 +340,7 @@ public abstract class Conditionals
{ {
return _elseExp; return _elseExp;
} }
@Override // from Object @Override // from Object
public String toString () public String toString ()
{ {
@@ -377,7 +379,7 @@ public abstract class Conditionals
public void addClasses (Collection<Class<? extends PersistentRecord>> classSet) public void addClasses (Collection<Class<? extends PersistentRecord>> classSet)
{ {
} }
@Override // from Object @Override // from Object
public String toString () public String toString ()
{ {
@@ -398,7 +400,7 @@ public abstract class Conditionals
{ {
builder.visit(this); builder.visit(this);
} }
public FullText getDefinition () public FullText getDefinition ()
{ {
return FullText.this; return FullText.this;
@@ -408,7 +410,7 @@ public abstract class Conditionals
public void addClasses (Collection<Class<? extends PersistentRecord>> classSet) public void addClasses (Collection<Class<? extends PersistentRecord>> classSet)
{ {
} }
@Override // from Object @Override // from Object
public String toString () public String toString ()
{ {
@@ -442,7 +444,7 @@ public abstract class Conditionals
{ {
return _name; return _name;
} }
public String getQuery () public String getQuery ()
{ {
return _query; return _query;
@@ -452,7 +454,7 @@ public abstract class Conditionals
{ {
return "FullText." + subType + "(" + _name + "=" + _query + ")"; return "FullText." + subType + "(" + _name + "=" + _query + ")";
} }
protected Class<? extends PersistentRecord> _pClass; protected Class<? extends PersistentRecord> _pClass;
protected String _name; protected String _name;
protected String _query; protected String _query;