@Test public void testBuildRecords() throws SQLException { MockDriver mockDriver = new MockDriver(columnMetas, indexMetas); DruidDataSource dataSource = new DruidDataSource(); dataSource.setUrl("jdbc:mock:xxx"); dataSource.setDriver(mockDriver); MockStatementBase mockStatement = new MockStatement(dataSource.getConnection().getConnection()); DataSourceProxy proxy = new DataSourceProxy(dataSource); TableMeta tableMeta = TableMetaCache.getTableMeta(proxy, "table_records_test"); ResultSet resultSet = mockDriver.executeQuery(mockStatement, "select * from table_records_test"); TableRecords tableRecords = TableRecords.buildRecords(tableMeta, resultSet); Assertions.assertNotNull(tableRecords); }
public static TableRecords buildRecords(TableMeta tmeta, ResultSet resultSet) throws SQLException { TableRecords records = new TableRecords(tmeta); ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); int columnCount = resultSetMetaData.getColumnCount(); while (resultSet.next()) { List<Field> fields = new ArrayList<>(columnCount); for (int i = 1; i <= columnCount; i++) { String colName = resultSetMetaData.getColumnName(i); ColumnMeta col = tmeta.getColumnMeta(colName); Field field = new Field(); field.setName(col.getColumnName()); if (tmeta.getPkName().equalsIgnoreCase(field.getName())) { field.setKeyType(KeyType.PrimaryKey); } field.setType(col.getDataType()); if (col.getDataType() == JDBCType.BLOB.getVendorTypeNumber()) { Blob blob = resultSet.getBlob(i); if (blob != null) { field.setValue(new SerialBlob(blob)); } } else if (col.getDataType() == JDBCType.CLOB.getVendorTypeNumber()) { Clob clob = resultSet.getClob(i); if (clob != null){ field.setValue(new SerialClob(clob)); } } else { field.setValue(resultSet.getObject(i)); } fields.add(field); } Row row = new Row(); row.setFields(fields); records.add(row); } return records; }
TableRecords { public static TableRecords buildRecords(TableMeta tmeta, ResultSet resultSet) throws SQLException { TableRecords records = new TableRecords(tmeta); ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); int columnCount = resultSetMetaData.getColumnCount(); while (resultSet.next()) { List<Field> fields = new ArrayList<>(columnCount); for (int i = 1; i <= columnCount; i++) { String colName = resultSetMetaData.getColumnName(i); ColumnMeta col = tmeta.getColumnMeta(colName); Field field = new Field(); field.setName(col.getColumnName()); if (tmeta.getPkName().equalsIgnoreCase(field.getName())) { field.setKeyType(KeyType.PrimaryKey); } field.setType(col.getDataType()); if (col.getDataType() == JDBCType.BLOB.getVendorTypeNumber()) { Blob blob = resultSet.getBlob(i); if (blob != null) { field.setValue(new SerialBlob(blob)); } } else if (col.getDataType() == JDBCType.CLOB.getVendorTypeNumber()) { Clob clob = resultSet.getClob(i); if (clob != null){ field.setValue(new SerialClob(clob)); } } else { field.setValue(resultSet.getObject(i)); } fields.add(field); } Row row = new Row(); row.setFields(fields); records.add(row); } return records; } }
TableRecords { public static TableRecords buildRecords(TableMeta tmeta, ResultSet resultSet) throws SQLException { TableRecords records = new TableRecords(tmeta); ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); int columnCount = resultSetMetaData.getColumnCount(); while (resultSet.next()) { List<Field> fields = new ArrayList<>(columnCount); for (int i = 1; i <= columnCount; i++) { String colName = resultSetMetaData.getColumnName(i); ColumnMeta col = tmeta.getColumnMeta(colName); Field field = new Field(); field.setName(col.getColumnName()); if (tmeta.getPkName().equalsIgnoreCase(field.getName())) { field.setKeyType(KeyType.PrimaryKey); } field.setType(col.getDataType()); if (col.getDataType() == JDBCType.BLOB.getVendorTypeNumber()) { Blob blob = resultSet.getBlob(i); if (blob != null) { field.setValue(new SerialBlob(blob)); } } else if (col.getDataType() == JDBCType.CLOB.getVendorTypeNumber()) { Clob clob = resultSet.getClob(i); if (clob != null){ field.setValue(new SerialClob(clob)); } } else { field.setValue(resultSet.getObject(i)); } fields.add(field); } Row row = new Row(); row.setFields(fields); records.add(row); } return records; } TableRecords();  TableRecords(TableMeta tableMeta); }
TableRecords { public static TableRecords buildRecords(TableMeta tmeta, ResultSet resultSet) throws SQLException { TableRecords records = new TableRecords(tmeta); ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); int columnCount = resultSetMetaData.getColumnCount(); while (resultSet.next()) { List<Field> fields = new ArrayList<>(columnCount); for (int i = 1; i <= columnCount; i++) { String colName = resultSetMetaData.getColumnName(i); ColumnMeta col = tmeta.getColumnMeta(colName); Field field = new Field(); field.setName(col.getColumnName()); if (tmeta.getPkName().equalsIgnoreCase(field.getName())) { field.setKeyType(KeyType.PrimaryKey); } field.setType(col.getDataType()); if (col.getDataType() == JDBCType.BLOB.getVendorTypeNumber()) { Blob blob = resultSet.getBlob(i); if (blob != null) { field.setValue(new SerialBlob(blob)); } } else if (col.getDataType() == JDBCType.CLOB.getVendorTypeNumber()) { Clob clob = resultSet.getClob(i); if (clob != null){ field.setValue(new SerialClob(clob)); } } else { field.setValue(resultSet.getObject(i)); } fields.add(field); } Row row = new Row(); row.setFields(fields); records.add(row); } return records; } TableRecords();  TableRecords(TableMeta tableMeta); String getTableName(); void setTableName(String tableName); List<Row> getRows(); void setRows(List<Row> rows); void setTableMeta(TableMeta tableMeta); int size(); void add(Row row); List<Field> pkRows(); TableMeta getTableMeta(); static TableRecords empty(TableMeta tableMeta); static TableRecords buildRecords(TableMeta tmeta, ResultSet resultSet); }
TableRecords { public static TableRecords buildRecords(TableMeta tmeta, ResultSet resultSet) throws SQLException { TableRecords records = new TableRecords(tmeta); ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); int columnCount = resultSetMetaData.getColumnCount(); while (resultSet.next()) { List<Field> fields = new ArrayList<>(columnCount); for (int i = 1; i <= columnCount; i++) { String colName = resultSetMetaData.getColumnName(i); ColumnMeta col = tmeta.getColumnMeta(colName); Field field = new Field(); field.setName(col.getColumnName()); if (tmeta.getPkName().equalsIgnoreCase(field.getName())) { field.setKeyType(KeyType.PrimaryKey); } field.setType(col.getDataType()); if (col.getDataType() == JDBCType.BLOB.getVendorTypeNumber()) { Blob blob = resultSet.getBlob(i); if (blob != null) { field.setValue(new SerialBlob(blob)); } } else if (col.getDataType() == JDBCType.CLOB.getVendorTypeNumber()) { Clob clob = resultSet.getClob(i); if (clob != null){ field.setValue(new SerialClob(clob)); } } else { field.setValue(resultSet.getObject(i)); } fields.add(field); } Row row = new Row(); row.setFields(fields); records.add(row); } return records; } TableRecords();  TableRecords(TableMeta tableMeta); String getTableName(); void setTableName(String tableName); List<Row> getRows(); void setRows(List<Row> rows); void setTableMeta(TableMeta tableMeta); int size(); void add(Row row); List<Field> pkRows(); TableMeta getTableMeta(); static TableRecords empty(TableMeta tableMeta); static TableRecords buildRecords(TableMeta tmeta, ResultSet resultSet);  }