use of org.h2.tools.SimpleResultSet in project h2database by h2database.
the class TestIndex method testFunctionIndexFunction.
/**
* This method is called from the database.
*
* @return the result set
*/
public static ResultSet testFunctionIndexFunction() {
// CommandContainer.recompileIfRequired()
for (StackTraceElement element : Thread.currentThread().getStackTrace()) {
if (element.getClassName().startsWith(Select.class.getName())) {
testFunctionIndexCounter++;
break;
}
}
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("ID", Types.INTEGER, ValueInt.PRECISION, 0);
rs.addColumn("VALUE", Types.INTEGER, ValueInt.PRECISION, 0);
rs.addRow(1, 10);
rs.addRow(2, 20);
rs.addRow(3, 30);
return rs;
}
use of org.h2.tools.SimpleResultSet in project h2database by h2database.
the class TestSpatial method getRandomGeometryTable.
/**
* Generate a result set with random geometry data.
* Used as an ALIAS function.
*
* @param seed the random seed
* @param rowCount the number of rows
* @param minX the smallest x
* @param maxX the largest x
* @param minY the smallest y
* @param maxY the largest y
* @param maxLength the maximum length
* @return a result set
*/
public static ResultSet getRandomGeometryTable(final long seed, final long rowCount, final double minX, final double maxX, final double minY, final double maxY, final double maxLength) {
SimpleResultSet rs = new SimpleResultSet(new SimpleRowSource() {
private final Random random = new Random(seed);
private int currentRow;
@Override
public Object[] readRow() throws SQLException {
if (currentRow++ < rowCount) {
return new Object[] { getRandomGeometry(random, minX, maxX, minY, maxY, maxLength) };
}
return null;
}
@Override
public void close() {
// nothing to do
}
@Override
public void reset() throws SQLException {
random.setSeed(seed);
}
});
rs.addColumn("the_geom", Types.OTHER, "GEOMETRY", Integer.MAX_VALUE, 0);
return rs;
}
use of org.h2.tools.SimpleResultSet in project h2database by h2database.
the class Function method getMatrix.
/**
* Creates a simple result set with two columns.
*
* @param conn the connection
* @param size the number of x and y values
* @return the result set with two columns
*/
public static ResultSet getMatrix(Connection conn, Integer size) throws SQLException {
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("X", Types.INTEGER, 10, 0);
rs.addColumn("Y", Types.INTEGER, 10, 0);
String url = conn.getMetaData().getURL();
if (url.equals("jdbc:columnlist:connection")) {
return rs;
}
for (int s = size.intValue(), x = 0; x < s; x++) {
for (int y = 0; y < s; y++) {
rs.addRow(x, y);
}
}
return rs;
}
use of org.h2.tools.SimpleResultSet in project h2database by h2database.
the class Function method simpleResultSet.
/**
* Creates a simple result set with one row.
*
* @return the result set
*/
public static ResultSet simpleResultSet() {
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("ID", Types.INTEGER, 10, 0);
rs.addColumn("NAME", Types.VARCHAR, 255, 0);
rs.addRow(0, "Hello");
return rs;
}
use of org.h2.tools.SimpleResultSet in project h2database by h2database.
the class ValueResultSet method getCopy.
/**
* Create a result set value for the given result set. The result set will
* be fully read in memory. The original result set is not closed.
*
* @param rs the result set
* @param maxrows the maximum number of rows to read (0 to just read the
* meta data)
* @return the value
*/
public static ValueResultSet getCopy(ResultSet rs, int maxrows) {
try {
ResultSetMetaData meta = rs.getMetaData();
int columnCount = meta.getColumnCount();
SimpleResultSet simple = new SimpleResultSet();
simple.setAutoClose(false);
ValueResultSet val = new ValueResultSet(simple);
for (int i = 0; i < columnCount; i++) {
String name = meta.getColumnLabel(i + 1);
int sqlType = meta.getColumnType(i + 1);
int precision = meta.getPrecision(i + 1);
int scale = meta.getScale(i + 1);
simple.addColumn(name, sqlType, precision, scale);
}
for (int i = 0; i < maxrows && rs.next(); i++) {
Object[] list = new Object[columnCount];
for (int j = 0; j < columnCount; j++) {
list[j] = rs.getObject(j + 1);
}
simple.addRow(list);
}
return val;
} catch (SQLException e) {
throw DbException.convert(e);
}
}
Aggregations