use of org.h2.expression.Alias in project h2database by h2database.
the class TestFunctions method testWhiteSpacesInParameters.
private void testWhiteSpacesInParameters() throws SQLException {
deleteDb("functions");
Connection conn = getConnection("functions");
Statement stat = conn.createStatement();
// with white space
stat.execute("CREATE ALIAS PARSE_INT2 FOR " + "\"java.lang.Integer.parseInt(java.lang.String, int)\"");
ResultSet rs;
rs = stat.executeQuery("CALL PARSE_INT2('473', 10)");
rs.next();
assertEquals(473, rs.getInt(1));
stat.execute("DROP ALIAS PARSE_INT2");
// without white space
stat.execute("CREATE ALIAS PARSE_INT2 FOR " + "\"java.lang.Integer.parseInt(java.lang.String,int)\"");
stat.execute("DROP ALIAS PARSE_INT2");
conn.close();
}
use of org.h2.expression.Alias in project h2database by h2database.
the class TestDeadlock method testDeadlockInFulltextSearch.
private void testDeadlockInFulltextSearch() throws SQLException {
deleteDb("deadlock");
String url = "deadlock";
Connection conn, conn2;
conn = getConnection(url);
conn2 = getConnection(url);
final Statement stat = conn.createStatement();
Statement stat2 = conn2.createStatement();
stat.execute("create alias if not exists ft_init for " + "\"org.h2.fulltext.FullText.init\"");
stat.execute("call ft_init()");
stat.execute("create table test(id int primary key, name varchar)");
stat.execute("call ft_create_index('PUBLIC', 'TEST', null)");
Task t = new Task() {
@Override
public void call() throws Exception {
while (!stop) {
stat.executeQuery("select * from test");
}
}
};
t.execute();
long start = System.nanoTime();
while (System.nanoTime() - start < TimeUnit.SECONDS.toNanos(1)) {
stat2.execute("insert into test values(1, 'Hello')");
stat2.execute("delete from test");
}
t.get();
conn2.close();
conn.close();
conn = getConnection(url);
conn.createStatement().execute("drop all objects");
conn.close();
}
use of org.h2.expression.Alias in project h2database by h2database.
the class TestSpatial method testJavaAlias.
/**
* Test java alias with Geometry type.
*/
private void testJavaAlias() throws SQLException {
deleteDb("spatial");
try (Connection conn = getConnection(URL)) {
Statement stat = conn.createStatement();
stat.execute("CREATE ALIAS T_GEOM_FROM_TEXT FOR \"" + TestSpatial.class.getName() + ".geomFromText\"");
stat.execute("create table test(id int primary key " + "auto_increment, the_geom geometry)");
stat.execute("insert into test(the_geom) values(" + "T_GEOM_FROM_TEXT('POLYGON ((" + "62 48, 84 48, 84 42, 56 34, 62 48))',1488))");
stat.execute("DROP ALIAS T_GEOM_FROM_TEXT");
ResultSet rs = stat.executeQuery("select the_geom from test");
assertTrue(rs.next());
assertEquals("POLYGON ((62 48, 84 48, 84 42, 56 34, 62 48))", rs.getObject(1).toString());
}
deleteDb("spatial");
}
use of org.h2.expression.Alias in project h2database by h2database.
the class TestSpatial method testTableFunctionGeometry.
/**
* Check that geometry column type is kept with a table function
*/
private void testTableFunctionGeometry() throws SQLException {
deleteDb("spatial");
try (Connection conn = getConnection(URL)) {
Statement stat = conn.createStatement();
stat.execute("CREATE ALIAS POINT_TABLE FOR \"" + TestSpatial.class.getName() + ".pointTable\"");
stat.execute("create table test as select * from point_table(1, 1)");
// Read column type
ResultSet columnMeta = conn.getMetaData().getColumns(null, null, "TEST", "THE_GEOM");
assertTrue(columnMeta.next());
assertEquals("geometry", columnMeta.getString("TYPE_NAME").toLowerCase());
assertFalse(columnMeta.next());
}
deleteDb("spatial");
}
use of org.h2.expression.Alias in project h2database by h2database.
the class TestOptimizations method testOptimizeInJoinSelect.
private void testOptimizeInJoinSelect() throws SQLException {
deleteDb("optimizations");
Connection conn = getConnection("optimizations");
Statement stat = conn.createStatement();
stat.execute("create table item(id int primary key)");
stat.execute("insert into item values(1)");
stat.execute("create alias opt for \"" + getClass().getName() + ".optimizeInJoinSelect\"");
PreparedStatement prep = conn.prepareStatement("select * from item where id in (select x from opt())");
ResultSet rs = prep.executeQuery();
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
assertFalse(rs.next());
conn.close();
}
Aggregations