本文整理汇总了Java中org.h2.tools.RunScript.main方法的典型用法代码示例。如果您正苦于以下问题:Java RunScript.main方法的具体用法?Java RunScript.main怎么用?Java RunScript.main使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.h2.tools.RunScript
的用法示例。
在下文中一共展示了RunScript.main方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: recreate
import org.h2.tools.RunScript; //导入方法依赖的package包/类
@RequiresNonNull("startupLogger")
private static void recreate(File dataDir) throws Exception {
File backupFile = new File(dataDir, "backup.sql");
if (backupFile.exists() && !backupFile.delete()) {
startupLogger.warn("recreate failed: cannot delete existing backup.sql");
}
Script.main("-url", "jdbc:h2:" + dataDir.getPath() + File.separator + "data", "-user", "sa",
"-script", backupFile.getPath());
File dbFile = new File(dataDir, "data.h2.db");
File dbBakFile = new File(dataDir, "data.h2.db.bak");
if (dbBakFile.exists() && !dbBakFile.delete()) {
startupLogger.warn("recreate failed, cannot delete existing file: {}",
dbBakFile.getPath());
}
if (!dbFile.renameTo(dbBakFile)) {
startupLogger.warn("recreate failed, cannot rename {} to {}", dbFile.getPath(),
dbBakFile.getPath());
return;
}
RunScript.main("-url", "jdbc:h2:" + dataDir.getPath() + File.separator + "data", "-script",
backupFile.getPath());
startupLogger.info("recreate succeeded");
// clean up
if (!dbBakFile.delete()) {
startupLogger.info("failed to clean-up, cannot delete file: {}", dbBakFile.getPath());
}
if (!backupFile.delete()) {
startupLogger.info("failed to clean-up, cannot delete file: {}", backupFile.getPath());
}
}
示例2: recover
import org.h2.tools.RunScript; //导入方法依赖的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());
}
}
示例3: maskCentralData
import org.h2.tools.RunScript; //导入方法依赖的package包/类
@RequiresNonNull("startupLogger")
private static void maskCentralData(File dataDir) throws Exception {
File maskScriptFile = File.createTempFile("mask-central-data", ".sql");
PrintWriter out = new PrintWriter(new FileWriter(maskScriptFile));
try {
// mask agent ids and agent rollup ids
out.println("update trace set headline = left(headline, position(': ', headline) + 1)"
+ " || " + applyHash("substr(headline, position(': ', headline) + 2)")
+ " where transaction_type <> 'Web' and headline like '%: %';");
// mask query strings
out.println("update trace set headline = left(headline, position('?', headline))"
+ " || " + applyHash("substr(headline, position('?', headline) + 1)")
+ " where transaction_type = 'Web' and headline like '%?%';");
// mask usernames
out.println("update trace set user = " + applyHash("user")
+ " where transaction_type = 'Web'" + " and user is not null;");
} finally {
out.close();
}
RunScript.main("-url", "jdbc:h2:" + dataDir.getPath() + File.separator + "data", "-user",
"sa", "-script", maskScriptFile.getPath());
if (!maskScriptFile.delete()) {
startupLogger.info("failed to clean-up, cannot delete file: {}",
maskScriptFile.getPath());
}
// re-create data file to eliminate any trace of previous values
recover(dataDir);
}
示例4: testConvertTraceFile
import org.h2.tools.RunScript; //导入方法依赖的package包/类
private void testConvertTraceFile() throws Exception {
deleteDb("toolsConvertTraceFile");
org.h2.Driver.load();
String url = "jdbc:h2:" + getBaseDir() + "/toolsConvertTraceFile";
url = getURL(url, true);
Connection conn = getConnection(url + ";TRACE_LEVEL_FILE=3", "sa", "sa");
Statement stat = conn.createStatement();
stat.execute(
"create table test(id int primary key, name varchar, amount decimal)");
PreparedStatement prep = conn.prepareStatement(
"insert into test values(?, ?, ?)");
prep.setInt(1, 1);
prep.setString(2, "Hello \\'Joe\n\\'");
prep.setBigDecimal(3, new BigDecimal("10.20"));
prep.executeUpdate();
stat.execute("create table test2(id int primary key,\n" +
"a real, b double, c bigint,\n" +
"d smallint, e boolean, f binary, g date, h time, i timestamp)",
Statement.NO_GENERATED_KEYS);
prep = conn.prepareStatement(
"insert into test2 values(1, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
prep.setFloat(1, Float.MIN_VALUE);
prep.setDouble(2, Double.MIN_VALUE);
prep.setLong(3, Long.MIN_VALUE);
prep.setShort(4, Short.MIN_VALUE);
prep.setBoolean(5, false);
prep.setBytes(6, new byte[] { (byte) 10, (byte) 20 });
prep.setDate(7, java.sql.Date.valueOf("2007-12-31"));
prep.setTime(8, java.sql.Time.valueOf("23:59:59"));
prep.setTimestamp(9, java.sql.Timestamp.valueOf("2007-12-31 23:59:59"));
prep.executeUpdate();
conn.close();
ConvertTraceFile.main("-traceFile", getBaseDir() +
"/toolsConvertTraceFile.trace.db", "-javaClass", getBaseDir() +
"/Test", "-script", getBaseDir() + "/test.sql");
FileUtils.delete(getBaseDir() + "/Test.java");
String trace = getBaseDir() + "/toolsConvertTraceFile.trace.db";
assertTrue(FileUtils.exists(trace));
String newTrace = getBaseDir() + "/test.trace.db";
FileUtils.delete(newTrace);
assertFalse(FileUtils.exists(newTrace));
FileUtils.move(trace, newTrace);
deleteDb("toolsConvertTraceFile");
Player.main(getBaseDir() + "/test.trace.db");
testTraceFile(url);
deleteDb("toolsConvertTraceFile");
RunScript.main("-url", url, "-user", "sa", "-script", getBaseDir() +
"/test.sql");
testTraceFile(url);
deleteDb("toolsConvertTraceFile");
FileUtils.delete(getBaseDir() + "/toolsConvertTraceFile.h2.sql");
FileUtils.delete(getBaseDir() + "/test.sql");
}
示例5: testScriptRunscriptLob
import org.h2.tools.RunScript; //导入方法依赖的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();
}
示例6: testScriptRunscript
import org.h2.tools.RunScript; //导入方法依赖的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");
}
示例7: main
import org.h2.tools.RunScript; //导入方法依赖的package包/类
/**
* This method is called when executing this sample application from the
* command line.
*
* @param args the command line parameters
*/
public static void main(String... args) throws Exception {
String file = "test.txt";
String cipher = "AES";
String filePassword = "password";
String compressionAlgorithm = "DEFLATE";
String url = "jdbc:h2:mem:test";
String user = "sa", dbPassword = "sa";
PrintWriter w = openScriptWriter(file,
compressionAlgorithm,
cipher, filePassword, "UTF-8");
w.println("create table test(id int primary key);");
w.println("insert into test select x from system_range(1, 10);");
w.close();
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection(url, user, dbPassword);
RunScript.main(
"-url", url,
"-user", user, "-password", dbPassword,
"-script", file,
"-options",
"compression", compressionAlgorithm,
"cipher", cipher,
"password", "'" + filePassword + "'"
);
Script.main(
"-url", url,
"-user", user, "-password", dbPassword,
"-script", file,
"-options",
"compression", compressionAlgorithm,
"cipher", cipher, "password", "'" + filePassword + "'"
);
conn.close();
LineNumberReader r = openScriptReader(file,
compressionAlgorithm,
cipher, filePassword, "UTF-8");
while (true) {
String line = r.readLine();
if (line == null) {
break;
}
System.out.println(line);
}
r.close();
}