Skip to content

Commit

Permalink
每个数据库实例通过DbSettings引用具体的参数设置
Browse files Browse the repository at this point in the history
  • Loading branch information
codefollower committed Mar 6, 2017
1 parent a2da896 commit 36f16f0
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 147 deletions.
Expand Up @@ -64,10 +64,11 @@ public static Session getAndRemoveInternalSession() {
private static final HashSet<String> KNOWN_SETTINGS = New.hashSet();

static {
KNOWN_SETTINGS.addAll(DbSettings.getDefaultSettings().getSettings().keySet());
KNOWN_SETTINGS.addAll(SetTypes.getTypes());

String[] connectionSettings = { "CIPHER", "CREATE", "CACHE_TYPE", "IGNORE_UNKNOWN_SETTINGS", "IFEXISTS", "INIT",
"PASSWORD", "RECOVER", "RECOVER_TEST", "USER", "PAGE_SIZE", "PASSWORD_HASH", "IS_LOCAL" };
String[] connectionSettings = { "IGNORE_UNKNOWN_SETTINGS", "IFEXISTS", "INIT", "USER", "PASSWORD",
"PASSWORD_HASH", "IS_LOCAL" };

for (String key : connectionSettings) {
if (SysProperties.CHECK && KNOWN_SETTINGS.contains(key)) {
Expand Down
21 changes: 19 additions & 2 deletions lealone-common/src/main/java/org/lealone/db/DbSettings.java
Expand Up @@ -11,6 +11,8 @@

import org.lealone.api.ErrorCode;
import org.lealone.common.exceptions.DbException;
import org.lealone.common.trace.TraceSystem;
import org.lealone.common.util.StringUtils;
import org.lealone.common.util.Utils;

/**
Expand Down Expand Up @@ -347,9 +349,19 @@ private DbSettings(Map<String, String> s) {

public final int net = get("NET", 0);

public final int block_io = get("BLOCK_IO", 0);
public final int blockIo = get("BLOCK_IO", 0);

public final int service_level = get("SERVICE_LEVEL", 0);
public final int serviceLevel = get("SERVICE_LEVEL", 0);

public final int cacheSize = get("CACHE_SIZE", Constants.DEFAULT_CACHE_SIZE);
public final int pageSize = get("PAGE_SIZE", Constants.DEFAULT_PAGE_SIZE);
public final String eventListener = get("DATABASE_EVENT_LISTENER", null);
public final String mode = get("MODE", null);
public final String cipher = get("CIPHER", null);
public final byte[] filePasswordHash = convertHexToBytes("FILE_PASSWORD_HASH", null);
public final byte[] fileEncryptionKey = convertHexToBytes("FILE_ENCRYPTION_KEY", null);
public final int traceLevelFile = get("TRACE_LEVEL_FILE", TraceSystem.DEFAULT_TRACE_LEVEL_FILE);
public final int traceLevelSystemOut = get("TRACE_LEVEL_SYSTEM_OUT", TraceSystem.DEFAULT_TRACE_LEVEL_SYSTEM_OUT);

/**
* Get the setting for the given key.
Expand Down Expand Up @@ -409,6 +421,11 @@ protected String get(String key, String defaultValue) {
return v;
}

private byte[] convertHexToBytes(String key, String defaultValue) {
String v = get(key, defaultValue);
return v == null ? null : StringUtils.convertHexToBytes(v);
}

/**
* Check if the settings contains the given key.
*
Expand Down
64 changes: 22 additions & 42 deletions lealone-common/src/main/java/org/lealone/db/SysProperties.java
Expand Up @@ -38,10 +38,6 @@
*
*/
public class SysProperties {
/**
* INTERNAL
*/
private static final String SCRIPT_DIRECTORY = "script.directory";

/**
* System property <code>file.encoding</code> (default: Cp1252).<br />
Expand Down Expand Up @@ -70,8 +66,7 @@ public class SysProperties {

/**
* 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.
* It is usually set by the system, and used as a replacement for ~ in file names.
*/
public static final String USER_HOME = Utils.getProperty("user.home", "");

Expand All @@ -85,21 +80,13 @@ public class SysProperties {
* System property <code>check</code> (default: true).<br />
* Assertions in the database engine.
*/
// ## CHECK ##
public static final boolean CHECK = getProperty("check", true);
/*/
public static final boolean CHECK = false;
//*/

/**
* System property <code>check2</code> (default: true).<br />
* Additional assertions in the database engine.
*/
// ## CHECK ##
public static final boolean CHECK2 = getProperty("check2", false);
/*/
public static final boolean CHECK2 = false;
//*/

/**
* System property <code>client.trace.directory</code> (default: trace.db/).<br />
Expand All @@ -116,8 +103,7 @@ public class SysProperties {

/**
* System property <code>datasource.trace.level</code> (default: 1).<br />
* The trace level of the data source implementation. Default is 1 for
* error.
* The trace level of the data source implementation. Default is 1 for error.
*/
public static final int DATASOURCE_TRACE_LEVEL = getProperty("datasource.trace.level", TraceSystem.ERROR);

Expand Down Expand Up @@ -159,8 +145,7 @@ public class SysProperties {
public static final boolean LOB_IN_DATABASE = getProperty("lob.in.database", true);

/**
* System property <code>lob.client.max.size.memory</code> (default:
* 1048576).<br />
* System property <code>lob.client.max.size.memory</code> (default: 1048576).<br />
* The maximum size of a LOB object to keep in memory on the client side
* when using the server mode.
*/
Expand Down Expand Up @@ -206,8 +191,7 @@ public class SysProperties {
public static final boolean OBJECT_CACHE = getProperty("object.cache", true);

/**
* System property <code>object.cache.max.per.element.size</code> (default:
* 4096).<br />
* System property <code>object.cache.max.per.element.size</code> (default: 4096).<br />
* The maximum size (precision) of an object in the cache.
*/
public static final int OBJECT_CACHE_MAX_PER_ELEMENT_SIZE = getProperty("object.cache.max.per.element.size", 4096);
Expand All @@ -219,13 +203,6 @@ public class SysProperties {
*/
public static final int OBJECT_CACHE_SIZE = MathUtils.nextPowerOf2(getProperty("object.cache.size", 1024));

/**
* System property <code>pg.client.encoding</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 = getProperty("pg.client.encoding", "UTF-8");

/**
* System property <code>prefix.temp.file</code> (default: lealone.temp).<br />
* The prefix for temporary files in the temp directory.
Expand Down Expand Up @@ -341,8 +318,7 @@ public class SysProperties {
* equal, but objects are not, the serialized forms (the byte arrays) are
* compared.
* <br />
* The string representation of the values use the toString method of
* object.
* The string representation of the values use the toString method of object.
* <br />
* In client-server mode, the server must have all required classes in the
* class path. On the client side, this setting is required to be disabled
Expand All @@ -367,14 +343,30 @@ public class SysProperties {
* (default: false).<br />
* Limited support for the old-style Oracle outer join with "(+)".
*/
public static final boolean OLD_STYLE_OUTER_JOIN = Utils.getProperty("old.style.outer.join", false);
public static final boolean OLD_STYLE_OUTER_JOIN = getProperty("old.style.outer.join", false);

/**
* INTERNAL
*/
private static final String SCRIPT_DIRECTORY = "script.directory";
private static final String BASE_DIR = "base.dir";

private SysProperties() {
// utility class
}

/**
* System property <code>scriptDirectory</code> (default: empty
* string).<br />
* Relative or absolute directory where the script files are stored to or
* read from.
*
* @return the current value
*/
public static String getScriptDirectory() {
return getProperty(SCRIPT_DIRECTORY, "");
}

/**
* INTERNAL
*/
Expand All @@ -397,18 +389,6 @@ public static String setBaseDir(String baseDir) {
return System.setProperty(Constants.PROJECT_NAME_PREFIX + BASE_DIR, baseDir);
}

/**
* System property <code>scriptDirectory</code> (default: empty
* string).<br />
* Relative or absolute directory where the script files are stored to or
* read from.
*
* @return the current value
*/
public static String getScriptDirectory() {
return getProperty(SCRIPT_DIRECTORY, "");
}

private static String getProperty(String key, String defaultValue) {
return Utils.getProperty(Constants.PROJECT_NAME_PREFIX + key, defaultValue);
}
Expand Down

0 comments on commit 36f16f0

Please sign in to comment.