本文整理汇总了Java中org.h2.tools.Server.runTool方法的典型用法代码示例。如果您正苦于以下问题:Java Server.runTool方法的具体用法?Java Server.runTool怎么用?Java Server.runTool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.h2.tools.Server
的用法示例。
在下文中一共展示了Server.runTool方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runServer
import org.h2.tools.Server; //导入方法依赖的package包/类
private String runServer(int exitCode, String... args) {
ByteArrayOutputStream buff = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(buff);
server = new Server();
server.setOut(ps);
int result = 0;
try {
server.runTool(args);
} catch (SQLException e) {
result = 1;
e.printStackTrace(ps);
}
assertEquals(exitCode, result);
ps.flush();
String s = new String(buff.toByteArray());
return s;
}
示例2: contextInitialized
import org.h2.tools.Server; //导入方法依赖的package包/类
@Override
public void contextInitialized(final ServletContextEvent sce) {
ServletContext context = sce.getServletContext();
WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(context);
try {
Server h2TestDb = new Server();
h2TestDb.runTool("-tcp", "-tcpDaemon", "-web", "-webDaemon",
"-webPort", ctx.getBean("testdb.webport", String.class));
context.setAttribute(H2_TESTDB, h2TestDb);
} catch (SQLException e) {
LOG.error("Could not start H2 test db", e);
}
DataSource datasource = ctx.getBean(DataSource.class);
ResourceDatabasePopulator populator = new ResourceDatabasePopulator(ctx.getResource("classpath:/testdb.sql"));
populator.setSqlScriptEncoding("UTF-8");
DataSourceInitializer init = new DataSourceInitializer();
init.setDataSource(datasource);
init.setEnabled(true);
init.setDatabasePopulator(populator);
init.afterPropertiesSet();
LOG.info("Database successfully initialized");
}
示例3: testTransfer
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testTransfer() throws Exception {
Server server = new Server();
server.setOut(new PrintStream(new ByteArrayOutputStream()));
server.runTool("-web", "-webPort", "8182", "-properties", "null");
File transfer = new File("transfer");
transfer.mkdirs();
try {
FileOutputStream f = new FileOutputStream("transfer/test.txt");
f.write("Hello World".getBytes());
f.close();
WebClient client = new WebClient();
String url = "http://localhost:8182";
String result = client.get(url);
client.readSessionId(result);
String test = client.get(url, "transfer/test.txt");
assertEquals("Hello World", test);
new File("transfer/testUpload.txt").delete();
client.upload(url + "/transfer/testUpload.txt",
"testUpload.txt", new ByteArrayInputStream(
"Hallo Welt".getBytes()));
byte[] d = IOUtils.readBytesAndClose(
new FileInputStream("transfer/testUpload.txt"), -1);
assertEquals("Hallo Welt", new String(d));
new File("transfer/testUpload.txt").delete();
} finally {
server.shutdown();
FileUtils.deleteRecursive("transfer", true);
}
}
示例4: testServer
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testServer() throws Exception {
Server server = new Server();
server.setOut(new PrintStream(new ByteArrayOutputStream()));
server.runTool("-web", "-webPort", "8182", "-properties",
"null", "-tcp", "-tcpPort", "9101");
try {
String url = "http://localhost:8182";
WebClient client;
String result;
client = new WebClient();
client.setAcceptLanguage("de-de,de;q=0.5");
result = client.get(url);
client.readSessionId(result);
result = client.get(url, "login.jsp");
assertEquals("text/html", client.getContentType());
assertContains(result, "Einstellung");
client.get(url, "favicon.ico");
assertEquals("image/x-icon", client.getContentType());
client.get(url, "ico_ok.gif");
assertEquals("image/gif", client.getContentType());
client.get(url, "tree.js");
assertEquals("text/javascript", client.getContentType());
client.get(url, "stylesheet.css");
assertEquals("text/css", client.getContentType());
client.get(url, "admin.do");
try {
client.get(url, "adminShutdown.do");
} catch (IOException e) {
// expected
Thread.sleep(1000);
}
} finally {
server.shutdown();
}
// it should be stopped now
server = Server.createTcpServer("-tcpPort", "9101");
server.start();
server.stop();
}
示例5: testIfExists
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testIfExists() throws Exception {
Connection conn = getConnection("jdbc:h2:mem:webExists",
getUser(), getPassword());
Server server = new Server();
server.setOut(new PrintStream(new ByteArrayOutputStream()));
server.runTool("-ifExists", "-web", "-webPort", "8182",
"-properties", "null", "-tcp", "-tcpPort", "9101");
try {
String url = "http://localhost:8182";
WebClient client;
String result;
client = new WebClient();
result = client.get(url);
client.readSessionId(result);
result = client.get(url, "login.jsp");
result = client.get(url, "test.do?driver=org.h2.Driver" +
"&url=jdbc:h2:mem:webExists" +
"&user=" + getUser() + "&password=" +
getPassword() + "&name=_test_");
assertTrue(result.indexOf("Exception") < 0);
result = client.get(url, "test.do?driver=org.h2.Driver" +
"&url=jdbc:h2:mem:web" +
"&user=" + getUser() + "&password=" +
getPassword() + "&name=_test_");
assertContains(result, "Exception");
} finally {
server.shutdown();
conn.close();
}
}
示例6: testTools
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testTools() throws Exception {
if (config.memory || config.cipher != null) {
return;
}
deleteDb("web");
Connection conn = getConnection("web");
conn.createStatement().execute(
"create table test(id int) as select 1");
conn.close();
Server server = new Server();
server.setOut(new PrintStream(new ByteArrayOutputStream()));
server.runTool("-web", "-webPort", "8182",
"-properties", "null", "-tcp", "-tcpPort", "9101");
try {
String url = "http://localhost:8182";
WebClient client;
String result;
client = new WebClient();
result = client.get(url);
client.readSessionId(result);
result = client.get(url, "tools.jsp");
FileUtils.delete(getBaseDir() + "/backup.zip");
result = client.get(url, "tools.do?tool=Backup&args=-dir," +
getBaseDir() + ",-db,web,-file," +
getBaseDir() + "/backup.zip");
deleteDb("web");
assertTrue(FileUtils.exists(getBaseDir() + "/backup.zip"));
result = client.get(url,
"tools.do?tool=DeleteDbFiles&args=-dir," +
getBaseDir() + ",-db,web");
String fn = getBaseDir() + "/web";
if (config.mvStore) {
fn += Constants.SUFFIX_MV_FILE;
} else {
fn += Constants.SUFFIX_PAGE_FILE;
}
assertFalse(FileUtils.exists(fn));
result = client.get(url, "tools.do?tool=Restore&args=-dir," +
getBaseDir() + ",-db,web,-file," + getBaseDir() +
"/backup.zip");
assertTrue(FileUtils.exists(fn));
FileUtils.delete(getBaseDir() + "/web.h2.sql");
FileUtils.delete(getBaseDir() + "/backup.zip");
result = client.get(url, "tools.do?tool=Recover&args=-dir," +
getBaseDir() + ",-db,web");
assertTrue(FileUtils.exists(getBaseDir() + "/web.h2.sql"));
FileUtils.delete(getBaseDir() + "/web.h2.sql");
result = client.get(url, "tools.do?tool=RunScript&args=-script," +
getBaseDir() + "/web.h2.sql,-url," + getURL("web", true) +
",-user," + getUser() + ",-password," + getPassword());
FileUtils.delete(getBaseDir() + "/web.h2.sql");
assertTrue(FileUtils.exists(fn));
deleteDb("web");
} finally {
server.shutdown();
}
}