本文整理汇总了Java中org.h2.tools.DeleteDbFiles类的典型用法代码示例。如果您正苦于以下问题:Java DeleteDbFiles类的具体用法?Java DeleteDbFiles怎么用?Java DeleteDbFiles使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DeleteDbFiles类属于org.h2.tools包,在下文中一共展示了DeleteDbFiles类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSplitDatabaseInZip
import org.h2.tools.DeleteDbFiles; //导入依赖的package包/类
private void testSplitDatabaseInZip() throws SQLException {
String dir = getBaseDir() + "/fs";
FileUtils.deleteRecursive(dir, false);
Connection conn;
Statement stat;
conn = getConnection("jdbc:h2:split:18:"+dir+"/test");
stat = conn.createStatement();
stat.execute(
"create table test(id int primary key, name varchar) " +
"as select x, space(10000) from system_range(1, 100)");
// stat.execute("shutdown defrag");
conn.close();
Backup.execute(dir + "/test.zip", dir, "", true);
DeleteDbFiles.execute("split:" + dir, "test", true);
conn = getConnection(
"jdbc:h2:split:zip:"+dir+"/test.zip!/test");
conn.createStatement().execute("select * from test where id=1");
conn.close();
FileUtils.deleteRecursive(dir, false);
}
示例2: setup
import org.h2.tools.DeleteDbFiles; //导入依赖的package包/类
/** Prepares Db and data source, which must be added to Camel registry. */
@BeforeClass
public static void setup() throws Exception {
DeleteDbFiles.execute("~", "jbpm-db-test", true);
h2Server = Server.createTcpServer(new String[0]);
h2Server.start();
setupDb();
DataSource ds = setupDataSource();
SimpleRegistry simpleRegistry = new SimpleRegistry();
simpleRegistry.put("myDs", ds);
handler = new CamelHandler(new SQLURIMapper(), new RequestPayloadMapper("payload"), new ResponsePayloadMapper("queryResult"), new DefaultCamelContext(simpleRegistry));
}
示例3: test
import org.h2.tools.DeleteDbFiles; //导入依赖的package包/类
private static void test() throws SQLException {
DeleteDbFiles.execute("data", "test", true);
Connection conn = DriverManager.getConnection("jdbc:h2:data/test");
Statement stat = conn.createStatement();
stat.execute("create table test1(id identity, name varchar)");
stat.execute("create table test2(id identity, name varchar)");
conn.setAutoCommit(true);
// use two tables to make sure the data stored on disk is not too simple
PreparedStatement prep1 = conn.prepareStatement(
"insert into test1(name) values(space(255))");
PreparedStatement prep2 = conn.prepareStatement(
"insert into test2(name) values(space(255))");
for (int i = 0; i < 50000; i++) {
if (i % 7 != 0) {
prep1.execute();
} else {
prep2.execute();
}
}
Profiler prof = new Profiler();
prof.startCollecting();
stat.execute("DROP TABLE test1");
prof.stopCollecting();
System.out.println(prof.getTop(3));
conn.close();
}
示例4: main
import org.h2.tools.DeleteDbFiles; //导入依赖的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;
conn = DriverManager.getConnection("jdbc:h2:data/test");
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key, name varchar)");
stat.execute("insert into test values(1, 'Hello')");
stat.execute("insert into test values(2, 'World')");
stat.execute("create linked table test_link" +
"('', 'jdbc:h2:data/test', '', '', 'TEST')");
stat.execute("set trace_level_system_out 2");
// the query sent to the linked database is
// SELECT * FROM PUBLIC.TEST T WHERE ID>=? AND ID<=? {1: 1, 2: 1};
// it should also include AND NAME='Hello'
stat.execute("select * from test_link " +
"where id = 1 and name = 'Hello'");
conn.close();
}
示例5: test
import org.h2.tools.DeleteDbFiles; //导入依赖的package包/类
private static void test() throws SQLException {
DeleteDbFiles.execute("data", "test", true);
Connection conn = DriverManager.getConnection("jdbc:h2:data/test");
Statement stat = conn.createStatement();
stat.execute("set max_operation_memory 100");
stat.execute("set max_memory_undo 100");
stat.execute("create table test(id identity, name varchar)");
conn.setAutoCommit(false);
PreparedStatement prep = conn.prepareStatement(
"insert into test(name) values(space(1024*1024))");
long time = System.currentTimeMillis();
for (int i = 0; i < 2500; i++) {
prep.execute();
long now = System.currentTimeMillis();
if (now > time + 5000) {
System.out.println(i);
time = now + 5000;
}
}
conn.rollback();
conn.close();
}
示例6: testRecoverClob
import org.h2.tools.DeleteDbFiles; //导入依赖的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();
}
示例7: testRecoverFulltext
import org.h2.tools.DeleteDbFiles; //导入依赖的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();
}
示例8: testDeleteFiles
import org.h2.tools.DeleteDbFiles; //导入依赖的package包/类
private void testDeleteFiles() throws SQLException {
deleteDb("testDeleteFiles");
Connection conn = getConnection("testDeleteFiles");
Statement stat = conn.createStatement();
stat.execute("create table test(c clob) as select space(10000) from dual");
conn.close();
// the name starts with the same string, but does not match it
DeleteDbFiles.execute(getBaseDir(), "testDelete", true);
conn = getConnection("testDeleteFiles");
stat = conn.createStatement();
ResultSet rs;
rs = stat.executeQuery("select * from test");
rs.next();
rs.getString(1);
conn.close();
deleteDb("testDeleteFiles");
}
示例9: beforeTest
import org.h2.tools.DeleteDbFiles; //导入依赖的package包/类
/**
* This method is called before a complete set of tests is run. It deletes
* old database files in the test directory and trace files. It also starts
* a TCP server if the test uses remote connections.
*/
public void beforeTest() throws SQLException {
Driver.load();
FileUtils.deleteRecursive(TestBase.BASE_TEST_DIR, true);
DeleteDbFiles.execute(TestBase.BASE_TEST_DIR, null, true);
FileUtils.deleteRecursive("trace.db", false);
if (networked) {
String[] args = ssl ? new String[] { "-tcpSSL", "-tcpPort", "9192" }
: new String[] { "-tcpPort", "9192" };
server = Server.createTcpServer(args);
try {
server.start();
} catch (SQLException e) {
System.out.println("FAIL: can not start server (may already be running)");
server = null;
}
}
}
示例10: main
import org.h2.tools.DeleteDbFiles; //导入依赖的package包/类
/**
* Called when ran from command line.
*
* @param args ignored
*/
public static void main(String... args) throws Exception {
// delete the database named 'test' in the user home directory
DeleteDbFiles.execute("~", "test", true);
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:~/test");
Statement stat = conn.createStatement();
// this line would initialize the database
// from the SQL script file 'init.sql'
// stat.execute("runscript from 'init.sql'");
stat.execute("create table test(id int primary key, name varchar(255))");
stat.execute("insert into test values(1, 'Hello')");
ResultSet rs;
rs = stat.executeQuery("select * from test");
while (rs.next()) {
System.out.println(rs.getString("name"));
}
stat.close();
conn.close();
}
示例11: main
import org.h2.tools.DeleteDbFiles; //导入依赖的package包/类
public static void main(String... args) throws Exception {
// delete the database named 'test' in the user home directory
DeleteDbFiles.execute("~", "test", true);
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:~/test", "admin", "admin");
Statement stat = conn.createStatement();
// this line would initialize the database
// from the SQL script file 'init.sql'
// stat.execute("runscript from 'init.sql'");
stat.execute("create table test(id int primary key, name varchar(255))");
stat.execute("insert into test values(1, 'Hello')");
ResultSet rs;
rs = stat.executeQuery("select * from test");
while (rs.next()) {
System.out.println(rs.getString("name"));
}
stat.close();
conn.close();
}
示例12: testCorrupt
import org.h2.tools.DeleteDbFiles; //导入依赖的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");
}
示例13: testCompressedAndUncompressed
import org.h2.tools.DeleteDbFiles; //导入依赖的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);
}
示例14: testImplicitRelativePath
import org.h2.tools.DeleteDbFiles; //导入依赖的package包/类
private void testImplicitRelativePath() throws Exception {
if (SysProperties.IMPLICIT_RELATIVE_PATH) {
return;
}
assertThrows(ErrorCode.URL_RELATIVE_TO_CWD, this).
getConnection("jdbc:h2:test");
assertThrows(ErrorCode.URL_RELATIVE_TO_CWD, this).
getConnection("jdbc:h2:data/test");
getConnection("jdbc:h2:./testDatabase").close();
DeleteDbFiles.execute(".", "testDatabase", true);
}
示例15: test
import org.h2.tools.DeleteDbFiles; //导入依赖的package包/类
@Override
public void test() throws Exception {
if (config.networked) {
return;
}
DeleteDbFiles.execute(getBaseDir(), null, true);
org.h2.Driver.load();
testSimpleResultSet();
testTcpServerWithoutPort();
testConsole();
testJdbcDriverUtils();
testWrongServer();
testDeleteFiles();
testScriptRunscriptLob();
testServerMain();
testRemove();
testConvertTraceFile();
testManagementDb();
testChangeFileEncryption(false);
if (!config.splitFileSystem) {
testChangeFileEncryption(true);
}
testChangeFileEncryptionWithWrongPassword();
testServer();
testScriptRunscript();
testBackupRestore();
testRecover();
FileUtils.delete(getBaseDir() + "/b2.sql");
FileUtils.delete(getBaseDir() + "/b2.sql.txt");
FileUtils.delete(getBaseDir() + "/b2.zip");
}