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


Java Recover类代码示例

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


Recover类属于org.h2.tools包,在下文中一共展示了Recover类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: testCompressedAndUncompressed

import org.h2.tools.Recover; //导入依赖的package包/类
private void testCompressedAndUncompressed() throws SQLException {
    DeleteDbFiles.execute(getBaseDir(), "recovery", true);
    DeleteDbFiles.execute(getBaseDir(), "recovery2", true);
    org.h2.Driver.load();
    Connection conn = getConnection("recovery");
    Statement stat = conn.createStatement();
    stat.execute("create table test(id int primary key, data clob)");
    stat.execute("insert into test values(1, space(10000))");
    stat.execute("set compress_lob lzf");
    stat.execute("insert into test values(2, space(10000))");
    conn.close();
    Recover rec = new Recover();
    rec.runTool("-dir", getBaseDir(), "-db", "recovery");
    Connection conn2 = getConnection("recovery2");
    Statement stat2 = conn2.createStatement();
    String name = "recovery.h2.sql";
    stat2.execute("runscript from '" + getBaseDir() + "/" + name + "'");
    stat2.execute("select * from test");
    conn2.close();

    conn = getConnection("recovery");
    stat = conn.createStatement();
    conn2 = getConnection("recovery2");
    stat2 = conn2.createStatement();

    assertEqualDatabases(stat, stat2);
    conn.close();
    conn2.close();
    DeleteDbFiles.execute(getBaseDir(), "recovery", true);
    DeleteDbFiles.execute(getBaseDir(), "recovery2", true);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:32,代码来源:TestRecovery.java

示例6: 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

示例7: testRecover

import org.h2.tools.Recover; //导入依赖的package包/类
private void testRecover() throws Exception {
    FileUtils.deleteRecursive(getBaseDir(), true);
    Connection conn;
    Statement stat;
    String url = "mvstore;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("insert into test values(1, 'Hello')");
    stat.execute("create table test2(name varchar)");
    stat.execute("insert into test2 values('Hello World')");
    conn.close();

    Recover.execute(getBaseDir(), "mvstore");
    DeleteDbFiles.execute(getBaseDir(), "mvstore", true);
    conn = getConnection(url);
    stat = conn.createStatement();
    stat.execute("runscript from '" + getBaseDir() + "/mvstore.h2.sql'");
    ResultSet rs;
    rs = stat.executeQuery("select * from test");
    assertTrue(rs.next());
    assertEquals(1, rs.getInt(1));
    assertEquals("Hello", rs.getString(2));
    rs = stat.executeQuery("select * from test2");
    assertTrue(rs.next());
    assertEquals("Hello World", rs.getString(1));
    conn.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:30,代码来源:TestMVTableEngine.java

示例8: 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

示例9: main

import org.h2.tools.Recover; //导入依赖的package包/类
/**
 * Run just this test.
 *
 * @param args ignored
 */
public static void main(String... args) throws Exception {
    DeleteDbFiles.execute("data", null, true);
    Class.forName("org.h2.Driver");
    Connection conn;
    long before = 0;
    for (int i = 0; i < 10; i++) {
        conn = DriverManager.getConnection("jdbc:h2:data/test");
        ResultSet rs;
        rs = conn.createStatement().executeQuery(
                "select count(*) from information_schema.lobs");
        rs.next();
        System.out.println("lobs: " + rs.getInt(1));
        rs = conn.createStatement().executeQuery(
                "select count(*) from information_schema.lob_map");
        rs.next();
        System.out.println("lob_map: " + rs.getInt(1));
        rs = conn.createStatement().executeQuery(
                "select count(*) from information_schema.lob_data");
        rs.next();
        System.out.println("lob_data: " + rs.getInt(1));
        conn.close();
        Recover.execute("data", "test");
        new File("data/test.h2.sql").renameTo(new File("data/test." + i + ".sql"));
        conn = DriverManager.getConnection("jdbc:h2:data/test");
        // ((JdbcConnection) conn).setPowerOffCount(i);
        ((JdbcConnection) conn).setPowerOffCount(28);
        String last = "connect";
        try {
            conn.createStatement().execute("drop table test if exists");
            last = "drop";
            conn.createStatement().execute("create table test(id identity, b blob)");
            last = "create";
            conn.createStatement().execute("insert into test values(1, space(10000))");
            last = "insert";
            conn.createStatement().execute("delete from test");
            last = "delete";
            conn.createStatement().execute("insert into test values(1, space(10000))");
            last = "insert2";
            conn.createStatement().execute("delete from test");
            last = "delete2";
        } catch (SQLException e) {
            // ignore
        } finally {
            JdbcUtils.closeSilently(conn);
        }
        long now = new File("data/test.h2.db").length();
        long diff = now - before;
        before = now;
        System.out.println(now + " " + diff + " " + i + " " + last);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:57,代码来源:TestDiskSpaceLeak.java

示例10: 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

示例11: 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

示例12: testRunScript

import org.h2.tools.Recover; //导入依赖的package包/类
private void testRunScript() throws SQLException {
    DeleteDbFiles.execute(getBaseDir(), "recovery", true);
    DeleteDbFiles.execute(getBaseDir(), "recovery2", true);
    org.h2.Driver.load();
    Connection conn = getConnection("recovery");
    Statement stat = conn.createStatement();
    stat.execute("create table \"Joe\"\"s Table\" as " +
            "select 1");
    stat.execute("create table test as " +
            "select * from system_range(1, 100)");
    stat.execute("create view \"TEST VIEW OF TABLE TEST\" as " +
            "select * from test");
    stat.execute("create table a(id int primary key) as " +
            "select * from system_range(1, 100)");
    stat.execute("create table b(id int references a(id)) as " +
            "select * from system_range(1, 100)");
    stat.execute("create table lob(c clob, b blob) as " +
            "select space(10000) || 'end', SECURE_RAND(10000)");
    stat.execute("create table d(d varchar) as " +
            "select space(10000) || 'end'");
    stat.execute("alter table a add foreign key(id) references b(id)");
    // all rows have the same value - so that SCRIPT can't re-order the rows
    stat.execute("create table e(id varchar) as " +
            "select space(10) from system_range(1, 1000)");
    stat.execute("create index idx_e_id on e(id)");
    conn.close();

    Recover rec = new Recover();
    ByteArrayOutputStream buff = new ByteArrayOutputStream();
    rec.setOut(new PrintStream(buff));
    rec.runTool("-dir", getBaseDir(), "-db", "recovery", "-trace");
    String out = new String(buff.toByteArray());
    assertTrue(out.contains("Created file"));

    Connection conn2 = getConnection("recovery2");
    Statement stat2 = conn2.createStatement();
    String name = "recovery.h2.sql";

    stat2.execute("runscript from '" + getBaseDir() + "/" + name + "'");
    stat2.execute("select * from test");
    conn2.close();

    conn = getConnection("recovery");
    stat = conn.createStatement();
    conn2 = getConnection("recovery2");
    stat2 = conn2.createStatement();

    assertEqualDatabases(stat, stat2);
    conn.close();
    conn2.close();

    Recover.execute(getBaseDir(), "recovery");

    deleteDb("recovery");
    deleteDb("recovery2");
    FileUtils.delete(getBaseDir() + "/recovery.h2.sql");
    String dir = getBaseDir() + "/recovery.lobs.db";
    FileUtils.deleteRecursive(dir, false);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:60,代码来源:TestRecovery.java

示例13: 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类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。