提交 304fb601 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 0ae9a7c4
......@@ -40,7 +40,9 @@ Hypersonic SQL or HSQLDB. H2 is built from scratch.
<h3>Version 1.0 (Current)</h3>
<h3>Version 1.0.x (2007-09-x)</h3><ul>
<li>Optimization for independent subqueries. For example, this query can now an index:
<li>System.exit is no longer called by the WebServer, the Console and the Server tool
(except to set the exit code if required). This is important when using OSGi.
</li><li>Optimization for independent subqueries. For example, this query can now an index:
SELECT * FROM TEST WHERE ID = (SELECT MAX(ID) FROM TEST)
This can be disabled by setting the system property h2.optimizeSubqueryCache to false.
</li><li>The explain plan now says: /* direct lookup query */ if the query can be processed directly without reading rows,
......
......@@ -24,6 +24,7 @@ import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.message.TraceSystem;
import org.h2.server.Service;
import org.h2.server.ShutdownHandler;
import org.h2.util.ByteUtils;
import org.h2.util.FileUtils;
import org.h2.util.JdbcUtils;
......@@ -35,8 +36,6 @@ import org.h2.util.SortedProperties;
public class WebServer implements Service {
// TODO tool: implement a watchdog for a server
private static final String DEFAULT_LANGUAGE = "en";
/**
......@@ -61,12 +60,12 @@ public class WebServer implements Service {
"Generic OneDollarDB|in.co.daffodil.db.jdbc.DaffodilDBDriver|jdbc:daffodilDB_embedded:school;path=C:/temp;create=true|sa",
"Generic DB2|COM.ibm.db2.jdbc.net.DB2Driver|jdbc:db2://<host>/<db>|" ,
"Generic Oracle|oracle.jdbc.driver.OracleDriver|jdbc:oracle:thin:@<host>:1521:<instance>|scott" ,
"Generic PostgreSQL|org.postgresql.Driver|jdbc:postgresql:<db>|" ,
"Generic MS SQL Server|com.microsoft.jdbc.sqlserver.SQLServerDriver|jdbc:Microsoft:sqlserver://localhost:1433;DatabaseName=sqlexpress|sa",
"Generic MS SQL Server 2005|com.microsoft.sqlserver.jdbc.SQLServerDriver|jdbc:sqlserver://localhost;DatabaseName=test|sa",
"Generic PostgreSQL|org.postgresql.Driver|jdbc:postgresql:<db>|" ,
"Generic MySQL|com.mysql.jdbc.Driver|jdbc:mysql://<host>:<port>/<db>|" ,
"Generic Derby (Embedded)|org.apache.derby.jdbc.EmbeddedDriver|jdbc:derby:test;create=true|sa",
"Generic Derby (Server)|org.apache.derby.jdbc.ClientDriver|jdbc:derby://localhost:1527/test;create=true|sa",
"Generic Derby (Embedded)|org.apache.derby.jdbc.EmbeddedDriver|jdbc:derby:test;create=true|sa",
"Generic HSQLDB|org.hsqldb.jdbcDriver|jdbc:hsqldb:test;hsqldb.default_table_type=cached|sa" ,
// this will be listed on top for new installations
"Generic H2|org.h2.Driver|jdbc:h2:~/test|sa",
......@@ -95,7 +94,7 @@ public class WebServer implements Service {
private String startDateTime;
private ServerSocket serverSocket;
private String url;
private boolean allowShutdown = true;
private ShutdownHandler shutdownHandler;
private Thread listenerThread;
byte[] getFile(String file) throws IOException {
......@@ -148,7 +147,6 @@ public class WebServer implements Service {
} while(sessions.get(newId) != null);
WebSession session = new WebSession(this);
session.put("sessionId", newId);
//session.put("ip", socket.getInetAddress().getCanonicalHostName());
session.put("ip", hostname);
session.put("language", DEFAULT_LANGUAGE);
sessions.put(newId, session);
......@@ -438,12 +436,14 @@ public class WebServer implements Service {
return JdbcUtils.getConnection(driver, url, user, password);
}
public void setAllowShutdown(boolean b) {
this.allowShutdown = b;
void shutdown() {
if (shutdownHandler != null) {
shutdownHandler.shutdown();
}
}
boolean getAllowShutdown() {
return allowShutdown;
public void setShutdownHandler(ShutdownHandler shutdownHandler) {
this.shutdownHandler = shutdownHandler;
}
}
......@@ -474,9 +474,7 @@ class WebThread extends Thread {
}
private String adminShutdown() {
if (server.getAllowShutdown()) {
System.exit(0);
}
server.shutdown();
return "admin.jsp";
}
......
......@@ -27,6 +27,7 @@ import java.awt.event.WindowEvent;
import java.io.InputStream;
import java.sql.SQLException;
import org.h2.server.ShutdownHandler;
import org.h2.util.IOUtils;
import org.h2.util.StartBrowser;
......@@ -36,11 +37,13 @@ import org.h2.util.StartBrowser;
* Otherwise, a small window opens.
*
*/
public class Console implements ActionListener, MouseListener {
public class Console implements ActionListener, MouseListener, ShutdownHandler {
private Font font;
private Image icon;
private Server web;
private Frame frame;
private static final int EXIT_ERROR = 1;
private Server web, tcp, pg;
/**
* The command line interface for this tool.
......@@ -50,12 +53,17 @@ public class Console implements ActionListener, MouseListener {
* @throws Exception
*/
public static void main(String[] args) throws Exception {
new Console().run(args);
int exitCode = new Console().run(args);
if (exitCode != 0) {
System.exit(exitCode);
}
}
private void run(String[] args) {
private int run(String[] args) {
int exitCode = 0;
try {
web = Server.createWebServer(args);
web.setShutdownHandler(this);
web.start();
} catch (SQLException e) {
if (web == null) {
......@@ -64,7 +72,6 @@ public class Console implements ActionListener, MouseListener {
System.out.println(web.getStatus());
}
}
Server tcp = null, pg = null;
try {
tcp = Server.createTcpServer(args);
tcp.start();
......@@ -105,7 +112,34 @@ public class Console implements ActionListener, MouseListener {
// but are wondering why nothing happens
StartBrowser.openURL(web.getURL());
if (!web.isRunning()) {
System.exit(1);
exitCode = EXIT_ERROR;
}
return exitCode;
}
/**
* INTERNAL
*/
public void shutdown() {
stopAll();
}
private void stopAll() {
if (web != null && web.isRunning()) {
web.stop();
web = null;
}
if (tcp != null && tcp.isRunning()) {
tcp.stop();
tcp = null;
}
if (pg != null && pg.isRunning()) {
pg.stop();
pg = null;
}
if (frame != null) {
frame.dispose();
frame = null;
}
}
......@@ -164,11 +198,11 @@ public class Console implements ActionListener, MouseListener {
}
private void showWindow(final boolean exit) {
final Frame frame = new Frame("H2 Console");
frame = new Frame("H2 Console");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
if (exit) {
System.exit(0);
stopAll();
} else {
frame.dispose();
}
......@@ -232,7 +266,7 @@ public class Console implements ActionListener, MouseListener {
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if ("exit".equals(command)) {
System.exit(0);
stopAll();
} else if ("console".equals(command)) {
startBrowser();
} else if ("status".equals(command)) {
......
......@@ -14,6 +14,7 @@ import org.h2.engine.Constants;
import org.h2.message.Message;
import org.h2.message.TraceSystem;
import org.h2.server.Service;
import org.h2.server.ShutdownHandler;
import org.h2.server.TcpServer;
import org.h2.server.ftp.FtpServer;
import org.h2.server.pg.PgServer;
......@@ -25,11 +26,13 @@ import org.h2.util.StartBrowser;
/**
* This tool can be used to start various database servers (listeners).
*/
public class Server implements Runnable {
public class Server implements Runnable, ShutdownHandler {
private String name;
private Service service;
private static final int EXIT_ERROR = 1;
private Server web, tcp, pg, ftp;
private ShutdownHandler shutdownHandler;
private void showUsage() {
System.out.println("java "+getClass().getName() + " [options]");
......@@ -164,7 +167,7 @@ public class Server implements Runnable {
shutdownTcpServer(tcpShutdownServer, tcpPassword, tcpShutdownForce);
}
if (tcpStart) {
Server tcp = createTcpServer(args);
tcp = createTcpServer(args);
try {
tcp.start();
} catch (SQLException e) {
......@@ -175,7 +178,7 @@ public class Server implements Runnable {
System.out.println(tcp.getStatus());
}
if (pgStart) {
Server pg = createPgServer(args);
pg = createPgServer(args);
try {
pg.start();
} catch (SQLException e) {
......@@ -186,7 +189,8 @@ public class Server implements Runnable {
System.out.println(pg.getStatus());
}
if (webStart) {
Server web = createWebServer(args);
web = createWebServer(args);
web.setShutdownHandler(this);
try {
web.start();
} catch (SQLException e) {
......@@ -203,7 +207,7 @@ public class Server implements Runnable {
}
}
if (ftpStart) {
Server ftp = createFtpServer(args);
ftp = createFtpServer(args);
try {
ftp.start();
} catch (SQLException e) {
......@@ -298,7 +302,10 @@ public class Server implements Runnable {
* @return the server
*/
public static Server createWebServer(String[] args) throws SQLException {
return new Server("H2 Console Server", new WebServer(), args);
WebServer service = new WebServer();
Server server = new Server("H2 Console Server", service, args);
service.setShutdownHandler(server);
return server;
}
/**
......@@ -355,7 +362,26 @@ public class Server implements Runnable {
} catch (InterruptedException e) {
// ignore
}
}
}
private void stopAll() {
if (web != null && web.isRunning()) {
web.stop();
web = null;
}
if (tcp != null && tcp.isRunning()) {
tcp.stop();
tcp = null;
}
if (pg != null && pg.isRunning()) {
pg.stop();
pg = null;
}
if (ftp != null && ftp.isRunning()) {
ftp.stop();
ftp = null;
}
}
/**
* Checks if the server is running.
......@@ -401,4 +427,22 @@ public class Server implements Runnable {
TraceSystem.traceThrowable(e);
}
}
/**
* INTERNAL
*/
public void setShutdownHandler(ShutdownHandler shutdownHandler) {
this.shutdownHandler = shutdownHandler;
}
/**
* INTERNAL
*/
public void shutdown() {
if (shutdownHandler != null) {
shutdownHandler.shutdown();
} else {
stopAll();
}
}
}
......@@ -143,37 +143,13 @@ java org.h2.test.TestAll timer
/*
Avoid System.exit()
Sorry.... I just read the doc and it says using LOG=0 can lead to
corruption...
"At startup, when corrupted, say if LOG=0 was used before"
In fact, the reason I mentioned this is that I found out it was slow
when used in a sub query, thus I split it in two queries and forgot to
mention it. Try this and you will see why:
DROP TABLE TEST;
CREATE TABLE TEST(COL1 BIGINT PRIMARY KEY, COL2 VARCHAR);
INSERT INTO TEST SELECT X, CONCAT('Test', X) FROM SYSTEM_RANGE(1,
1000000);
SELECT MAX(COL1) FROM TEST;
SELECT * FROM TEST where col1=(select MAX(COL1) from test)
SELECT MAX(COL1) FROM TEST;
MAX(COL1)
1000000
(1 row, 0 ms)
SELECT * FROM TEST where col1=(select MAX(COL1) from test);
COL1 COL2
1000000 Test1000000
(1 row, 6815 ms)
I generally felt that sub queries were not properly optimized in h2
and I had to split them all (I understand it's a complex thing (I've
worked a (very) little on db2 a long long time ago...))
add MVCC
slow:
......
......@@ -42,7 +42,6 @@ public class WebServlet extends HttpServlet {
String[] args = new String[list.size()];
list.toArray(args);
server = new WebServer();
server.setAllowShutdown(false);
try {
server.init(args);
} catch (Exception e) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论