Use the SelectClause to obtain our types so that the main record class is

always properly added. Also made SelectClause freak out if it's provided with
bogus clauses.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2395 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
samskivert
2008-09-05 23:17:37 +00:00
parent 8eeff2c670
commit 1066186765
3 changed files with 12 additions and 10 deletions
@@ -211,8 +211,9 @@ public abstract class DepotRepository
{
final List<Key<T>> keys = new ArrayList<Key<T>>();
final DepotMarshaller<T> marsh = _ctx.getMarshaller(type);
final SQLBuilder builder = _ctx.getSQLBuilder(DepotTypes.getDepotTypes(_ctx, clauses));
builder.newQuery(new SelectClause<T>(type, marsh.getPrimaryKeyFields(), clauses));
SelectClause<T> select = new SelectClause<T>(type, marsh.getPrimaryKeyFields(), clauses);
final SQLBuilder builder = _ctx.getSQLBuilder(DepotTypes.getDepotTypes(_ctx, select));
builder.newQuery(select);
if (forUpdate) {
_ctx.invoke(new Modifier(null) {
@@ -64,7 +64,7 @@ public abstract class FindAllQuery<T extends PersistentRecord>
if (_marsh.getComputed() != null) {
throw new IllegalArgumentException(
"This algorithm doesn't work on @Computed records.");
"This algorithm doesn't work on @Computed records.");
}
for (QueryClause clause : clauses) {
if (clause instanceof FieldOverride) {
@@ -73,10 +73,10 @@ public abstract class FindAllQuery<T extends PersistentRecord>
}
}
DepotTypes types = DepotTypes.getDepotTypes(ctx, clauses);
types.addClass(ctx, type);
_builder = _ctx.getSQLBuilder(types);
_clauses = clauses;
SelectClause<T> select =
new SelectClause<T>(_type, _marsh.getPrimaryKeyFields(), clauses);
_builder = _ctx.getSQLBuilder(DepotTypes.getDepotTypes(ctx, select));
_builder.newQuery(select);
}
public List<T> invoke (Connection conn, DatabaseLiaison liaison)
@@ -86,7 +86,6 @@ public abstract class FindAllQuery<T extends PersistentRecord>
List<Key<T>> allKeys = new ArrayList<Key<T>>();
Set<Key<T>> fetchKeys = new HashSet<Key<T>>();
_builder.newQuery(new SelectClause<T>(_type, _marsh.getPrimaryKeyFields(), _clauses));
PreparedStatement stmt = _builder.prepare(conn);
try {
ResultSet rs = stmt.executeQuery();
@@ -166,8 +165,6 @@ public abstract class FindAllQuery<T extends PersistentRecord>
JDBCUtil.close(stmt);
}
}
protected Collection<? extends QueryClause> _clauses;
}
/**
@@ -99,6 +99,10 @@ public class SelectClause<T extends PersistentRecord> extends QueryClause
"Query can't contain multiple For Update clauses.");
}
_forUpdate = (ForUpdate) clause;
} else {
throw new IllegalArgumentException(
"Unknown clause provided in select " + clause + ".");
}
}
}