提交 31bdce51 authored 作者: Thomas Mueller's avatar Thomas Mueller

Various system properties have been replaced with database level settings.

上级 16679fbf
...@@ -18,7 +18,11 @@ Change Log ...@@ -18,7 +18,11 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>When the system property h2.nestedJoins was enabled, some outer joins returned the wrong result. <ul><li>Various system properties have been replaced with database level settings:
analyzeAuto, analyzeSample, databaseToUpper,...
See the javadoc documentation of DbSettings for details.
The system properties are still supported for backward compatibility.
</li><li>When the system property h2.nestedJoins was enabled, some outer joins returned the wrong result.
</li><li>Opening a database could throw a NullPointerException. </li><li>Opening a database could throw a NullPointerException.
</li><li>After a crash, the database file did not always shrink because </li><li>After a crash, the database file did not always shrink because
old transaction log pages were not removed from the file. old transaction log pages were not removed from the file.
......
...@@ -42,6 +42,8 @@ See also <a href="build.html#providing_patches">Providing Patches</a>. ...@@ -42,6 +42,8 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
</li><li>For RUNSCRIPT and SCRIPT (commands and tools), use UTF-8 by default. </li><li>For RUNSCRIPT and SCRIPT (commands and tools), use UTF-8 by default.
</li><li>Set h2.maxMemoryRowsDistinct to a lower value. </li><li>Set h2.maxMemoryRowsDistinct to a lower value.
</li><li>Enable h2.optimizeInsertFromSelect (speed up CREATE TABLE ... AS SELECT). </li><li>Enable h2.optimizeInsertFromSelect (speed up CREATE TABLE ... AS SELECT).
</li><li>Possibly enable h2.queryCacheSize.
</li><li>Possibly enable h2.databaseToUpper.
</li></ul> </li></ul>
<h2>Priority 1</h2> <h2>Priority 1</h2>
......
...@@ -82,6 +82,7 @@ org.h2.api<br /> ...@@ -82,6 +82,7 @@ org.h2.api<br />
<b>Constants</b><br /> <b>Constants</b><br />
org.h2.constant<br /> org.h2.constant<br />
<a href="org/h2/constant/DbSettings.html" target="javadoc">DbSettings</a><br />
<a href="org/h2/constant/ErrorCode.html" target="javadoc">ErrorCode</a><br /> <a href="org/h2/constant/ErrorCode.html" target="javadoc">ErrorCode</a><br />
<a href="org/h2/constant/SysProperties.html" target="javadoc">SysProperties</a><br /> <a href="org/h2/constant/SysProperties.html" target="javadoc">SysProperties</a><br />
<br /> <br />
......
...@@ -183,10 +183,11 @@ public class Parser { ...@@ -183,10 +183,11 @@ public class Parser {
private boolean rightsChecked; private boolean rightsChecked;
private boolean recompileAlways; private boolean recompileAlways;
private ArrayList<Parameter> indexedParameterList; private ArrayList<Parameter> indexedParameterList;
private boolean identifiersToUpper = SysProperties.IDENTIFIERS_TO_UPPER; private final boolean identifiersToUpper;
public Parser(Session session) { public Parser(Session session) {
database = session.getDatabase(); database = session.getDatabase();
this.identifiersToUpper = database.getSettings().databaseToUpper;
this.session = session; this.session = session;
} }
...@@ -1774,10 +1775,10 @@ public class Parser { ...@@ -1774,10 +1775,10 @@ public class Parser {
esc = readConcat(); esc = readConcat();
} }
recompileAlways = true; recompileAlways = true;
r = new CompareLike(database.getCompareMode(), r, b, esc, false); r = new CompareLike(database, r, b, esc, false);
} else if (readIf("REGEXP")) { } else if (readIf("REGEXP")) {
Expression b = readConcat(); Expression b = readConcat();
r = new CompareLike(database.getCompareMode(), r, b, null, true); r = new CompareLike(database, r, b, null, true);
} else if (readIf("IS")) { } else if (readIf("IS")) {
if (readIf("NOT")) { if (readIf("NOT")) {
if (readIf("NULL")) { if (readIf("NULL")) {
...@@ -1898,7 +1899,7 @@ public class Parser { ...@@ -1898,7 +1899,7 @@ public class Parser {
function.setParameter(0, r); function.setParameter(0, r);
r = function; r = function;
} }
r = new CompareLike(database.getCompareMode(), r, readSum(), null, true); r = new CompareLike(database, r, readSum(), null, true);
} else if (readIf("!~")) { } else if (readIf("!~")) {
if (readIf("*")) { if (readIf("*")) {
Function function = Function.getFunction(database, "CAST"); Function function = Function.getFunction(database, "CAST");
...@@ -1906,7 +1907,7 @@ public class Parser { ...@@ -1906,7 +1907,7 @@ public class Parser {
function.setParameter(0, r); function.setParameter(0, r);
r = function; r = function;
} }
r = new ConditionNot(new CompareLike(database.getCompareMode(), r, readSum(), null, true)); r = new ConditionNot(new CompareLike(database, r, readSum(), null, true));
} else { } else {
return r; return r;
} }
......
...@@ -8,7 +8,6 @@ package org.h2.command.ddl; ...@@ -8,7 +8,6 @@ package org.h2.command.ddl;
import org.h2.command.CommandInterface; import org.h2.command.CommandInterface;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.constant.SysProperties;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Right; import org.h2.engine.Right;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -27,10 +26,11 @@ public class Analyze extends DefineCommand { ...@@ -27,10 +26,11 @@ public class Analyze extends DefineCommand {
/** /**
* The sample size. * The sample size.
*/ */
private int sampleRows = SysProperties.ANALYZE_SAMPLE; private int sampleRows;
public Analyze(Session session) { public Analyze(Session session) {
super(session); super(session);
sampleRows = session.getDatabase().getSettings().analyzeSample;
} }
public int update() { public int update() {
......
...@@ -9,7 +9,6 @@ package org.h2.command.ddl; ...@@ -9,7 +9,6 @@ package org.h2.command.ddl;
import java.util.ArrayList; import java.util.ArrayList;
import org.h2.command.CommandInterface; import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.constraint.ConstraintReferential; import org.h2.constraint.ConstraintReferential;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Right; import org.h2.engine.Right;
...@@ -30,10 +29,11 @@ public class DropTable extends SchemaCommand { ...@@ -30,10 +29,11 @@ public class DropTable extends SchemaCommand {
private String tableName; private String tableName;
private Table table; private Table table;
private DropTable next; private DropTable next;
private int dropAction = SysProperties.DROP_RESTRICT ? ConstraintReferential.RESTRICT : ConstraintReferential.CASCADE; private int dropAction;
public DropTable(Session session, Schema schema) { public DropTable(Session session, Schema schema) {
super(session, schema); super(session, schema);
dropAction = session.getDatabase().getSettings().dropRestrict ? ConstraintReferential.RESTRICT : ConstraintReferential.CASCADE;
} }
/** /**
......
...@@ -8,7 +8,6 @@ package org.h2.command.ddl; ...@@ -8,7 +8,6 @@ package org.h2.command.ddl;
import org.h2.command.CommandInterface; import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.constraint.ConstraintReferential; import org.h2.constraint.ConstraintReferential;
import org.h2.engine.DbObject; import org.h2.engine.DbObject;
import org.h2.engine.Right; import org.h2.engine.Right;
...@@ -26,10 +25,11 @@ public class DropView extends SchemaCommand { ...@@ -26,10 +25,11 @@ public class DropView extends SchemaCommand {
private String viewName; private String viewName;
private boolean ifExists; private boolean ifExists;
private int dropAction = SysProperties.DROP_RESTRICT ? ConstraintReferential.RESTRICT : ConstraintReferential.CASCADE; private int dropAction;
public DropView(Session session, Schema schema) { public DropView(Session session, Schema schema) {
super(session, schema); super(session, schema);
dropAction = session.getDatabase().getSettings().dropRestrict ? ConstraintReferential.RESTRICT : ConstraintReferential.CASCADE;
} }
public void setIfExists(boolean b) { public void setIfExists(boolean b) {
......
/*
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.constant;
import java.util.Properties;
import org.h2.engine.SettingsBase;
/**
* This class contains various database-level settings. To override the
* documented default value for a database, append the setting in the database
* URL: "jdbc:h2:test;analyzeSample=100" when opening the first connection to
* the database. The settings can not be changed once the database is open.
* <p>
* Some settings are a last resort and temporary solution to work around a
* problem in the application or database engine. Also, there are system
* properties to enable features that are not yet fully tested or that are not
* backward compatible.
* </p>
*/
public class DbSettings extends SettingsBase {
private static DbSettings defaultSettings;
/**
* Database setting <code>analyzeAuto</code> (default: 0).<br />
* After changing this many rows, ANALYZE is automatically run for a table.
* Automatically running ANALYZE is disabled if set to 0. If set to 1000,
* then ANALYZE will run against each user table after about 1000 changes to
* that table. The time between running ANALYZE doubles each time since
* starting the database. It is not run on local temporary tables, and
* tables that have a trigger on SELECT.
*/
public int analyzeAuto = get("analyzeAuto", 0);
/**
* Database setting <code>analyzeSample</code> (default: 10000).<br />
* The default sample size when analyzing a table.
*/
public int analyzeSample = get("analyzeSample", 10000);
/**
* Database setting <code>databaseToUpper</code> (default: true).<br />
* Database short names are converted to uppercase for the DATABASE()
* function, and in the CATALOG column of all database meta data methods.
* Setting this to "false" is experimental.
*/
public boolean databaseToUpper = get("databaseToUpper", true);
/**
* Database setting <code>defaultEscape</code> (default: \).<br />
* The default escape character for LIKE comparisons. To select no escape
* character, use an empty string.
*/
public String defaultEscape = get("defaultEscape", "\\");
/**
* Database setting <code>defragAlways</code> (default: false).<br />
* Each time the database is closed, it is fully defragmented (SHUTDOWN DEFRAG).
*/
public boolean defragAlways = get("defragAlways", false);
/**
* Database setting <code>dropRestrict</code> (default: false).<br />
* Whether the default action for DROP TABLE and DROP VIEW is RESTRICT. For
* most databases, the default action is RESTRICT, but for compatibility
* with older versions of H2 the default action is currently CASCADE. This will
* change in a future version of H2.
*/
public boolean dropRestrict = get("dropRestrict", false);
/**
* Database setting <code>estimatedFunctionTableRows</code> (default:
* 1000).<br />
* The estimated number of rows in a function table (for example, CSVREAD or
* FTL_SEARCH). This value is used by the optimizer.
*/
public int estimatedFunctionTableRows = get("estimatedFunctionTableRows", 1000);
/**
* Database setting <code>functionsInSchema</code> (default:
* false).<br />
* If set, all functions are stored in a schema. Specially, the SCRIPT statement
* will always include the schema name in the CREATE ALIAS statement.
* This is not backward compatible with H2 versions 1.2.134 and older.
*/
public boolean functionsInSchema = get("functionsInSchema", false);
/**
* Database setting <code>queryCacheSize</code> (default: 0).<br />
* The size of the query cache. Each session has it's own cache with the
* given size. The cache is only used if the SQL statement and all
* parameters match. Only the last returned result per query is cached. Only
* SELECT statements are cached (excluding UNION and FOR UPDATE statements).
* This works for both statements and prepared statement.
*/
public int queryCacheSize = get("queryCacheSize", 0);
private DbSettings(Properties p) {
super(p);
}
/**
* INTERNAL.
* Get the settings for the given properties (may be null).
*
* @param p the properties
* @return the settings
*/
public static DbSettings getInstance(Properties p) {
if (p == null || p.isEmpty()) {
if (defaultSettings == null) {
defaultSettings = new DbSettings(new Properties());
}
return defaultSettings;
}
return new DbSettings(p);
}
}
...@@ -85,6 +85,7 @@ public class SysProperties { ...@@ -85,6 +85,7 @@ public class SysProperties {
* System property <code>h2.analyzeSample</code> (default: 10000).<br /> * System property <code>h2.analyzeSample</code> (default: 10000).<br />
* The default sample size when analyzing a table. * The default sample size when analyzing a table.
*/ */
// DbSettings
public static final int ANALYZE_SAMPLE = getIntSetting("h2.analyzeSample", 10000); public static final int ANALYZE_SAMPLE = getIntSetting("h2.analyzeSample", 10000);
/** /**
...@@ -96,6 +97,7 @@ public class SysProperties { ...@@ -96,6 +97,7 @@ public class SysProperties {
* starting the database. It is not run on local temporary tables, and * starting the database. It is not run on local temporary tables, and
* tables that have a trigger on SELECT. * tables that have a trigger on SELECT.
*/ */
// DbSettings
public static final int ANALYZE_AUTO = getIntSetting("h2.analyzeAuto", 0); public static final int ANALYZE_AUTO = getIntSetting("h2.analyzeAuto", 0);
/** /**
...@@ -109,6 +111,7 @@ public class SysProperties { ...@@ -109,6 +111,7 @@ public class SysProperties {
* for all databases except MySQL. For MySQL, it is always enabled. * for all databases except MySQL. For MySQL, it is always enabled.
*/ */
public static final boolean ALIAS_COLUMN_NAME = getBooleanSetting("h2.aliasColumnName", false); public static final boolean ALIAS_COLUMN_NAME = getBooleanSetting("h2.aliasColumnName", false);
// TODO Mode
/** /**
* System property <code>h2.allowBigDecimalExtensions</code> (default: * System property <code>h2.allowBigDecimalExtensions</code> (default:
...@@ -151,6 +154,7 @@ public class SysProperties { ...@@ -151,6 +154,7 @@ public class SysProperties {
* The default cache size in KB. * The default cache size in KB.
*/ */
public static final int CACHE_SIZE_DEFAULT = getIntSetting("h2.cacheSizeDefault", 16 * 1024); public static final int CACHE_SIZE_DEFAULT = getIntSetting("h2.cacheSizeDefault", 16 * 1024);
// TODO constant
/** /**
* System property <code>h2.cacheTypeDefault</code> (default: LRU).<br /> * System property <code>h2.cacheTypeDefault</code> (default: LRU).<br />
...@@ -159,6 +163,7 @@ public class SysProperties { ...@@ -159,6 +163,7 @@ public class SysProperties {
* cacheSizeIndexShift. * cacheSizeIndexShift.
*/ */
public static final String CACHE_TYPE_DEFAULT = getStringSetting("h2.cacheTypeDefault", "LRU"); public static final String CACHE_TYPE_DEFAULT = getStringSetting("h2.cacheTypeDefault", "LRU");
// TODO constant
/** /**
* System property <code>h2.check</code> (default: true).<br /> * System property <code>h2.check</code> (default: true).<br />
...@@ -193,13 +198,14 @@ public class SysProperties { ...@@ -193,13 +198,14 @@ public class SysProperties {
public static final String CLIENT_TRACE_DIRECTORY = getStringSetting("h2.clientTraceDirectory", "trace.db/"); public static final String CLIENT_TRACE_DIRECTORY = getStringSetting("h2.clientTraceDirectory", "trace.db/");
/** /**
* System property <code>h2.commandCacheSize</code> (default: 0).<br /> * System property <code>h2.queryCacheSize</code> (default: 0).<br />
* The size of the query cache. Each session has it's own cache with the * The size of the query cache. Each session has it's own cache with the
* given size. The cache is only used if the SQL statement and all * given size. The cache is only used if the SQL statement and all
* parameters match. Only the last returned result per query is cached. Only * parameters match. Only the last returned result per query is cached. Only
* SELECT statements are cached (excluding UNION and FOR UPDATE statements). * SELECT statements are cached (excluding UNION and FOR UPDATE statements).
* This works for both statements and prepared statement. * This works for both statements and prepared statement.
*/ */
// DbSettings
public static final int QUERY_CACHE_SIZE = getIntSetting("h2.queryCacheSize", 0); public static final int QUERY_CACHE_SIZE = getIntSetting("h2.queryCacheSize", 0);
/** /**
...@@ -214,6 +220,7 @@ public class SysProperties { ...@@ -214,6 +220,7 @@ public class SysProperties {
* function, and in the CATALOG column of all database meta data methods. * function, and in the CATALOG column of all database meta data methods.
* Setting this to "false" is experimental. * Setting this to "false" is experimental.
*/ */
// DbSettings
public static final boolean DATABASE_TO_UPPER = getBooleanSetting("h2.databaseToUpper", true); public static final boolean DATABASE_TO_UPPER = getBooleanSetting("h2.databaseToUpper", true);
/** /**
...@@ -221,6 +228,7 @@ public class SysProperties { ...@@ -221,6 +228,7 @@ public class SysProperties {
* The default escape character for LIKE comparisons. To select no escape * The default escape character for LIKE comparisons. To select no escape
* character, use an empty string. * character, use an empty string.
*/ */
// DbSettings
public static final String DEFAULT_ESCAPE = getStringSetting("h2.defaultEscape", "\\"); public static final String DEFAULT_ESCAPE = getStringSetting("h2.defaultEscape", "\\");
/** /**
...@@ -229,6 +237,7 @@ public class SysProperties { ...@@ -229,6 +237,7 @@ public class SysProperties {
* The default for the setting MAX_OPERATION_MEMORY. * The default for the setting MAX_OPERATION_MEMORY.
*/ */
public static final int DEFAULT_MAX_OPERATION_MEMORY = getIntSetting("h2.defaultMaxOperationMemory", 100000); public static final int DEFAULT_MAX_OPERATION_MEMORY = getIntSetting("h2.defaultMaxOperationMemory", 100000);
// TODO constant
/** /**
* System property <code>h2.defaultMaxLengthInplaceLob</code> * System property <code>h2.defaultMaxLengthInplaceLob</code>
...@@ -236,6 +245,7 @@ public class SysProperties { ...@@ -236,6 +245,7 @@ public class SysProperties {
* The default maximum length of an LOB that is stored in the database file. * The default maximum length of an LOB that is stored in the database file.
*/ */
public static final int DEFAULT_MAX_LENGTH_INPLACE_LOB = getIntSetting("h2.defaultMaxLengthInplaceLob", 4096); public static final int DEFAULT_MAX_LENGTH_INPLACE_LOB = getIntSetting("h2.defaultMaxLengthInplaceLob", 4096);
// TODO constant
/** /**
* System property <code>h2.defaultMaxLengthInplaceLob2</code> * System property <code>h2.defaultMaxLengthInplaceLob2</code>
...@@ -244,6 +254,7 @@ public class SysProperties { ...@@ -244,6 +254,7 @@ public class SysProperties {
* Only used if h2.lobInDatabase is enabled. * Only used if h2.lobInDatabase is enabled.
*/ */
public static final int DEFAULT_MAX_LENGTH_INPLACE_LOB2 = getIntSetting("h2.defaultMaxLengthInplaceLob2", 128); public static final int DEFAULT_MAX_LENGTH_INPLACE_LOB2 = getIntSetting("h2.defaultMaxLengthInplaceLob2", 128);
// TODO constant
/** /**
* System property <code>h2.defaultResultSetConcurrency</code> (default: * System property <code>h2.defaultResultSetConcurrency</code> (default:
...@@ -252,12 +263,14 @@ public class SysProperties { ...@@ -252,12 +263,14 @@ public class SysProperties {
* Connection.createStatement() or prepareStatement(String sql). * Connection.createStatement() or prepareStatement(String sql).
*/ */
public static final int DEFAULT_RESULT_SET_CONCURRENCY = getIntSetting("h2.defaultResultSetConcurrency", ResultSet.CONCUR_READ_ONLY); public static final int DEFAULT_RESULT_SET_CONCURRENCY = getIntSetting("h2.defaultResultSetConcurrency", ResultSet.CONCUR_READ_ONLY);
// TODO constant
/** /**
* System property <code>h2.defragAlways</code> (default: false).<br /> * System property <code>h2.defragAlways</code> (default: false).<br />
* Each time the database is closed, it is fully defragmented (SHUTDOWN DEFRAG). * Each time the database is closed, it is fully defragmented (SHUTDOWN DEFRAG).
*/ */
public static boolean defragAlways = getBooleanSetting("h2.defragAlways", false); public static boolean defragAlways = getBooleanSetting("h2.defragAlways", false);
// DbSettings
/** /**
* System property <code>h2.dataSourceTraceLevel</code> (default: 1).<br /> * System property <code>h2.dataSourceTraceLevel</code> (default: 1).<br />
...@@ -271,12 +284,14 @@ public class SysProperties { ...@@ -271,12 +284,14 @@ public class SysProperties {
* The default value for the MAX_MEMORY_UNDO setting. * The default value for the MAX_MEMORY_UNDO setting.
*/ */
public static final int DEFAULT_MAX_MEMORY_UNDO = getIntSetting("h2.defaultMaxMemoryUndo", 50000); public static final int DEFAULT_MAX_MEMORY_UNDO = getIntSetting("h2.defaultMaxMemoryUndo", 50000);
// TODO constant
/** /**
* System property <code>h2.defaultLockMode</code> (default: 3).<br /> * System property <code>h2.defaultLockMode</code> (default: 3).<br />
* The default value for the LOCK_MODE setting. * The default value for the LOCK_MODE setting.
*/ */
public static final int DEFAULT_LOCK_MODE = getIntSetting("h2.defaultLockMode", Constants.LOCK_MODE_READ_COMMITTED); public static final int DEFAULT_LOCK_MODE = getIntSetting("h2.defaultLockMode", Constants.LOCK_MODE_READ_COMMITTED);
// TODO constant
/** /**
* System property <code>h2.delayWrongPasswordMin</code> (default: 250).<br /> * System property <code>h2.delayWrongPasswordMin</code> (default: 250).<br />
...@@ -304,6 +319,7 @@ public class SysProperties { ...@@ -304,6 +319,7 @@ public class SysProperties {
* with older versions of H2 the default action is currently CASCADE. This will * with older versions of H2 the default action is currently CASCADE. This will
* change in a future version of H2. * change in a future version of H2.
*/ */
// DbSettings
public static final boolean DROP_RESTRICT = getBooleanSetting("h2.dropRestrict", false); public static final boolean DROP_RESTRICT = getBooleanSetting("h2.dropRestrict", false);
/** /**
...@@ -312,6 +328,7 @@ public class SysProperties { ...@@ -312,6 +328,7 @@ public class SysProperties {
* The estimated number of rows in a function table (for example, CSVREAD or * The estimated number of rows in a function table (for example, CSVREAD or
* FTL_SEARCH). This value is used by the optimizer. * FTL_SEARCH). This value is used by the optimizer.
*/ */
// DbSettings
public static final int ESTIMATED_FUNCTION_TABLE_ROWS = getIntSetting("h2.estimatedFunctionTableRows", 1000); public static final int ESTIMATED_FUNCTION_TABLE_ROWS = getIntSetting("h2.estimatedFunctionTableRows", 1000);
/** /**
...@@ -327,6 +344,7 @@ public class SysProperties { ...@@ -327,6 +344,7 @@ public class SysProperties {
* will always include the schema name in the CREATE ALIAS statement. * will always include the schema name in the CREATE ALIAS statement.
* This is not backward compatible with H2 versions 1.2.134 and older. * This is not backward compatible with H2 versions 1.2.134 and older.
*/ */
// DbSettings
public static final boolean FUNCTIONS_IN_SCHEMA = getBooleanSetting("h2.functionsInSchema", false); public static final boolean FUNCTIONS_IN_SCHEMA = getBooleanSetting("h2.functionsInSchema", false);
/** /**
...@@ -334,7 +352,9 @@ public class SysProperties { ...@@ -334,7 +352,9 @@ public class SysProperties {
* Unquoted identifiers in SQL statements are case insensitive and converted * Unquoted identifiers in SQL statements are case insensitive and converted
* to uppercase. * to uppercase.
*/ */
// DbSettings
public static final boolean IDENTIFIERS_TO_UPPER = getBooleanSetting("h2.identifiersToUpper", true); public static final boolean IDENTIFIERS_TO_UPPER = getBooleanSetting("h2.identifiersToUpper", true);
/** /**
* System property <code>h2.largeResultBufferSize</code> (default: 4096).<br /> * System property <code>h2.largeResultBufferSize</code> (default: 4096).<br />
* Buffer size for large result sets. Set this value to 0 to disable the * Buffer size for large result sets. Set this value to 0 to disable the
......
...@@ -12,6 +12,7 @@ import java.util.Arrays; ...@@ -12,6 +12,7 @@ import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Properties; import java.util.Properties;
import org.h2.command.dml.SetTypes; import org.h2.command.dml.SetTypes;
import org.h2.constant.DbSettings;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.message.DbException; import org.h2.message.DbException;
...@@ -204,6 +205,7 @@ public class ConnectionInfo implements Cloneable { ...@@ -204,6 +205,7 @@ public class ConnectionInfo implements Cloneable {
} }
private void readSettingsFromURL() { private void readSettingsFromURL() {
DbSettings dbSettings = DbSettings.getInstance(null);
int idx = url.indexOf(';'); int idx = url.indexOf(';');
if (idx >= 0) { if (idx >= 0) {
String settings = url.substring(idx + 1); String settings = url.substring(idx + 1);
...@@ -217,7 +219,7 @@ public class ConnectionInfo implements Cloneable { ...@@ -217,7 +219,7 @@ public class ConnectionInfo implements Cloneable {
String value = setting.substring(equal + 1); String value = setting.substring(equal + 1);
String key = setting.substring(0, equal); String key = setting.substring(0, equal);
key = StringUtils.toUpperEnglish(key); key = StringUtils.toUpperEnglish(key);
if (!isKnownSetting(key)) { if (!isKnownSetting(key) && !dbSettings.containsKey(key)) {
throw DbException.get(ErrorCode.UNSUPPORTED_SETTING_1, key); throw DbException.get(ErrorCode.UNSUPPORTED_SETTING_1, key);
} }
String old = prop.getProperty(key); String old = prop.getProperty(key);
...@@ -559,4 +561,20 @@ public class ConnectionInfo implements Cloneable { ...@@ -559,4 +561,20 @@ public class ConnectionInfo implements Cloneable {
this.name = serverKey; this.name = serverKey;
} }
public DbSettings getDbSettings() {
DbSettings defaultSettings = DbSettings.getInstance(null);
Properties p = null;
for (Object s : prop.keySet()) {
String k = s.toString();
if (!isKnownSetting(k) && defaultSettings.containsKey(k)) {
if (p == null) {
p = new Properties();
}
p.put(k, prop.get(k));
prop.remove(k);
}
}
return DbSettings.getInstance(p);
}
} }
...@@ -19,6 +19,7 @@ import java.util.StringTokenizer; ...@@ -19,6 +19,7 @@ import java.util.StringTokenizer;
import org.h2.api.DatabaseEventListener; import org.h2.api.DatabaseEventListener;
import org.h2.command.ddl.CreateTableData; import org.h2.command.ddl.CreateTableData;
import org.h2.command.dml.SetTypes; import org.h2.command.dml.SetTypes;
import org.h2.constant.DbSettings;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.constraint.Constraint; import org.h2.constraint.Constraint;
...@@ -168,9 +169,11 @@ public class Database implements DataHandler { ...@@ -168,9 +169,11 @@ public class Database implements DataHandler {
private LobStorage lobStorage; private LobStorage lobStorage;
private int pageSize = SysProperties.PAGE_SIZE; private int pageSize = SysProperties.PAGE_SIZE;
private int defaultTableType = Table.TYPE_CACHED; private int defaultTableType = Table.TYPE_CACHED;
private DbSettings dbSettings;
public Database(ConnectionInfo ci, String cipher) { public Database(ConnectionInfo ci, String cipher) {
String name = ci.getName(); String name = ci.getName();
this.dbSettings = ci.getDbSettings();
this.compareMode = CompareMode.getInstance(null, 0); this.compareMode = CompareMode.getInstance(null, 0);
this.persistent = ci.isPersistent(); this.persistent = ci.isPersistent();
this.filePasswordHash = ci.getFilePasswordHash(); this.filePasswordHash = ci.getFilePasswordHash();
...@@ -481,7 +484,7 @@ public class Database implements DataHandler { ...@@ -481,7 +484,7 @@ public class Database implements DataHandler {
if (n == null || n.length() == 0) { if (n == null || n.length() == 0) {
n = "unnamed"; n = "unnamed";
} }
return SysProperties.DATABASE_TO_UPPER ? StringUtils.toUpperEnglish(n) : n; return getSettings().databaseToUpper ? StringUtils.toUpperEnglish(n) : n;
} }
private synchronized void open(int traceLevelFile, int traceLevelSystemOut) { private synchronized void open(int traceLevelFile, int traceLevelSystemOut) {
...@@ -2275,4 +2278,8 @@ public class Database implements DataHandler { ...@@ -2275,4 +2278,8 @@ public class Database implements DataHandler {
this.multiVersion = multiVersion; this.multiVersion = multiVersion;
} }
public DbSettings getSettings() {
return dbSettings;
}
} }
...@@ -191,7 +191,7 @@ public class FunctionAlias extends SchemaObjectBase { ...@@ -191,7 +191,7 @@ public class FunctionAlias extends SchemaObjectBase {
public String getSQL() { public String getSQL() {
// TODO can remove this method once FUNCTIONS_IN_SCHEMA is enabled // TODO can remove this method once FUNCTIONS_IN_SCHEMA is enabled
if (SysProperties.FUNCTIONS_IN_SCHEMA || !getSchema().getName().equals(Constants.SCHEMA_MAIN)) { if (database.getSettings().functionsInSchema || !getSchema().getName().equals(Constants.SCHEMA_MAIN)) {
return super.getSQL(); return super.getSQL();
} }
return Parser.quoteIdentifier(getName()); return Parser.quoteIdentifier(getName());
......
...@@ -101,15 +101,12 @@ public class Session extends SessionWithState { ...@@ -101,15 +101,12 @@ public class Session extends SessionWithState {
private int modificationId; private int modificationId;
private int modificationIdState; private int modificationIdState;
private int objectId; private int objectId;
private int queryCacheSize = SysProperties.QUERY_CACHE_SIZE; private final int queryCacheSize;
private SmallLRUCache<String, Command> queryCache; private SmallLRUCache<String, Command> queryCache;
public Session() {
// to create a new session using the factory
}
public Session(Database database, User user, int id) { public Session(Database database, User user, int id) {
this.database = database; this.database = database;
this.queryCacheSize = database.getSettings().queryCacheSize;
this.undoLog = new UndoLog(this); this.undoLog = new UndoLog(this);
this.user = user; this.user = user;
this.id = id; this.id = id;
......
/*
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.engine;
import java.util.Properties;
import org.h2.constant.ErrorCode;
import org.h2.message.DbException;
/**
* The base class for settings.
*/
public class SettingsBase {
private Properties properties;
protected SettingsBase(Properties p) {
this.properties = p;
}
protected boolean get(String key, boolean defaultValue) {
String s = get(key, "" + defaultValue);
try {
return Boolean.valueOf(s).booleanValue();
} catch (NumberFormatException e) {
throw DbException.get(ErrorCode.DATA_CONVERSION_ERROR_1, e, "key:" + key + " value:" + s);
}
}
protected int get(String key, int defaultValue) {
String s = get(key, "" + defaultValue);
try {
return Integer.decode(s);
} catch (NumberFormatException e) {
throw DbException.get(ErrorCode.DATA_CONVERSION_ERROR_1, e, "key:" + key + " value:" + s);
}
}
protected String get(String key, String defaultValue) {
String keyUpper = key.toUpperCase();
String v = properties.getProperty(keyUpper);
if (v == null) {
v = System.getProperty("h2." + key);
}
if (v == null) {
properties.put(keyUpper, defaultValue);
v = defaultValue;
}
return v;
}
public boolean containsKey(String k) {
return properties.containsKey(k);
}
}
...@@ -9,7 +9,7 @@ package org.h2.expression; ...@@ -9,7 +9,7 @@ package org.h2.expression;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException; import java.util.regex.PatternSyntaxException;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.index.IndexCondition; import org.h2.index.IndexCondition;
import org.h2.message.DbException; import org.h2.message.DbException;
...@@ -27,9 +27,9 @@ import org.h2.value.ValueString; ...@@ -27,9 +27,9 @@ import org.h2.value.ValueString;
public class CompareLike extends Condition { public class CompareLike extends Condition {
private static final int MATCH = 0, ONE = 1, ANY = 2; private static final int MATCH = 0, ONE = 1, ANY = 2;
private static final Character DEFAULT_ESCAPE_CHAR = getEscapeChar(SysProperties.DEFAULT_ESCAPE);
private final CompareMode compareMode; private final CompareMode compareMode;
private final String defaultEscape;
private Expression left; private Expression left;
private Expression right; private Expression right;
private Expression escape; private Expression escape;
...@@ -48,8 +48,13 @@ public class CompareLike extends Condition { ...@@ -48,8 +48,13 @@ public class CompareLike extends Condition {
private boolean fastCompare; private boolean fastCompare;
private boolean invalidPattern; private boolean invalidPattern;
public CompareLike(CompareMode compareMode, Expression left, Expression right, Expression escape, boolean regexp) { public CompareLike(Database db, Expression left, Expression right, Expression escape, boolean regexp) {
this(db.getCompareMode(), db.getSettings().defaultEscape, left, right, escape, regexp);
}
public CompareLike(CompareMode compareMode, String defaultEscape, Expression left, Expression right, Expression escape, boolean regexp) {
this.compareMode = compareMode; this.compareMode = compareMode;
this.defaultEscape = defaultEscape;
this.regexp = regexp; this.regexp = regexp;
this.left = left; this.left = left;
this.right = right; this.right = right;
...@@ -124,12 +129,12 @@ public class CompareLike extends Condition { ...@@ -124,12 +129,12 @@ public class CompareLike extends Condition {
private Character getEscapeChar(Value e) { private Character getEscapeChar(Value e) {
if (e == null) { if (e == null) {
return DEFAULT_ESCAPE_CHAR; return getEscapeChar(defaultEscape);
} }
String es = e.getString(); String es = e.getString();
Character esc; Character esc;
if (es == null) { if (es == null) {
esc = DEFAULT_ESCAPE_CHAR; esc = getEscapeChar(defaultEscape);
} else if (es.length() == 0) { } else if (es.length() == 0) {
esc = null; esc = null;
} else if (es.length() > 1) { } else if (es.length() > 1) {
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
package org.h2.expression; package org.h2.expression;
import org.h2.command.Parser; import org.h2.command.Parser;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.engine.FunctionAlias; import org.h2.engine.FunctionAlias;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -85,7 +84,7 @@ public class JavaFunction extends Expression implements FunctionCall { ...@@ -85,7 +84,7 @@ public class JavaFunction extends Expression implements FunctionCall {
public String getSQL() { public String getSQL() {
StatementBuilder buff = new StatementBuilder(); StatementBuilder buff = new StatementBuilder();
// TODO always append the schema once FUNCTIONS_IN_SCHEMA is enabled // TODO always append the schema once FUNCTIONS_IN_SCHEMA is enabled
if (SysProperties.FUNCTIONS_IN_SCHEMA || if (functionAlias.getDatabase().getSettings().functionsInSchema ||
!functionAlias.getSchema().getName().equals(Constants.SCHEMA_MAIN)) { !functionAlias.getSchema().getName().equals(Constants.SCHEMA_MAIN)) {
buff.append(Parser.quoteIdentifier(functionAlias.getSchema().getName())).append('.'); buff.append(Parser.quoteIdentifier(functionAlias.getSchema().getName())).append('.');
} }
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
*/ */
package org.h2.index; package org.h2.index;
import org.h2.constant.SysProperties;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.result.ResultInterface; import org.h2.result.ResultInterface;
...@@ -56,7 +55,7 @@ public class FunctionIndex extends BaseIndex { ...@@ -56,7 +55,7 @@ public class FunctionIndex extends BaseIndex {
if (functionTable.canGetRowCount()) { if (functionTable.canGetRowCount()) {
expectedRows = functionTable.getRowCountApproximation(); expectedRows = functionTable.getRowCountApproximation();
} else { } else {
expectedRows = SysProperties.ESTIMATED_FUNCTION_TABLE_ROWS; expectedRows = database.getSettings().estimatedFunctionTableRows;
} }
return expectedRows * 10; return expectedRows * 10;
} }
......
...@@ -474,7 +474,7 @@ public class PageStore implements CacheWriter { ...@@ -474,7 +474,7 @@ public class PageStore implements CacheWriter {
boolean isCompactFully = compactMode == CommandInterface.SHUTDOWN_COMPACT; boolean isCompactFully = compactMode == CommandInterface.SHUTDOWN_COMPACT;
boolean isDefrag = compactMode == CommandInterface.SHUTDOWN_DEFRAG; boolean isDefrag = compactMode == CommandInterface.SHUTDOWN_DEFRAG;
if (SysProperties.defragAlways) { if (database.getSettings().defragAlways) {
isCompactFully = isDefrag = true; isCompactFully = isDefrag = true;
} }
......
...@@ -59,7 +59,7 @@ public class RegularTable extends TableBase { ...@@ -59,7 +59,7 @@ public class RegularTable extends TableBase {
private boolean containsLargeObject; private boolean containsLargeObject;
private PageDataIndex mainIndex; private PageDataIndex mainIndex;
private int changesSinceAnalyze; private int changesSinceAnalyze;
private int nextAnalyze = SysProperties.ANALYZE_AUTO; private int nextAnalyze;
/** /**
* True if one thread ever was waiting to lock this table. This is to avoid * True if one thread ever was waiting to lock this table. This is to avoid
...@@ -70,6 +70,7 @@ public class RegularTable extends TableBase { ...@@ -70,6 +70,7 @@ public class RegularTable extends TableBase {
public RegularTable(CreateTableData data) { public RegularTable(CreateTableData data) {
super(data); super(data);
nextAnalyze = database.getSettings().analyzeAuto;
this.isHidden = data.isHidden; this.isHidden = data.isHidden;
if (data.persistData && database.isPersistent()) { if (data.persistData && database.isPersistent()) {
mainIndex = new PageDataIndex(this, data.id, IndexColumn.wrap(getColumns()), IndexType.createScan(data.persistData), data.create, data.session); mainIndex = new PageDataIndex(this, data.id, IndexColumn.wrap(getColumns()), IndexType.createScan(data.persistData), data.create, data.session);
......
...@@ -44,7 +44,7 @@ public class TestPattern extends TestBase { ...@@ -44,7 +44,7 @@ public class TestPattern extends TestBase {
private void testPattern() { private void testPattern() {
CompareMode mode = CompareMode.getInstance(null, 0); CompareMode mode = CompareMode.getInstance(null, 0);
CompareLike comp = new CompareLike(mode, null, null, null, false); CompareLike comp = new CompareLike(mode, "\\", null, null, null, false);
test(comp, "B", "%_"); test(comp, "B", "%_");
test(comp, "A", "A%"); test(comp, "A", "A%");
test(comp, "A", "A%%"); test(comp, "A", "A%%");
......
...@@ -658,4 +658,4 @@ skiing honor marketing sleeping dlucene timezones shifted analyzed insists ...@@ -658,4 +658,4 @@ skiing honor marketing sleeping dlucene timezones shifted analyzed insists
train joining bilingual existed extremely fog bordercolor overlapping train joining bilingual existed extremely fog bordercolor overlapping
unlocking webkit dalvik recorded defrag marschall helping victor philippe unlocking webkit dalvik recorded defrag marschall helping victor philippe
pyankov enctype multipart boundary mistake enlarge demonstrates aggregating pyankov enctype multipart boundary mistake enlarge demonstrates aggregating
bypassing khtml doubled inlined defragmented registers bypassing khtml doubled inlined defragmented registers leftover
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论