public static void build(Config config, ResultSet rs, BiFunction<Record, Boolean, Boolean> func) throws SQLException { ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); String[] labelNames = new String[columnCount + 1]; int[] types = new int[columnCount + 1]; ModelBuilder.me.buildLabelNamesAndTypes(rsmd, labelNames, types); Record previous = null; while (rs.next()) { Record record = new Record(); CPI.setColumnsMap(record, config.getContainerFactory().getColumnsMap()); Map<String, Object> columns = record.getColumns(); for (int i = 1; i <= columnCount; i++) { Object value; if (types[i] < Types.BLOB) { value = rs.getObject(i); } else { if (types[i] == Types.CLOB) { value = ModelBuilder.me.handleClob(rs.getClob(i)); } else if (types[i] == Types.NCLOB) { value = ModelBuilder.me.handleClob(rs.getNClob(i)); } else if (types[i] == Types.BLOB) { value = ModelBuilder.me.handleBlob(rs.getBlob(i)); } else { value = rs.getObject(i); } } columns.put(labelNames[i], value); } if (func != null && previous != null) { if (!func.apply(previous, false)) { break; } } previous = record; } if (func != null && previous != null) { func.apply(previous, true); } }
项目:JFinal
而那个时候, resultSet 只是一个迭代器,也不知道是不是处在最后一条记录
就是说封装受限于被封装功能提供的特性