use of org.h2.command.dml.Set in project h2database by h2database.
the class FunctionMultiReturn method polar2Cartesian.
/**
* Convert polar coordinates to cartesian coordinates. The function may be
* called twice, once to retrieve the result columns (with null parameters),
* and the second time to return the data.
*
* @param r the distance from the point 0/0
* @param alpha the angle
* @return a result set with two columns: x and y
*/
public static ResultSet polar2Cartesian(Double r, Double alpha) {
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("X", Types.DOUBLE, 0, 0);
rs.addColumn("Y", Types.DOUBLE, 0, 0);
if (r != null && alpha != null) {
double x = r.doubleValue() * Math.cos(alpha.doubleValue());
double y = r.doubleValue() * Math.sin(alpha.doubleValue());
rs.addRow(x, y);
}
return rs;
}
use of org.h2.command.dml.Set in project h2database by h2database.
the class FunctionMultiReturn method polar2CartesianSet.
/**
* Convert a set of polar coordinates to cartesian coordinates. The function
* may be called twice, once to retrieve the result columns (with null
* parameters), and the second time to return the data.
*
* @param conn the connection
* @param query the query
* @return a result set with the coordinates
*/
public static ResultSet polar2CartesianSet(Connection conn, String query) throws SQLException {
SimpleResultSet result = new SimpleResultSet();
result.addColumn("R", Types.DOUBLE, 0, 0);
result.addColumn("A", Types.DOUBLE, 0, 0);
result.addColumn("X", Types.DOUBLE, 0, 0);
result.addColumn("Y", Types.DOUBLE, 0, 0);
if (query != null) {
ResultSet rs = conn.createStatement().executeQuery(query);
while (rs.next()) {
double r = rs.getDouble("R");
double alpha = rs.getDouble("A");
double x = r * Math.cos(alpha);
double y = r * Math.sin(alpha);
result.addRow(r, alpha, x, y);
}
}
return result;
}
use of org.h2.command.dml.Set in project h2database by h2database.
the class TestMVTableEngine method testShrinkDatabaseFile.
private void testShrinkDatabaseFile() throws Exception {
if (config.memory) {
return;
}
deleteDb(getTestName());
String dbName = getTestName() + ";MV_STORE=TRUE";
Connection conn;
Statement stat;
long maxSize = 0;
// by default, the database does not shrink for 45 seconds
int retentionTime = 45000;
for (int i = 0; i < 20; i++) {
// the first 10 times, keep the default retention time
// then switch to 0, at which point the database file
// should stop to grow
conn = getConnection(dbName);
stat = conn.createStatement();
if (i == 10) {
stat.execute("set retention_time 0");
retentionTime = 0;
}
ResultSet rs = stat.executeQuery("select value from information_schema.settings " + "where name='RETENTION_TIME'");
assertTrue(rs.next());
assertEquals(retentionTime, rs.getInt(1));
stat.execute("create table test(id int primary key, data varchar)");
stat.execute("insert into test select x, space(100) " + "from system_range(1, 1000)");
// this table is kept
if (i < 10) {
stat.execute("create table test" + i + "(id int primary key, data varchar) " + "as select x, space(10) from system_range(1, 100)");
}
// force writing the chunk
stat.execute("checkpoint");
// drop the table - but the chunk is still used
stat.execute("drop table test");
stat.execute("checkpoint");
stat.execute("shutdown immediately");
try {
conn.close();
} catch (Exception e) {
// ignore
}
String fileName = getBaseDir() + "/" + getTestName() + Constants.SUFFIX_MV_FILE;
long size = FileUtils.size(fileName);
if (i < 10) {
maxSize = (int) (Math.max(size, maxSize) * 1.2);
} else if (size > maxSize) {
fail(i + " size: " + size + " max: " + maxSize);
}
}
long sizeOld = FileUtils.size(getBaseDir() + "/" + getTestName() + Constants.SUFFIX_MV_FILE);
conn = getConnection(dbName);
stat = conn.createStatement();
stat.execute("shutdown compact");
conn.close();
long sizeNew = FileUtils.size(getBaseDir() + "/" + getTestName() + Constants.SUFFIX_MV_FILE);
assertTrue("new: " + sizeNew + " old: " + sizeOld, sizeNew < sizeOld);
}
use of org.h2.command.dml.Set in project h2database by h2database.
the class TestMVTableEngine method testWriteDelay.
private void testWriteDelay() throws Exception {
if (config.memory) {
return;
}
Connection conn;
Statement stat;
ResultSet rs;
deleteDb(getTestName());
conn = getConnection(getTestName() + ";MV_STORE=TRUE");
stat = conn.createStatement();
stat.execute("create table test(id int)");
stat.execute("set write_delay 0");
stat.execute("insert into test values(1)");
stat.execute("shutdown immediately");
try {
conn.close();
} catch (Exception e) {
// ignore
}
conn = getConnection(getTestName() + ";MV_STORE=TRUE");
stat = conn.createStatement();
rs = stat.executeQuery("select * from test");
assertTrue(rs.next());
conn.close();
}
use of org.h2.command.dml.Set in project h2database by h2database.
the class TestMVTableEngine method testTwoPhaseCommit.
private void testTwoPhaseCommit() throws Exception {
if (config.memory) {
return;
}
Connection conn;
Statement stat;
deleteDb(getTestName());
String url = getTestName() + ";MV_STORE=TRUE";
url = getURL(url, true);
conn = getConnection(url);
stat = conn.createStatement();
stat.execute("create table test(id int primary key, name varchar)");
stat.execute("set write_delay 0");
conn.setAutoCommit(false);
stat.execute("insert into test values(1, 'Hello')");
stat.execute("prepare commit test_tx");
stat.execute("shutdown immediately");
JdbcUtils.closeSilently(conn);
conn = getConnection(url);
stat = conn.createStatement();
ResultSet rs;
rs = stat.executeQuery("select * from information_schema.in_doubt");
assertTrue(rs.next());
stat.execute("commit transaction test_tx");
rs = stat.executeQuery("select * from test");
assertTrue(rs.next());
conn.close();
}
Aggregations