Implement the SQL 'exists' operator. I think this is our first serious subquery clause. Seems to work well.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2252 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -54,14 +54,6 @@ public class DefaultLiaison extends BaseLiaison
|
|||||||
// nothing doing
|
// nothing doing
|
||||||
}
|
}
|
||||||
|
|
||||||
// from DatabaseLiaison
|
|
||||||
public void initializeGenerator (
|
|
||||||
Connection conn, String table, String column, int value, int size)
|
|
||||||
throws SQLException
|
|
||||||
{
|
|
||||||
// nothing doing
|
|
||||||
}
|
|
||||||
|
|
||||||
// from DatabaseLiaison
|
// from DatabaseLiaison
|
||||||
public int lastInsertedId (Connection conn, String table, String column)
|
public int lastInsertedId (Connection conn, String table, String column)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
|
|||||||
@@ -75,14 +75,6 @@ public class PostgreSQLLiaison extends BaseLiaison
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initializeGenerator (
|
|
||||||
Connection conn, String table, String column, int first, int step)
|
|
||||||
throws SQLException
|
|
||||||
{
|
|
||||||
executeQuery(conn, "alter sequence \"" + table + "_" + column + "_seq\" " +
|
|
||||||
" restart with " + first + " increment " + step);
|
|
||||||
}
|
|
||||||
|
|
||||||
// from DatabaseLiaison
|
// from DatabaseLiaison
|
||||||
public void deleteGenerator (Connection conn, String table, String column)
|
public void deleteGenerator (Connection conn, String table, String column)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import com.samskivert.jdbc.depot.expression.FunctionExp;
|
|||||||
import com.samskivert.jdbc.depot.expression.LiteralExp;
|
import com.samskivert.jdbc.depot.expression.LiteralExp;
|
||||||
import com.samskivert.jdbc.depot.expression.SQLExpression;
|
import com.samskivert.jdbc.depot.expression.SQLExpression;
|
||||||
import com.samskivert.jdbc.depot.expression.ValueExp;
|
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.In;
|
||||||
import com.samskivert.jdbc.depot.operator.Conditionals.IsNull;
|
import com.samskivert.jdbc.depot.operator.Conditionals.IsNull;
|
||||||
import com.samskivert.jdbc.depot.operator.Conditionals.FullTextMatch;
|
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)
|
public void visit (SelectClause<? extends PersistentRecord> selectClause)
|
||||||
throws Exception
|
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.LiteralExp;
|
||||||
import com.samskivert.jdbc.depot.expression.SQLExpression;
|
import com.samskivert.jdbc.depot.expression.SQLExpression;
|
||||||
import com.samskivert.jdbc.depot.expression.ValueExp;
|
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.In;
|
||||||
import com.samskivert.jdbc.depot.operator.Conditionals.IsNull;
|
import com.samskivert.jdbc.depot.operator.Conditionals.IsNull;
|
||||||
import com.samskivert.jdbc.depot.operator.Conditionals.FullTextMatch;
|
import com.samskivert.jdbc.depot.operator.Conditionals.FullTextMatch;
|
||||||
@@ -312,6 +313,13 @@ public abstract class BuildVisitor implements ExpressionVisitor
|
|||||||
_builder.append("?");
|
_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)
|
public void visit (SelectClause<? extends PersistentRecord> selectClause)
|
||||||
throws Exception
|
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.UpdateClause;
|
||||||
import com.samskivert.jdbc.depot.clause.Where;
|
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.In;
|
||||||
import com.samskivert.jdbc.depot.operator.Conditionals.IsNull;
|
import com.samskivert.jdbc.depot.operator.Conditionals.IsNull;
|
||||||
import com.samskivert.jdbc.depot.operator.Conditionals.FullTextMatch;
|
import com.samskivert.jdbc.depot.operator.Conditionals.FullTextMatch;
|
||||||
@@ -92,6 +93,8 @@ public interface ExpressionVisitor
|
|||||||
throws Exception;
|
throws Exception;
|
||||||
public void visit (ValueExp valueExp)
|
public void visit (ValueExp valueExp)
|
||||||
throws Exception;
|
throws Exception;
|
||||||
|
public void visit (Exists<? extends PersistentRecord> exists)
|
||||||
|
throws Exception;
|
||||||
public void visit (SelectClause<? extends PersistentRecord> selectClause)
|
public void visit (SelectClause<? extends PersistentRecord> selectClause)
|
||||||
throws Exception;
|
throws Exception;
|
||||||
public void visit (UpdateClause<? extends PersistentRecord> updateClause)
|
public void visit (UpdateClause<? extends PersistentRecord> updateClause)
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ package com.samskivert.jdbc.depot.operator;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import com.samskivert.jdbc.depot.PersistentRecord;
|
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.ColumnExp;
|
||||||
import com.samskivert.jdbc.depot.expression.ExpressionVisitor;
|
import com.samskivert.jdbc.depot.expression.ExpressionVisitor;
|
||||||
import com.samskivert.jdbc.depot.expression.SQLExpression;
|
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
|
* An attempt at a dialect-agnostic full-text search condition, such as MySQL's MATCH() and
|
||||||
* PostgreSQL's @@ TO_TSQUERY(...) abilities.
|
* PostgreSQL's @@ TO_TSQUERY(...) abilities.
|
||||||
@@ -265,7 +292,7 @@ public abstract class Conditionals
|
|||||||
{
|
{
|
||||||
return _pClass;
|
return _pClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getQuery ()
|
public String getQuery ()
|
||||||
{
|
{
|
||||||
return _query;
|
return _query;
|
||||||
|
|||||||
Reference in New Issue
Block a user