From 96bd8b56a004e602349bbb9fc57e2d0c55be3847 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 10 Sep 2008 18:09:23 +0000 Subject: [PATCH] We're seeing some weirdness here, so let's log the original statement along with the actual set of wanted and obtained keys when we have a mismatch. --- .../samskivert/jdbc/depot/FindAllQuery.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/java/com/samskivert/jdbc/depot/FindAllQuery.java b/src/java/com/samskivert/jdbc/depot/FindAllQuery.java index 5a1f7b5..cbd9ba2 100644 --- a/src/java/com/samskivert/jdbc/depot/FindAllQuery.java +++ b/src/java/com/samskivert/jdbc/depot/FindAllQuery.java @@ -87,6 +87,7 @@ public abstract class FindAllQuery Set> fetchKeys = new HashSet>(); PreparedStatement stmt = _builder.prepare(conn); + String stmtString = stmt.toString(); // for debugging try { ResultSet rs = stmt.executeQuery(); while (rs.next()) { @@ -111,7 +112,7 @@ public abstract class FindAllQuery JDBCUtil.close(stmt); } - return loadAndResolve(conn, allKeys, fetchKeys, entities); + return loadAndResolve(conn, allKeys, fetchKeys, entities, stmtString); } } @@ -147,7 +148,7 @@ public abstract class FindAllQuery fetchKeys.add(key); } - return loadAndResolve(conn, _keys, fetchKeys, entities); + return loadAndResolve(conn, _keys, fetchKeys, entities, null); } protected Collection> _keys; @@ -228,7 +229,8 @@ public abstract class FindAllQuery } protected List loadAndResolve (Connection conn, Collection> allKeys, - Set> fetchKeys, Map, T> entities) + Set> fetchKeys, Map, T> entities, + String origStmt) throws SQLException { // if we're fetching a huge number of records, we have to do it in multiple queries @@ -242,11 +244,11 @@ public abstract class FindAllQuery iter.remove(); } keyCount -= keys.size(); - loadRecords(conn, keys, entities); + loadRecords(conn, keys, entities, origStmt); } while (keyCount > 0); } else if (fetchKeys.size() > 0) { - loadRecords(conn, fetchKeys, entities); + loadRecords(conn, fetchKeys, entities, origStmt); } List result = new ArrayList(); @@ -259,7 +261,8 @@ public abstract class FindAllQuery return result; } - protected void loadRecords (Connection conn, Set> keys, Map, T> entities) + protected void loadRecords (Connection conn, Set> keys, Map, T> entities, + String origStmt) throws SQLException { _builder.newQuery(new SelectClause(_type, _marsh.getFieldNames(), @@ -276,8 +279,8 @@ public abstract class FindAllQuery cnt++; } if (cnt != keys.size()) { - log.warning("Row count mismatch in second pass [query=" + stmt + - ", wanted=" + keys.size() + ", got=" + cnt + + log.warning("Row count mismatch in second pass [origQuery=" + origStmt + + ", wanted=" + keys + ", got=" + entities.keySet() + ", dups=" + dups + "]"); }