Search in sources :

Example 1 with SimpleRowSource

use of org.h2.tools.SimpleRowSource 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;
}
Also used : SimpleResultSet(org.h2.tools.SimpleResultSet) Random(java.util.Random) SQLException(java.sql.SQLException) SimpleRowSource(org.h2.tools.SimpleRowSource) Point(org.locationtech.jts.geom.Point) Savepoint(java.sql.Savepoint)

Aggregations

SQLException (java.sql.SQLException)1 Savepoint (java.sql.Savepoint)1 Random (java.util.Random)1 SimpleResultSet (org.h2.tools.SimpleResultSet)1 SimpleRowSource (org.h2.tools.SimpleRowSource)1 Point (org.locationtech.jts.geom.Point)1