Added Conditionals.IsNull. Modified Key() to use IsNull if a null value is
passed in for a column value. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1982 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -22,8 +22,10 @@ package com.samskivert.jdbc.depot;
|
||||
|
||||
import com.samskivert.jdbc.depot.clause.Where;
|
||||
import com.samskivert.jdbc.depot.expression.ColumnExp;
|
||||
import com.samskivert.jdbc.depot.expression.LiteralExp;
|
||||
import com.samskivert.jdbc.depot.expression.ValueExp;
|
||||
import com.samskivert.jdbc.depot.operator.Conditionals.Equals;
|
||||
import com.samskivert.jdbc.depot.operator.Conditionals.IsNull;
|
||||
import com.samskivert.jdbc.depot.operator.Logic.And;
|
||||
import com.samskivert.jdbc.depot.operator.SQLOperator;
|
||||
|
||||
@@ -80,7 +82,8 @@ public class Key extends Where
|
||||
{
|
||||
SQLOperator[] comparisons = new Equals[columns.length];
|
||||
for (int ii = 0; ii < columns.length; ii ++) {
|
||||
comparisons[ii] = new Equals(columns[ii], new ValueExp(values[ii]));
|
||||
comparisons[ii] = (values[ii] == null) ?
|
||||
new IsNull(columns[ii]) : new Equals(columns[ii], new ValueExp(values[ii]));
|
||||
}
|
||||
return new And(comparisons);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,37 @@ import com.samskivert.jdbc.depot.expression.ValueExp;
|
||||
*/
|
||||
public abstract class Conditionals
|
||||
{
|
||||
/** The SQL 'is null' operator. */
|
||||
public static class IsNull
|
||||
implements SQLOperator
|
||||
{
|
||||
public IsNull (Class pClass, String pColumn)
|
||||
{
|
||||
this(new ColumnExp(pClass, pColumn));
|
||||
}
|
||||
|
||||
public IsNull (ColumnExp column)
|
||||
{
|
||||
_column = column;
|
||||
}
|
||||
|
||||
// from SQLExpression
|
||||
public void appendExpression (Query query, StringBuilder builder)
|
||||
{
|
||||
_column.appendExpression(query, builder);
|
||||
builder.append(" is null");
|
||||
}
|
||||
|
||||
// from SQLExpression
|
||||
public int bindArguments (PreparedStatement pstmt, int argIdx)
|
||||
throws SQLException
|
||||
{
|
||||
return argIdx;
|
||||
}
|
||||
|
||||
protected ColumnExp _column;
|
||||
}
|
||||
|
||||
/** The SQL '=' operator. */
|
||||
public static class Equals extends BinaryOperator
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user