提交 e5c25628 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 b09fd536
...@@ -132,8 +132,10 @@ public class WebServer implements Service { ...@@ -132,8 +132,10 @@ public class WebServer implements Service {
// TODO web: support using a different properties file // TODO web: support using a different properties file
appServer = new AppServer(args); appServer = new AppServer(args);
SimpleDateFormat format = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z", new Locale("en", "")); SimpleDateFormat format = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z", new Locale("en", ""));
synchronized(format) {
format.setTimeZone(TimeZone.getTimeZone("GMT")); format.setTimeZone(TimeZone.getTimeZone("GMT"));
startDateTime = format.format(new Date()); startDateTime = format.format(new Date());
}
trace(startDateTime); trace(startDateTime);
for(int i=0; i<LANGUAGES.length; i++) { for(int i=0; i<LANGUAGES.length; i++) {
languages.add(LANGUAGES[i][0]); languages.add(LANGUAGES[i][0]);
......
...@@ -8,6 +8,7 @@ import java.awt.Button; ...@@ -8,6 +8,7 @@ import java.awt.Button;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Font; import java.awt.Font;
import java.awt.Frame; import java.awt.Frame;
import java.awt.GraphicsEnvironment;
import java.awt.GridBagConstraints; import java.awt.GridBagConstraints;
import java.awt.GridBagLayout; import java.awt.GridBagLayout;
import java.awt.Image; import java.awt.Image;
...@@ -26,8 +27,6 @@ import java.awt.event.WindowEvent; ...@@ -26,8 +27,6 @@ import java.awt.event.WindowEvent;
import java.io.InputStream; import java.io.InputStream;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.message.Message;
import org.h2.tools.Server;
import org.h2.util.IOUtils; import org.h2.util.IOUtils;
import org.h2.util.StartBrowser; import org.h2.util.StartBrowser;
...@@ -39,7 +38,8 @@ import org.h2.util.StartBrowser; ...@@ -39,7 +38,8 @@ import org.h2.util.StartBrowser;
*/ */
public class Console implements ActionListener, MouseListener { public class Console implements ActionListener, MouseListener {
private static final Font FONT = new Font("Dialog", Font.PLAIN, 11); private Font font;
private Image icon;
private Server web; private Server web;
/** /**
...@@ -57,28 +57,49 @@ public class Console implements ActionListener, MouseListener { ...@@ -57,28 +57,49 @@ public class Console implements ActionListener, MouseListener {
try { try {
web = Server.createWebServer(args); web = Server.createWebServer(args);
web.start(); web.start();
Server.createTcpServer(args).start();
Server.createOdbcServer(args).start();
} catch (SQLException e) { } catch (SQLException e) {
if (e.getErrorCode() == Message.EXCEPTION_OPENING_PORT_1) { if(web == null) {
System.out.println("Port is in use, maybe another server server already running on " + web.getURL()); e.printStackTrace();
} else {
System.out.println(web.getStatus());
}
}
Server tcp = null, odbc = null;
try {
tcp = Server.createTcpServer(args);
tcp.start();
} catch(SQLException e) {
if(tcp == null) {
e.printStackTrace();
} else { } else {
System.out.println(tcp.getStatus());
}
}
try {
odbc = Server.createOdbcServer(args);
odbc.start();
} catch(SQLException e) {
if(odbc == null) {
e.printStackTrace(); e.printStackTrace();
} else {
System.out.println(odbc.getStatus());
} }
} }
if(!GraphicsEnvironment.isHeadless()) {
font = new Font("Dialog", Font.PLAIN, 11);
try { try {
InputStream in = getClass().getResourceAsStream("/org/h2/res/h2.png"); InputStream in = getClass().getResourceAsStream("/org/h2/res/h2.png");
Image image = null;
if(in != null) { if(in != null) {
byte[] imageData = IOUtils.readBytesAndClose(in, -1); byte[] imageData = IOUtils.readBytesAndClose(in, -1);
image = Toolkit.getDefaultToolkit().createImage(imageData); icon = Toolkit.getDefaultToolkit().createImage(imageData);
} }
if(!createTrayIcon(image)) { if(!createTrayIcon()) {
showWindow(image); showWindow();
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
}
// start browser anyway (even if the server is already running) // start browser anyway (even if the server is already running)
// because some people don't look at the output, // because some people don't look at the output,
// but are wondering why nothing happens // but are wondering why nothing happens
...@@ -88,7 +109,7 @@ public class Console implements ActionListener, MouseListener { ...@@ -88,7 +109,7 @@ public class Console implements ActionListener, MouseListener {
} }
} }
private boolean createTrayIcon(Image image) { private boolean createTrayIcon() {
try { try {
// SystemTray.isSupported(); // SystemTray.isSupported();
Boolean supported = (Boolean) Class.forName("java.awt.SystemTray"). Boolean supported = (Boolean) Class.forName("java.awt.SystemTray").
...@@ -103,33 +124,38 @@ public class Console implements ActionListener, MouseListener { ...@@ -103,33 +124,38 @@ public class Console implements ActionListener, MouseListener {
MenuItem itemConsole = new MenuItem("H2 Console"); MenuItem itemConsole = new MenuItem("H2 Console");
itemConsole.setActionCommand("console"); itemConsole.setActionCommand("console");
itemConsole.addActionListener(this); itemConsole.addActionListener(this);
itemConsole.setFont(FONT); itemConsole.setFont(font);
menuConsole.add(itemConsole); menuConsole.add(itemConsole);
MenuItem itemStatus = new MenuItem("Status");
itemConsole.setActionCommand("status");
itemConsole.addActionListener(this);
itemConsole.setFont(font);
menuConsole.add(itemStatus);
MenuItem itemExit = new MenuItem("Exit"); MenuItem itemExit = new MenuItem("Exit");
itemExit.setFont(FONT); itemExit.setFont(font);
itemExit.setActionCommand("exit"); itemExit.setActionCommand("exit");
itemExit.addActionListener(this); itemExit.addActionListener(this);
menuConsole.add(itemExit); menuConsole.add(itemExit);
// TrayIcon icon = new TrayIcon(image, "H2 Database Engine", menuConsole); // TrayIcon icon = new TrayIcon(image, "H2 Database Engine", menuConsole);
Object icon = Class.forName("java.awt.TrayIcon"). Object trayIcon = Class.forName("java.awt.TrayIcon").
getConstructor(new Class[] { Image.class, String.class, PopupMenu.class }). getConstructor(new Class[] { Image.class, String.class, PopupMenu.class }).
newInstance(new Object[] { image, "H2 Database Engine", menuConsole }); newInstance(new Object[] { icon, "H2 Database Engine", menuConsole });
// SystemTray tray = SystemTray.getSystemTray(); // SystemTray tray = SystemTray.getSystemTray();
Object tray = Class.forName("java.awt.SystemTray"). Object tray = Class.forName("java.awt.SystemTray").
getMethod("getSystemTray", new Class[0]). getMethod("getSystemTray", new Class[0]).
invoke(null, new Object[0]); invoke(null, new Object[0]);
// icon.addMouseListener(this); // trayIcon.addMouseListener(this);
icon.getClass(). trayIcon.getClass().
getMethod("addMouseListener", new Class[]{MouseListener.class}). getMethod("addMouseListener", new Class[]{MouseListener.class}).
invoke(icon, new Object[]{this}); invoke(trayIcon, new Object[]{this});
// tray.add(icon); // tray.add(icon);
tray.getClass(). tray.getClass().
getMethod("add", new Class[] { Class.forName("java.awt.TrayIcon") }). getMethod("add", new Class[] { Class.forName("java.awt.TrayIcon") }).
invoke(tray, new Object[] { icon }); invoke(tray, new Object[] { trayIcon });
return true; return true;
} catch (Exception e) { } catch (Exception e) {
...@@ -137,15 +163,15 @@ public class Console implements ActionListener, MouseListener { ...@@ -137,15 +163,15 @@ public class Console implements ActionListener, MouseListener {
} }
} }
private void showWindow(Image image) { private void showWindow() {
Frame frame = new Frame("H2 Console"); Frame frame = new Frame("H2 Console");
frame.addWindowListener(new WindowAdapter() { frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) { public void windowClosing(WindowEvent we) {
System.exit(0); System.exit(0);
} }
}); });
if(image != null) { if(icon != null) {
frame.setIconImage(image); frame.setIconImage(icon);
} }
frame.setResizable(false); frame.setResizable(false);
frame.setBackground(SystemColor.control); frame.setBackground(SystemColor.control);
...@@ -161,14 +187,14 @@ public class Console implements ActionListener, MouseListener { ...@@ -161,14 +187,14 @@ public class Console implements ActionListener, MouseListener {
c.insets.bottom = 2; c.insets.bottom = 2;
Label label = new Label("H2 Console URL:", Label.LEFT); Label label = new Label("H2 Console URL:", Label.LEFT);
label.setFont(FONT); label.setFont(font);
c.anchor = GridBagConstraints.WEST; c.anchor = GridBagConstraints.WEST;
c.gridwidth = GridBagConstraints.EAST; c.gridwidth = GridBagConstraints.EAST;
frame.add(label, c); frame.add(label, c);
TextField text = new TextField(); TextField text = new TextField();
text.setEditable(false); text.setEditable(false);
text.setFont(FONT); text.setFont(font);
text.setText(web.getURL()); text.setText(web.getURL());
text.setFocusable(false); text.setFocusable(false);
c.anchor = GridBagConstraints.EAST; c.anchor = GridBagConstraints.EAST;
...@@ -184,7 +210,7 @@ public class Console implements ActionListener, MouseListener { ...@@ -184,7 +210,7 @@ public class Console implements ActionListener, MouseListener {
startBrowser.setFocusable(false); startBrowser.setFocusable(false);
startBrowser.setActionCommand("console"); startBrowser.setActionCommand("console");
startBrowser.addActionListener(this); startBrowser.addActionListener(this);
startBrowser.setFont(FONT); startBrowser.setFont(font);
c.anchor = GridBagConstraints.EAST; c.anchor = GridBagConstraints.EAST;
c.gridwidth = GridBagConstraints.REMAINDER; c.gridwidth = GridBagConstraints.REMAINDER;
frame.add(startBrowser, c); frame.add(startBrowser, c);
...@@ -200,10 +226,13 @@ public class Console implements ActionListener, MouseListener { ...@@ -200,10 +226,13 @@ public class Console implements ActionListener, MouseListener {
* INTERNAL * INTERNAL
*/ */
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("exit")) { String command = e.getActionCommand();
if ("exit".equals(command)) {
System.exit(0); System.exit(0);
} else if (e.getActionCommand().equals("console")) { } else if ("console".equals(command)) {
startBrowser(); startBrowser();
} else if ("status".equals(command)) {
showWindow();
} }
} }
......
...@@ -271,7 +271,7 @@ public class Server implements Runnable { ...@@ -271,7 +271,7 @@ public class Server implements Runnable {
} }
} }
private String getStatus() { String getStatus() {
StringBuffer buff = new StringBuffer(); StringBuffer buff = new StringBuffer();
if(isRunning()) { if(isRunning()) {
buff.append(service.getType()); buff.append(service.getType());
......
...@@ -379,8 +379,10 @@ public class StringUtils { ...@@ -379,8 +379,10 @@ public class StringUtils {
*/ */
public static String formatDateTime(Date date, String format, String locale, String timezone) throws SQLException { public static String formatDateTime(Date date, String format, String locale, String timezone) throws SQLException {
SimpleDateFormat dateFormat = getDateFormat(format, locale, timezone); SimpleDateFormat dateFormat = getDateFormat(format, locale, timezone);
synchronized(dateFormat) {
return dateFormat.format(date); return dateFormat.format(date);
} }
}
/** /**
* Parses a date using a format string * Parses a date using a format string
...@@ -388,7 +390,9 @@ public class StringUtils { ...@@ -388,7 +390,9 @@ public class StringUtils {
public static Date parseDateTime(String date, String format, String locale, String timezone) throws SQLException { public static Date parseDateTime(String date, String format, String locale, String timezone) throws SQLException {
SimpleDateFormat dateFormat = getDateFormat(format, locale, timezone); SimpleDateFormat dateFormat = getDateFormat(format, locale, timezone);
try { try {
synchronized(dateFormat) {
return dateFormat.parse(date); return dateFormat.parse(date);
}
} catch(ParseException e) { } catch(ParseException e) {
throw Message.getSQLException(Message.PARSE_ERROR_1, date); throw Message.getSQLException(Message.PARSE_ERROR_1, date);
} }
...@@ -396,6 +400,8 @@ public class StringUtils { ...@@ -396,6 +400,8 @@ public class StringUtils {
private static SimpleDateFormat getDateFormat(String format, String locale, String timezone) throws SQLException { private static SimpleDateFormat getDateFormat(String format, String locale, String timezone) throws SQLException {
try { try {
// currently, a new instance is create for each call
// however, could cache the last few instances
SimpleDateFormat df; SimpleDateFormat df;
if(locale == null) { if(locale == null) {
df = new SimpleDateFormat(format); df = new SimpleDateFormat(format);
......
...@@ -93,23 +93,12 @@ java -Xmx512m -Xrunhprof:cpu=samples,depth=8 org.h2.tools.RunScript -url jdbc:h2 ...@@ -93,23 +93,12 @@ java -Xmx512m -Xrunhprof:cpu=samples,depth=8 org.h2.tools.RunScript -url jdbc:h2
test.printSystem(); test.printSystem();
/* /*
Newletter, newsfeed hochladen
SimpleDateFormat must be synchronized externally
call cast(null as null)
h2 console: headless mode
h2 console system tray: menu item to open window h2 console system tray: menu item to open window
Set h2.indexNew to false Set h2.indexNew to false
16 > 2007-06-17
testHalt testHalt
support ~ dir
Mail http://sf.net/projects/samooha Mail http://sf.net/projects/samooha
java.lang.Exception: query was too quick; result: 0 time:968 java.lang.Exception: query was too quick; result: 0 time:968
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论