String selectSQL = "someselectStmt"; StatementResultSetHandler stmtHandler = conn.GetStatementResultSetHandler(); MockResultSet result = stmtHandler.createResultSet(); result.addRow(new Integer[]{new Integer(1)}); stmtHandler.prepareResultSet(selectSQL, result);
private void configureMetadata() throws SQLException { ((MockDatabaseMetaData) cx.getMetaData()).setSearchStringEscape(""); MockResultSet tableTypes = new MockResultSet("TABLE_TYPES"); tableTypes.addColumn("TABLE_TYPE"); tableTypes.addRow(new Object[] {"TABLE"}); ((MockDatabaseMetaData) cx.getMetaData()).setTableTypes(tableTypes); MockResultSet tables = new MockResultSet("TABLES"); tables.addColumn("TABLE_SCHEM"); tables.addColumn("TABLE_NAME"); tables.addRow(new Object[] {"", SAMPLE_FEATURE_NAME}); ((MockDatabaseMetaData) cx.getMetaData()).setTables(tables); MockResultSet key = new MockResultSet("KEY"); key.addColumn("COLUMN_NAME"); key.addColumn("DATA_TYPE"); key.addRow(new Object[] {"ID", 1}); ((MockDatabaseMetaData) cx.getMetaData()) .setPrimaryKeys(null, null, SAMPLE_FEATURE_NAME, key); MockResultSet columns = new MockResultSet("COLUMNS"); columns.addColumn("COLUMN_NAME"); columns.addColumn("DATA_TYPE"); columns.addRow(new Object[] {"ID", 1}); ((MockDatabaseMetaData) cx.getMetaData()) .setColumns(null, null, SAMPLE_FEATURE_NAME, "ID", columns); }
/** * Adds a row to the simulated database table. * If there are not enough columns (initially there * are no columns, you have to specify them with the * <code>addColumn</code> methods) the missing columns will * be added automatically. Automatically created columns * will get the name <i>ColumnX</i> where <i>X</i> is * the column index. * @param values the row data as array, the array index * corresponds to the column index, i.e. * values[0] will be stored in the first column * and so on */ public void addRow(Object[] values) { List valueList = Arrays.asList(values); addRow(valueList); }
/** * Adds a row to the simulated database table. * If there are not enough columns (initially there * are no columns, you have to specify them with the * <code>addColumn</code> methods) the missing columns will * be added automatically. Automatically created columns * will get the name <i>ColumnX</i> where <i>X</i> is * the column index. * @param values the row data as array, the array index * corresponds to the column index, i.e. * values[0] will be stored in the first column * and so on */ public void addRow(Object[] values) { List valueList = Arrays.asList(values); addRow(valueList); }
/** * Adds a row to the simulated database table. * If there are not enough columns (initially there * are no columns, you have to specify them with the * <code>addColumn</code> methods) the missing columns will * be added automatically. Automatically created columns * will get the name <i>ColumnX</i> where <i>X</i> is * the column index. * @param values the row data as array, the array index * corresponds to the column index, i.e. * values[0] will be stored in the first column * and so on */ public void addRow(Object[] values) { List<Object> valueList = Arrays.asList(values); addRow(valueList); }
public void addRow(HashMap<String,Object> row) throws Exception { if(! row.keySet().equals(columnMap.keySet())) { throw new Exception("Columns on row don't match results set"); } List<Object> vals = new ArrayList<Object>(); for(String col : row.keySet()) { vals.add(row.get(col)); } addRow(vals); }
/** * Returns a <code>MockResultSet</code> with the given ID, containing * values based on the elements given at construction. * * @param id the ID for the result set. This argument cannot be * <code>null</code>. */ public MockResultSet create(String id) { if (id != null) { MockResultSet resultSet = new MockResultSet(id); if (columnNames != null) { for (String columnName : columnNames) { resultSet.addColumn(columnName); } } for (String[] aStringMatrix : stringMatrix) { resultSet.addRow(aStringMatrix); } return resultSet; } throw new IllegalArgumentException("the result set ID cannot be null"); } }
/** * Returns a <code>MockResultSet</code> with the given ID, containing * values based on the elements given at construction. * * @param id the ID for the result set. This argument cannot be * <code>null</code>. */ public MockResultSet create(String id) { if (id != null) { MockResultSet resultSet = new MockResultSet(id); if (columnNames != null) { for (int ii = 0; ii < columnNames.length; ii++) { resultSet.addColumn(columnNames[ii]); } } for (int jj = 0; jj < stringMatrix.length; jj++) { resultSet.addRow(stringMatrix[jj]); } return resultSet; } throw new IllegalArgumentException("the result set ID cannot be null"); } }
/** * Returns a <code>MockResultSet</code> with the given ID, containing * values based on the elements given at construction. * * @param id the ID for the result set. This argument cannot be * <code>null</code>. */ public MockResultSet create(String id) { if (id != null) { MockResultSet resultSet = new MockResultSet(id); if (columnNames != null) { for (int ii = 0; ii < columnNames.length; ii++) { resultSet.addColumn(columnNames[ii]); } } for (int jj = 0; jj < stringMatrix.length; jj++) { resultSet.addRow(stringMatrix[jj]); } return resultSet; } throw new IllegalArgumentException("the result set ID cannot be null"); } }
mockResultSet.addRow(list);
resultSet.addRow(values);
curCol++; resultSet.addRow(cRowValues);
curCol++; resultSet.addRow(cRowValues);
resultSet.addRow(values);
curCol++; resultSet.addRow(cRowValues);
resultSet.addRow(values);
cRowValues[curCol] = value; resultSet.addRow(cRowValues);