当前位置: 首页>>代码示例>>Java>>正文


Java Recover.main方法代码示例

本文整理汇总了Java中org.h2.tools.Recover.main方法的典型用法代码示例。如果您正苦于以下问题:Java Recover.main方法的具体用法?Java Recover.main怎么用?Java Recover.main使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.h2.tools.Recover的用法示例。


在下文中一共展示了Recover.main方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testRecoverClob

import org.h2.tools.Recover; //导入方法依赖的package包/类
private void testRecoverClob() throws Exception {
    DeleteDbFiles.execute(getBaseDir(), "recovery", true);
    Connection conn = getConnection("recovery");
    Statement stat = conn.createStatement();
    stat.execute("create table test(id int, data clob)");
    stat.execute("insert into test values(1, space(100000))");
    conn.close();
    Recover.main("-dir", getBaseDir(), "-db", "recovery");
    DeleteDbFiles.execute(getBaseDir(), "recovery", true);
    conn = getConnection(
            "recovery;init=runscript from '" +
            getBaseDir() + "/recovery.h2.sql'");
    stat = conn.createStatement();
    stat.execute("select * from test");
    conn.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:17,代码来源:TestRecovery.java

示例2: testRecoverFulltext

import org.h2.tools.Recover; //导入方法依赖的package包/类
private void testRecoverFulltext() throws Exception {
    DeleteDbFiles.execute(getBaseDir(), "recovery", true);
    Connection conn = getConnection("recovery");
    Statement stat = conn.createStatement();
    stat.execute("CREATE ALIAS IF NOT EXISTS FTL_INIT " +
            "FOR \"org.h2.fulltext.FullTextLucene.init\"");
    stat.execute("CALL FTL_INIT()");
    stat.execute("create table test(id int primary key, name varchar) as " +
            "select 1, 'Hello'");
    stat.execute("CALL FTL_CREATE_INDEX('PUBLIC', 'TEST', 'NAME')");
    conn.close();
    Recover.main("-dir", getBaseDir(), "-db", "recovery");
    DeleteDbFiles.execute(getBaseDir(), "recovery", true);
    conn = getConnection(
            "recovery;init=runscript from '" +
            getBaseDir() + "/recovery.h2.sql'");
    conn.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:19,代码来源:TestRecovery.java

示例3: testRemove

import org.h2.tools.Recover; //导入方法依赖的package包/类
private void testRemove() throws SQLException {
    if (config.mvStore) {
        return;
    }
    deleteDb("toolsRemove");
    org.h2.Driver.load();
    String url = "jdbc:h2:" + getBaseDir() + "/toolsRemove";
    Connection conn = getConnection(url, "sa", "sa");
    Statement stat = conn.createStatement();
    stat.execute("create table test(id int primary key, name varchar)");
    stat.execute("insert into test values(1, 'Hello')");
    conn.close();
    Recover.main("-dir", getBaseDir(), "-db", "toolsRemove",
            "-removePassword");
    conn = getConnection(url, "sa", "");
    stat = conn.createStatement();
    ResultSet rs;
    rs = stat.executeQuery("select * from test");
    rs.next();
    assertEquals(1, rs.getInt(1));
    assertEquals("Hello", rs.getString(2));
    conn.close();
    deleteDb("toolsRemove");
    FileUtils.delete(getBaseDir() + "/toolsRemove.h2.sql");
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:26,代码来源:TestTools.java

示例4: testCorrupt

import org.h2.tools.Recover; //导入方法依赖的package包/类
private void testCorrupt() throws Exception {
    if (config.mvStore) {
        // not needed for MV_STORE=TRUE
        return;
    }
    DeleteDbFiles.execute(getBaseDir(), "recovery", true);
    Connection conn = getConnection("recovery");
    Statement stat = conn.createStatement();
    stat.execute("create table test(id int, name varchar) as " +
            "select 1, 'Hello World1'");
    conn.close();
    FileChannel f = FileUtils.open(getBaseDir() + "/recovery.h2.db", "rw");
    byte[] buff = new byte[Constants.DEFAULT_PAGE_SIZE];
    while (f.position() < f.size()) {
        FileUtils.readFully(f, ByteBuffer.wrap(buff));
        if (new String(buff).contains("Hello World1")) {
            buff[buff.length - 1]++;
            f.position(f.position() - buff.length);
            f.write(ByteBuffer.wrap(buff));
        }
    }
    f.close();
    Recover.main("-dir", getBaseDir(), "-db", "recovery");
    String script = IOUtils.readStringAndClose(
            new InputStreamReader(
            FileUtils.newInputStream(getBaseDir() + "/recovery.h2.sql")), -1);
    assertContains(script, "checksum mismatch");
    assertContains(script, "dump:");
    assertContains(script, "Hello World2");
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:31,代码来源:TestRecovery.java

示例5: testTraceFile

import org.h2.tools.Recover; //导入方法依赖的package包/类
private void testTraceFile(String url) throws SQLException {
    Connection conn;
    Recover.main("-removePassword", "-dir", getBaseDir(), "-db",
            "toolsConvertTraceFile");
    conn = getConnection(url, "sa", "");
    Statement stat = conn.createStatement();
    ResultSet rs;
    rs = stat.executeQuery("select * from test");
    rs.next();
    assertEquals(1, rs.getInt(1));
    assertEquals("Hello \\'Joe\n\\'", rs.getString(2));
    assertEquals("10.20", rs.getBigDecimal(3).toString());
    assertFalse(rs.next());
    rs = stat.executeQuery("select * from test2");
    rs.next();
    assertEquals(Float.MIN_VALUE, rs.getFloat("a"));
    assertEquals(Double.MIN_VALUE, rs.getDouble("b"));
    assertEquals(Long.MIN_VALUE, rs.getLong("c"));
    assertEquals(Short.MIN_VALUE, rs.getShort("d"));
    assertTrue(!rs.getBoolean("e"));
    assertEquals(new byte[] { (byte) 10, (byte) 20 }, rs.getBytes("f"));
    assertEquals("2007-12-31", rs.getString("g"));
    assertEquals("23:59:59", rs.getString("h"));
    assertEquals("2007-12-31 23:59:59.0", rs.getString("i"));
    assertFalse(rs.next());
    conn.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:28,代码来源:TestTools.java

示例6: recover

import org.h2.tools.Recover; //导入方法依赖的package包/类
@RequiresNonNull("startupLogger")
private static void recover(File dataDir) throws Exception {
    File recoverFile = new File(dataDir, "data.h2.sql");
    if (recoverFile.exists() && !recoverFile.delete()) {
        startupLogger.warn("recover failed: cannot delete existing data.h2.sql");
    }
    Recover.main("-dir", dataDir.getPath(), "-db", "data");
    File dbFile = new File(dataDir, "data.h2.db");
    File dbBakFile = new File(dataDir, "data.h2.db.bak");
    if (dbBakFile.exists() && !dbBakFile.delete()) {
        startupLogger.warn("recover failed, cannot delete existing file: {}",
                dbBakFile.getPath());
    }
    if (!dbFile.renameTo(dbBakFile)) {
        startupLogger.warn("recover failed, cannot rename {} to {}", dbFile.getPath(),
                dbBakFile.getPath());
        return;
    }
    RunScript.main("-url", "jdbc:h2:" + dataDir.getPath() + File.separator + "data", "-script",
            recoverFile.getPath());
    startupLogger.info("recover succeeded");

    // clean up
    if (!dbBakFile.delete()) {
        startupLogger.info("failed to clean-up, cannot delete file: {}", dbBakFile.getPath());
    }
    if (!recoverFile.delete()) {
        startupLogger.info("failed to clean-up, cannot delete file: {}", recoverFile.getPath());
    }
}
 
开发者ID:glowroot,项目名称:glowroot,代码行数:31,代码来源:ToolMain.java

示例7: testRedoTransactions

import org.h2.tools.Recover; //导入方法依赖的package包/类
private void testRedoTransactions() throws Exception {
    if (config.mvStore) {
        // not needed for MV_STORE=TRUE
        return;
    }
    DeleteDbFiles.execute(getBaseDir(), "recovery", true);
    Connection conn = getConnection("recovery");
    Statement stat = conn.createStatement();
    stat.execute("set write_delay 0");
    stat.execute("create table test(id int primary key, name varchar)");
    stat.execute("insert into test select x, 'Hello' from system_range(1, 5)");
    stat.execute("create table test2(id int primary key)");
    stat.execute("drop table test2");
    stat.execute("update test set name = 'Hallo' where id < 3");
    stat.execute("delete from test where id = 1");
    stat.execute("shutdown immediately");
    try {
        conn.close();
    } catch (Exception e) {
        // ignore
    }
    Recover.main("-dir", getBaseDir(), "-db", "recovery", "-transactionLog");
    DeleteDbFiles.execute(getBaseDir(), "recovery", true);
    conn = getConnection("recovery;init=runscript from '" +
            getBaseDir() + "/recovery.h2.sql'");
    stat = conn.createStatement();
    ResultSet rs;
    rs = stat.executeQuery("select * from test order by id");
    assertTrue(rs.next());
    assertEquals(2, rs.getInt(1));
    assertEquals("Hallo", rs.getString(2));
    assertTrue(rs.next());
    assertEquals(3, rs.getInt(1));
    assertEquals("Hello", rs.getString(2));
    assertTrue(rs.next());
    assertEquals(4, rs.getInt(1));
    assertEquals("Hello", rs.getString(2));
    assertTrue(rs.next());
    assertEquals(5, rs.getInt(1));
    assertEquals("Hello", rs.getString(2));
    assertFalse(rs.next());
    conn.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:44,代码来源:TestRecovery.java

示例8: testWithTransactionLog

import org.h2.tools.Recover; //导入方法依赖的package包/类
private void testWithTransactionLog() throws SQLException {
    if (config.mvStore) {
        // not needed for MV_STORE=TRUE
        return;
    }
    DeleteDbFiles.execute(getBaseDir(), "recovery", true);
    Connection conn = getConnection("recovery");
    Statement stat = conn.createStatement();
    stat.execute("create table truncate(id int primary key) as " +
            "select x from system_range(1, 1000)");
    stat.execute("create table test(id int primary key, data int, text varchar)");
    stat.execute("create index on test(data, id)");
    stat.execute("insert into test direct select x, 0, null " +
            "from system_range(1, 1000)");
    stat.execute("insert into test values(-1, -1, space(10000))");
    stat.execute("checkpoint");
    stat.execute("delete from test where id = -1");
    stat.execute("truncate table truncate");
    conn.setAutoCommit(false);
    long base = 0;
    while (true) {
        ResultSet rs = stat.executeQuery(
                    "select value from information_schema.settings " +
                    "where name = 'info.FILE_WRITE'");
        rs.next();
        long count = rs.getLong(1);
        if (base == 0) {
            base = count;
        } else if (count > base + 10) {
            break;
        }
        stat.execute("update test set data=0");
        stat.execute("update test set text=space(10000) where id = 0");
        stat.execute("update test set data=1, text = null");
        conn.commit();
    }
    stat.execute("shutdown immediately");
    try {
        conn.close();
    } catch (Exception e) {
        // expected
    }
    Recover.main("-dir", getBaseDir(), "-db", "recovery");
    conn = getConnection("recovery");
    conn.close();
    Recover.main("-dir", getBaseDir(), "-db", "recovery", "-removePassword");
    conn = getConnection("recovery", getUser(), "");
    conn.close();
    DeleteDbFiles.execute(getBaseDir(), "recovery", true);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:51,代码来源:TestRecovery.java

示例9: testRecover

import org.h2.tools.Recover; //导入方法依赖的package包/类
private void testRecover() throws SQLException {
    deleteDb("toolsRecover");
    org.h2.Driver.load();
    String url = getURL("toolsRecover", true);
    Connection conn = getConnection(url, "sa", "sa");
    Statement stat = conn.createStatement();
    stat.execute("create table test(id int primary key, " +
            "name varchar, b blob, c clob)");
    stat.execute("create table \"test 2\"(id int primary key, name varchar)");
    stat.execute("comment on table test is ';-)'");
    stat.execute("insert into test values" +
            "(1, 'Hello', SECURE_RAND(4100), '\u00e4' || space(4100))");
    ResultSet rs;
    rs = stat.executeQuery("select * from test");
    rs.next();
    byte[] b1 = rs.getBytes(3);
    String s1 = rs.getString(4);

    conn.close();
    Recover.main("-dir", getBaseDir(), "-db", "toolsRecover");

    // deleteDb would delete the .lob.db directory as well
    // deleteDb("toolsRecover");
    ArrayList<String> list = FileLister.getDatabaseFiles(getBaseDir(),
            "toolsRecover", true);
    for (String fileName : list) {
        if (!FileUtils.isDirectory(fileName)) {
            FileUtils.delete(fileName);
        }
    }

    conn = getConnection(url);
    stat = conn.createStatement();
    String suffix = ".h2.sql";
    stat.execute("runscript from '" + getBaseDir() + "/toolsRecover" +
            suffix + "'");
    rs = stat.executeQuery("select * from \"test 2\"");
    assertFalse(rs.next());
    rs = stat.executeQuery("select * from test");
    rs.next();
    assertEquals(1, rs.getInt(1));
    assertEquals("Hello", rs.getString(2));
    byte[] b2 = rs.getBytes(3);
    String s2 = rs.getString(4);
    assertEquals("\u00e4 ", s2.substring(0, 2));
    assertEquals(4100, b2.length);
    assertEquals(4101, s2.length());
    assertEquals(b1, b2);
    assertEquals(s1, s2);
    assertFalse(rs.next());
    conn.close();
    deleteDb("toolsRecover");
    FileUtils.delete(getBaseDir() + "/toolsRecover.h2.sql");
    String dir = getBaseDir() + "/toolsRecover.lobs.db";
    FileUtils.deleteRecursive(dir, false);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:57,代码来源:TestTools.java


注:本文中的org.h2.tools.Recover.main方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。