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

--no commit message

--no commit message
上级 476b0169
...@@ -35,6 +35,7 @@ Hypersonic SQL or HSQLDB. H2 is built from scratch. ...@@ -35,6 +35,7 @@ Hypersonic SQL or HSQLDB. H2 is built from scratch.
<h3>Version 1.0 (Current)</h3> <h3>Version 1.0 (Current)</h3>
<h3>Version 1.0 / TODO</h3><ul> <h3>Version 1.0 / TODO</h3><ul>
<li>Selecting a column using the syntax schemaName.tableName.columName did not work in all cases.
<li>Can now parse timestamps with timezone information (Z or +/-hh:mm) and dates before year 1. <li>Can now parse timestamps with timezone information (Z or +/-hh:mm) and dates before year 1.
However dates before year 1 are not formatted correctly (this is a Java problem). However dates before year 1 are not formatted correctly (this is a Java problem).
<li>When stopping the TCP server from an application and immediately afterwards staring it again <li>When stopping the TCP server from an application and immediately afterwards staring it again
......
...@@ -11,23 +11,24 @@ package org.h2.engine; ...@@ -11,23 +11,24 @@ package org.h2.engine;
* - System.out > trace messages * - System.out > trace messages
* *
* Release checklist * Release checklist
* - Run FindBugs
* - Update latest version in build.html: http://mirrors.ibiblio.org/pub/mirrors/maven2/com/h2database/h2/ * - Update latest version in build.html: http://mirrors.ibiblio.org/pub/mirrors/maven2/com/h2database/h2/
* - ant jarClient, check jar file size * - ant jarClient, check jar file size
* - try compiling with JDK 1.3, 1.4, 1.5 and 1.6 * - Compiling with JDK 1.3, 1.4, 1.5 and 1.6
* set path=C:\Programme\Java\jdk1.6.0\bin;%PATH% * set path=C:\Programme\Java\jdk1.6.0\bin;%PATH%
* - change FAQ (next release planned, known bugs) * - Change FAQ (next release planned, known bugs)
* - check version, change build number in Constants.java and build.xml * - Check version, change build number in Constants.java and build.xml
* - check code coverage * - Check code coverage
* - No " Message.getInternalError" (must be "throw Message.getInternalError") * - No " Message.getInternalError" (must be "throw Message.getInternalError")
* - No TODO in the docs * - No TODO in the docs
* - Run regression test with JDK 1.4 and 1.5 * - Run regression test with JDK 1.4 and 1.5
* - Change version(s) in performance.html; use latest versions of other databases * - Change version(s) in performance.html; use latest versions of other databases
* - Run 'ant benchmark' (with JDK 1.4 currently) * - Run 'ant benchmark' (with JDK 1.4 currently)
* - copy the benchmark results and update the performance page and diagram * - Copy the benchmark results and update the performance page and diagram
* (remove rows 2*open/close, 2*executed statement) * (remove rows 2*open/close, 2*executed statement)
* *
* - documentation: if there are new files, add them to MergeDocs * - Documentation: if there are new files, add them to MergeDocs
* - documentation: check if all javadoc files are in the index * - Documentation: check if all javadoc files are in the index
* - ant docs * - ant docs
* - PDF (15 min) * - PDF (15 min)
* - footer * - footer
...@@ -35,18 +36,18 @@ package org.h2.engine; ...@@ -35,18 +36,18 @@ package org.h2.engine;
* - tables (optimal size) * - tables (optimal size)
* - orphan control, page breaks * - orphan control, page breaks
* - table of contents * - table of contents
* - switch off auto-build * - Switch off auto-build
* - ant all * - ant all
* - make sure odbc files are the * - Make sure odbc files are the
* - make sure the pdf file is there * - Make sure the pdf file is there
* - make sure the build files are removed * - Make sure the build files are removed
* - ant zip * - ant zip
* - windows installer (nsis) * - Windows installer (nsis)
* - test * - Test
* - test the windows service * - Test the windows service
* - TestSystemExit * - TestSystemExit
* - test with hibernate * - Test with hibernate
* - scan for viruses * - Scan for viruses
* *
* - Send a mail to Google Groups * - Send a mail to Google Groups
* - newsletter: prepare, send (always send to BCC!!) * - newsletter: prepare, send (always send to BCC!!)
...@@ -185,7 +186,7 @@ public class Constants { ...@@ -185,7 +186,7 @@ public class Constants {
public static final int ALLOW_LITERALS_ALL = 2; public static final int ALLOW_LITERALS_ALL = 2;
public static final int DEFAULT_ALLOW_LITERALS = ALLOW_LITERALS_ALL; public static final int DEFAULT_ALLOW_LITERALS = ALLOW_LITERALS_ALL;
public static boolean AUTO_CONVERT_LOB_TO_FILES = true; public static final boolean AUTO_CONVERT_LOB_TO_FILES = true;
public static final boolean ALLOW_EMTPY_BTREE_PAGES = true; public static final boolean ALLOW_EMTPY_BTREE_PAGES = true;
public static final String CONN_URL_INTERNAL = "jdbc:default:connection"; public static final String CONN_URL_INTERNAL = "jdbc:default:connection";
public static final String CONN_URL_COLUMNLIST = "jdbc:columnlist:connection"; public static final String CONN_URL_COLUMNLIST = "jdbc:columnlist:connection";
...@@ -205,28 +206,28 @@ public class Constants { ...@@ -205,28 +206,28 @@ public class Constants {
// for testing only // for testing only
public static int CACHE_MIN_RECORDS = 16; public static int CACHE_MIN_RECORDS = 16;
public static int MIN_WRITE_DELAY = getIntSetting("h2.minWriteDelay", 5); public static final int MIN_WRITE_DELAY = getIntSetting("h2.minWriteDelay", 5);
public static boolean CHECK = getBooleanSetting("h2.check", true); public static boolean CHECK = getBooleanSetting("h2.check", true);
public static boolean CHECK2 = getBooleanSetting("h2.check2", false); public static final boolean CHECK2 = getBooleanSetting("h2.check2", false);
// TODO: also remove DataHandler.allocateObjectId, createTempFile when setting this to true and removing it // TODO: also remove DataHandler.allocateObjectId, createTempFile when setting this to true and removing it
public static boolean LOB_FILES_IN_DIRECTORIES = getBooleanSetting("h2.lobFilesInDirectories", false); public static final boolean LOB_FILES_IN_DIRECTORIES = getBooleanSetting("h2.lobFilesInDirectories", false);
public static int LOB_FILES_PER_DIRECTORY = getIntSetting("h2.lobFilesPerDirectory", 256); public static final int LOB_FILES_PER_DIRECTORY = getIntSetting("h2.lobFilesPerDirectory", 256);
public static boolean MULTI_THREADED_KERNEL = getBooleanSetting("h2.multiThreadedKernel", false); public static boolean MULTI_THREADED_KERNEL = getBooleanSetting("h2.multiThreadedKernel", false);
public static boolean RUN_FINALIZERS = getBooleanSetting("h2.runFinalizers", true); public static boolean RUN_FINALIZERS = getBooleanSetting("h2.runFinalizers", true);
public static boolean OPTIMIZE_MIN_MAX = getBooleanSetting("h2.optimizeMinMax", true); public static final boolean OPTIMIZE_MIN_MAX = getBooleanSetting("h2.optimizeMinMax", true);
public static boolean OPTIMIZE_IN = getBooleanSetting("h2.optimizeIn", true); public static final boolean OPTIMIZE_IN = getBooleanSetting("h2.optimizeIn", true);
public static int REDO_BUFFER_SIZE = getIntSetting("h2.redoBufferSize", 256 * 1024); public static final int REDO_BUFFER_SIZE = getIntSetting("h2.redoBufferSize", 256 * 1024);
public static boolean RECOMPILE_ALWAYS = getBooleanSetting("h2.recompileAlways", false); public static final boolean RECOMPILE_ALWAYS = getBooleanSetting("h2.recompileAlways", false);
public static boolean OPTIMIZE_SUBQUERY_CACHE = getBooleanSetting("h2.optimizeSubqueryCache", true); public static final boolean OPTIMIZE_SUBQUERY_CACHE = getBooleanSetting("h2.optimizeSubqueryCache", true);
public static boolean OVERFLOW_EXCEPTIONS = getBooleanSetting("h2.overflowExceptions", true); public static final boolean OVERFLOW_EXCEPTIONS = getBooleanSetting("h2.overflowExceptions", true);
public static boolean LOG_ALL_ERRORS = getBooleanSetting("h2.logAllErrors", false); public static final boolean LOG_ALL_ERRORS = getBooleanSetting("h2.logAllErrors", false);
public static String LOG_ALL_ERRORS_FILE = getStringSetting("h2.logAllErrorsFile", "h2errors.txt"); public static final String LOG_ALL_ERRORS_FILE = getStringSetting("h2.logAllErrorsFile", "h2errors.txt");
public static int SERVER_CACHED_OBJECTS = getIntSetting("h2.serverCachedObjects", 64); public static final int SERVER_CACHED_OBJECTS = getIntSetting("h2.serverCachedObjects", 64);
public static final int SERVER_SMALL_RESULTSET_SIZE = getIntSetting("h2.serverSmallResultSetSize", 100); public static final int SERVER_SMALL_RESULTSET_SIZE = getIntSetting("h2.serverSmallResultSetSize", 100);
public static final int EMERGENCY_SPACE_INITIAL = getIntSetting("h2.emergencySpaceInitial", 1 * 1024 * 1024); public static final int EMERGENCY_SPACE_INITIAL = getIntSetting("h2.emergencySpaceInitial", 1 * 1024 * 1024);
public static final int EMERGENCY_SPACE_MIN = getIntSetting("h2.emergencySpaceMin", 128 * 1024); public static final int EMERGENCY_SPACE_MIN = getIntSetting("h2.emergencySpaceMin", 128 * 1024);
......
...@@ -1314,7 +1314,7 @@ public class Database implements DataHandler { ...@@ -1314,7 +1314,7 @@ public class Database implements DataHandler {
return lockMode; return lockMode;
} }
public void setCloseDelay(int value) { public synchronized void setCloseDelay(int value) {
this.closeDelay = value; this.closeDelay = value;
} }
...@@ -1416,7 +1416,7 @@ public class Database implements DataHandler { ...@@ -1416,7 +1416,7 @@ public class Database implements DataHandler {
return ignoreCase; return ignoreCase;
} }
public void setDeleteFilesOnDisconnect(boolean b) { public synchronized void setDeleteFilesOnDisconnect(boolean b) {
this.deleteFilesOnDisconnect = b; this.deleteFilesOnDisconnect = b;
} }
......
...@@ -9,6 +9,7 @@ import java.util.HashMap; ...@@ -9,6 +9,7 @@ import java.util.HashMap;
import org.h2.command.Parser; import org.h2.command.Parser;
import org.h2.command.dml.Select; import org.h2.command.dml.Select;
import org.h2.engine.Constants;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.message.Message; import org.h2.message.Message;
...@@ -44,6 +45,7 @@ public class ExpressionColumn extends Expression { ...@@ -44,6 +45,7 @@ public class ExpressionColumn extends Expression {
public ExpressionColumn(Database database, Select select, String schemaName, String tableAlias, String columnName) { public ExpressionColumn(Database database, Select select, String schemaName, String tableAlias, String columnName) {
this.database = database; this.database = database;
this.select = select; this.select = select;
this.schemaName = schemaName;
this.tableAlias = tableAlias; this.tableAlias = tableAlias;
this.columnName = columnName; this.columnName = columnName;
} }
...@@ -58,7 +60,8 @@ public class ExpressionColumn extends Expression { ...@@ -58,7 +60,8 @@ public class ExpressionColumn extends Expression {
if(tableAlias != null) { if(tableAlias != null) {
sql = Parser.quoteIdentifier(tableAlias) + "." + sql; sql = Parser.quoteIdentifier(tableAlias) + "." + sql;
} }
if(schemaName != null) { if(schemaName != null && !schemaName.equals(Constants.SCHEMA_MAIN)) {
int todoTempSolution;
sql = Parser.quoteIdentifier(schemaName) + "." + sql; sql = Parser.quoteIdentifier(schemaName) + "." + sql;
} }
return sql; return sql;
......
...@@ -38,7 +38,7 @@ public class JdbcDataSource extends TraceObject implements XADataSource, DataSou ...@@ -38,7 +38,7 @@ public class JdbcDataSource extends TraceObject implements XADataSource, DataSou
private static final long serialVersionUID = 1288136338451857771L; private static final long serialVersionUID = 1288136338451857771L;
private transient JdbcDataSourceFactory factory; private transient JdbcDataSourceFactory factory = new JdbcDataSourceFactory();
private transient PrintWriter logWriter; private transient PrintWriter logWriter;
private int timeout; private int timeout;
private String user; private String user;
...@@ -46,7 +46,6 @@ public class JdbcDataSource extends TraceObject implements XADataSource, DataSou ...@@ -46,7 +46,6 @@ public class JdbcDataSource extends TraceObject implements XADataSource, DataSou
private String url; private String url;
public JdbcDataSource() { public JdbcDataSource() {
this.factory = new JdbcDataSourceFactory();
int id = getNextId(TraceObject.DATASOURCE); int id = getNextId(TraceObject.DATASOURCE);
setTrace(factory.getTrace(), TraceObject.DATASOURCE, id); setTrace(factory.getTrace(), TraceObject.DATASOURCE, id);
} }
......
...@@ -109,7 +109,7 @@ public class Sequence extends SchemaObject { ...@@ -109,7 +109,7 @@ public class Sequence extends SchemaObject {
// nothing to do // nothing to do
} }
public long getCurrentValue() { public synchronized long getCurrentValue() {
return value - increment; return value - increment;
} }
......
...@@ -18,6 +18,8 @@ import java.util.ArrayList; ...@@ -18,6 +18,8 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import org.h2.command.Parser; import org.h2.command.Parser;
import org.h2.engine.Constants; import org.h2.engine.Constants;
...@@ -303,13 +305,14 @@ public class Recover implements DataHandler { ...@@ -303,13 +305,14 @@ public class Recover implements DataHandler {
FileStore store = null; FileStore store = null;
int size = 0; int size = 0;
String n = fileName + (lobCompression ? ".comp" : "") + ".txt"; String n = fileName + (lobCompression ? ".comp" : "") + ".txt";
InputStream in = null;
try { try {
out = new FileOutputStream(n); out = new FileOutputStream(n);
textStorage = Database.isTextStorage(fileName, false); textStorage = Database.isTextStorage(fileName, false);
byte[] magic = Database.getMagic(textStorage); byte[] magic = Database.getMagic(textStorage);
store = FileStore.open(null, fileName, magic); store = FileStore.open(null, fileName, magic);
store.init(); store.init();
InputStream in = new BufferedInputStream(new FileStoreInputStream(store, this, lobCompression)); in = new BufferedInputStream(new FileStoreInputStream(store, this, lobCompression));
byte[] buffer = new byte[Constants.IO_BUFFER_SIZE]; byte[] buffer = new byte[Constants.IO_BUFFER_SIZE];
while(true) { while(true) {
int l = in.read(buffer); int l = in.read(buffer);
...@@ -326,6 +329,7 @@ public class Recover implements DataHandler { ...@@ -326,6 +329,7 @@ public class Recover implements DataHandler {
} }
} finally { } finally {
IOUtils.closeSilently(out); IOUtils.closeSilently(out);
IOUtils.closeSilently(in);
closeSilently(store); closeSilently(store);
} }
if(size == 0) { if(size == 0) {
...@@ -714,8 +718,9 @@ public class Recover implements DataHandler { ...@@ -714,8 +718,9 @@ public class Recover implements DataHandler {
writer.println(m.getSQL() + ";"); writer.println(m.getSQL() + ";");
} }
for(Iterator it = tableMap.keySet().iterator(); it.hasNext(); ) { for(Iterator it = tableMap.keySet().iterator(); it.hasNext(); ) {
Integer objectId = (Integer) it.next(); Map.Entry entry = (Entry) it.next();
String name = (String) tableMap.get(objectId); Integer objectId = (Integer) entry.getKey();
String name = (String) entry.getValue();
writer.println("INSERT INTO " + name +" SELECT * FROM O_" + objectId + ";"); writer.println("INSERT INTO " + name +" SELECT * FROM O_" + objectId + ";");
} }
for(Iterator it = objectIdSet.iterator(); it.hasNext(); ) { for(Iterator it = objectIdSet.iterator(); it.hasNext(); ) {
......
...@@ -21,6 +21,7 @@ import java.util.Iterator; ...@@ -21,6 +21,7 @@ import java.util.Iterator;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.util.JdbcUtils;
import org.h2.util.ScriptReader; import org.h2.util.ScriptReader;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
...@@ -215,18 +216,19 @@ public class RunScript { ...@@ -215,18 +216,19 @@ public class RunScript {
} }
private static void executeRunscript(String url, String user, String password, String fileName, String options) throws SQLException { private static void executeRunscript(String url, String user, String password, String fileName, String options) throws SQLException {
Connection conn = null;
Statement stat = null;
try { try {
org.h2.Driver.load(); org.h2.Driver.load();
Connection conn = DriverManager.getConnection(url, user, password); conn = DriverManager.getConnection(url, user, password);
Statement stat = conn.createStatement(); stat = conn.createStatement();
String sql = "RUNSCRIPT FROM '" + fileName + "' " + options; String sql = "RUNSCRIPT FROM '" + fileName + "' " + options;
try { stat.execute(sql);
stat.execute(sql);
} finally {
conn.close();
}
} catch (Exception e) { } catch (Exception e) {
throw Message.convert(e); throw Message.convert(e);
} finally {
JdbcUtils.closeSilently(stat);
JdbcUtils.closeSilently(conn);
} }
} }
......
...@@ -17,6 +17,7 @@ import org.h2.server.Service; ...@@ -17,6 +17,7 @@ import org.h2.server.Service;
import org.h2.server.TcpServer; import org.h2.server.TcpServer;
import org.h2.server.ftp.FtpServer; import org.h2.server.ftp.FtpServer;
import org.h2.server.web.WebServer; import org.h2.server.web.WebServer;
import org.h2.util.JdbcUtils;
import org.h2.util.MathUtils; import org.h2.util.MathUtils;
import org.h2.util.StartBrowser; import org.h2.util.StartBrowser;
...@@ -230,9 +231,11 @@ public class Server implements Runnable { ...@@ -230,9 +231,11 @@ public class Server implements Runnable {
throw Message.convert(e); throw Message.convert(e);
} }
for(int i=0; i<2; i++) { for(int i=0; i<2; i++) {
Connection conn = null;
PreparedStatement prep = null;
try { try {
Connection conn = DriverManager.getConnection("jdbc:h2:" + url + "/" + db, "sa", password); conn = DriverManager.getConnection("jdbc:h2:" + url + "/" + db, "sa", password);
PreparedStatement prep = conn.prepareStatement("CALL STOP_SERVER(?, ?, ?)"); prep = conn.prepareStatement("CALL STOP_SERVER(?, ?, ?)");
prep.setInt(1, port); prep.setInt(1, port);
prep.setString(2, password); prep.setString(2, password);
prep.setInt(3, force ? TcpServer.SHUTDOWN_FORCE : TcpServer.SHUTDOWN_NORMAL); prep.setInt(3, force ? TcpServer.SHUTDOWN_FORCE : TcpServer.SHUTDOWN_NORMAL);
...@@ -244,18 +247,15 @@ public class Server implements Runnable { ...@@ -244,18 +247,15 @@ public class Server implements Runnable {
} else { } else {
throw e; throw e;
} }
} finally {
try {
conn.close();
} catch(SQLException e) {
// ignore
}
} }
break; break;
} catch(SQLException e) { } catch(SQLException e) {
if(i == 1) { if(i == 1) {
throw e; throw e;
} }
} finally {
JdbcUtils.closeSilently(prep);
JdbcUtils.closeSilently(conn);
} }
} }
} }
...@@ -338,7 +338,8 @@ public class Server implements Runnable { ...@@ -338,7 +338,8 @@ public class Server implements Runnable {
private static void wait(int i) { private static void wait(int i) {
try { try {
// sleep at most 4096 ms // sleep at most 4096 ms
Thread.sleep(i * i); long sleep = (long)i * (long)i;
Thread.sleep(sleep);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// ignore // ignore
} }
......
...@@ -48,7 +48,7 @@ public class ByteUtils { ...@@ -48,7 +48,7 @@ public class ByteUtils {
public static byte[] convertStringToBytes(String s) throws SQLException { public static byte[] convertStringToBytes(String s) throws SQLException {
int len = s.length(); int len = s.length();
if (len < 0 || len % 2 == 1) { if (len % 2 != 0) {
throw Message.getSQLException(Message.HEX_STRING_ODD_1, s); throw Message.getSQLException(Message.HEX_STRING_ODD_1, s);
} }
len /= 2; len /= 2;
......
...@@ -233,7 +233,8 @@ public class FileUtils { ...@@ -233,7 +233,8 @@ public class FileUtils {
} }
try { try {
// sleep at most 256 ms // sleep at most 256 ms
Thread.sleep(i * i); long sleep = (long)i * (long)i;
Thread.sleep(sleep);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// ignore // ignore
} }
......
package org.h2.util; package org.h2.util;
import java.sql.Connection; import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
...@@ -26,4 +27,14 @@ public class JdbcUtils { ...@@ -26,4 +27,14 @@ public class JdbcUtils {
} }
} }
public static void closeSilently(ResultSet rs) {
if(rs != null) {
try {
rs.close();
} catch(SQLException e) {
// ignore
}
}
}
} }
...@@ -286,7 +286,7 @@ public abstract class TestBase { ...@@ -286,7 +286,7 @@ public abstract class TestBase {
for(int i=0; i<a.length(); i++) { for(int i=0; i<a.length(); i++) {
String s = a.substring(0, i); String s = a.substring(0, i);
if(!b.startsWith(s)) { if(!b.startsWith(s)) {
s = s.substring(0, i) + "<*>" + s.substring(i); a = a.substring(0, i) + "<*>" + a.substring(i);
break; break;
} }
} }
......
...@@ -16,8 +16,8 @@ public class BenchA implements Bench { ...@@ -16,8 +16,8 @@ public class BenchA implements Bench {
private Database db; private Database db;
private int branches; private int branches;
private int tellers = branches * 20; private int tellers;
private int accounts = branches * 100; private int accounts;
private int size; private int size;
private static final String FILLER = "abcdefghijklmnopqrstuvwxyz"; private static final String FILLER = "abcdefghijklmnopqrstuvwxyz";
......
...@@ -371,7 +371,7 @@ public class BenchCThread { ...@@ -371,7 +371,7 @@ public class BenchCThread {
rs.next(); rs.next();
rs.getString(1); // c_first rs.getString(1); // c_first
rs.getString(2); // c_middle rs.getString(2); // c_middle
c_last = rs.getString(3); rs.getString(3); // c_last
rs.getString(4); // c_street_1 rs.getString(4); // c_street_1
rs.getString(5); // c_street_2 rs.getString(5); // c_street_2
rs.getString(6); // c_city rs.getString(6); // c_city
...@@ -499,7 +499,7 @@ public class BenchCThread { ...@@ -499,7 +499,7 @@ public class BenchCThread {
rs.getBigDecimal(1); // c_balance rs.getBigDecimal(1); // c_balance
rs.getString(2); // c_first rs.getString(2); // c_first
rs.getString(3); // c_middle rs.getString(3); // c_middle
c_last = rs.getString(4); rs.getString(4); // c_last
rs.close(); rs.close();
} }
prep = prepare("SELECT MAX(O_ID) " prep = prepare("SELECT MAX(O_ID) "
......
...@@ -20,6 +20,7 @@ import java.util.StringTokenizer; ...@@ -20,6 +20,7 @@ import java.util.StringTokenizer;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.tools.Server; import org.h2.tools.Server;
import org.h2.util.JdbcUtils;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
class Database { class Database {
...@@ -129,7 +130,13 @@ class Database { ...@@ -129,7 +130,13 @@ class Database {
Connection conn = DriverManager.getConnection(url, user, password); Connection conn = DriverManager.getConnection(url, user, password);
if(url.startsWith("jdbc:derby:")) { if(url.startsWith("jdbc:derby:")) {
// Derby: use higher cache size // Derby: use higher cache size
conn.createStatement().execute("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.storage.pageSize', '8192')"); Statement stat = null;
try {
stat = conn.createStatement();
stat.execute("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.storage.pageSize', '8192')");
} finally {
JdbcUtils.closeSilently(stat);
}
} }
return conn; return conn;
} }
......
...@@ -10,10 +10,13 @@ import java.sql.Connection; ...@@ -10,10 +10,13 @@ import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Properties; import java.util.Properties;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.util.IOUtils;
import org.h2.util.JdbcUtils;
public class TestPerformance { public class TestPerformance {
...@@ -29,13 +32,20 @@ public class TestPerformance { ...@@ -29,13 +32,20 @@ public class TestPerformance {
} }
private void openResults(boolean init) throws Exception { private void openResults(boolean init) throws Exception {
Connection conn = getResultConnection(); Connection conn = null;
if(init) { Statement stat = null;
conn.createStatement().execute("DROP TABLE IF EXISTS RESULTS"); try {
conn = getResultConnection();
stat = conn.createStatement();
if(init) {
stat.execute("DROP TABLE IF EXISTS RESULTS");
}
stat.execute("CREATE TABLE IF NOT EXISTS RESULTS(TESTID INT, TEST VARCHAR, "
+ "UNIT VARCHAR, DBID INT, DB VARCHAR, RESULT VARCHAR)");
} finally {
JdbcUtils.closeSilently(stat);
JdbcUtils.closeSilently(conn);
} }
conn.createStatement().execute("CREATE TABLE IF NOT EXISTS RESULTS(TESTID INT, TEST VARCHAR, "
+ "UNIT VARCHAR, DBID INT, DB VARCHAR, RESULT VARCHAR)");
conn.close();
} }
private void test(String[] args) throws Exception { private void test(String[] args) throws Exception {
...@@ -84,42 +94,53 @@ public class TestPerformance { ...@@ -84,42 +94,53 @@ public class TestPerformance {
return; return;
} }
ArrayList results = ((Database)dbs.get(0)).getResults(); ArrayList results = ((Database)dbs.get(0)).getResults();
Connection conn = getResultConnection(); Connection conn = null;
PreparedStatement prep = conn.prepareStatement( PreparedStatement prep = null;
"INSERT INTO RESULTS(TESTID, TEST, UNIT, DBID, DB, RESULT) VALUES(?, ?, ?, ?, ?, ?)"); Statement stat = null;
for(int i=0; i<results.size(); i++) { PrintWriter writer = null;
Object[] res = (Object[])results.get(i); try {
prep.setInt(1, i); conn = getResultConnection();
prep.setString(2, res[0].toString()); stat = conn.createStatement();
prep.setString(3, res[1].toString()); prep = conn.prepareStatement(
for(int j=0; j<dbs.size(); j++) { "INSERT INTO RESULTS(TESTID, TEST, UNIT, DBID, DB, RESULT) VALUES(?, ?, ?, ?, ?, ?)");
Database db = (Database)dbs.get(j); for(int i=0; i<results.size(); i++) {
prep.setInt(4, db.getId()); Object[] res = (Object[])results.get(i);
prep.setString(5, db.getName()); prep.setInt(1, i);
ArrayList r = db.getResults(); prep.setString(2, res[0].toString());
Object[] v = (Object[])r.get(i); prep.setString(3, res[1].toString());
prep.setString(6, v[2].toString()); for(int j=0; j<dbs.size(); j++) {
prep.execute(); Database db = (Database)dbs.get(j);
prep.setInt(4, db.getId());
prep.setString(5, db.getName());
ArrayList r = db.getResults();
Object[] v = (Object[])r.get(i);
prep.setString(6, v[2].toString());
prep.execute();
}
} }
writer = new PrintWriter(new FileWriter(out));
ResultSet rs = stat.executeQuery(
"CALL '<table><tr><th>Test Case</th><th>Unit</th>' "
+"|| SELECT GROUP_CONCAT('<th>' || DB || '</th>' ORDER BY DBID SEPARATOR '') FROM "
+"(SELECT DISTINCT DBID, DB FROM RESULTS)"
+"|| '</tr>' || CHAR(10) "
+"|| SELECT GROUP_CONCAT('<tr><td>' || TEST || '</td><td>' || UNIT || '</td>' || ( "
+"SELECT GROUP_CONCAT('<td>' || RESULT || '</td>' ORDER BY DBID SEPARATOR '') FROM RESULTS R2 WHERE "
+"R2.TESTID = R1.TESTID) || '</tr>' ORDER BY TESTID SEPARATOR CHAR(10)) FROM "
+"(SELECT DISTINCT TESTID, TEST, UNIT FROM RESULTS) R1"
+"|| '</table>'"
);
rs.next();
String result = rs.getString(1);
writer.println(result);
} finally {
JdbcUtils.closeSilently(prep);
JdbcUtils.closeSilently(stat);
JdbcUtils.closeSilently(conn);
IOUtils.closeSilently(writer);
} }
PrintWriter writer = new PrintWriter(new FileWriter(out));
ResultSet rs = conn.createStatement().executeQuery(
"CALL '<table><tr><th>Test Case</th><th>Unit</th>' "
+"|| SELECT GROUP_CONCAT('<th>' || DB || '</th>' ORDER BY DBID SEPARATOR '') FROM "
+"(SELECT DISTINCT DBID, DB FROM RESULTS)"
+"|| '</tr>' || CHAR(10) "
+"|| SELECT GROUP_CONCAT('<tr><td>' || TEST || '</td><td>' || UNIT || '</td>' || ( "
+"SELECT GROUP_CONCAT('<td>' || RESULT || '</td>' ORDER BY DBID SEPARATOR '') FROM RESULTS R2 WHERE "
+"R2.TESTID = R1.TESTID) || '</tr>' ORDER BY TESTID SEPARATOR CHAR(10)) FROM "
+"(SELECT DISTINCT TESTID, TEST, UNIT FROM RESULTS) R1"
+"|| '</table>'"
);
rs.next();
String result = rs.getString(1);
writer.println(result);
conn.close();
// ResultSet rsDbs = conn.createStatement().executeQuery("SELECT DB RESULTS GROUP BY DBID, DB ORDER BY DBID"); // ResultSet rsDbs = conn.createStatement().executeQuery("SELECT DB RESULTS GROUP BY DBID, DB ORDER BY DBID");
// while(rsDbs.next()) { // while(rsDbs.next()) {
// writer.println("<th>" + rsDbs.getString(1) + "</th>"); // writer.println("<th>" + rsDbs.getString(1) + "</th>");
...@@ -154,7 +175,6 @@ public class TestPerformance { ...@@ -154,7 +175,6 @@ public class TestPerformance {
// } // }
// writer.println("</table>"); // writer.println("</table>");
writer.close();
System.out.println("Test finished"); System.out.println("Test finished");
System.exit(0); System.exit(0);
} }
......
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.cases;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.h2.tools.Csv;
public class TestCloseAtShutdown extends Thread {
Connection conn;
TestCloseAtShutdown() {
Csv csv = null;
csv.setFieldSeparatorWrite(";");
}
public void run() {
try {
Thread.sleep(100);
} catch(Exception e) {
// ignore
}
System.out.println("hook app");
try {
conn.getAutoCommit();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
Class.forName("org.h2.Driver");
TestCloseAtShutdown closer = new TestCloseAtShutdown();
Runtime.getRuntime().addShutdownHook(closer);
Connection conn = DriverManager.getConnection("jdbc:h2:test2;TRACE_LEVEL_FILE=3;DB_CLOSE_ON_EXIT=FALSE", "sa", "sa");
closer.conn = conn;
conn.getAutoCommit();
}
}
...@@ -87,6 +87,7 @@ public class Coverage { ...@@ -87,6 +87,7 @@ public class Coverage {
c.processAll(); c.processAll();
c.data.close(); c.data.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
} }
} }
...@@ -154,8 +155,6 @@ public class Coverage { ...@@ -154,8 +155,6 @@ public class Coverage {
} }
File f = new File(name); File f = new File(name);
File fnew = new File(name + ".new"); File fnew = new File(name + ".new");
String key = name;
key = key.replace('\\', '.');
try { try {
writer = new BufferedWriter(new FileWriter(fnew)); writer = new BufferedWriter(new FileWriter(fnew));
Reader r = new BufferedReader(new FileReader(f)); Reader r = new BufferedReader(new FileReader(f));
......
...@@ -9,6 +9,8 @@ import java.io.FileReader; ...@@ -9,6 +9,8 @@ import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import org.h2.util.IOUtils;
/** /**
* The class used at runtime to measure the code usage and performance. * The class used at runtime to measure the code usage and performance.
*/ */
...@@ -16,8 +18,8 @@ public class Profile extends Thread { ...@@ -16,8 +18,8 @@ public class Profile extends Thread {
public static final boolean LIST_UNVISITED = true; public static final boolean LIST_UNVISITED = true;
public static final boolean FAST = false; public static final boolean FAST = false;
public static final boolean TRACE = false; public static final boolean TRACE = false;
public static final Profile main = new Profile();
public static int current; public static int current;
public static Profile main = new Profile();
private BufferedWriter trace; private BufferedWriter trace;
public int[] count; public int[] count;
public int[] time; public int[] time;
...@@ -74,11 +76,12 @@ public class Profile extends Thread { ...@@ -74,11 +76,12 @@ public class Profile extends Thread {
} }
Profile() { Profile() {
FileReader reader = null;
try { try {
LineNumberReader r = new LineNumberReader(new FileReader( reader = new FileReader("profile.txt");
"profile.txt")); LineNumberReader r = new LineNumberReader(reader);
while (r.readLine() != null) { while (r.readLine() != null) {
// nothing // nothing - just count lines
} }
maxIndex = r.getLineNumber(); maxIndex = r.getLineNumber();
count = new int[maxIndex]; count = new int[maxIndex];
...@@ -88,6 +91,8 @@ public class Profile extends Thread { ...@@ -88,6 +91,8 @@ public class Profile extends Thread {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
System.exit(1); System.exit(1);
} finally {
IOUtils.closeSilently(reader);
} }
} }
...@@ -115,28 +120,36 @@ public class Profile extends Thread { ...@@ -115,28 +120,36 @@ public class Profile extends Thread {
printLine('='); printLine('=');
print("NOT COVERED"); print("NOT COVERED");
printLine('-'); printLine('-');
LineNumberReader r = new LineNumberReader(new FileReader("profile.txt")); FileReader reader = null;
BufferedWriter writer = new BufferedWriter(new FileWriter("notcovered.txt")); FileWriter fwriter = null;
int unvisited = 0; try {
int unvisitedthrow = 0; reader = new FileReader("profile.txt");
for (int i = 0; i < maxIndex; i++) { LineNumberReader r = new LineNumberReader(reader);
String line = r.readLine(); fwriter = new FileWriter("notcovered.txt");
if (count[i] == 0) { BufferedWriter writer = new BufferedWriter(fwriter);
if (!line.endsWith("throw")) { int unvisited = 0;
writer.write(line + "\r\n"); int unvisitedthrow = 0;
if(LIST_UNVISITED) { for (int i = 0; i < maxIndex; i++) {
print(line+"\r\n"); String line = r.readLine();
if (count[i] == 0) {
if (!line.endsWith("throw")) {
writer.write(line + "\r\n");
if(LIST_UNVISITED) {
print(line+"\r\n");
}
unvisited++;
} else {
unvisitedthrow++;
} }
unvisited++;
} else {
unvisitedthrow++;
} }
} }
int percent = (100 * unvisited / maxIndex);
print("Not covered: " + percent + " % " + " (" + unvisited + " of "
+ maxIndex + "; throw=" + unvisitedthrow + ")");
} finally {
IOUtils.closeSilently(fwriter);
IOUtils.closeSilently(reader);
} }
writer.close();
int percent = (100 * unvisited / maxIndex);
print("Not covered: " + percent + " % " + " (" + unvisited + " of "
+ maxIndex + "; throw=" + unvisitedthrow + ")");
} }
void listTop(String title, int[] list, int max) throws Exception { void listTop(String title, int[] list, int max) throws Exception {
...@@ -171,23 +184,29 @@ public class Profile extends Thread { ...@@ -171,23 +184,29 @@ public class Profile extends Thread {
list[bigIndex] = -(big + 1); list[bigIndex] = -(big + 1);
index[i] = bigIndex; index[i] = bigIndex;
} }
LineNumberReader r = new LineNumberReader(new FileReader("profile.txt")); FileReader reader = null;
for (int i = 0; i < maxIndex; i++) { try {
String line = r.readLine(); reader = new FileReader("profile.txt");
int k = list[i]; LineNumberReader r = new LineNumberReader(reader);
if (k < 0) { for (int i = 0; i < maxIndex; i++) {
k = -(k + 1); String line = r.readLine();
list[i] = k; int k = list[i];
for (int j = 0; j < max; j++) { if (k < 0) {
if (index[j] == i) { k = -(k + 1);
int percent = (100 * k / total); list[i] = k;
text[j] = k + " " + percent + "%: " + line; for (int j = 0; j < max; j++) {
if (index[j] == i) {
int percent = (100 * k / total);
text[j] = k + " " + percent + "%: " + line;
}
} }
} }
} }
} for (int i = 0; i < max; i++) {
for (int i = 0; i < max; i++) { print(text[i]);
print(text[i]); }
} finally {
IOUtils.closeSilently(reader);
} }
} }
......
...@@ -1725,15 +1725,13 @@ select "PUBLIC".test."ID" from test; ...@@ -1725,15 +1725,13 @@ select "PUBLIC".test."ID" from test;
> -- > --
> rows: 0 > rows: 0
select "PUBLIC"."TEST"."ID" from test; select public."TEST"."ID" from test;
> ID > ID
> -- > --
> rows: 0 > rows: 0
select "public"."TEST"."ID" from test; select "public"."TEST"."ID" from test;
> ID > exception
> --
> rows: 0
drop table test; drop table test;
> ok > ok
......
create schema a;
create table a.test(id int);
insert into a.test values(1);
create schema b;
create table b.test(id int);
insert into b.test values(2);
select a.test.id + b.test.id from a.test, b.test;
> 3;
drop schema a;
drop schema b;
select date '+0011-01-01'; select date '+0011-01-01';
> 0011-01-01; > 0011-01-01;
select date'-0010-01-01'; select date'-0010-01-01';
......
...@@ -18,6 +18,7 @@ import org.h2.bnf.Bnf; ...@@ -18,6 +18,7 @@ import org.h2.bnf.Bnf;
import org.h2.server.web.PageParser; import org.h2.server.web.PageParser;
import org.h2.tools.indexer.Indexer; import org.h2.tools.indexer.Indexer;
import org.h2.util.IOUtils; import org.h2.util.IOUtils;
import org.h2.util.JdbcUtils;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
public class GenerateDoc { public class GenerateDoc {
...@@ -80,22 +81,27 @@ public class GenerateDoc { ...@@ -80,22 +81,27 @@ public class GenerateDoc {
} }
void map(String key, String sql) throws Exception { void map(String key, String sql) throws Exception {
ResultSet rs = conn.createStatement().executeQuery(sql); ResultSet rs = null;
ArrayList list = new ArrayList(); try {
while(rs.next()) { rs = conn.createStatement().executeQuery(sql);
HashMap map = new HashMap(); ArrayList list = new ArrayList();
ResultSetMetaData meta = rs.getMetaData(); while(rs.next()) {
for(int i=0; i<meta.getColumnCount(); i++) { HashMap map = new HashMap();
String k = StringUtils.toLowerEnglish(meta.getColumnLabel(i+1)); ResultSetMetaData meta = rs.getMetaData();
String value = rs.getString(i+1); for(int i=0; i<meta.getColumnCount(); i++) {
map.put(k, PageParser.escapeHtml(value)); String k = StringUtils.toLowerEnglish(meta.getColumnLabel(i+1));
String value = rs.getString(i+1);
map.put(k, PageParser.escapeHtml(value));
}
String topic = rs.getString("TOPIC");
String syntax = rs.getString("SYNTAX");
syntax = bnf.getSyntax(topic, syntax);
map.put("syntax", PageParser.escapeHtml(syntax));
list.add(map);
} }
String topic = rs.getString("TOPIC"); session.put(key, list);
String syntax = rs.getString("SYNTAX"); } finally {
syntax = bnf.getSyntax(topic, syntax); JdbcUtils.closeSilently(rs);
map.put("syntax", PageParser.escapeHtml(syntax));
list.add(map);
} }
session.put(key, list);
} }
} }
...@@ -168,7 +168,7 @@ public class Indexer { ...@@ -168,7 +168,7 @@ public class Indexer {
return; return;
} }
if(!noIndex.contains(fileName)) { if(!noIndex.contains(fileName)) {
page = new Page(pages.size(), fileName, name); page = new Page(pages.size(), fileName);
pages.add(page); pages.add(page);
readPage(file); readPage(file);
} }
......
...@@ -8,16 +8,14 @@ package org.h2.tools.indexer; ...@@ -8,16 +8,14 @@ package org.h2.tools.indexer;
public class Page { public class Page {
int id; int id;
String fileName; String fileName;
String name;
String title; String title;
// TODO page.totalWeight is currently not used // TODO page.totalWeight is currently not used
int totalWeight; int totalWeight;
int relations; int relations;
Page(int id, String fileName, String name) { Page(int id, String fileName) {
this.id = id; this.id = id;
this.fileName = fileName; this.fileName = fileName;
this.name = name;
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论