Search in sources :

Example 11 with Backup

use of org.h2.tools.Backup in project h2database by h2database.

the class TestMVTableEngine method testRollbackAfterCrash.

private void testRollbackAfterCrash() throws Exception {
    if (config.memory) {
        return;
    }
    Connection conn;
    Statement stat;
    deleteDb(getTestName());
    String url = getTestName() + ";MV_STORE=TRUE";
    String url2 = getTestName() + "2;MV_STORE=TRUE";
    conn = getConnection(url);
    stat = conn.createStatement();
    stat.execute("create table test(id int)");
    stat.execute("insert into test values(0)");
    stat.execute("set write_delay 0");
    conn.setAutoCommit(false);
    stat.execute("insert into test values(1)");
    stat.execute("shutdown immediately");
    JdbcUtils.closeSilently(conn);
    conn = getConnection(url);
    stat = conn.createStatement();
    ResultSet rs = stat.executeQuery("select row_count_estimate " + "from information_schema.tables where table_name='TEST'");
    rs.next();
    assertEquals(1, rs.getLong(1));
    stat.execute("drop table test");
    stat.execute("create table test(id int primary key, data clob)");
    stat.execute("insert into test values(1, space(10000))");
    conn.setAutoCommit(false);
    stat.execute("delete from test");
    stat.execute("checkpoint");
    stat.execute("shutdown immediately");
    JdbcUtils.closeSilently(conn);
    conn = getConnection(url);
    stat = conn.createStatement();
    rs = stat.executeQuery("select * from test");
    assertTrue(rs.next());
    stat.execute("drop all objects delete files");
    conn.close();
    conn = getConnection(url);
    stat = conn.createStatement();
    stat.execute("create table test(id int primary key, name varchar)");
    stat.execute("create index idx_name on test(name, id)");
    stat.execute("insert into test select x, x || space(200 * x) " + "from system_range(1, 10)");
    conn.setAutoCommit(false);
    stat.execute("delete from test where id > 5");
    stat.execute("backup to '" + getBaseDir() + "/" + getTestName() + ".zip'");
    conn.rollback();
    Restore.execute(getBaseDir() + "/" + getTestName() + ".zip", getBaseDir(), getTestName() + "2");
    Connection conn2;
    conn2 = getConnection(url2);
    conn.close();
    conn2.close();
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) JdbcConnection(org.h2.jdbc.JdbcConnection) ResultSet(java.sql.ResultSet)

Aggregations

Connection (java.sql.Connection)5 Statement (java.sql.Statement)4 SQLException (java.sql.SQLException)3 JdbcConnection (org.h2.jdbc.JdbcConnection)3 DbException (org.h2.message.DbException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintStream (java.io.PrintStream)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 AlterTableAddConstraint (org.h2.command.ddl.AlterTableAddConstraint)2 AlterTableDropConstraint (org.h2.command.ddl.AlterTableDropConstraint)2 AlterTableRenameConstraint (org.h2.command.ddl.AlterTableRenameConstraint)2 ConditionInParameter (org.h2.expression.ConditionInParameter)2 Expression (org.h2.expression.Expression)2 Parameter (org.h2.expression.Parameter)2 ValueExpression (org.h2.expression.ValueExpression)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1