Implement the SQL 'exists' operator. I think this is our first serious subquery clause. Seems to work well.
This commit is contained in:
@@ -43,6 +43,7 @@ import com.samskivert.jdbc.depot.expression.FunctionExp;
|
||||
import com.samskivert.jdbc.depot.expression.LiteralExp;
|
||||
import com.samskivert.jdbc.depot.expression.SQLExpression;
|
||||
import com.samskivert.jdbc.depot.expression.ValueExp;
|
||||
import com.samskivert.jdbc.depot.operator.Conditionals.Exists;
|
||||
import com.samskivert.jdbc.depot.operator.Conditionals.In;
|
||||
import com.samskivert.jdbc.depot.operator.Conditionals.IsNull;
|
||||
import com.samskivert.jdbc.depot.operator.Conditionals.FullTextMatch;
|
||||
@@ -191,6 +192,12 @@ public class BindVisitor implements ExpressionVisitor
|
||||
}
|
||||
}
|
||||
|
||||
public void visit (Exists<? extends PersistentRecord> exists)
|
||||
throws Exception
|
||||
{
|
||||
exists.getSubClause().accept(this);
|
||||
}
|
||||
|
||||
public void visit (SelectClause<? extends PersistentRecord> selectClause)
|
||||
throws Exception
|
||||
{
|
||||
|
||||
@@ -47,6 +47,7 @@ import com.samskivert.jdbc.depot.expression.FunctionExp;
|
||||
import com.samskivert.jdbc.depot.expression.LiteralExp;
|
||||
import com.samskivert.jdbc.depot.expression.SQLExpression;
|
||||
import com.samskivert.jdbc.depot.expression.ValueExp;
|
||||
import com.samskivert.jdbc.depot.operator.Conditionals.Exists;
|
||||
import com.samskivert.jdbc.depot.operator.Conditionals.In;
|
||||
import com.samskivert.jdbc.depot.operator.Conditionals.IsNull;
|
||||
import com.samskivert.jdbc.depot.operator.Conditionals.FullTextMatch;
|
||||
@@ -312,6 +313,13 @@ public abstract class BuildVisitor implements ExpressionVisitor
|
||||
_builder.append("?");
|
||||
}
|
||||
|
||||
public void visit (Exists<? extends PersistentRecord> exists)
|
||||
throws Exception
|
||||
{
|
||||
_builder.append("exists ");
|
||||
exists.getSubClause().accept(this);
|
||||
}
|
||||
|
||||
public void visit (SelectClause<? extends PersistentRecord> selectClause)
|
||||
throws Exception
|
||||
{
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.samskivert.jdbc.depot.clause.SelectClause;
|
||||
import com.samskivert.jdbc.depot.clause.UpdateClause;
|
||||
import com.samskivert.jdbc.depot.clause.Where;
|
||||
|
||||
import com.samskivert.jdbc.depot.operator.Conditionals.Exists;
|
||||
import com.samskivert.jdbc.depot.operator.Conditionals.In;
|
||||
import com.samskivert.jdbc.depot.operator.Conditionals.IsNull;
|
||||
import com.samskivert.jdbc.depot.operator.Conditionals.FullTextMatch;
|
||||
@@ -92,6 +93,8 @@ public interface ExpressionVisitor
|
||||
throws Exception;
|
||||
public void visit (ValueExp valueExp)
|
||||
throws Exception;
|
||||
public void visit (Exists<? extends PersistentRecord> exists)
|
||||
throws Exception;
|
||||
public void visit (SelectClause<? extends PersistentRecord> selectClause)
|
||||
throws Exception;
|
||||
public void visit (UpdateClause<? extends PersistentRecord> updateClause)
|
||||
|
||||
@@ -23,6 +23,7 @@ package com.samskivert.jdbc.depot.operator;
|
||||
import java.util.Collection;
|
||||
|
||||
import com.samskivert.jdbc.depot.PersistentRecord;
|
||||
import com.samskivert.jdbc.depot.clause.SelectClause;
|
||||
import com.samskivert.jdbc.depot.expression.ColumnExp;
|
||||
import com.samskivert.jdbc.depot.expression.ExpressionVisitor;
|
||||
import com.samskivert.jdbc.depot.expression.SQLExpression;
|
||||
@@ -247,6 +248,32 @@ public abstract class Conditionals
|
||||
}
|
||||
}
|
||||
|
||||
/** The SQL ' exists' operator. */
|
||||
public static class Exists<T extends PersistentRecord> implements SQLOperator
|
||||
{
|
||||
public Exists (SelectClause<T> clause)
|
||||
{
|
||||
_clause = clause;
|
||||
}
|
||||
|
||||
public void accept (ExpressionVisitor builder) throws Exception
|
||||
{
|
||||
builder.visit(this);
|
||||
}
|
||||
|
||||
public void addClasses (Collection<Class<? extends PersistentRecord>> classSet)
|
||||
{
|
||||
_clause.addClasses(classSet);
|
||||
}
|
||||
|
||||
public SelectClause<T> getSubClause ()
|
||||
{
|
||||
return _clause;
|
||||
}
|
||||
|
||||
protected SelectClause<T> _clause;
|
||||
}
|
||||
|
||||
/**
|
||||
* An attempt at a dialect-agnostic full-text search condition, such as MySQL's MATCH() and
|
||||
* PostgreSQL's @@ TO_TSQUERY(...) abilities.
|
||||
@@ -265,7 +292,7 @@ public abstract class Conditionals
|
||||
{
|
||||
return _pClass;
|
||||
}
|
||||
|
||||
|
||||
public String getQuery ()
|
||||
{
|
||||
return _query;
|
||||
|
||||
Reference in New Issue
Block a user