Added Conditionals.IsNull. Modified Key() to use IsNull if a null value is
passed in for a column value.
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.clause.Where;
|
||||||
import com.samskivert.jdbc.depot.expression.ColumnExp;
|
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.expression.ValueExp;
|
||||||
import com.samskivert.jdbc.depot.operator.Conditionals.Equals;
|
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.Logic.And;
|
||||||
import com.samskivert.jdbc.depot.operator.SQLOperator;
|
import com.samskivert.jdbc.depot.operator.SQLOperator;
|
||||||
|
|
||||||
@@ -80,7 +82,8 @@ public class Key extends Where
|
|||||||
{
|
{
|
||||||
SQLOperator[] comparisons = new Equals[columns.length];
|
SQLOperator[] comparisons = new Equals[columns.length];
|
||||||
for (int ii = 0; ii < columns.length; ii ++) {
|
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);
|
return new And(comparisons);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,37 @@ import com.samskivert.jdbc.depot.expression.ValueExp;
|
|||||||
*/
|
*/
|
||||||
public abstract class Conditionals
|
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. */
|
/** The SQL '=' operator. */
|
||||||
public static class Equals extends BinaryOperator
|
public static class Equals extends BinaryOperator
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user