提交 91eb57ed authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 95c8ef4c
......@@ -15,7 +15,11 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul>
<li>UPDATE SET column=DEFAULT is now supported.
<li>The performance of text comparison has been improved when using locale sensitive
string comparison (SET COLLATOR). Now CollationKey is used with a LRU cache.
The default cache size is 10000, and can be changed using the system property
h2.collatorCacheSize. Use 0 to disable the cache.
</li><li>UPDATE SET column=DEFAULT is now supported.
</li></ul>
<h2>Version 1.0.67 (2008-02-22)</h2>
......
......@@ -10,6 +10,7 @@ import java.text.Collator;
import org.h2.command.Prepared;
import org.h2.compress.Compressor;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.engine.Database;
import org.h2.engine.DbObject;
import org.h2.engine.Mode;
......@@ -119,10 +120,10 @@ public class Set extends Prepared {
CompareMode compareMode;
StringBuffer buff = new StringBuffer(stringValue);
if (stringValue.equals(CompareMode.OFF)) {
compareMode = new CompareMode(null, null);
compareMode = new CompareMode(null, null, 0);
} else {
Collator coll = CompareMode.getCollator(stringValue);
compareMode = new CompareMode(coll, stringValue);
compareMode = new CompareMode(coll, stringValue, SysProperties.getCollatorCacheSize());
buff.append(" STRENGTH ");
if (getIntValue() == Collator.IDENTICAL) {
buff.append("IDENTICAL");
......
......@@ -31,6 +31,11 @@ public class SysProperties {
*/
public static final String H2_LOG_DELETE_DELAY = "h2.logDeleteDelay";
/**
* INTERNAL
*/
public static final String H2_COLLATOR_CACHE_SIZE = "h2.collatorCacheSize";
/**
* System property <code>file.encoding</code> (default: Cp1252).<br />
* It is usually set by the system and is the default encoding used for the RunScript and CSV tool.
......@@ -339,6 +344,12 @@ public class SysProperties {
*/
public static final int LARGE_RESULT_BUFFER_SIZE = getIntSetting("h2.largeResultBufferSize", 4 * 1024);
/**
* System property <code>h2.collatorCacheSize</code> (default: 10000).<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 = getCollatorCacheSize();
private static String baseDir = getStringSetting("h2.baseDir", null);
private static boolean getBooleanSetting(String name, boolean defaultValue) {
......@@ -413,4 +424,11 @@ public class SysProperties {
public static int getLogFileDeleteDelay() {
return getIntSetting(H2_LOG_DELETE_DELAY, 0);
}
/**
* INTERNAL
*/
public static int getCollatorCacheSize() {
return getIntSetting(H2_COLLATOR_CACHE_SIZE, 32000);
}
}
......@@ -150,7 +150,7 @@ public class Database implements DataHandler {
private int maxOperationMemory = SysProperties.DEFAULT_MAX_OPERATION_MEMORY;
public Database(String name, ConnectionInfo ci, String cipher) throws SQLException {
this.compareMode = new CompareMode(null, null);
this.compareMode = new CompareMode(null, null, 0);
this.persistent = ci.isPersistent();
this.filePasswordHash = ci.getFilePasswordHash();
this.databaseName = name;
......
......@@ -718,6 +718,7 @@ public class MetaTable extends Table {
add(rows, new String[]{"h2.check", "" + SysProperties.CHECK});
add(rows, new String[]{"h2.check2", "" + SysProperties.CHECK2});
add(rows, new String[]{"h2.clientTraceDirectory", SysProperties.CLIENT_TRACE_DIRECTORY});
add(rows, new String[]{SysProperties.H2_COLLATOR_CACHE_SIZE, "" + SysProperties.getCollatorCacheSize()});
add(rows, new String[]{"h2.defaultMaxMemoryUndo", "" + SysProperties.DEFAULT_MAX_MEMORY_UNDO});
add(rows, new String[]{"h2.emergencySpaceInitial", "" + SysProperties.EMERGENCY_SPACE_INITIAL});
add(rows, new String[]{"h2.emergencySpaceMin", "" + SysProperties.EMERGENCY_SPACE_MIN});
......
......@@ -23,10 +23,19 @@ public class StartBrowser {
// Runtime.getRuntime().exec("open " + url + "/index.html");
Runtime.getRuntime().exec("open " + url);
} else {
System.out.println("Please open a browser and go to "+ url);
try {
Runtime.getRuntime().exec("firefox " + url);
} catch (Exception e) {
try {
Runtime.getRuntime().exec("mozilla-firefox " + url);
} catch (Exception e2) {
// No success in detection.
System.out.println("Please open a browser and go to " + url);
}
}
}
} catch (IOException e) {
System.out.println("Failed to start a browser to open the url " + url);
System.out.println("Failed to start a browser to open the URL " + url);
e.printStackTrace();
}
}
......
......@@ -4,9 +4,11 @@
*/
package org.h2.value;
import java.text.CollationKey;
import java.text.Collator;
import java.util.Locale;
import org.h2.util.SmallLRUCache;
import org.h2.util.StringUtils;
/**
......@@ -18,9 +20,15 @@ public class CompareMode {
public static final String OFF = "OFF";
private final Collator collator;
private final String name;
private final SmallLRUCache collationKeys;
public CompareMode(Collator collator, String name) {
public CompareMode(Collator collator, String name, int cacheSize) {
this.collator = collator;
if (collator != null && cacheSize != 0) {
collationKeys = new SmallLRUCache(cacheSize);
} else {
collationKeys = null;
}
this.name = name == null ? OFF : name;
}
......@@ -49,10 +57,28 @@ public class CompareMode {
a = a.toUpperCase();
b = b.toUpperCase();
}
int comp = collator.compare(a, b);
int comp;
if (collationKeys != null) {
CollationKey aKey = getKey(a);
CollationKey bKey = getKey(b);
comp = aKey.compareTo(bKey);
} else {
comp = collator.compare(a, b);
}
return comp;
}
private CollationKey getKey(String a) {
synchronized (collationKeys) {
CollationKey key = (CollationKey) collationKeys.get(a);
if (key == null) {
key = collator.getCollationKey(a);
collationKeys.put(a, key);
}
return key;
}
}
public static String getName(Locale l) {
Locale english = Locale.ENGLISH;
String name = l.getDisplayLanguage(english) + ' ' + l.getDisplayCountry(english) + ' ' + l.getVariant();
......
......@@ -155,6 +155,8 @@ java org.h2.test.TestAll timer
/*
test startBrowser in Linux
fix or disable the linear hash index
delete old ipowerb content
......
......@@ -14,7 +14,7 @@ import org.h2.value.CompareMode;
public class TestPattern extends TestBase {
public void test() throws Exception {
CompareMode mode = new CompareMode(null, null);
CompareMode mode = new CompareMode(null, null, 100);
CompareLike comp = new CompareLike(mode, null, null, null, false);
test(comp, "B", "%_");
test(comp, "A", "A%");
......
......@@ -23,7 +23,7 @@ import org.h2.value.ValueInt;
*/
public class TestValueHashMap extends TestBase implements DataHandler {
CompareMode compareMode = new CompareMode(null, null);
CompareMode compareMode = new CompareMode(null, null, 0);
public void test() throws Exception {
ValueHashMap map = new ValueHashMap(this);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论