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

Various system properties have been replaced with database level settings.

上级 c5a3778e
...@@ -125,6 +125,14 @@ public class DbSettings extends SettingsBase { ...@@ -125,6 +125,14 @@ public class DbSettings extends SettingsBase {
*/ */
public final int queryCacheSize = get("QUERY_CACHE_SIZE", 0); public final int queryCacheSize = get("QUERY_CACHE_SIZE", 0);
/**
* Database setting <code>MAX_QUERY_TIMEOUT</code> (default: 0).<br />
* The maximum timeout of a query in milliseconds. The default is 0, meaning
* no limit. Please note the actual query timeout may be set to a lower
* value.
*/
public int maxQueryTimeout = get("MAX_QUERY_TIMEOUT", 0);
private DbSettings(HashMap<String, String> s) { private DbSettings(HashMap<String, String> s) {
super(s); super(s);
} }
......
...@@ -37,12 +37,6 @@ public class SysProperties { ...@@ -37,12 +37,6 @@ public class SysProperties {
*/ */
public static final String H2_SCRIPT_DIRECTORY = "h2.scriptDirectory"; public static final String H2_SCRIPT_DIRECTORY = "h2.scriptDirectory";
/**
* INTERNAL
*/
public static final String H2_MAX_QUERY_TIMEOUT = "h2.maxQueryTimeout";
// TODO DbSettings
/** /**
* INTERNAL * INTERNAL
*/ */
...@@ -638,16 +632,6 @@ public class SysProperties { ...@@ -638,16 +632,6 @@ public class SysProperties {
return getStringSetting(H2_SCRIPT_DIRECTORY, ""); return getStringSetting(H2_SCRIPT_DIRECTORY, "");
} }
/**
* System property <code>h2.maxQueryTimeout</code> (default: 0).<br />
* The maximum timeout of a query. The default is 0, meaning no limit.
*
* @return the current value
*/
public static int getMaxQueryTimeout() {
return getIntSetting(H2_MAX_QUERY_TIMEOUT, 0);
}
/** /**
* System property <code>h2.collatorCacheSize</code> (default: 32000).<br /> * System property <code>h2.collatorCacheSize</code> (default: 32000).<br />
* The cache size for collation keys (in elements). Used when a collator has * The cache size for collation keys (in elements). Used when a collator has
......
...@@ -28,6 +28,7 @@ import org.h2.util.Utils; ...@@ -28,6 +28,7 @@ import org.h2.util.Utils;
*/ */
public class ConnectionInfo implements Cloneable { public class ConnectionInfo implements Cloneable {
private static final HashSet<String> KNOWN_SETTINGS = New.hashSet(); private static final HashSet<String> KNOWN_SETTINGS = New.hashSet();
private Properties prop = new Properties(); private Properties prop = new Properties();
private String originalURL; private String originalURL;
private String url; private String url;
...@@ -562,10 +563,9 @@ public class ConnectionInfo implements Cloneable { ...@@ -562,10 +563,9 @@ public class ConnectionInfo implements Cloneable {
this.name = serverKey; this.name = serverKey;
} }
public DbSettings getDbSettings() { DbSettings getDbSettings() {
DbSettings defaultSettings = DbSettings.getInstance(null); DbSettings defaultSettings = DbSettings.getInstance(null);
HashMap<String, String> s = null; HashMap<String, String> s = null;
ArrayList<String> remove = New.arrayList();
for (Object k : prop.keySet()) { for (Object k : prop.keySet()) {
String key = k.toString(); String key = k.toString();
if (!isKnownSetting(key) && defaultSettings.containsKey(key)) { if (!isKnownSetting(key) && defaultSettings.containsKey(key)) {
...@@ -573,11 +573,7 @@ public class ConnectionInfo implements Cloneable { ...@@ -573,11 +573,7 @@ public class ConnectionInfo implements Cloneable {
s = New.hashMap(); s = New.hashMap();
} }
s.put(key, prop.getProperty(key)); s.put(key, prop.getProperty(key));
remove.add(key);
}
} }
for (String r : remove) {
prop.remove(r);
} }
return DbSettings.getInstance(s); return DbSettings.getInstance(s);
} }
......
...@@ -484,7 +484,7 @@ public class Database implements DataHandler { ...@@ -484,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 getSettings().databaseToUpper ? StringUtils.toUpperEnglish(n) : n; return dbSettings.databaseToUpper ? StringUtils.toUpperEnglish(n) : n;
} }
private synchronized void open(int traceLevelFile, int traceLevelSystemOut) { private synchronized void open(int traceLevelFile, int traceLevelSystemOut) {
......
...@@ -10,6 +10,7 @@ import java.util.HashMap; ...@@ -10,6 +10,7 @@ import java.util.HashMap;
import org.h2.command.CommandInterface; import org.h2.command.CommandInterface;
import org.h2.command.Parser; import org.h2.command.Parser;
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;
...@@ -157,7 +158,12 @@ public class Engine implements SessionFactory { ...@@ -157,7 +158,12 @@ public class Engine implements SessionFactory {
} }
} }
session.setAllowLiterals(true); session.setAllowLiterals(true);
DbSettings defaultSettings = DbSettings.getInstance(null);
for (String setting : ci.getKeys()) { for (String setting : ci.getKeys()) {
if (defaultSettings.containsKey(setting)) {
// database setting are only used when opening the database
continue;
}
String value = ci.getProperty(setting); String value = ci.getProperty(setting);
try { try {
CommandInterface command = session.prepareCommand("SET " + Parser.quoteIdentifier(setting) + " " CommandInterface command = session.prepareCommand("SET " + Parser.quoteIdentifier(setting) + " "
......
...@@ -95,7 +95,7 @@ public class Session extends SessionWithState { ...@@ -95,7 +95,7 @@ public class Session extends SessionWithState {
private long currentCommandStart; private long currentCommandStart;
private HashMap<String, Value> variables; private HashMap<String, Value> variables;
private HashSet<ResultInterface> temporaryResults; private HashSet<ResultInterface> temporaryResults;
private int queryTimeout = SysProperties.getMaxQueryTimeout(); private int queryTimeout;
private boolean commitOrRollbackDisabled; private boolean commitOrRollbackDisabled;
private Table waitForLock; private Table waitForLock;
private int modificationId; private int modificationId;
...@@ -106,6 +106,7 @@ public class Session extends SessionWithState { ...@@ -106,6 +106,7 @@ public class Session extends SessionWithState {
public Session(Database database, User user, int id) { public Session(Database database, User user, int id) {
this.database = database; this.database = database;
this.queryTimeout = database.getSettings().maxQueryTimeout;
this.queryCacheSize = database.getSettings().queryCacheSize; this.queryCacheSize = database.getSettings().queryCacheSize;
this.undoLog = new UndoLog(this); this.undoLog = new UndoLog(this);
this.user = user; this.user = user;
...@@ -1125,7 +1126,7 @@ public class Session extends SessionWithState { ...@@ -1125,7 +1126,7 @@ public class Session extends SessionWithState {
} }
public void setQueryTimeout(int queryTimeout) { public void setQueryTimeout(int queryTimeout) {
int max = SysProperties.getMaxQueryTimeout(); int max = database.getSettings().maxQueryTimeout;
if (max != 0 && (max < queryTimeout || queryTimeout == 0)) { if (max != 0 && (max < queryTimeout || queryTimeout == 0)) {
// the value must be at most max // the value must be at most max
queryTimeout = max; queryTimeout = max;
......
...@@ -12,9 +12,7 @@ import java.sql.ResultSet; ...@@ -12,9 +12,7 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Savepoint; import java.sql.Savepoint;
import java.sql.Statement; import java.sql.Statement;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/** /**
...@@ -149,10 +147,7 @@ public class TestCancel extends TestBase { ...@@ -149,10 +147,7 @@ public class TestCancel extends TestBase {
private void testMaxQueryTimeout() throws SQLException { private void testMaxQueryTimeout() throws SQLException {
deleteDb("cancel"); deleteDb("cancel");
int oldMax = SysProperties.getMaxQueryTimeout(); Connection conn = getConnection("cancel;MAX_QUERY_TIMEOUT=10");
try {
System.setProperty(SysProperties.H2_MAX_QUERY_TIMEOUT, "" + 10);
Connection conn = getConnection("cancel");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
try { try {
stat.executeQuery("SELECT MAX(RAND()) FROM SYSTEM_RANGE(1, 100000000)"); stat.executeQuery("SELECT MAX(RAND()) FROM SYSTEM_RANGE(1, 100000000)");
...@@ -161,9 +156,6 @@ public class TestCancel extends TestBase { ...@@ -161,9 +156,6 @@ public class TestCancel extends TestBase {
assertEquals(ErrorCode.STATEMENT_WAS_CANCELED, e.getErrorCode()); assertEquals(ErrorCode.STATEMENT_WAS_CANCELED, e.getErrorCode());
} }
conn.close(); conn.close();
} finally {
System.setProperty("h2.maxQueryTimeout", "" + oldMax);
}
} }
/** /**
......
...@@ -32,7 +32,6 @@ import java.util.Comparator; ...@@ -32,7 +32,6 @@ import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.jdbc.JdbcConnection; import org.h2.jdbc.JdbcConnection;
import org.h2.store.FileLister; import org.h2.store.FileLister;
import org.h2.test.TestAll; import org.h2.test.TestAll;
...@@ -177,7 +176,7 @@ public class TestCrashAPI extends TestBase implements Runnable { ...@@ -177,7 +176,7 @@ public class TestCrashAPI extends TestBase implements Runnable {
// can not use FILE_LOCK=NO, otherwise something could be written into // can not use FILE_LOCK=NO, otherwise something could be written into
// the database in the finalize method // the database in the finalize method
String add = ""; String add = ";MAX_QUERY_TIMEOUT=10000";
// int testing; // int testing;
// if(openCount >= 32) { // if(openCount >= 32) {
...@@ -263,7 +262,7 @@ public class TestCrashAPI extends TestBase implements Runnable { ...@@ -263,7 +262,7 @@ public class TestCrashAPI extends TestBase implements Runnable {
return conn; return conn;
} }
private void testOne(int seed) throws SQLException { public void testCase(int seed) throws SQLException {
printTime("seed: " + seed); printTime("seed: " + seed);
callCount = 0; callCount = 0;
openCount = 0; openCount = 0;
...@@ -513,14 +512,4 @@ public class TestCrashAPI extends TestBase implements Runnable { ...@@ -513,14 +512,4 @@ public class TestCrashAPI extends TestBase implements Runnable {
return this; return this;
} }
public void testCase(int i) throws SQLException {
int old = SysProperties.getMaxQueryTimeout();
try {
System.setProperty(SysProperties.H2_MAX_QUERY_TIMEOUT, "" + 10000);
testOne(i);
} finally {
System.setProperty(SysProperties.H2_MAX_QUERY_TIMEOUT, "" + old);
}
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论