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

Remove unused code.

上级 75e1a835
......@@ -18,7 +18,10 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>The database URL option ACCESS_MODE_LOG is no longer supported.
<ul><li>Tools: the method run(String... args) has been renamed to runTool(String... args)
so it can't be confused with run().
</li><li>Server.startWebServer(Connection) was not working as expected.
</li><li>The database URL option ACCESS_MODE_LOG is no longer supported.
</li><li>The database URL option RECOVER has currently no effect.
</li><li>Converting an old (non-page store) database is no longer supported using this version.
</li><li>The system property "h2.overflowExceptions" is no longer supported.
......
......@@ -3510,7 +3510,7 @@ public class Parser {
} else if (readIf("TABLE")) {
int defaultMode;
Setting setting = database.findSetting(SetTypes.getTypeName(SetTypes.DEFAULT_TABLE_TYPE));
defaultMode = setting == null ? Constants.DEFAULT_TABLE_TYPE : setting.getIntValue();
defaultMode = setting == null ? Table.TYPE_CACHED : setting.getIntValue();
return parseCreateTable(false, false, defaultMode == Table.TYPE_CACHED);
} else if (readIf("VIEW")) {
return parseCreateView(force);
......
......@@ -8,7 +8,6 @@ package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.command.Prepared;
import org.h2.engine.Constants;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.result.ResultInterface;
......@@ -23,7 +22,11 @@ import org.h2.util.StatementBuilder;
*/
public class Analyze extends DefineCommand {
private int sampleRows = Constants.SELECTIVITY_ANALYZE_SAMPLE_ROWS;
/**
* The sample size.
* The default value is also in the documentation.
*/
private int sampleRows = 10000;
public Analyze(Session session) {
super(session);
......
......@@ -38,6 +38,11 @@ import org.h2.value.Value;
*/
public abstract class ScriptBase extends Prepared implements DataHandler {
/**
* The default name of the script file if .zip compression is used.
*/
private static final String SCRIPT_SQL = "script.sql";
/**
* The output stream.
*/
......@@ -130,7 +135,7 @@ public abstract class ScriptBase extends Prepared implements DataHandler {
} else {
OutputStream o = FileUtils.openFileOutputStream(file, false);
out = new BufferedOutputStream(o, Constants.IO_BUFFER_SIZE);
out = CompressTool.wrapOutputStream(out, compressionAlgorithm, Constants.SCRIPT_SQL);
out = CompressTool.wrapOutputStream(out, compressionAlgorithm, SCRIPT_SQL);
}
}
......@@ -153,9 +158,9 @@ public abstract class ScriptBase extends Prepared implements DataHandler {
throw Message.convertIOException(e, file);
}
in = new BufferedInputStream(inStream, Constants.IO_BUFFER_SIZE);
in = CompressTool.wrapInputStream(in, compressionAlgorithm, Constants.SCRIPT_SQL);
in = CompressTool.wrapInputStream(in, compressionAlgorithm, SCRIPT_SQL);
if (in == null) {
throw Message.getSQLException(ErrorCode.FILE_NOT_FOUND_1, Constants.SCRIPT_SQL + " in " + file);
throw Message.getSQLException(ErrorCode.FILE_NOT_FOUND_1, SCRIPT_SQL + " in " + file);
}
}
}
......
......@@ -55,11 +55,6 @@ public class Constants {
*/
public static final int VERSION_MINOR = 2;
/**
* The version number (major.minor) of this database.
*/
public static final double VERSION = VERSION_MAJOR + VERSION_MINOR / 10.;
/**
* Constant meaning both numbers and text is allowed in SQL statements.
*/
......@@ -76,27 +71,11 @@ public class Constants {
*/
public static final int ALLOW_LITERALS_NUMBERS = 1;
/**
* Automatically convert large LOB objects to files even if they have been
* set using setBytes.
*/
public static final boolean AUTO_CONVERT_LOB_TO_FILES = true;
/**
* The maximum scale of a BigDecimal value.
*/
public static final int BIG_DECIMAL_SCALE_MAX = 100000;
/**
* The minimum number of entries to keep in the cache.
*/
public static final int CACHE_MIN_RECORDS = 16;
/**
* The name of the character set used in this database.
*/
public static final String CHARACTER_SET_NAME = "Unicode";
/**
* The value of the cluster setting if clustering is disabled.
*/
......@@ -121,45 +100,18 @@ public class Constants {
*/
public static final int COST_ROW_OFFSET = 1000;
/**
* The default name of the system user. This name is only used as long as
* there is no administrator user registered.
*/
public static final String DBA_NAME = "DBA";
/**
* The number of milliseconds after which to check for a deadlock if locking
* is not successful.
*/
public static final int DEADLOCK_CHECK = 100;
/**
* The default value of the ALLOW_LITERALS setting
*/
public static final int DEFAULT_ALLOW_LITERALS = ALLOW_LITERALS_ALL;
/**
* The default data page size.
*/
public static final int DEFAULT_DATA_PAGE_SIZE = 512;
/**
* If the HTTP server should allow connections from other computers by
* default.
*/
public static final boolean DEFAULT_HTTP_ALLOW_OTHERS = false;
/**
* The default port number of the HTTP server (for the H2 Console).
* This value is also in the documentation and in the Server javadoc.
*/
public static final int DEFAULT_HTTP_PORT = 8082;
/**
* The default SSL setting for the HTTP server.
*/
public static final boolean DEFAULT_HTTP_SSL = false;
/**
* The default value for the maximum log file size.
*/
......@@ -178,25 +130,15 @@ public class Constants {
/**
* The default port of the TCP server.
* This port is also used in the documentation.
* This port is also used in the documentation and in the Server javadoc.
*/
public static final int DEFAULT_SERVER_PORT = 9092;
/**
* The default table type when creating new tables.
*/
public static final int DEFAULT_TABLE_TYPE = 0;
public static final int DEFAULT_TCP_PORT = 9092;
/**
* The default delay in milliseconds before the log file is written.
*/
public static final int DEFAULT_WRITE_DELAY = 500;
/**
* The name of the JDBC driver.
*/
public static final String DRIVER_NAME = "H2 JDBC Driver";
/**
* The password is hashed this many times
* to slow down dictionary attacks.
......@@ -204,25 +146,10 @@ public class Constants {
public static final int ENCRYPTION_KEY_HASH_ITERATIONS = 1024;
/**
* The 'word size' of a file (the minimum allocation size).
* The block of a file. It is also the encryption block size.
*/
public static final int FILE_BLOCK_SIZE = 16;
/**
* The maximum number of bytes a file should be expanded in one step.
*/
public static final int FILE_MAX_INCREMENT = 32 * 1024 * 1024;
/**
* The minimum file size in bytes.
*/
public static final int FILE_MIN_SIZE = 128 * 1024;
/**
* The page size of a file.
*/
public static final int FILE_PAGE_SIZE = 8 * 1024;
/**
* For testing, the lock timeout is smaller than for interactive use cases.
* This value could be increased to about 5 or 10 seconds.
......@@ -269,28 +196,6 @@ public class Constants {
*/
public static final int LOCK_SLEEP = 1000;
/**
* The file header used for binary files.
*/
public static final String MAGIC_FILE_HEADER = "-- H2 0.5/B -- ".substring(0, FILE_BLOCK_SIZE - 1) + "\n";
/**
* If old text file headers should be supported. This setting can be removed
* in future versions (required for compatibility with version 1.1.103).
*/
public static final boolean MAGIC_FILE_HEADER_SUPPORT_TEXT = true;
/**
* The name of the in-memory management database used by the TCP server
* to keep the active sessions.
*/
public static final String MANAGEMENT_DB_PREFIX = "management_db_";
/**
* The user name of the management database.
*/
public static final String MANAGEMENT_DB_USER = "sa";
/**
* The highest possible parameter index.
*/
......@@ -317,37 +222,16 @@ public class Constants {
*/
public static final String PREFIX_PRIMARY_KEY = "PRIMARY_KEY_";
/**
* The product name. This value must stay like that, see
* http://opensource.atlassian.com/projects/hibernate/browse/HHH-2682
*/
public static final String PRODUCT_NAME = "H2";
/**
* Every user belongs to this role.
*/
public static final String PUBLIC_ROLE_NAME = "PUBLIC";
/**
* The name of the schema that contains the information schema tables.
*/
public static final String SCHEMA_INFORMATION = "INFORMATION_SCHEMA";
/**
* The name of the default schema.
*/
public static final String SCHEMA_MAIN = "PUBLIC";
/**
* The default name of the script file if .zip compression is used.
*/
public static final String SCRIPT_SQL = "script.sql";
/**
* The default sample size for the ANALYZE statement.
*/
public static final int SELECTIVITY_ANALYZE_SAMPLE_ROWS = 10000;
/**
* The default selectivity (used if the selectivity is not calculated).
*/
......@@ -363,11 +247,6 @@ public class Constants {
*/
public static final String SERVER_PROPERTIES_FILE = ".h2.server.properties";
/**
* The title of the server properties file.
*/
public static final String SERVER_PROPERTIES_TITLE = "H2 Server Properties";
/**
* Queries that take longer than this number of milliseconds are written to
* the trace file with the level info.
......@@ -411,11 +290,6 @@ public class Constants {
*/
public static final String SUFFIX_TRACE_FILE = ".trace.db";
/**
* The table name suffix used to create internal temporary tables.
*/
public static final String TEMP_TABLE_PREFIX = "TEMP_TABLE_";
/**
* The delay that is to be used if throttle has been enabled.
*/
......
......@@ -78,6 +78,12 @@ public class Database implements DataHandler {
private static int initialPowerOffCount;
/**
* The default name of the system user. This name is only used as long as
* there is no administrator user registered.
*/
private static final String SYSTEM_USER_NAME = "DBA";
private final boolean persistent;
private final String databaseName;
private final String databaseShortName;
......@@ -127,7 +133,7 @@ public class Database implements DataHandler {
private int maxMemoryUndo = SysProperties.DEFAULT_MAX_MEMORY_UNDO;
private int lockMode = SysProperties.DEFAULT_LOCK_MODE;
private int maxLengthInplaceLob = SysProperties.DEFAULT_MAX_LENGTH_INPLACE_LOB;
private int allowLiterals = Constants.DEFAULT_ALLOW_LITERALS;
private int allowLiterals = Constants.ALLOW_LITERALS_ALL;
private int powerOffCount = initialPowerOffCount;
private int closeDelay;
......@@ -544,9 +550,9 @@ public class Database implements DataHandler {
traceSystem = new TraceSystem(null);
log = new LogSystem(null, false, null);
}
systemUser = new User(this, 0, Constants.DBA_NAME, true);
systemUser = new User(this, 0, SYSTEM_USER_NAME, true);
mainSchema = new Schema(this, 0, Constants.SCHEMA_MAIN, systemUser, true);
infoSchema = new Schema(this, -1, Constants.SCHEMA_INFORMATION, systemUser, true);
infoSchema = new Schema(this, -1, "INFORMATION_SCHEMA", systemUser, true);
schemas.put(mainSchema.getName(), mainSchema);
schemas.put(infoSchema.getName(), infoSchema);
publicRole = new Role(this, 0, Constants.PUBLIC_ROLE_NAME, true);
......@@ -581,13 +587,13 @@ public class Database implements DataHandler {
Cursor cursor = metaIdIndex.find(systemSession, null, null);
// first, create all function aliases and sequences because
// they might be used in create table / view / constraints and so on
ObjectArray<MetaRecord> records = ObjectArray.newInstance();
ArrayList<MetaRecord> records = New.arrayList();
while (cursor.next()) {
MetaRecord rec = new MetaRecord(cursor.get());
objectIds.set(rec.getId());
records.add(rec);
}
MetaRecord.sort(records);
Collections.sort(records);
for (MetaRecord rec : records) {
rec.execute(this, systemSession, eventListener);
}
......@@ -595,7 +601,7 @@ public class Database implements DataHandler {
recompileInvalidViews(systemSession);
starting = false;
addDefaultSetting(systemSession, SetTypes.DEFAULT_LOCK_TIMEOUT, null, Constants.INITIAL_LOCK_TIMEOUT);
addDefaultSetting(systemSession, SetTypes.DEFAULT_TABLE_TYPE, null, Constants.DEFAULT_TABLE_TYPE);
addDefaultSetting(systemSession, SetTypes.DEFAULT_TABLE_TYPE, null, Table.TYPE_CACHED);
addDefaultSetting(systemSession, SetTypes.CACHE_SIZE, null, SysProperties.CACHE_SIZE_DEFAULT);
addDefaultSetting(systemSession, SetTypes.CLUSTER, Constants.CLUSTERING_DISABLED, 0);
addDefaultSetting(systemSession, SetTypes.WRITE_DELAY, null, Constants.DEFAULT_WRITE_DELAY);
......@@ -805,7 +811,7 @@ public class Database implements DataHandler {
HashMap<String, DbObject> map = getMap(obj.getType());
if (obj.getType() == DbObject.USER) {
User user = (User) obj;
if (user.isAdmin() && systemUser.getName().equals(Constants.DBA_NAME)) {
if (user.isAdmin() && systemUser.getName().equals(SYSTEM_USER_NAME)) {
systemUser.rename(user.getName());
}
}
......@@ -1595,7 +1601,7 @@ public class Database implements DataHandler {
public synchronized String getTempTableName(Session session) {
String tempName;
do {
tempName = Constants.TEMP_TABLE_PREFIX + session.getId() + "_" + nextTempTableId++;
tempName = "TEMP_TABLE_" + session.getId() + "_" + nextTempTableId++;
} while (mainSchema.findTableOrView(session, tempName) != null);
return tempName;
}
......
......@@ -7,13 +7,11 @@
package org.h2.engine;
import java.sql.SQLException;
import java.util.Comparator;
import org.h2.api.DatabaseEventListener;
import org.h2.command.Prepared;
import org.h2.message.Message;
import org.h2.message.Trace;
import org.h2.result.SearchRow;
import org.h2.util.ObjectArray;
import org.h2.value.ValueInt;
import org.h2.value.ValueString;
......@@ -21,7 +19,7 @@ import org.h2.value.ValueString;
* A record in the system table of the database.
* It contains the SQL statement to create the database object.
*/
public class MetaRecord {
public class MetaRecord implements Comparable<MetaRecord> {
private int id;
private int objectType;
......@@ -39,24 +37,6 @@ public class MetaRecord {
sql = obj.getCreateSQL();
}
/**
* Sort the list of meta records by 'create order'.
*
* @param records the list of meta records
*/
public static void sort(ObjectArray<MetaRecord> records) {
records.sort(new Comparator<MetaRecord>() {
public int compare(MetaRecord m1, MetaRecord m2) {
int c1 = DbObjectBase.getCreateOrder(m1.getObjectType());
int c2 = DbObjectBase.getCreateOrder(m2.getObjectType());
if (c1 != c2) {
return c1 - c2;
}
return m1.getId() - m2.getId();
}
});
}
void setRecord(SearchRow r) {
r.setValue(0, ValueInt.get(id));
r.setValue(1, ValueInt.get(0));
......@@ -101,4 +81,19 @@ public class MetaRecord {
return sql;
}
/**
* Sort the list of meta records by 'create order'.
*
* @param other the other record
* @return -1, 0, or 1
*/
public int compareTo(MetaRecord other) {
int c1 = DbObjectBase.getCreateOrder(getObjectType());
int c2 = DbObjectBase.getCreateOrder(other.getObjectType());
if (c1 != c2) {
return c1 - c2;
}
return getId() - other.getId();
}
}
......@@ -91,7 +91,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
}
private Transfer initTransfer(ConnectionInfo ci, String db, String server) throws IOException, SQLException {
Socket socket = NetUtils.createSocket(server, Constants.DEFAULT_SERVER_PORT, ci.isSSL());
Socket socket = NetUtils.createSocket(server, Constants.DEFAULT_TCP_PORT, ci.isSSL());
Transfer trans = new Transfer(this);
trans.setSocket(socket);
trans.setSSL(ci.isSSL());
......
......@@ -56,9 +56,9 @@ public class JdbcBlob extends TraceObject implements Blob {
long size = 0;
InputStream in = value.getInputStream();
try {
byte[] buff = new byte[Constants.FILE_BLOCK_SIZE];
byte[] buff = new byte[Constants.IO_BUFFER_SIZE];
while (true) {
int len = in.read(buff, 0, Constants.FILE_BLOCK_SIZE);
int len = in.read(buff, 0, Constants.IO_BUFFER_SIZE);
if (len <= 0) {
break;
}
......
......@@ -63,9 +63,9 @@ public class JdbcClob extends TraceObject implements Clob
Reader in = value.getReader();
try {
long size = 0;
char[] buff = new char[Constants.FILE_BLOCK_SIZE];
char[] buff = new char[Constants.IO_BUFFER_SIZE];
while (true) {
int len = in.read(buff, 0, Constants.FILE_BLOCK_SIZE);
int len = in.read(buff, 0, Constants.IO_BUFFER_SIZE);
if (len <= 0) {
break;
}
......
......@@ -58,11 +58,13 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
/**
* Gets the database product name.
*
* @return the product name
* @return the product name ("H2")
*/
public String getDatabaseProductName() {
debugCodeCall("getDatabaseProductName");
return Constants.PRODUCT_NAME;
// This value must stay like that, see
// http://opensource.atlassian.com/projects/hibernate/browse/HHH-2682
return "H2";
}
/**
......@@ -78,11 +80,11 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
/**
* Gets the name of the JDBC driver.
*
* @return the driver name
* @return the driver name ("H2 JDBC Driver")
*/
public String getDriverName() {
debugCodeCall("getDriverName");
return Constants.DRIVER_NAME;
return "H2 JDBC Driver";
}
/**
......
......@@ -62,13 +62,12 @@ import org.h2.message.Message;
* (<a href="http://www.source-code.biz">www.source-code.biz</a>)
* @author Thomas Mueller (ported to Java 1.4, some changes)
*/
public class JdbcConnectionPool implements DataSource {
public class JdbcConnectionPool implements DataSource, ConnectionEventListener {
private static final int DEFAULT_TIMEOUT = 5 * 60;
private final ConnectionPoolDataSource dataSource;
private final Stack<PooledConnection> recycledConnections = new Stack<PooledConnection>();
private final PoolConnectionEventListener poolConnectionEventListener = new PoolConnectionEventListener();
private PrintWriter logWriter;
private int maxConnections = 10;
private int timeout = DEFAULT_TIMEOUT;
......@@ -224,7 +223,7 @@ public class JdbcConnectionPool implements DataSource {
}
Connection conn = pc.getConnection();
activeConnections++;
pc.addConnectionEventListener(poolConnectionEventListener);
pc.addConnectionEventListener(this);
return conn;
}
......@@ -288,22 +287,22 @@ public class JdbcConnectionPool implements DataSource {
}
/**
* This event listener informs the connection pool that about closed and
* broken connections.
* INTERNAL
*/
class PoolConnectionEventListener implements ConnectionEventListener {
public void connectionClosed(ConnectionEvent event) {
PooledConnection pc = (PooledConnection) event.getSource();
pc.removeConnectionEventListener(this);
recycleConnection(pc);
}
/**
* INTERNAL
*/
public void connectionErrorOccurred(ConnectionEvent event) {
PooledConnection pc = (PooledConnection) event.getSource();
pc.removeConnectionEventListener(this);
disposeConnection(pc);
}
}
/**
* Returns the number of active (open) connections of this pool. This is the
......
......@@ -8,7 +8,6 @@ package org.h2.log;
import java.sql.SQLException;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.message.Message;
......@@ -124,7 +123,7 @@ public class UndoLog {
String fileName = database.createTempFile();
file = database.openFile(fileName, "rw", false);
file.seek(FileStore.HEADER_LENGTH);
rowBuff = Data.create(database, Constants.DEFAULT_DATA_PAGE_SIZE);
rowBuff = Data.create(database, SysProperties.PAGE_SIZE);
Data buff = rowBuff;
for (int i = 0; i < records.size(); i++) {
UndoLogRecord r = records.get(i);
......
......@@ -64,7 +64,7 @@ class ResultDiskBuffer implements ResultExternal {
this.sort = sort;
this.columnCount = columnCount;
Database db = session.getDatabase();
rowBuff = Data.create(db, Constants.DEFAULT_DATA_PAGE_SIZE);
rowBuff = Data.create(db, SysProperties.PAGE_SIZE);
String fileName = session.getDatabase().createTempFile();
file = session.getDatabase().openFile(fileName, "rw", false);
file.setCheckedWriting(false);
......
......@@ -90,7 +90,7 @@ public class RowList {
String fileName = db.createTempFile();
file = db.openFile(fileName, "rw", false);
file.seek(FileStore.HEADER_LENGTH);
rowBuff = Data.create(db, Constants.DEFAULT_DATA_PAGE_SIZE);
rowBuff = Data.create(db, SysProperties.PAGE_SIZE);
file.seek(FileStore.HEADER_LENGTH);
}
Data buff = rowBuff;
......
......@@ -41,15 +41,15 @@ import org.h2.util.New;
*/
public class TcpServer implements Service {
/**
* The default port to use for the TCP server.
* This value is also in the documentation and in the Server javadoc.
*/
public static final int DEFAULT_PORT = 9092;
private static final int SHUTDOWN_NORMAL = 0;
private static final int SHUTDOWN_FORCE = 1;
/**
* The name of the in-memory management database used by the TCP server
* to keep the active sessions.
*/
private static final String MANAGEMENT_DB_PREFIX = "management_db_";
private static final Map<Integer, TcpServer> SERVERS = Collections.synchronizedMap(new HashMap<Integer, TcpServer>());
private int port;
......@@ -77,7 +77,7 @@ public class TcpServer implements Service {
* @return the database name (usually starting with mem:)
*/
public static String getManagementDbName(int port) {
return "mem:" + Constants.MANAGEMENT_DB_PREFIX + port;
return "mem:" + MANAGEMENT_DB_PREFIX + port;
}
private void initManagementDb() throws SQLException {
......@@ -144,7 +144,7 @@ public class TcpServer implements Service {
}
public void init(String... args) {
port = DEFAULT_PORT;
port = Constants.DEFAULT_TCP_PORT;
for (int i = 0; args != null && i < args.length; i++) {
String a = args[i];
if ("-trace".equals(a)) {
......@@ -373,7 +373,7 @@ public class TcpServer implements Service {
* @param force if the server should be stopped immediately
*/
public static synchronized void shutdown(String url, String password, boolean force) throws SQLException {
int port = Constants.DEFAULT_SERVER_PORT;
int port = Constants.DEFAULT_TCP_PORT;
int idx = url.indexOf(':', "jdbc:h2:".length());
if (idx >= 0) {
String p = url.substring(idx + 1);
......
......@@ -6,6 +6,7 @@
*/
package org.h2.server.web;
import org.h2.util.MathUtils;
import org.h2.util.StringUtils;
/**
......@@ -13,7 +14,7 @@ import org.h2.util.StringUtils;
* such as the database URL, user name and password.
* This class is used by the H2 Console.
*/
public class ConnectionInfo {
public class ConnectionInfo implements Comparable<ConnectionInfo> {
/**
* The driver class name.
*/
......@@ -59,4 +60,8 @@ public class ConnectionInfo {
return StringUtils.arrayCombine(new String[] { name, driver, url, user }, '|');
}
public int compareTo(ConnectionInfo o) {
return MathUtils.compare(lastAccess, o.lastAccess);
}
}
......@@ -358,7 +358,7 @@ public class WebApp implements DatabaseEventListener {
PrintStream out = new PrintStream(outBuff, false, "UTF-8");
tool.setOut(out);
try {
tool.run(argList);
tool.runTool(argList);
out.flush();
String o = new String(outBuff.toByteArray(), "UTF-8");
String result = PageParser.escapeHtml(o);
......
......@@ -17,7 +17,6 @@ import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
......@@ -221,8 +220,8 @@ public class WebServer implements Service {
// TODO web: support using a different properties file
Properties prop = loadProperties();
port = SortedProperties.getIntProperty(prop, "webPort", Constants.DEFAULT_HTTP_PORT);
ssl = SortedProperties.getBooleanProperty(prop, "webSSL", Constants.DEFAULT_HTTP_SSL);
allowOthers = SortedProperties.getBooleanProperty(prop, "webAllowOthers", Constants.DEFAULT_HTTP_ALLOW_OTHERS);
ssl = SortedProperties.getBooleanProperty(prop, "webSSL", false);
allowOthers = SortedProperties.getBooleanProperty(prop, "webAllowOthers", false);
for (int i = 0; args != null && i < args.length; i++) {
String a = args[i];
if ("-webPort".equals(a)) {
......@@ -307,6 +306,10 @@ public class WebServer implements Service {
}
}
public boolean isStopped() {
return serverSocket == null;
}
public void stop() {
if (serverSocket != null) {
try {
......@@ -527,12 +530,7 @@ public class WebServer implements Service {
} else {
settings.addAll(connInfoMap.values());
}
Collections.sort(settings, new Comparator<ConnectionInfo>() {
public int compare(ConnectionInfo o1, ConnectionInfo o2) {
return MathUtils.compare(o2.lastAccess, o1.lastAccess);
}
}
);
Collections.sort(settings);
return settings;
}
......@@ -559,7 +557,7 @@ public class WebServer implements Service {
}
}
OutputStream out = FileUtils.openFileOutputStream(getPropertiesFileName(), false);
prop.store(out, Constants.SERVER_PROPERTIES_TITLE);
prop.store(out, "H2 Server Properties");
out.close();
} catch (Exception e) {
TraceSystem.traceThrowable(e);
......
......@@ -1027,7 +1027,6 @@ public class Data {
* until the size is a multiple of Constants.FILE_BLOCK_SIZE.
*/
public void fillAligned() {
// TODO datapage: fillAligned should not use a fixed constant '2'
// 0..6 > 8, 7..14 > 16, 15..22 > 24, ...
fill(MathUtils.roundUp(pos + 2, Constants.FILE_BLOCK_SIZE));
}
......
......@@ -35,7 +35,7 @@ import org.h2.value.Transfer;
* to it. It uses a cooperative locking protocol. Usually a .lock.db file is
* used, but locking by creating a socket is supported as well.
*/
public class FileLock {
public class FileLock implements Runnable {
/**
* This locking method means no locking is used at all.
......@@ -68,32 +68,32 @@ public class FileLock {
/**
* The lock file name.
*/
volatile String fileName;
private volatile String fileName;
/**
* The server socket (only used when using the SOCKET mode).
*/
volatile ServerSocket serverSocket;
private volatile ServerSocket serverSocket;
/**
* The file system.
*/
FileSystem fs;
private FileSystem fs;
/**
* The number of milliseconds to sleep after checking a file.
*/
int sleep;
private int sleep;
/**
* The trace object.
*/
Trace trace;
private Trace trace;
/**
* The last time the lock file was written.
*/
long lastWrite;
private long lastWrite;
private String method, ipAddress;
private Properties properties;
......@@ -220,7 +220,7 @@ public class FileLock {
boolean running = false;
String id = prop.getProperty("id");
try {
Socket socket = NetUtils.createSocket(server, Constants.DEFAULT_SERVER_PORT, false);
Socket socket = NetUtils.createSocket(server, Constants.DEFAULT_TCP_PORT, false);
Transfer transfer = new Transfer(null);
transfer.setSocket(socket);
transfer.init();
......@@ -343,31 +343,7 @@ public class FileLock {
fileName = null;
throw getExceptionFatal("Concurrent update", null);
}
watchdog = new Thread(new Runnable() {
public void run() {
try {
while (fileName != null) {
// trace.debug("watchdog check");
try {
if (!fs.exists(fileName) || fs.getLastModified(fileName) != lastWrite) {
save();
}
Thread.sleep(sleep);
} catch (OutOfMemoryError e) {
// ignore
} catch (InterruptedException e) {
// ignore
} catch (NullPointerException e) {
// ignore
} catch (Exception e) {
trace.debug("watchdog", e);
}
}
} catch (Exception e) {
trace.debug("watchdog", e);
}
}
});
watchdog = new Thread(this);
watchdog.setName("H2 File Lock Watchdog " + fileName);
watchdog.setDaemon(true);
watchdog.setPriority(Thread.MAX_PRIORITY - 1);
......@@ -439,20 +415,7 @@ public class FileLock {
return;
}
save();
watchdog = new Thread(new Runnable() {
public void run() {
while (serverSocket != null) {
try {
trace.debug("watchdog accept");
Socket s = serverSocket.accept();
s.close();
} catch (Exception e) {
trace.debug("watchdog", e);
}
}
trace.debug("watchdog end");
}
});
watchdog = new Thread(this);
watchdog.setDaemon(true);
watchdog.setName("H2 File Lock Watchdog (Socket) " + fileName);
watchdog.start();
......@@ -510,4 +473,38 @@ public class FileLock {
return uniqueId;
}
public void run() {
try {
while (fileName != null) {
// trace.debug("watchdog check");
try {
if (!fs.exists(fileName) || fs.getLastModified(fileName) != lastWrite) {
save();
}
Thread.sleep(sleep);
} catch (OutOfMemoryError e) {
// ignore
} catch (InterruptedException e) {
// ignore
} catch (NullPointerException e) {
// ignore
} catch (Exception e) {
trace.debug("watchdog", e);
}
}
while (serverSocket != null) {
try {
trace.debug("watchdog accept");
Socket s = serverSocket.accept();
s.close();
} catch (Exception e) {
trace.debug("watchdog", e);
}
}
} catch (Exception e) {
trace.debug("watchdog", e);
}
trace.debug("watchdog end");
}
}
......@@ -38,6 +38,11 @@ public class FileStore {
*/
protected static final byte[] EMPTY = new byte[16 * 1024];
/**
* The magic file header.
*/
private static final String HEADER = "-- H2 0.5/B -- ".substring(0, Constants.FILE_BLOCK_SIZE - 1) + "\n";
/**
* The file name.
*/
......@@ -144,7 +149,7 @@ public class FileStore {
* @return the random salt or the magic
*/
protected byte[] generateSalt() {
return Constants.MAGIC_FILE_HEADER.getBytes();
return HEADER.getBytes();
}
/**
......@@ -179,7 +184,7 @@ public class FileStore {
public void init() throws SQLException {
int len = Constants.FILE_BLOCK_SIZE;
byte[] salt;
byte[] magic = Constants.MAGIC_FILE_HEADER.getBytes();
byte[] magic = HEADER.getBytes();
if (length() < HEADER_LENGTH) {
// write unencrypted
checkedWriting = false;
......@@ -195,12 +200,6 @@ public class FileStore {
seek(0);
byte[] buff = new byte[len];
readFullyDirect(buff, 0, len);
if (Constants.MAGIC_FILE_HEADER_SUPPORT_TEXT) {
if (buff[10] == 'T') {
buff[10] = 'B';
textMode = true;
}
}
if (ByteUtils.compareNotNull(buff, magic) != 0) {
throw Message.getSQLException(ErrorCode.FILE_VERSION_ERROR_1, name);
}
......
......@@ -71,6 +71,8 @@ public class MetaTable extends Table {
*/
public static final long ROW_COUNT_APPROXIMATION = 1000;
private static final String CHARACTER_SET_NAME = "Unicode";
private static final int TABLES = 0;
private static final int COLUMNS = 1;
private static final int INDEXES = 2;
......@@ -693,7 +695,7 @@ public class MetaTable extends Table {
// NUMERIC_SCALE
"" + c.getScale(),
// CHARACTER_SET_NAME
Constants.CHARACTER_SET_NAME,
CHARACTER_SET_NAME,
// COLLATION_NAME
collation,
// TYPE_NAME
......@@ -1159,7 +1161,7 @@ public class MetaTable extends Table {
// SCHEMA_OWNER
identifier(schema.getOwner().getName()),
// DEFAULT_CHARACTER_SET_NAME
Constants.CHARACTER_SET_NAME,
CHARACTER_SET_NAME,
// DEFAULT_COLLATION_NAME
collation,
// IS_DEFAULT
......
......@@ -55,10 +55,10 @@ public class Backup extends Tool {
* @param args the command line arguments
*/
public static void main(String... args) throws SQLException {
new Backup().run(args);
new Backup().runTool(args);
}
public void run(String... args) throws SQLException {
public void runTool(String... args) throws SQLException {
String zipFileName = "backup.zip";
String dir = ".";
String db = null;
......
......@@ -53,10 +53,10 @@ public class ChangeFileEncryption extends Tool {
* @param args the command line arguments
*/
public static void main(String... args) throws SQLException {
new ChangeFileEncryption().run(args);
new ChangeFileEncryption().runTool(args);
}
public void run(String... args) throws SQLException {
public void runTool(String... args) throws SQLException {
String dir = ".";
String cipher = null;
char[] decryptPassword = null;
......
......@@ -27,15 +27,15 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
//## AWT end ##
import org.h2.server.ShutdownHandler;
import org.h2.util.Resources;
import org.h2.util.Tool;
import java.io.IOException;
//## AWT end ##
import java.sql.SQLException;
import org.h2.constant.SysProperties;
import org.h2.server.ShutdownHandler;
import org.h2.util.StartBrowser;
/**
......@@ -46,12 +46,13 @@ import org.h2.util.StartBrowser;
*/
public class Console extends Tool implements
//## AWT begin ##
ActionListener, MouseListener,
ActionListener, MouseListener, WindowListener,
//## AWT end ##
ShutdownHandler {
//## AWT begin ##
Frame frame;
private Frame frame;
private boolean trayIcon;
private Font font;
private Button startBrowser;
//## AWT end ##
......@@ -85,7 +86,7 @@ ShutdownHandler {
* @param args the command line arguments
*/
public static void main(String... args) throws SQLException {
new Console().run(args);
new Console().runTool(args);
}
/**
......@@ -95,7 +96,7 @@ ShutdownHandler {
*
* @param args the command line arguments
*/
public void run(String... args) throws SQLException {
public void runTool(String... args) throws SQLException {
isWindows = SysProperties.getStringSetting("os.name", "").startsWith("Windows");
boolean tcpStart = false, pgStart = false, webStart = false, toolStart = false;
boolean browserStart = false;
......@@ -153,7 +154,7 @@ ShutdownHandler {
loadFont();
try {
if (!createTrayIcon()) {
showWindow(true);
showWindow();
}
} catch (Exception e) {
e.printStackTrace();
......@@ -303,19 +304,21 @@ ShutdownHandler {
}
Image icon = loadImage(iconFile);
// TrayIcon icon = new TrayIcon(image, "H2 Database Engine", menuConsole);
Object trayIcon = Class.forName("java.awt.TrayIcon").
Object ti = Class.forName("java.awt.TrayIcon").
getConstructor(Image.class, String.class, PopupMenu.class).
newInstance(icon, "H2 Database Engine", menuConsole);
// trayIcon.addMouseListener(this);
trayIcon.getClass().
ti.getClass().
getMethod("addMouseListener", MouseListener.class).
invoke(trayIcon, this);
invoke(ti, this);
// tray.add(icon);
tray.getClass().
getMethod("add", Class.forName("java.awt.TrayIcon")).
invoke(tray, trayIcon);
invoke(tray, ti);
this.trayIcon = true;
return true;
} catch (Exception e) {
......@@ -323,17 +326,12 @@ ShutdownHandler {
}
}
private void showWindow(final boolean exit) {
frame = new Frame("H2 Console");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
if (exit) {
stopAll();
} else {
frame.dispose();
}
private void showWindow() {
if (frame != null) {
return;
}
});
frame = new Frame("H2 Console");
frame.addWindowListener(this);
Image image = loadImage("/org/h2/res/h2.png");
if (image != null) {
frame.setIconImage(image);
......@@ -425,7 +423,7 @@ ShutdownHandler {
} else if ("console".equals(command)) {
startBrowser();
} else if ("status".equals(command)) {
showWindow(false);
showWindow();
} else if (startBrowser == e.getSource()) {
// for some reason, IKVM ignores setActionCommand
startBrowser();
......@@ -480,4 +478,72 @@ ShutdownHandler {
}
//## AWT end ##
/**
* INTERNAL
*/
//## AWT begin ##
public void windowClosing(WindowEvent e) {
if (trayIcon) {
frame.dispose();
frame = null;
} else {
stopAll();
}
}
//## AWT end ##
/**
* INTERNAL
*/
//## AWT begin ##
public void windowActivated(WindowEvent e) {
// nothing to do
}
//## AWT end ##
/**
* INTERNAL
*/
//## AWT begin ##
public void windowClosed(WindowEvent e) {
// nothing to do
}
//## AWT end ##
/**
* INTERNAL
*/
//## AWT begin ##
public void windowDeactivated(WindowEvent e) {
// nothing to do
}
//## AWT end ##
/**
* INTERNAL
*/
//## AWT begin ##
public void windowDeiconified(WindowEvent e) {
// nothing to do
}
//## AWT end ##
/**
* INTERNAL
*/
//## AWT begin ##
public void windowIconified(WindowEvent e) {
// nothing to do
}
//## AWT end ##
/**
* INTERNAL
*/
//## AWT begin ##
public void windowOpened(WindowEvent e) {
// nothing to do
}
//## AWT end ##
}
......@@ -74,10 +74,10 @@ public class ConvertTraceFile extends Tool {
* @param args the command line arguments
*/
public static void main(String... args) throws SQLException {
new ConvertTraceFile().run(args);
new ConvertTraceFile().runTool(args);
}
public void run(String... args) throws SQLException {
public void runTool(String... args) throws SQLException {
String traceFile = "test.trace.db";
String javaClass = "Test";
String script = "test.sql";
......
......@@ -44,10 +44,10 @@ public class CreateCluster extends Tool {
* @param args the command line arguments
*/
public static void main(String... args) throws SQLException {
new CreateCluster().run(args);
new CreateCluster().runTool(args);
}
public void run(String... args) throws SQLException {
public void runTool(String... args) throws SQLException {
String urlSource = null;
String urlTarget = null;
String user = "sa";
......
......@@ -39,10 +39,10 @@ public class DeleteDbFiles extends Tool {
* @param args the command line arguments
*/
public static void main(String... args) throws SQLException {
new DeleteDbFiles().run(args);
new DeleteDbFiles().runTool(args);
}
public void run(String... args) throws SQLException {
public void runTool(String... args) throws SQLException {
String dir = ".";
String db = null;
boolean quiet = false;
......
......@@ -21,7 +21,7 @@ import org.h2.util.StringUtils;
* The algorithm used is database independent, the only requirement
* is that the engine supports a range index (for example b-tree).
*/
public class MultiDimension {
public class MultiDimension implements Comparator<long[]> {
private static final MultiDimension INSTANCE = new MultiDimension();
......@@ -239,11 +239,7 @@ public class MultiDimension {
}
private void optimize(ArrayList<long[]> list, int total) {
Collections.sort(list, new Comparator<long[]>() {
public int compare(long[] a, long[] b) {
return a[0] > b[0] ? 1 : -1;
}
});
Collections.sort(list, this);
for (int minGap = 10;; minGap += minGap / 2) {
for (int i = 0; i < list.size() - 1; i++) {
long[] current = list.get(i);
......@@ -264,6 +260,10 @@ public class MultiDimension {
}
}
public int compare(long[] a, long[] b) {
return a[0] > b[0] ? 1 : -1;
}
private void addMortonRanges(ArrayList<long[]> list, int[] min, int[] max, int len, int level) {
if (level > 100) {
throw new IllegalArgumentException("Stop");
......
......@@ -17,6 +17,7 @@ import java.io.PrintWriter;
import java.io.Reader;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
......@@ -46,7 +47,6 @@ import org.h2.util.FileUtils;
import org.h2.util.IOUtils;
import org.h2.util.IntArray;
import org.h2.util.New;
import org.h2.util.ObjectArray;
import org.h2.util.RandomUtils;
import org.h2.util.SmallLRUCache;
import org.h2.util.StatementBuilder;
......@@ -69,7 +69,7 @@ public class Recover extends Tool implements DataHandler {
private int recordLength;
private int valueId;
private boolean trace;
private ObjectArray<MetaRecord> schema;
private ArrayList<MetaRecord> schema;
private HashSet<Integer> objectIdSet;
private HashMap<Integer, String> tableMap;
private boolean remove;
......@@ -99,7 +99,7 @@ public class Recover extends Tool implements DataHandler {
* @param args the command line arguments
*/
public static void main(String... args) throws SQLException {
new Recover().run(args);
new Recover().runTool(args);
}
/**
......@@ -113,7 +113,7 @@ public class Recover extends Tool implements DataHandler {
*
* @param args the command line arguments
*/
public void run(String... args) throws SQLException {
public void runTool(String... args) throws SQLException {
String dir = ".";
String db = null;
for (int i = 0; args != null && i < args.length; i++) {
......@@ -1014,14 +1014,14 @@ public class Recover extends Tool implements DataHandler {
}
private void resetSchema() {
schema = ObjectArray.newInstance();
schema = New.arrayList();
objectIdSet = New.hashSet();
tableMap = New.hashMap();
}
private void writeSchema(PrintWriter writer) {
writer.println("---- Schema ----------");
MetaRecord.sort(schema);
Collections.sort(schema);
for (MetaRecord m : schema) {
String sql = m.getSQL();
// create, but not referential integrity constraints and so on
......
......@@ -45,10 +45,10 @@ public class Restore extends Tool {
* @param args the command line arguments
*/
public static void main(String... args) throws SQLException {
new Restore().run(args);
new Restore().runTool(args);
}
public void run(String... args) throws SQLException {
public void runTool(String... args) throws SQLException {
String zipFileName = "backup.zip";
String dir = ".";
String db = null;
......
......@@ -65,7 +65,7 @@ public class RunScript extends Tool {
* @param args the command line arguments
*/
public static void main(String... args) throws SQLException {
new RunScript().run(args);
new RunScript().runTool(args);
}
/**
......@@ -86,7 +86,7 @@ public class RunScript extends Tool {
*
* @param args the command line arguments
*/
public void run(String... args) throws SQLException {
public void runTool(String... args) throws SQLException {
String url = null;
String user = "sa";
String password = "";
......
......@@ -48,10 +48,10 @@ public class Script extends Tool {
* @param args the command line arguments
*/
public static void main(String... args) throws SQLException {
new Script().run(args);
new Script().runTool(args);
}
public void run(String... args) throws SQLException {
public void runTool(String... args) throws SQLException {
String url = null;
String user = "sa";
String password = "";
......
......@@ -100,10 +100,10 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
* @param args the command line arguments
*/
public static void main(String... args) throws SQLException {
new Server().run(args);
new Server().runTool(args);
}
public void run(String... args) throws SQLException {
public void runTool(String... args) throws SQLException {
boolean tcpStart = false, pgStart = false, webStart = false;
boolean browserStart = false;
boolean tcpShutdown = false, tcpShutdownForce = false;
......@@ -441,32 +441,27 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
/**
* Start a web server and a browser that uses the given connection. The
* current transaction is preserved. This is specially useful to manually
* inspect the database when debugging.
* inspect the database when debugging. This method return as soon as the
* user has disconnected.
*
* @param conn the database connection (the database must be open)
*/
public static void startWebServer(Connection conn) throws SQLException {
final Object waitUntilDisconnected = new Object();
WebServer webServer = new WebServer();
Server server = new Server(webServer, new String[] { "-webPort", "0" });
webServer.setShutdownHandler(new ShutdownHandler() {
public void shutdown() {
synchronized (waitUntilDisconnected) {
waitUntilDisconnected.notifyAll();
}
}
});
server.start();
Server web = new Server(webServer, new String[] { "-webPort", "0" });
web.start();
Server server = new Server();
server.web = web;
webServer.setShutdownHandler(server);
String url = webServer.addSession(conn);
StartBrowser.openURL(url);
synchronized (waitUntilDisconnected) {
while (!webServer.isStopped()) {
try {
waitUntilDisconnected.wait();
Thread.sleep(1000);
} catch (InterruptedException e) {
// ignore
}
}
webServer.stop();
}
}
......@@ -34,7 +34,7 @@ import org.h2.util.Tool;
* Interactive command line tool to access a database using JDBC.
* @h2.resource
*/
public class Shell extends Tool {
public class Shell extends Tool implements Runnable {
private static final int HISTORY_COUNT = 20;
......@@ -48,6 +48,7 @@ public class Shell extends Tool {
// Windows: '\u00b3';
private char boxVertical = '|';
private ArrayList<String> history = New.arrayList();
private boolean stopHide;
/**
* Options are case sensitive. Supported options are:
......@@ -70,7 +71,7 @@ public class Shell extends Tool {
* @param args the command line arguments
*/
public static void main(String... args) throws SQLException {
new Shell().run(args);
new Shell().runTool(args);
}
/**
......@@ -105,7 +106,7 @@ public class Shell extends Tool {
*
* @param args the command line settings
*/
public void run(String... args) throws SQLException {
public void runTool(String... args) throws SQLException {
String url = null;
String user = "";
String password = "";
......@@ -401,15 +402,28 @@ public class Shell extends Tool {
} catch (Exception e) {
// ignore, use the default solution
}
Thread passwordHider = new Thread(this);
stopHide = false;
passwordHider.start();
print("Password > ");
String p = readLine();
stopHide = true;
try {
passwordHider.join();
} catch (InterruptedException e) {
// ignore
}
print("\b\b");
return p;
}
/**
* This thread hides the password by repeatedly printing
* INTERNAL.
* Hides the password by repeatedly printing
* backspace, backspace, &gt;, &lt;.
*/
class PasswordHider extends Thread {
volatile boolean stop;
public void run() {
while (!stop) {
while (!stopHide) {
print("\b\b><");
try {
Thread.sleep(10);
......@@ -418,20 +432,7 @@ public class Shell extends Tool {
}
}
}
}
PasswordHider thread = new PasswordHider();
thread.start();
print("Password > ");
String p = readLine();
thread.stop = true;
try {
thread.join();
} catch (InterruptedException e) {
// ignore
}
print("\b\b");
return p;
}
private String readLine(String defaultValue) throws IOException {
String s = readLine();
......
......@@ -9,7 +9,6 @@ package org.h2.util;
import java.math.BigDecimal;
import java.sql.SQLException;
import org.h2.engine.Constants;
import org.h2.message.Message;
/**
......@@ -17,6 +16,11 @@ import org.h2.message.Message;
*/
public class MathUtils {
/**
* The maximum scale of a BigDecimal value.
*/
private static final int BIG_DECIMAL_SCALE_MAX = 100000;
private MathUtils() {
// utility class
}
......@@ -84,9 +88,9 @@ public class MathUtils {
* @return the scaled value
*/
public static BigDecimal setScale(BigDecimal bd, int scale) throws SQLException {
if (scale > Constants.BIG_DECIMAL_SCALE_MAX) {
if (scale > BIG_DECIMAL_SCALE_MAX) {
throw Message.getInvalidValueException("" + scale, "scale");
} else if (scale < -Constants.BIG_DECIMAL_SCALE_MAX) {
} else if (scale < -BIG_DECIMAL_SCALE_MAX) {
throw Message.getInvalidValueException("" + scale, "scale");
}
return bd.setScale(scale, BigDecimal.ROUND_HALF_UP);
......
......@@ -6,10 +6,9 @@
*/
package org.h2.util;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import org.h2.engine.Constants;
......@@ -148,34 +147,46 @@ public class Profiler implements Runnable {
}
}
public static void main(String... args) {
Profiler p = new Profiler();
p.startCollecting();
org.h2.Driver.load();
Locale.getAvailableLocales();
p.stopCollecting();
System.out.println(p.getTop(10));
}
/**
* Get the top stack traces.
*
* @param max the maximum number of results
* @param count the maximum number of stack traces
* @return the stack traces.
*/
public String getTop(int max) {
public String getTop(int count) {
StringBuilder buff = new StringBuilder();
buff.append("Profiler: top ").append(max).append(" stack trace(s) of ").append(time).
buff.append("Profiler: top ").append(count).append(" stack trace(s) of ").append(time).
append(" ms [build-").append(Constants.BUILD_ID).append("]\n");
@SuppressWarnings("unchecked")
Map.Entry<String, Integer>[] array = new Map.Entry[counts.size()];
counts.entrySet().toArray(array);
Arrays.sort(array, new Comparator<Map.Entry<String, Integer>>() {
public int compare(Map.Entry<String, Integer> a, Map.Entry<String, Integer> b) {
return b.getValue() - a.getValue();
}
});
int x = 0, min = 0;
for (Map.Entry<String, Integer> el : array) {
if (++x >= max) {
if (el.getValue() < min) {
for (int x = 0, min = 0;;) {
int highest = 0;
Map.Entry<String, Integer> best = null;
for (Map.Entry<String, Integer> el : counts.entrySet()) {
if (el.getValue() > highest) {
best = el;
highest = el.getValue();
}
}
if (best == null) {
break;
}
counts.remove(best.getKey());
if (++x >= count) {
if (best.getValue() < min) {
break;
}
min = el.getValue();
min = best.getValue();
}
buff.append(el.getValue()).append('/').append(total).
append('\n').append(el.getKey());
buff.append(best.getValue()).append('/').append(total).
append('\n').append(best.getKey());
}
buff.append('.');
return buff.toString();
......
......@@ -64,6 +64,7 @@ public class RandomUtils {
}
}
};
try {
Thread t = new Thread(runnable);
// let the process terminate even if generating the seed is really slow
......
......@@ -18,7 +18,6 @@ import java.io.PrintWriter;
import java.io.Writer;
import java.sql.SQLException;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.Properties;
import java.util.TreeMap;
......@@ -36,13 +35,12 @@ public class SortedProperties extends Properties {
private static final long serialVersionUID = 1L;
public synchronized Enumeration<Object> keys() {
Vector<Object> v = new Vector<Object>(keySet());
Collections.sort(v, new Comparator<Object>() {
public int compare(Object o1, Object o2) {
return o1.toString().compareTo(o2.toString());
Vector<String> v = new Vector<String>();
for (Object o : keySet()) {
v.add(o.toString());
}
});
return v.elements();
Collections.sort(v);
return new Vector<Object>(v).elements();
}
/**
......
......@@ -39,7 +39,7 @@ public abstract class Tool {
*
* @param args the argument list
*/
public abstract void run(String... args) throws SQLException;
public abstract void runTool(String... args) throws SQLException;
/**
* Throw a SQLException saying this command line option is not supported.
......
......@@ -709,7 +709,7 @@ public class ValueLob extends Value {
* @param h the data handler
*/
public void convertToFileIfRequired(DataHandler h) throws SQLException {
if (Constants.AUTO_CONVERT_LOB_TO_FILES && small != null && small.length > h.getMaxLengthInplaceLob()) {
if (small != null && small.length > h.getMaxLengthInplaceLob()) {
boolean compress = h.getLobCompressionAlgorithm(type) != null;
int len = getBufferSize(h, compress, Long.MAX_VALUE);
int tabId = tableId;
......
......@@ -286,7 +286,8 @@ java org.h2.test.TestAll timer
System.setProperty("h2.check2", "true");
/*
check client jar file size
remove ObjectArray
Constants.FILE_BLOCK_SIZE and others
simplify SysProperties
combine small classes (StringCache / utils...)
......
......@@ -60,7 +60,7 @@ public class TestShell extends TestBase {
shell.setIn(toolIn);
shell.setOut(toolOut);
shell.setErr(toolOut);
shell.run();
shell.runTool();
} catch (SQLException e) {
e.printStackTrace();
} finally {
......
......@@ -198,7 +198,7 @@ public class TestTools extends TestBase {
server.setOut(ps);
int result = 0;
try {
server.run(args);
server.runTool(args);
} catch (SQLException e) {
result = 1;
e.printStackTrace(ps);
......
......@@ -148,10 +148,10 @@ public class FtpServer extends Tool implements Service {
* @param args the command line arguments
*/
public static void main(String... args) throws SQLException {
new FtpServer().run(args);
new FtpServer().runTool(args);
}
public void run(String... args) throws SQLException {
public void runTool(String... args) throws SQLException {
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i];
if (arg == null) {
......
......@@ -27,7 +27,7 @@ public class FileViewer extends Tool {
* @param args the command line arguments
*/
public static void main(String... args) throws SQLException {
new FileViewer().run(args);
new FileViewer().runTool(args);
}
protected void showUsage() {
......@@ -44,7 +44,7 @@ public class FileViewer extends Tool {
// getClass().getName().replace('.', '/') + ".html");
}
public void run(String... args) throws SQLException {
public void runTool(String... args) throws SQLException {
String file = null;
String find = null;
boolean head = false, tail = false;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论