private List<AccountGroupAgreement> getAccountGroupAgreements( ReviewDb db, Map<Integer, ContributorAgreement> agreements) throws SQLException { Statement stmt = ((JdbcSchema) db).getConnection().createStatement(); try { ResultSet rs = stmt.executeQuery( "SELECT group_id, cla_id, accepted_on, reviewed_by, reviewed_on, " + " review_comments " + "FROM account_group_agreements"); try { List<AccountGroupAgreement> groupAgreements = Lists.newArrayList(); while (rs.next()) { AccountGroupAgreement a = new AccountGroupAgreement(); a.groupId = new AccountGroup.Id(rs.getInt(1)); a.claId = rs.getInt(2); if (!agreements.containsKey(a.claId)) { continue; // Agreement is invalid } a.acceptedOn = rs.getTimestamp(3); a.reviewedBy = new Account.Id(rs.getInt(4)); if (rs.wasNull()) { a.reviewedBy = null; } a.reviewedOn = rs.getTimestamp(5); if (rs.wasNull()) { a.reviewedOn = null; } a.reviewComments = rs.getString(6); if (rs.wasNull()) { a.reviewComments = null; } groupAgreements.add(a); } Collections.sort( groupAgreements, new Comparator<AccountGroupAgreement>() { @Override public int compare(AccountGroupAgreement a1, AccountGroupAgreement a2) { return Long.compare(a1.getTime(), a2.getTime()); } }); return groupAgreements; } finally { rs.close(); } } finally { stmt.close(); } }