private List<T> select(boolean distinct) { List<T> result = New.arrayList(); TableDefinition<T> def = from.getAliasDefinition(); SQLStatement stat = getSelectStatement(distinct); def.appendSelectList(stat); appendFromWhere(stat); ResultSet rs = stat.executeQuery(); Statement s = null; try { s = rs.getStatement(); while (rs.next()) { T item = from.newObject(); from.getAliasDefinition().readRow(item, rs); result.add(item); } } catch (SQLException e) { throw new RuntimeException(e); } finally { JdbcUtils.closeSilently(rs); JdbcUtils.closeSilently(s); } return result; }
private <X> List<X> select(Class<X> clazz, X x, boolean distinct) { List<X> result = New.arrayList(); TableDefinition<X> def = db.define(clazz); SQLStatement stat = getSelectStatement(distinct); def.appendSelectList(stat, this, x); appendFromWhere(stat); ResultSet rs = stat.executeQuery(); Statement s = null; try { s = rs.getStatement(); while (rs.next()) { X row = ClassUtils.newObject(clazz); def.readRow(row, rs); result.add(row); } } catch (SQLException e) { throw new RuntimeException(e); } finally { JdbcUtils.closeSilently(rs); JdbcUtils.closeSilently(s); } return result; }