本文整理汇总了Java中org.h2.tools.Server.stop方法的典型用法代码示例。如果您正苦于以下问题:Java Server.stop方法的具体用法?Java Server.stop怎么用?Java Server.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.h2.tools.Server
的用法示例。
在下文中一共展示了Server.stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testWrongUrl
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testWrongUrl() throws Exception {
deleteDb("autoReconnect");
Server tcp = Server.createTcpServer().start();
try {
conn = getConnection("jdbc:h2:" + getBaseDir() +
"/autoReconnect;AUTO_SERVER=TRUE");
assertThrows(ErrorCode.DATABASE_ALREADY_OPEN_1, this).
getConnection("jdbc:h2:" + getBaseDir() +
"/autoReconnect;OPEN_NEW=TRUE");
assertThrows(ErrorCode.DATABASE_ALREADY_OPEN_1, this).
getConnection("jdbc:h2:" + getBaseDir() +
"/autoReconnect;OPEN_NEW=TRUE");
conn.close();
conn = getConnection("jdbc:h2:tcp://localhost/" + getBaseDir() +
"/autoReconnect");
assertThrows(ErrorCode.DATABASE_ALREADY_OPEN_1, this).
getConnection("jdbc:h2:" + getBaseDir() +
"/autoReconnect;AUTO_SERVER=TRUE;OPEN_NEW=TRUE");
conn.close();
} finally {
tcp.stop();
}
}
示例2: testLowerCaseIdentifiers
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testLowerCaseIdentifiers() throws SQLException {
if (!getPgJdbcDriver()) {
return;
}
deleteDb("test");
Connection conn = getConnection(
"test;DATABASE_TO_UPPER=false", "sa", "sa");
Statement stat = conn.createStatement();
stat.execute("create table test(id int, name varchar(255))");
Server server = Server.createPgServer(
"-baseDir", getBaseDir(), "-pgPort", "5535", "-pgDaemon");
server.start();
try {
Connection conn2;
conn2 = DriverManager.getConnection(
"jdbc:postgresql://localhost:5535/test", "sa", "sa");
stat = conn2.createStatement();
stat.execute("select * from test");
conn2.close();
} finally {
server.stop();
}
conn.close();
deleteDb("test");
}
示例3: testPgAdapter
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testPgAdapter() throws SQLException {
deleteDb("test");
Server server = Server.createPgServer(
"-baseDir", getBaseDir(), "-pgPort", "5535", "-pgDaemon");
assertEquals(5535, server.getPort());
assertEquals("Not started", server.getStatus());
server.start();
assertStartsWith(server.getStatus(), "PG server running at pg://");
try {
if (getPgJdbcDriver()) {
testPgClient();
}
} finally {
server.stop();
}
}
示例4: testKeyAlias
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testKeyAlias() throws SQLException {
if (!getPgJdbcDriver()) {
return;
}
Server server = Server.createPgServer(
"-pgPort", "5535", "-pgDaemon", "-key", "test", "mem:test");
server.start();
try {
Connection conn = DriverManager.getConnection(
"jdbc:postgresql://localhost:5535/test", "sa", "sa");
Statement stat = conn.createStatement();
// confirm that we've got the in memory implementation
// by creating a table and checking flags
stat.execute("create table test(id int primary key, name varchar)");
ResultSet rs = stat.executeQuery(
"select storage_type from information_schema.tables " +
"where table_name = 'TEST'");
assertTrue(rs.next());
assertEquals("MEMORY", rs.getString(1));
conn.close();
} finally {
server.stop();
}
}
示例5: testOldClientNewServer
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testOldClientNewServer() throws Exception {
Server server = org.h2.tools.Server.createTcpServer("-tcpPort", "9001");
server.start();
assertThrows(ErrorCode.DRIVER_VERSION_ERROR_2, driver).connect(
"jdbc:h2:tcp://localhost:9001/mem:test", null);
server.stop();
Class<?> serverClass = cl.loadClass("org.h2.tools.Server");
Method m;
m = serverClass.getMethod("createTcpServer", String[].class);
Object serverOld = m.invoke(null, new Object[] { new String[] {
"-tcpPort", "9001" } });
m = serverOld.getClass().getMethod("start");
m.invoke(serverOld);
Connection conn;
conn = org.h2.Driver.load().connect("jdbc:h2:mem:", null);
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("call 1");
rs.next();
assertEquals(1, rs.getInt(1));
conn.close();
m = serverOld.getClass().getMethod("stop");
m.invoke(serverOld);
}
示例6: test
import org.h2.tools.Server; //导入方法依赖的package包/类
private void test(String dir) throws Exception {
Server server = FtpServer.createFtpServer(
"-ftpDir", dir, "-ftpPort", "8121").start();
FtpServer ftp = (FtpServer) server.getService();
ftp.setEventListener(this);
FtpClient client = FtpClient.open("localhost:8121");
client.login("sa", "sa");
client.makeDirectory("ftp");
client.changeWorkingDirectory("ftp");
assertEquals("CWD", lastEvent.getCommand());
client.makeDirectory("hello");
client.changeWorkingDirectory("hello");
client.changeDirectoryUp();
assertEquals("CDUP", lastEvent.getCommand());
client.nameList("hello");
client.removeDirectory("hello");
client.close();
server.stop();
}
示例7: testAlreadyRunning
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testAlreadyRunning() throws Exception {
Server server = Server.createWebServer(
"-webPort", "8182", "-properties", "null");
server.start();
assertTrue(server.getStatus().contains("server running"));
Server server2 = Server.createWebServer(
"-webPort", "8182", "-properties", "null");
assertEquals("Not started", server2.getStatus());
try {
server2.start();
fail();
} catch (Exception e) {
assertTrue(e.toString().contains("port may be in use"));
assertTrue(server2.getStatus().contains(
"could not be started"));
}
server.stop();
}
示例8: stopServer
import org.h2.tools.Server; //导入方法依赖的package包/类
private void stopServer() {
if (server != null) {
Server s = server;
// avoid calling stop recursively
// because stopping the server will
// try to close the database as well
server = null;
s.stop();
}
}
示例9: main
import org.h2.tools.Server; //导入方法依赖的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 {
// start the server, allows to access the database remotely
Server server = Server.createTcpServer("-tcpPort", "9081");
server.start();
System.out.println(
"You can access the database remotely now, using the URL:");
System.out.println(
"jdbc:h2:tcp://localhost:9081/~/test (user: sa, password: sa)");
// now use the database in your application in embedded mode
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection(
"jdbc:h2:~/test", "sa", "sa");
// some simple 'business usage'
Statement stat = conn.createStatement();
stat.execute("DROP TABLE TIMER IF EXISTS");
stat.execute("CREATE TABLE TIMER(ID INT PRIMARY KEY, TIME VARCHAR)");
System.out.println("Execute this a few times: " +
"SELECT TIME FROM TIMER");
System.out.println("To stop this application " +
"(and the server), run: DROP TABLE TIMER");
try {
while (true) {
// runs forever, except if you drop the table remotely
stat.execute("MERGE INTO TIMER VALUES(1, NOW())");
Thread.sleep(1000);
}
} catch (SQLException e) {
System.out.println("Error: " + e.toString());
}
conn.close();
// stop the server
server.stop();
}
示例10: testManagementDb
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testManagementDb() throws SQLException {
int count = getSize(2, 10);
for (int i = 0; i < count; i++) {
Server tcpServer = Server.
createTcpServer("-tcpPort", "9192").start();
tcpServer.stop();
tcpServer = Server.createTcpServer("-tcpPassword", "abc",
"-tcpPort", "9192").start();
tcpServer.stop();
}
}
示例11: 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();
}
示例12: testReadOnlyInZip
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testReadOnlyInZip() throws SQLException {
if (config.cipher != null) {
return;
}
deleteDb("readonlyInZip");
String dir = getBaseDir();
Connection conn = getConnection("readonlyInZip");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT) AS " +
"SELECT X FROM SYSTEM_RANGE(1, 20)");
conn.close();
Backup.execute(dir + "/readonly.zip", dir, "readonlyInZip", true);
conn = getConnection(
"jdbc:h2:zip:"+dir+"/readonly.zip!/readonlyInZip", getUser(), getPassword());
conn.createStatement().execute("select * from test where id=1");
conn.close();
Server server = Server.createTcpServer("-tcpPort", "9081", "-baseDir", dir);
server.start();
try {
conn = getConnection(
"jdbc:h2:tcp://localhost:9081/zip:readonly.zip!/readonlyInZip",
getUser(), getPassword());
conn.createStatement().execute("select * from test where id=1");
conn.close();
FilePathZip2.register();
conn = getConnection(
"jdbc:h2:tcp://localhost:9081/zip2:readonly.zip!/readonlyInZip",
getUser(), getPassword());
conn.createStatement().execute("select * from test where id=1");
conn.close();
} finally {
server.stop();
}
deleteDb("readonlyInZip");
}
示例13: testClob
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testClob() 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;
String url1 = getURL("jdbc:h2:tcp://localhost:" + port1 + "/test", false);
Server n1 = org.h2.tools.Server.createTcpServer("-tcpPort",
"" + port1, "-baseDir", getBaseDir() + "/node1").start();
conn = getConnection(url1, user, password);
stat = conn.createStatement();
stat.execute("create table t1(id int, name clob)");
stat.execute("insert into t1 values(1, repeat('Hello', 50))");
conn.close();
String url2 = getURL("jdbc:h2:tcp://localhost:" + port2 + "/test", false);
Server n2 = org.h2.tools.Server.createTcpServer("-tcpPort",
"" + port2 , "-baseDir", getBaseDir() + "/node2").start();
String urlCluster = getURL("jdbc:h2:tcp://" + serverList + "/test", true);
CreateCluster.main("-urlSource", url1, "-urlTarget", url2,
"-user", user, "-password", password, "-serverList",
serverList);
conn = getConnection(urlCluster, user, password);
conn.close();
n1.stop();
n2.stop();
deleteFiles();
}
示例14: stop
import org.h2.tools.Server; //导入方法依赖的package包/类
@Action(
value = "h2-db-web-console-stop",
results = { @Result(name = "sucess", location = "h2-db-web-console-start.jsp") }
)
@SkipValidation
public String stop() throws Exception {
synchronized (lock) {
Server server = (Server)application.get("h2DbWebServer");
if (server != null && server.isRunning(false)) {
server.stop();
}
}
return "sucess";
}
示例15: testCancelQuery
import org.h2.tools.Server; //导入方法依赖的package包/类
private void testCancelQuery() throws Exception {
if (!getPgJdbcDriver()) {
return;
}
Server server = Server.createPgServer(
"-pgPort", "5535", "-pgDaemon", "-key", "test", "mem:test");
server.start();
ExecutorService executor = Executors.newSingleThreadExecutor();
try {
Connection conn = DriverManager.getConnection(
"jdbc:postgresql://localhost:5535/test", "sa", "sa");
final Statement stat = conn.createStatement();
stat.execute("create alias sleep for \"java.lang.Thread.sleep\"");
// create a table with 200 rows (cancel interval is 127)
stat.execute("create table test(id int)");
for (int i = 0; i < 200; i++) {
stat.execute("insert into test (id) values (rand())");
}
Future<Boolean> future = executor.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws SQLException {
return stat.execute("select id, sleep(5) from test");
}
});
// give it a little time to start and then cancel it
Thread.sleep(100);
stat.cancel();
try {
future.get();
throw new IllegalStateException();
} catch (ExecutionException e) {
assertStartsWith(e.getCause().getMessage(),
"ERROR: canceling statement due to user request");
} finally {
conn.close();
}
} finally {
server.stop();
executor.shutdown();
}
deleteDb("test");
}