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

The H2 JDBC client can now be used in an unsigned Applet. The problem was that…

The H2 JDBC client can now be used in an unsigned Applet. The problem was that System.getProperty throws a SecurityException, which is now ignored.
上级 91fad8b1
......@@ -17,13 +17,30 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>Issue 308: Statement.getGeneratedKeys() now returns an empty result set if no key was generated.
<ul><li>The H2 JDBC client can now be used in an unsigned Applet.
The problem was that System.getProperty throws a SecurityException, which is now ignored.
</li><li>The condition "in(select ...)" did not work correctly if the subquery
could not be converted to a "distinct" query, as in:
"select * from dual where x in (select x from dual group by x order by max(x))".
</li><li>In the last release, the error code for "Wrong user name or password" was still
08004 instead of 28000, which resulted in the wrong error message.
</li><li>In some cases, creating a new table or altering an existing table threw the exception:
Unique index or primary key violation: "PRIMARY KEY ON """".PAGE_INDEX".
</li><li>The Shell tool no longer supports the built-in command "show",
because it is a legal SQL statement for H2 and MySQL.
However, the "describe" command is still supported, and now lists all tables
if called without parameter.
</li><li>The sorted insert mode (as in "insert into ... direct sorted select")
did not work for not-persisted tables in a persisted database.
It threw a ClassCastException.
</li><li>Issue 308: Statement.getGeneratedKeys() now returns an empty result set if no key was generated.
</li><li>The h2small.jar (created with build jarSmall) included the Android API.
This has been removed, shrinking the jar file by 21 KB.
</li><li>When creating a table, the precision must now be at least as large as the scale.
</li><li>Support for Java 1.3 and Java 1.4 has been removed.
</li><li>Improved error message for syntax error: the list of expected tokens was sometimes not set correctly.
</li><li>Files do not grow more than 128 pages. For large databases, 20% was too much.
</li><li>Database file growth can now be limited using the database setting PAGE_STORE_MAX_GROWTH.
Slower growth may slow down operation, but speed up closing database.
</li></ul>
<h2>Version 1.3.154 (2011-04-04)</h2>
......
......@@ -9,6 +9,7 @@ package org.h2.constant;
import org.h2.engine.Constants;
import org.h2.message.TraceSystem;
import org.h2.util.MathUtils;
import org.h2.util.Utils;
/**
* The constants defined in this class are initialized from system properties.
......@@ -48,32 +49,32 @@ public class SysProperties {
* It is usually set by the system and is the default encoding used for the
* RunScript and CSV tool.
*/
public static final String FILE_ENCODING = getStringSetting("file.encoding", "Cp1252");
public static final String FILE_ENCODING = Utils.getProperty("file.encoding", "Cp1252");
/**
* System property <code>file.separator</code> (default: /).<br />
* It is usually set by the system, and used to build absolute file names.
*/
public static final String FILE_SEPARATOR = getStringSetting("file.separator", "/");
public static final String FILE_SEPARATOR = Utils.getProperty("file.separator", "/");
/**
* System property <code>java.specification.version</code>.<br />
* It is set by the system. Examples: 1.4, 1.5, 1.6.
*/
public static final String JAVA_SPECIFICATION_VERSION = getStringSetting("java.specification.version", "1.4");
public static final String JAVA_SPECIFICATION_VERSION = Utils.getProperty("java.specification.version", "1.4");
/**
* System property <code>line.separator</code> (default: \n).<br />
* It is usually set by the system, and used by the script and trace tools.
*/
public static final String LINE_SEPARATOR = getStringSetting("line.separator", "\n");
public static final String LINE_SEPARATOR = Utils.getProperty("line.separator", "\n");
/**
* System property <code>user.home</code> (empty string if not set).<br />
* It is usually set by the system, and used as a replacement for ~ in file
* names.
*/
public static final String USER_HOME = getStringSetting("user.home", "");
public static final String USER_HOME = Utils.getProperty("user.home", "");
/**
* System property <code>h2.allowBigDecimalExtensions</code> (default:
......@@ -81,13 +82,13 @@ public class SysProperties {
* When enabled, classes that extend BigDecimal are supported in
* PreparedStatement.setBigDecimal.
*/
public static final boolean ALLOW_BIG_DECIMAL_EXTENSIONS = getBooleanSetting("h2.allowBigDecimalExtensions", false);
public static final boolean ALLOW_BIG_DECIMAL_EXTENSIONS = Utils.getProperty("h2.allowBigDecimalExtensions", false);
/**
* System property <code>h2.allowedClasses</code> (default: *).<br />
* Comma separated list of class names or prefixes.
*/
public static final String ALLOWED_CLASSES = getStringSetting("h2.allowedClasses", "*");
public static final String ALLOWED_CLASSES = Utils.getProperty("h2.allowedClasses", "*");
/**
* System property <code>h2.browser</code> (default: null).<br />
......@@ -96,27 +97,27 @@ public class SysProperties {
* For Mac OS, if the default browser is not Safari and you want to use Safari,
* use: <code>java -Dh2.browser="open,-a,Safari,%url" ...</code>.
*/
public static final String BROWSER = getStringSetting(H2_BROWSER, null);
public static final String BROWSER = Utils.getProperty(H2_BROWSER, null);
/**
* System property <code>h2.enableAnonymousSSL</code> (default: true).<br />
* When using SSL connection, the anonymous cipher suite
* SSL_DH_anon_WITH_RC4_128_MD5 should be enabled.
*/
public static final boolean ENABLE_ANONYMOUS_SSL = getBooleanSetting("h2.enableAnonymousSSL", true);
public static final boolean ENABLE_ANONYMOUS_SSL = Utils.getProperty("h2.enableAnonymousSSL", true);
/**
* System property <code>h2.bindAddress</code> (default: null).<br />
* The bind address to use.
*/
public static final String BIND_ADDRESS = getStringSetting("h2.bindAddress", null);
public static final String BIND_ADDRESS = Utils.getProperty("h2.bindAddress", null);
/**
* System property <code>h2.check</code> (default: true).<br />
* Assertions in the database engine.
*/
//## CHECK begin ##
public static final boolean CHECK = getBooleanSetting("h2.check", true);
public static final boolean CHECK = Utils.getProperty("h2.check", true);
//## CHECK end ##
/*## NO_CHECK begin ##
......@@ -128,7 +129,7 @@ public class SysProperties {
* Additional assertions in the database engine.
*/
//## CHECK begin ##
public static final boolean CHECK2 = getBooleanSetting("h2.check2", false);
public static final boolean CHECK2 = Utils.getProperty("h2.check2", false);
//## CHECK end ##
/*## NO_CHECK begin ##
......@@ -141,27 +142,27 @@ public class SysProperties {
* Directory where the trace files of the JDBC client are stored (only for
* client / server).
*/
public static final String CLIENT_TRACE_DIRECTORY = getStringSetting("h2.clientTraceDirectory", "trace.db/");
public static final String CLIENT_TRACE_DIRECTORY = Utils.getProperty("h2.clientTraceDirectory", "trace.db/");
/**
* System property <code>h2.collatorCacheSize</code> (default: 32000).<br />
* The cache size for collation keys (in elements). Used when a collator has
* been set for the database.
*/
public static final int COLLATOR_CACHE_SIZE = getIntSetting("h2.collatorCacheSize", 32000);
public static final int COLLATOR_CACHE_SIZE = Utils.getProperty("h2.collatorCacheSize", 32000);
/**
* System property <code>h2.consoleStream</code> (default: true).<br />
* H2 Console: stream query results.
*/
public static final boolean CONSOLE_STREAM = getBooleanSetting("h2.consoleStream", true);
public static final boolean CONSOLE_STREAM = Utils.getProperty("h2.consoleStream", true);
/**
* System property <code>h2.dataSourceTraceLevel</code> (default: 1).<br />
* The trace level of the data source implementation. Default is 1 for
* error.
*/
public static final int DATASOURCE_TRACE_LEVEL = getIntSetting("h2.dataSourceTraceLevel", TraceSystem.ERROR);
public static final int DATASOURCE_TRACE_LEVEL = Utils.getProperty("h2.dataSourceTraceLevel", TraceSystem.ERROR);
/**
* System property <code>h2.delayWrongPasswordMin</code> (default: 250).<br />
......@@ -171,7 +172,7 @@ public class SysProperties {
* logins will double the time until DELAY_WRONG_PASSWORD_MAX.
* To disable the delay, set this system property to 0.
*/
public static final int DELAY_WRONG_PASSWORD_MIN = getIntSetting("h2.delayWrongPasswordMin", 250);
public static final int DELAY_WRONG_PASSWORD_MIN = Utils.getProperty("h2.delayWrongPasswordMin", 250);
/**
* System property <code>h2.delayWrongPasswordMax</code> (default: 4000).<br />
......@@ -180,38 +181,38 @@ public class SysProperties {
* delay is reset after a successful login. The value 0 means there is no
* maximum delay.
*/
public static final int DELAY_WRONG_PASSWORD_MAX = getIntSetting("h2.delayWrongPasswordMax", 4000);
public static final int DELAY_WRONG_PASSWORD_MAX = Utils.getProperty("h2.delayWrongPasswordMax", 4000);
/**
* System property <code>h2.emptyPassword</code> (default: true).<br />
* Don't use a secure hash if the user name and password are empty or not set.
*/
public static final boolean EMPTY_PASSWORD = getBooleanSetting("h2.emptyPassword", true);
public static final boolean EMPTY_PASSWORD = Utils.getProperty("h2.emptyPassword", true);
/**
* System property <code>h2.lobCloseBetweenReads</code> (default: false).<br />
* Close LOB files between read operations.
*/
public static boolean lobCloseBetweenReads = getBooleanSetting("h2.lobCloseBetweenReads", false);
public static boolean lobCloseBetweenReads = Utils.getProperty("h2.lobCloseBetweenReads", false);
/**
* System property <code>h2.lobFilesPerDirectory</code> (default: 256).<br />
* Maximum number of LOB files per directory.
*/
public static final int LOB_FILES_PER_DIRECTORY = getIntSetting("h2.lobFilesPerDirectory", 256);
public static final int LOB_FILES_PER_DIRECTORY = Utils.getProperty("h2.lobFilesPerDirectory", 256);
/**
* System property <code>h2.lobInDatabase</code> (default: false).<br />
* Store LOB files in the database.
*/
public static final boolean LOB_IN_DATABASE = getBooleanSetting("h2.lobInDatabase", Constants.VERSION_MINOR >= 3);
public static final boolean LOB_IN_DATABASE = Utils.getProperty("h2.lobInDatabase", Constants.VERSION_MINOR >= 3);
/**
* System property <code>h2.lobClientMaxSizeMemory</code> (default: 65536).<br />
* The maximum size of a LOB object to keep in memory on the client side
* when using the server mode.
*/
public static final int LOB_CLIENT_MAX_SIZE_MEMORY = getIntSetting("h2.lobClientMaxSizeMemory", 65536);
public static final int LOB_CLIENT_MAX_SIZE_MEMORY = Utils.getProperty("h2.lobClientMaxSizeMemory", 65536);
/**
* System property <code>h2.maxFileRetry</code> (default: 16).<br />
......@@ -221,33 +222,33 @@ public class SysProperties {
* running garbage collection may close files if the user forgot to call
* Connection.close() or InputStream.close().
*/
public static final int MAX_FILE_RETRY = Math.max(1, getIntSetting("h2.maxFileRetry", 16));
public static final int MAX_FILE_RETRY = Math.max(1, Utils.getProperty("h2.maxFileRetry", 16));
/**
* System property <code>h2.maxReconnect</code> (default: 3).<br />
* The maximum number of tries to reconnect in a row.
*/
public static final int MAX_RECONNECT = getIntSetting("h2.maxReconnect", 3);
public static final int MAX_RECONNECT = Utils.getProperty("h2.maxReconnect", 3);
/**
* System property <code>h2.maxTraceDataLength</code> (default: 65535).<br />
* The maximum size of a LOB value that is written as data to the trace system.
*/
public static final long MAX_TRACE_DATA_LENGTH = getIntSetting("h2.maxTraceDataLength", 65535);
public static final long MAX_TRACE_DATA_LENGTH = Utils.getProperty("h2.maxTraceDataLength", 65535);
/**
* System property <code>h2.minColumnNameMap</code> (default: 3).<br />
* The minimum number of columns where a hash table is created when result set
* methods with column name (instead of column index) parameter are called.
*/
public static final int MIN_COLUMN_NAME_MAP = getIntSetting("h2.minColumnNameMap", 3);
public static final int MIN_COLUMN_NAME_MAP = Utils.getProperty("h2.minColumnNameMap", 3);
/**
* System property <code>h2.nioLoadMapped</code> (default: false).<br />
* If the mapped buffer should be loaded when the file is opened.
* This can improve performance.
*/
public static final boolean NIO_LOAD_MAPPED = getBooleanSetting("h2.nioLoadMapped", false);
public static final boolean NIO_LOAD_MAPPED = Utils.getProperty("h2.nioLoadMapped", false);
/**
* System property <code>h2.nioCleanerHack</code> (default: false).<br />
......@@ -256,41 +257,41 @@ public class SysProperties {
* is garbage collected. See also
* http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4724038
*/
public static final boolean NIO_CLEANER_HACK = getBooleanSetting("h2.nioCleanerHack", false);
public static final boolean NIO_CLEANER_HACK = Utils.getProperty("h2.nioCleanerHack", false);
/**
* System property <code>h2.objectCache</code> (default: true).<br />
* Cache commonly used values (numbers, strings). There is a shared cache
* for all values.
*/
public static final boolean OBJECT_CACHE = getBooleanSetting("h2.objectCache", true);
public static final boolean OBJECT_CACHE = Utils.getProperty("h2.objectCache", true);
/**
* System property <code>h2.objectCacheMaxPerElementSize</code> (default:
* 4096).<br />
* The maximum size (precision) of an object in the cache.
*/
public static final int OBJECT_CACHE_MAX_PER_ELEMENT_SIZE = getIntSetting("h2.objectCacheMaxPerElementSize", 4096);
public static final int OBJECT_CACHE_MAX_PER_ELEMENT_SIZE = Utils.getProperty("h2.objectCacheMaxPerElementSize", 4096);
/**
* System property <code>h2.objectCacheSize</code> (default: 1024).<br />
* The maximum number of objects in the cache.
* This value must be a power of 2.
*/
public static final int OBJECT_CACHE_SIZE = MathUtils.nextPowerOf2(getIntSetting("h2.objectCacheSize", 1024));
public static final int OBJECT_CACHE_SIZE = MathUtils.nextPowerOf2(Utils.getProperty("h2.objectCacheSize", 1024));
/**
* System property <code>h2.pgClientEncoding</code> (default: UTF-8).<br />
* Default client encoding for PG server. It is used if the client does not
* sends his encoding.
*/
public static final String PG_DEFAULT_CLIENT_ENCODING = getStringSetting("h2.pgClientEncoding", "UTF-8");
public static final String PG_DEFAULT_CLIENT_ENCODING = Utils.getProperty("h2.pgClientEncoding", "UTF-8");
/**
* System property <code>h2.prefixTempFile</code> (default: h2.temp).<br />
* The prefix for temporary files in the temp directory.
*/
public static final String PREFIX_TEMP_FILE = getStringSetting("h2.prefixTempFile", "h2.temp");
public static final String PREFIX_TEMP_FILE = Utils.getProperty("h2.prefixTempFile", "h2.temp");
/**
* System property <code>h2.returnLobObjects</code> (default: true).<br />
......@@ -298,26 +299,26 @@ public class SysProperties {
* java.sql.Clob / java.sql.Blob object. When set to false, it will return a
* java.io.Reader / java.io.InputStream.
*/
public static final boolean RETURN_LOB_OBJECTS = getBooleanSetting("h2.returnLobObjects", true);
public static final boolean RETURN_LOB_OBJECTS = Utils.getProperty("h2.returnLobObjects", true);
/**
* System property <code>h2.runFinalize</code> (default: true).<br />
* Run finalizers to detect unclosed connections.
*/
public static boolean runFinalize = getBooleanSetting("h2.runFinalize", true);
public static boolean runFinalize = Utils.getProperty("h2.runFinalize", true);
/**
* System property <code>h2.serverCachedObjects</code> (default: 64).<br />
* TCP Server: number of cached objects per session.
*/
public static final int SERVER_CACHED_OBJECTS = getIntSetting("h2.serverCachedObjects", 64);
public static final int SERVER_CACHED_OBJECTS = Utils.getProperty("h2.serverCachedObjects", 64);
/**
* System property <code>h2.serverResultSetFetchSize</code>
* (default: 100).<br />
* The default result set fetch size when using the server mode.
*/
public static final int SERVER_RESULT_SET_FETCH_SIZE = getIntSetting("h2.serverResultSetFetchSize", 100);
public static final int SERVER_RESULT_SET_FETCH_SIZE = Utils.getProperty("h2.serverResultSetFetchSize", 100);
/**
* System property <code>h2.socketConnectRetry</code> (default: 16).<br />
......@@ -325,13 +326,13 @@ public class SysProperties {
* to open a socket, see bug
* http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6213296
*/
public static final int SOCKET_CONNECT_RETRY = getIntSetting("h2.socketConnectRetry", 16);
public static final int SOCKET_CONNECT_RETRY = Utils.getProperty("h2.socketConnectRetry", 16);
/**
* System property <code>h2.socketConnectTimeout</code> (default: 2000).<br />
* The timeout in milliseconds to connect to a server.
*/
public static final int SOCKET_CONNECT_TIMEOUT = getIntSetting("h2.socketConnectTimeout", 2000);
public static final int SOCKET_CONNECT_TIMEOUT = Utils.getProperty("h2.socketConnectTimeout", 2000);
/**
* System property <code>h2.sortNullsHigh</code> (default: false).<br />
......@@ -339,13 +340,13 @@ public class SysProperties {
* is at the end of a result set in an ascending sort and at
* the beginning of a result set in a descending sort.
*/
public static final boolean SORT_NULLS_HIGH = getBooleanSetting("h2.sortNullsHigh", false);
public static final boolean SORT_NULLS_HIGH = Utils.getProperty("h2.sortNullsHigh", false);
/**
* System property <code>h2.splitFileSizeShift</code> (default: 30).<br />
* The maximum file size of a split file is 1L &lt;&lt; x.
*/
public static final long SPLIT_FILE_SIZE_SHIFT = getIntSetting("h2.splitFileSizeShift", 30);
public static final long SPLIT_FILE_SIZE_SHIFT = Utils.getProperty("h2.splitFileSizeShift", 30);
/**
* System property <code>h2.syncMethod</code> (default: sync).<br />
......@@ -357,13 +358,13 @@ public class SysProperties {
* "": do not call a method (fast but there is a risk of data loss
* on power failure).
*/
public static final String SYNC_METHOD = getStringSetting("h2.syncMethod", "sync");
public static final String SYNC_METHOD = Utils.getProperty("h2.syncMethod", "sync");
/**
* System property <code>h2.traceIO</code> (default: false).<br />
* Trace all I/O operations.
*/
public static final boolean TRACE_IO = getBooleanSetting("h2.traceIO", false);
public static final boolean TRACE_IO = Utils.getProperty("h2.traceIO", false);
/**
* System property <code>h2.webMaxValueLength</code> (default: 100000).<br />
......@@ -371,7 +372,7 @@ public class SysProperties {
* The data in the database is not truncated, it is only to avoid out of memory
* in the H2 Console application.
*/
public static final int WEB_MAX_VALUE_LENGTH = getIntSetting("h2.webMaxValueLength", 100000);
public static final int WEB_MAX_VALUE_LENGTH = Utils.getProperty("h2.webMaxValueLength", 100000);
private static final String H2_BASE_DIR = "h2.baseDir";
......@@ -379,51 +380,6 @@ public class SysProperties {
// utility class
}
private static boolean getBooleanSetting(String name, boolean defaultValue) {
String s = getProperty(name);
if (s != null) {
try {
return Boolean.valueOf(s).booleanValue();
} catch (NumberFormatException e) {
// ignore
}
}
return defaultValue;
}
private static String getProperty(String name) {
try {
return System.getProperty(name);
} catch (Exception e) {
// SecurityException
// applets may not do that - ignore
return null;
}
}
/**
* INTERNAL
*/
public static String getStringSetting(String name, String defaultValue) {
String s = getProperty(name);
return s == null ? defaultValue : s;
}
/**
* INTERNAL
*/
public static int getIntSetting(String name, int defaultValue) {
String s = getProperty(name);
if (s != null) {
try {
return Integer.decode(s).intValue();
} catch (NumberFormatException e) {
// ignore
}
}
return defaultValue;
}
/**
* INTERNAL
*/
......@@ -438,7 +394,7 @@ public class SysProperties {
* INTERNAL
*/
public static String getBaseDir() {
return getStringSetting(H2_BASE_DIR, null);
return Utils.getProperty(H2_BASE_DIR, null);
}
/**
......@@ -450,7 +406,7 @@ public class SysProperties {
* @return the current value
*/
public static String getScriptDirectory() {
return getStringSetting(H2_SCRIPT_DIRECTORY, "");
return Utils.getProperty(H2_SCRIPT_DIRECTORY, "");
}
}
......@@ -9,6 +9,7 @@ package org.h2.engine;
import java.util.HashMap;
import org.h2.constant.ErrorCode;
import org.h2.message.DbException;
import org.h2.util.Utils;
/**
* The base class for settings.
......@@ -75,7 +76,7 @@ public class SettingsBase {
String sysProperty = buff.toString();
String v = settings.get(key);
if (v == null) {
v = System.getProperty(sysProperty, defaultValue);
v = Utils.getProperty(sysProperty, defaultValue);
settings.put(key, v);
}
return v;
......
......@@ -37,6 +37,7 @@ import org.h2.util.JdbcUtils;
import org.h2.util.New;
import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils;
import org.h2.util.Utils;
/*## LUCENE2 begin ##
import org.apache.lucene.index.IndexModifier;
import org.apache.lucene.search.Hits;
......@@ -60,7 +61,7 @@ public class FullTextLucene extends FullText {
/**
* Whether the text content should be stored in the Lucene index.
*/
protected static final boolean STORE_DOCUMENT_TEXT_IN_INDEX = Boolean.getBoolean("h2.storeDocumentTextInIndex");
protected static final boolean STORE_DOCUMENT_TEXT_IN_INDEX = Utils.getProperty("h2.storeDocumentTextInIndex", false);
private static final HashMap<String, IndexAccess> INDEX_ACCESS = New.hashMap();
private static final String TRIGGER_PREFIX = "FTL_";
......
......@@ -21,6 +21,7 @@ import org.h2.constant.SysProperties;
import org.h2.message.DbException;
import org.h2.util.IOUtils;
import org.h2.util.StringUtils;
import org.h2.util.Utils;
/**
* This file system stores files on disk.
......@@ -166,7 +167,7 @@ public class FileSystemDisk extends FileSystem {
String prefix = new File(name).getName();
File dir;
if (inTempDir) {
dir = new File(System.getProperty("java.io.tmpdir"));
dir = new File(Utils.getProperty("java.io.tmpdir", "."));
} else {
dir = new File(name).getAbsoluteFile().getParentFile();
IOUtils.mkdirs(dir);
......
......@@ -18,7 +18,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import org.h2.command.Command;
import org.h2.constant.SysProperties;
import org.h2.constraint.Constraint;
import org.h2.constraint.ConstraintCheck;
import org.h2.constraint.ConstraintReferential;
......@@ -861,7 +860,7 @@ public class MetaTable extends Table {
"user.country", "user.language", "user.variant", "file.encoding"
};
for (String s : settings) {
add(rows, "property." + s, SysProperties.getStringSetting(s, ""));
add(rows, "property." + s, Utils.getProperty(s, ""));
}
}
add(rows, "EXCLUSIVE", database.getExclusiveSession() == null ? "FALSE" : "TRUE");
......
......@@ -32,7 +32,6 @@ import java.awt.event.WindowListener;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import org.h2.constant.SysProperties;
import org.h2.server.ShutdownHandler;
import org.h2.util.JdbcUtils;
import org.h2.util.Tool;
......@@ -109,7 +108,7 @@ ShutdownHandler {
* @param args the command line arguments
*/
public void runTool(String... args) throws SQLException {
isWindows = SysProperties.getStringSetting("os.name", "").startsWith("Windows");
isWindows = Utils.getProperty("os.name", "").startsWith("Windows");
boolean tcpStart = false, pgStart = false, webStart = false, toolStart = false;
boolean browserStart = false;
boolean startDefaultServers = true;
......
......@@ -488,9 +488,9 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
*/
public static void openBrowser(String url) throws Exception {
try {
String osName = SysProperties.getStringSetting("os.name", "linux").toLowerCase();
String osName = Utils.getProperty("os.name", "linux").toLowerCase();
Runtime rt = Runtime.getRuntime();
String browser = System.getProperty(SysProperties.H2_BROWSER);
String browser = Utils.getProperty(SysProperties.H2_BROWSER, null);
if (browser != null) {
if (browser.startsWith("call:")) {
browser = browser.substring("call:".length());
......
......@@ -115,7 +115,7 @@ public class DbUpgrade {
String script = null;
try {
if (scriptInTempDir) {
new File(System.getProperty("java.io.tmpdir")).mkdirs();
new File(Utils.getProperty("java.io.tmpdir", ".")).mkdirs();
script = File.createTempFile("h2dbmigration", "backup.sql").getAbsolutePath();
} else {
script = name + ".script.sql";
......
......@@ -168,7 +168,7 @@ public class CacheLRU implements Cache {
} else {
// can't remove any record, because the records can not be removed
// hopefully this does not happen frequently, but it can happen
writer.getTrace().info("Cannot remove records, cache size too small? records:" + recordCount + " memory:" + memory);
writer.getTrace().info("cannot remove records, cache size too small? records:" + recordCount + " memory:" + memory);
break;
}
}
......
......@@ -39,7 +39,7 @@ public class SourceCompiler {
*/
HashMap<String, Class<?>> compiled = New.hashMap();
private String compileDir = System.getProperty("java.io.tmpdir");
private String compileDir = Utils.getProperty("java.io.tmpdir", ".");
static {
Class<?> clazz;
......
......@@ -650,4 +650,60 @@ public class Utils {
return clazz;
}
/**
* Get the system property. If the system property is not set, or if a
* security exception occurs, the default value is returned.
*
* @param key the key
* @param defaultValue the default value
* @return the value
*/
public static String getProperty(String key, String defaultValue) {
try {
return System.getProperty(key, defaultValue);
} catch (SecurityException se) {
return defaultValue;
}
}
/**
* Get the system property. If the system property is not set, or if a
* security exception occurs, the default value is returned.
*
* @param key the key
* @param defaultValue the default value
* @return the value
*/
public static int getProperty(String key, int defaultValue) {
String s = getProperty(key, null);
if (s != null) {
try {
return Integer.decode(s).intValue();
} catch (NumberFormatException e) {
// ignore
}
}
return defaultValue;
}
/**
* Get the system property. If the system property is not set, or if a
* security exception occurs, the default value is returned.
*
* @param key the key
* @param defaultValue the default value
* @return the value
*/
public static boolean getProperty(String key, boolean defaultValue) {
String s = getProperty(key, null);
if (s != null) {
try {
return Boolean.valueOf(s).booleanValue();
} catch (NumberFormatException e) {
// ignore
}
}
return defaultValue;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论