Search in sources :

Example 21 with Aggregate

use of org.h2.api.Aggregate in project h2database by h2database.

the class TestSpatial method testAggregateWithGeometry.

private void testAggregateWithGeometry() throws SQLException {
    deleteDb("spatialIndex");
    try (Connection conn = getConnection("spatialIndex")) {
        Statement st = conn.createStatement();
        st.execute("CREATE AGGREGATE TABLE_ENVELOPE FOR \"" + TableEnvelope.class.getName() + "\"");
        st.execute("CREATE TABLE test(the_geom GEOMETRY)");
        st.execute("INSERT INTO test VALUES ('POINT(1 1)'), (null), (null), ('POINT(10 5)')");
        ResultSet rs = st.executeQuery("select TABLE_ENVELOPE(the_geom) from test");
        assertEquals("geometry", rs.getMetaData().getColumnTypeName(1).toLowerCase());
        assertTrue(rs.next());
        assertTrue(rs.getObject(1) instanceof Geometry);
        assertTrue(new Envelope(1, 10, 1, 5).equals(((Geometry) rs.getObject(1)).getEnvelopeInternal()));
        assertFalse(rs.next());
    }
    deleteDb("spatialIndex");
}
Also used : ValueGeometry(org.h2.value.ValueGeometry) Geometry(org.locationtech.jts.geom.Geometry) Statement(java.sql.Statement) Connection(java.sql.Connection) SimpleResultSet(org.h2.tools.SimpleResultSet) ResultSet(java.sql.ResultSet) Envelope(org.locationtech.jts.geom.Envelope)

Aggregations

UserAggregate (org.h2.engine.UserAggregate)8 Expression (org.h2.expression.Expression)6 ValueExpression (org.h2.expression.ValueExpression)6 Aggregate (org.h2.api.Aggregate)5 Connection (java.sql.Connection)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 Statement (java.sql.Statement)4 SimpleResultSet (org.h2.tools.SimpleResultSet)4 ValueString (org.h2.value.ValueString)4 CallableStatement (java.sql.CallableStatement)3 PreparedStatement (java.sql.PreparedStatement)3 ConditionInSelect (org.h2.expression.ConditionInSelect)3 Column (org.h2.table.Column)3 IndexColumn (org.h2.table.IndexColumn)3 DatabaseMetaData (java.sql.DatabaseMetaData)2 AlterTableAddConstraint (org.h2.command.ddl.AlterTableAddConstraint)2 AlterTableAlterColumn (org.h2.command.ddl.AlterTableAlterColumn)2 DropFunctionAlias (org.h2.command.ddl.DropFunctionAlias)2 DropSchema (org.h2.command.ddl.DropSchema)2