本文整理汇总了Java中org.h2.tools.DeleteDbFiles.main方法的典型用法代码示例。如果您正苦于以下问题:Java DeleteDbFiles.main方法的具体用法?Java DeleteDbFiles.main怎么用?Java DeleteDbFiles.main使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.h2.tools.DeleteDbFiles
的用法示例。
在下文中一共展示了DeleteDbFiles.main方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBackupRestore
import org.h2.tools.DeleteDbFiles; //导入方法依赖的package包/类
private void testBackupRestore() throws SQLException {
org.h2.Driver.load();
String url = "jdbc:h2:" + getBaseDir() + "/testBackupRestore";
String user = "sa", password = "abc";
final String fileName = getBaseDir() + "/b2.zip";
DeleteDbFiles.main("-dir", getBaseDir(), "-db", "testBackupRestore",
"-quiet");
Connection conn = getConnection(url, user, password);
conn.createStatement().execute(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)");
conn.createStatement().execute("INSERT INTO TEST VALUES(1, 'Hello')");
conn.close();
Backup.main("-file", fileName, "-dir", getBaseDir(), "-db",
"testBackupRestore", "-quiet");
DeleteDbFiles.main("-dir", getBaseDir(), "-db", "testBackupRestore",
"-quiet");
Restore.main("-file", fileName, "-dir", getBaseDir(), "-db",
"testBackupRestore", "-quiet");
conn = getConnection("jdbc:h2:" + getBaseDir() + "/testBackupRestore",
"sa", "abc");
ResultSet rs = conn.createStatement()
.executeQuery("SELECT * FROM TEST");
assertTrue(rs.next());
assertFalse(rs.next());
new AssertThrows(ErrorCode.CANNOT_CHANGE_SETTING_WHEN_OPEN_1) {
@Override
public void test() throws SQLException {
// must fail when the database is in use
Backup.main("-file", fileName, "-dir", getBaseDir(), "-db",
"testBackupRestore");
}
};
conn.close();
DeleteDbFiles.main("-dir", getBaseDir(), "-db", "testBackupRestore",
"-quiet");
}
示例2: testChangeFileEncryption
import org.h2.tools.DeleteDbFiles; //导入方法依赖的package包/类
private void testChangeFileEncryption(boolean split) throws SQLException {
org.h2.Driver.load();
final String dir = (split ? "split:19:" : "") + getBaseDir();
String url = "jdbc:h2:" + dir + "/testChangeFileEncryption;CIPHER=AES";
DeleteDbFiles.execute(dir, "testChangeFileEncryption", true);
Connection conn = getConnection(url, "sa", "abc 123");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, DATA CLOB) "
+ "AS SELECT X, SPACE(3000) FROM SYSTEM_RANGE(1, 300)");
conn.close();
String[] args = { "-dir", dir, "-db", "testChangeFileEncryption",
"-cipher", "AES", "-decrypt", "abc", "-quiet" };
ChangeFileEncryption.main(args);
args = new String[] { "-dir", dir, "-db", "testChangeFileEncryption",
"-cipher", "AES", "-encrypt", "def", "-quiet" };
ChangeFileEncryption.main(args);
conn = getConnection(url, "sa", "def 123");
stat = conn.createStatement();
stat.execute("SELECT * FROM TEST");
new AssertThrows(ErrorCode.CANNOT_CHANGE_SETTING_WHEN_OPEN_1) {
@Override
public void test() throws SQLException {
ChangeFileEncryption.main(new String[] { "-dir", dir, "-db",
"testChangeFileEncryption", "-cipher", "AES",
"-decrypt", "def", "-quiet" });
}
};
conn.close();
args = new String[] { "-dir", dir, "-db", "testChangeFileEncryption",
"-quiet" };
DeleteDbFiles.main(args);
}
示例3: testChangeFileEncryptionWithWrongPassword
import org.h2.tools.DeleteDbFiles; //导入方法依赖的package包/类
private void testChangeFileEncryptionWithWrongPassword() throws SQLException {
if (config.mvStore) {
// the file system encryption abstraction used by the MVStore
// doesn't detect wrong passwords
return;
}
org.h2.Driver.load();
final String dir = getBaseDir();
// TODO: this doesn't seem to work in MVSTORE mode yet
String url = "jdbc:h2:" + dir + "/testChangeFileEncryption;CIPHER=AES";
DeleteDbFiles.execute(dir, "testChangeFileEncryption", true);
Connection conn = getConnection(url, "sa", "abc 123");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, DATA CLOB) "
+ "AS SELECT X, SPACE(3000) FROM SYSTEM_RANGE(1, 300)");
conn.close();
// try with wrong password, this used to have a bug where it kept the
// file handle open
new AssertThrows(SQLException.class) {
@Override
public void test() throws SQLException {
ChangeFileEncryption.execute(dir, "testChangeFileEncryption",
"AES", "wrong".toCharArray(),
"def".toCharArray(), true);
}
};
ChangeFileEncryption.execute(dir, "testChangeFileEncryption",
"AES", "abc".toCharArray(), "def".toCharArray(),
true);
conn = getConnection(url, "sa", "def 123");
stat = conn.createStatement();
stat.execute("SELECT * FROM TEST");
conn.close();
String[] args = new String[] { "-dir", dir, "-db", "testChangeFileEncryption", "-quiet" };
DeleteDbFiles.main(args);
}
示例4: testScriptRunscriptLob
import org.h2.tools.DeleteDbFiles; //导入方法依赖的package包/类
private void testScriptRunscriptLob() throws Exception {
org.h2.Driver.load();
String url = getURL("jdbc:h2:" + getBaseDir() +
"/testScriptRunscriptLob", true);
String user = "sa", password = "abc";
String fileName = getBaseDir() + "/b2.sql";
Connection conn = getConnection(url, user, password);
conn.createStatement().execute(
"CREATE TABLE TEST(ID INT PRIMARY KEY, BDATA BLOB, CDATA CLOB)");
PreparedStatement prep = conn.prepareStatement(
"INSERT INTO TEST VALUES(?, ?, ?)");
prep.setInt(1, 1);
prep.setNull(2, Types.BLOB);
prep.setNull(3, Types.CLOB);
prep.execute();
prep.setInt(1, 2);
prep.setString(2, "face");
prep.setString(3, "face");
prep.execute();
Random random = new Random(1);
prep.setInt(1, 3);
byte[] large = new byte[getSize(10 * 1024, 100 * 1024)];
random.nextBytes(large);
prep.setBytes(2, large);
String largeText = new String(large, "ISO-8859-1");
prep.setString(3, largeText);
prep.execute();
for (int i = 0; i < 2; i++) {
ResultSet rs = conn.createStatement().executeQuery(
"SELECT * FROM TEST ORDER BY ID");
rs.next();
assertEquals(1, rs.getInt(1));
assertTrue(rs.getString(2) == null);
assertTrue(rs.getString(3) == null);
rs.next();
assertEquals(2, rs.getInt(1));
assertEquals("face", rs.getString(2));
assertEquals("face", rs.getString(3));
rs.next();
assertEquals(3, rs.getInt(1));
assertEquals(large, rs.getBytes(2));
assertEquals(largeText, rs.getString(3));
assertFalse(rs.next());
conn.close();
Script.main("-url", url, "-user", user, "-password", password,
"-script", fileName);
DeleteDbFiles.main("-dir", getBaseDir(), "-db",
"testScriptRunscriptLob", "-quiet");
RunScript.main("-url", url, "-user", user, "-password", password,
"-script", fileName);
conn = getConnection("jdbc:h2:" + getBaseDir() +
"/testScriptRunscriptLob", "sa", "abc");
}
conn.close();
}
示例5: testScriptRunscript
import org.h2.tools.DeleteDbFiles; //导入方法依赖的package包/类
private void testScriptRunscript() throws SQLException {
org.h2.Driver.load();
String url = getURL("jdbc:h2:" + getBaseDir() + "/testScriptRunscript",
true);
String user = "sa", password = "abc";
String fileName = getBaseDir() + "/b2.sql";
DeleteDbFiles.main("-dir", getBaseDir(), "-db", "testScriptRunscript",
"-quiet");
Connection conn = getConnection(url, user, password);
conn.createStatement().execute("CREATE TABLE \u00f6()");
conn.createStatement().execute(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)");
conn.createStatement().execute("INSERT INTO TEST VALUES(1, 'Hello')");
conn.close();
Script.main("-url", url, "-user", user, "-password", password,
"-script", fileName, "-options", "nodata", "compression",
"lzf", "cipher", "aes", "password", "'123'", "charset",
"'utf-8'");
Script.main("-url", url, "-user", user, "-password", password,
"-script", fileName + ".txt");
DeleteDbFiles.main("-dir", getBaseDir(), "-db", "testScriptRunscript",
"-quiet");
RunScript.main("-url", url, "-user", user, "-password", password,
"-script", fileName, "-options", "compression", "lzf",
"cipher", "aes", "password", "'123'", "charset", "'utf-8'");
conn = getConnection(
"jdbc:h2:" + getBaseDir() + "/testScriptRunscript", "sa", "abc");
ResultSet rs = conn.createStatement()
.executeQuery("SELECT * FROM TEST");
assertFalse(rs.next());
rs = conn.createStatement().executeQuery("SELECT * FROM \u00f6");
assertFalse(rs.next());
conn.close();
DeleteDbFiles.main("-dir", getBaseDir(), "-db", "testScriptRunscript",
"-quiet");
RunScript tool = new RunScript();
ByteArrayOutputStream buff = new ByteArrayOutputStream();
tool.setOut(new PrintStream(buff));
tool.runTool("-url", url, "-user", user, "-password", password,
"-script", fileName + ".txt", "-showResults");
assertTrue(buff.toString().contains("Hello"));
// test parsing of BLOCKSIZE option
DeleteDbFiles.main("-dir", getBaseDir(), "-db", "testScriptRunscript",
"-quiet");
conn = getConnection(url, user, password);
conn.createStatement().execute(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)");
conn.close();
Script.main("-url", url, "-user", user, "-password", password,
"-script", fileName, "-options", "simple", "blocksize",
"8192");
}
示例6: testRecover
import org.h2.tools.DeleteDbFiles; //导入方法依赖的package包/类
private void testRecover() throws SQLException {
if (config.memory || config.networked || config.cipher != null) {
return;
}
int port1 = 9191, port2 = 9192;
String serverList = "localhost:" + port1 + ",localhost:" + port2;
deleteFiles();
org.h2.Driver.load();
String user = getUser(), password = getPassword();
Connection conn;
Statement stat;
ResultSet rs;
String url1 = getURL("jdbc:h2:tcp://localhost:" + port1 + "/test", true);
String url2 = getURL("jdbc:h2:tcp://localhost:" + port2 + "/test", true);
String urlCluster = getURL("jdbc:h2:tcp://" + serverList + "/test", true);
Server server1 = org.h2.tools.Server.createTcpServer(
"-tcpPort", "" + port1, "-baseDir", getBaseDir() + "/node1").start();
Server server2 = org.h2.tools.Server.createTcpServer(
"-tcpPort", "" + port2 , "-baseDir", getBaseDir() + "/node2").start();
CreateCluster.main("-urlSource", url1, "-urlTarget", url2,
"-user", user, "-password", password, "-serverList",
serverList);
conn = getConnection(urlCluster, user, password);
stat = conn.createStatement();
stat.execute("create table t1(id int, name varchar(30))");
stat.execute("insert into t1 values(1, 'a'), (2, 'b'), (3, 'c')");
rs = stat.executeQuery("select count(*) from t1");
rs.next();
assertEquals(3, rs.getInt(1));
server2.stop();
DeleteDbFiles.main("-dir", getBaseDir() + "/node2", "-quiet");
stat.execute("insert into t1 values(4, 'd'), (5, 'e')");
rs = stat.executeQuery("select count(*) from t1");
rs.next();
assertEquals(5, rs.getInt(1));
server2 = org.h2.tools.Server.createTcpServer("-tcpPort",
"" + port2 , "-baseDir", getBaseDir() + "/node2").start();
CreateCluster.main("-urlSource", url1, "-urlTarget", url2,
"-user", user, "-password", password, "-serverList",
serverList);
conn.close();
conn = getConnection(urlCluster, user, password);
stat = conn.createStatement();
rs = stat.executeQuery("select count(*) from t1");
rs.next();
assertEquals(5, rs.getInt(1));
conn.close();
server1.stop();
server2.stop();
deleteFiles();
}
示例7: deleteFiles
import org.h2.tools.DeleteDbFiles; //导入方法依赖的package包/类
private void deleteFiles() throws SQLException {
DeleteDbFiles.main("-dir", getBaseDir() + "/node1", "-quiet");
DeleteDbFiles.main("-dir", getBaseDir() + "/node2", "-quiet");
FileUtils.delete(getBaseDir() + "/node1");
FileUtils.delete(getBaseDir() + "/node2");
}