From 13121249cbd18e69848438810d2b4b9c307a337e Mon Sep 17 00:00:00 2001 From: Par Winzell Date: Sun, 6 Apr 2008 14:57:14 +0000 Subject: [PATCH] The query is in no way guaranteed to uniquely keyed rows, so let's stuff the result into a Set. We should probably add the 'unique' modifier to the actual query, but that requires a bit more cross-dialect-and-version research than I'm willing to give it just now. --- .../com/samskivert/jdbc/depot/FindAllQuery.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/java/com/samskivert/jdbc/depot/FindAllQuery.java b/src/java/com/samskivert/jdbc/depot/FindAllQuery.java index d7fb828..fad7685 100644 --- a/src/java/com/samskivert/jdbc/depot/FindAllQuery.java +++ b/src/java/com/samskivert/jdbc/depot/FindAllQuery.java @@ -26,8 +26,10 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import com.samskivert.io.PersistenceException; @@ -82,7 +84,7 @@ public abstract class FindAllQuery { Map, T> entities = new HashMap, T>(); List> allKeys = new ArrayList>(); - List> fetchKeys = new ArrayList>(); + Set> fetchKeys = new HashSet>(); _builder.newQuery(new SelectClause(_type, _marsh.getPrimaryKeyFields(), _clauses)); PreparedStatement stmt = _builder.prepare(conn); @@ -116,16 +118,18 @@ public abstract class FindAllQuery if (_marsh.getPrimaryKeyFields().length == 1) { // Single-column keys result in the compact IN(keyVal1, keyVal2, ...) Comparable[] keyFieldValues = new Comparable[fetchKeys.size()]; - for (int ii = 0; ii < keyFieldValues.length; ii ++) { - keyFieldValues[ii] = fetchKeys.get(ii).condition.getValues().get(0); + int ii = 0; + for (Key key : fetchKeys) { + keyFieldValues[ii ++] = key.condition.getValues().get(0); } condition = new In(_type, _marsh.getPrimaryKeyFields()[0], keyFieldValues); } else { // Multi-column keys result in OR'd AND's, of unknown efficiency (TODO check). SQLExpression[] keyArray = new SQLExpression[fetchKeys.size()]; - for (int ii = 0; ii < keyArray.length; ii ++) { - keyArray[ii] = fetchKeys.get(ii).condition; + int ii = 0; + for (Key key : fetchKeys) { + keyArray[ii ++] = key.condition; } condition = new Or(keyArray); }