提交 8c67eba9 authored 作者: Thomas Mueller's avatar Thomas Mueller

Merge pull request #146 from svladykin/compare-mode2

Improved CompareMode
...@@ -10,7 +10,6 @@ import java.io.BufferedOutputStream; ...@@ -10,7 +10,6 @@ import java.io.BufferedOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.api.JavaObjectSerializer; import org.h2.api.JavaObjectSerializer;
import org.h2.command.Prepared; import org.h2.command.Prepared;
...@@ -31,6 +30,7 @@ import org.h2.tools.CompressTool; ...@@ -31,6 +30,7 @@ import org.h2.tools.CompressTool;
import org.h2.util.IOUtils; import org.h2.util.IOUtils;
import org.h2.util.SmallLRUCache; import org.h2.util.SmallLRUCache;
import org.h2.util.TempFileDeleter; import org.h2.util.TempFileDeleter;
import org.h2.value.CompareMode;
/** /**
* This class is the base for RunScriptCommand and ScriptCommand. * This class is the base for RunScriptCommand and ScriptCommand.
...@@ -259,4 +259,9 @@ abstract class ScriptBase extends Prepared implements DataHandler { ...@@ -259,4 +259,9 @@ abstract class ScriptBase extends Prepared implements DataHandler {
public JavaObjectSerializer getJavaObjectSerializer() { public JavaObjectSerializer getJavaObjectSerializer() {
return session.getDataHandler().getJavaObjectSerializer(); return session.getDataHandler().getJavaObjectSerializer();
} }
@Override
public CompareMode getCompareMode() {
return session.getDataHandler().getCompareMode();
}
} }
...@@ -1530,6 +1530,7 @@ public class Database implements DataHandler { ...@@ -1530,6 +1530,7 @@ public class Database implements DataHandler {
return cluster; return cluster;
} }
@Override
public CompareMode getCompareMode() { public CompareMode getCompareMode() {
return compareMode; return compareMode;
} }
......
...@@ -8,7 +8,6 @@ package org.h2.engine; ...@@ -8,7 +8,6 @@ package org.h2.engine;
import java.io.IOException; import java.io.IOException;
import java.net.Socket; import java.net.Socket;
import java.util.ArrayList; import java.util.ArrayList;
import org.h2.api.DatabaseEventListener; import org.h2.api.DatabaseEventListener;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.api.JavaObjectSerializer; import org.h2.api.JavaObjectSerializer;
...@@ -32,6 +31,7 @@ import org.h2.util.New; ...@@ -32,6 +31,7 @@ import org.h2.util.New;
import org.h2.util.SmallLRUCache; import org.h2.util.SmallLRUCache;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
import org.h2.util.TempFileDeleter; import org.h2.util.TempFileDeleter;
import org.h2.value.CompareMode;
import org.h2.value.Transfer; import org.h2.value.Transfer;
import org.h2.value.Value; import org.h2.value.Value;
...@@ -90,6 +90,8 @@ public class SessionRemote extends SessionWithState implements DataHandler { ...@@ -90,6 +90,8 @@ public class SessionRemote extends SessionWithState implements DataHandler {
private JavaObjectSerializer javaObjectSerializer; private JavaObjectSerializer javaObjectSerializer;
private volatile boolean javaObjectSerializerInitialized; private volatile boolean javaObjectSerializerInitialized;
private CompareMode compareMode = CompareMode.getInstance(null, 0);
public SessionRemote(ConnectionInfo ci) { public SessionRemote(ConnectionInfo ci) {
this.connectionInfo = ci; this.connectionInfo = ci;
...@@ -846,4 +848,9 @@ public class SessionRemote extends SessionWithState implements DataHandler { ...@@ -846,4 +848,9 @@ public class SessionRemote extends SessionWithState implements DataHandler {
public void addTemporaryLob(Value v) { public void addTemporaryLob(Value v) {
// do nothing // do nothing
} }
@Override
public CompareMode getCompareMode() {
return compareMode;
}
} }
...@@ -81,7 +81,6 @@ public class JdbcConnection extends TraceObject implements Connection { ...@@ -81,7 +81,6 @@ public class JdbcConnection extends TraceObject implements Connection {
private int savepointId; private int savepointId;
private String catalog; private String catalog;
private Statement executingStatement; private Statement executingStatement;
private final CompareMode compareMode = CompareMode.getInstance(null, 0);
private final CloseWatcher watcher; private final CloseWatcher watcher;
private int queryTimeoutCache = -1; private int queryTimeoutCache = -1;
...@@ -1938,7 +1937,7 @@ public class JdbcConnection extends TraceObject implements Connection { ...@@ -1938,7 +1937,7 @@ public class JdbcConnection extends TraceObject implements Connection {
} }
CompareMode getCompareMode() { CompareMode getCompareMode() {
return compareMode; return session.getDataHandler().getCompareMode();
} }
/** /**
......
...@@ -9,6 +9,7 @@ import org.h2.api.JavaObjectSerializer; ...@@ -9,6 +9,7 @@ import org.h2.api.JavaObjectSerializer;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.util.SmallLRUCache; import org.h2.util.SmallLRUCache;
import org.h2.util.TempFileDeleter; import org.h2.util.TempFileDeleter;
import org.h2.value.CompareMode;
/** /**
* A data handler contains a number of callback methods, mostly related to CLOB * A data handler contains a number of callback methods, mostly related to CLOB
...@@ -113,4 +114,11 @@ public interface DataHandler { ...@@ -113,4 +114,11 @@ public interface DataHandler {
* column of type OTHER * column of type OTHER
*/ */
JavaObjectSerializer getJavaObjectSerializer(); JavaObjectSerializer getJavaObjectSerializer();
/**
* Return compare mode.
*
* @return Compare mode.
*/
CompareMode getCompareMode();
} }
...@@ -28,7 +28,6 @@ import java.util.Iterator; ...@@ -28,7 +28,6 @@ import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.zip.CRC32; import java.util.zip.CRC32;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.api.JavaObjectSerializer; import org.h2.api.JavaObjectSerializer;
import org.h2.compress.CompressLZF; import org.h2.compress.CompressLZF;
...@@ -72,6 +71,7 @@ import org.h2.util.StringUtils; ...@@ -72,6 +71,7 @@ import org.h2.util.StringUtils;
import org.h2.util.TempFileDeleter; import org.h2.util.TempFileDeleter;
import org.h2.util.Tool; import org.h2.util.Tool;
import org.h2.util.Utils; import org.h2.util.Utils;
import org.h2.value.CompareMode;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueArray; import org.h2.value.ValueArray;
import org.h2.value.ValueLob; import org.h2.value.ValueLob;
...@@ -1730,4 +1730,9 @@ public class Recover extends Tool implements DataHandler { ...@@ -1730,4 +1730,9 @@ public class Recover extends Tool implements DataHandler {
public JavaObjectSerializer getJavaObjectSerializer() { public JavaObjectSerializer getJavaObjectSerializer() {
return null; return null;
} }
@Override
public CompareMode getCompareMode() {
return CompareMode.getInstance(null, 0);
}
} }
...@@ -47,7 +47,7 @@ public class CompareMode { ...@@ -47,7 +47,7 @@ public class CompareMode {
*/ */
public static final String UNSIGNED = "UNSIGNED"; public static final String UNSIGNED = "UNSIGNED";
private static CompareMode lastUsed; private static volatile CompareMode lastUsed;
private static final boolean CAN_USE_ICU4J; private static final boolean CAN_USE_ICU4J;
...@@ -86,8 +86,7 @@ public class CompareMode { ...@@ -86,8 +86,7 @@ public class CompareMode {
* @param strength the collation strength * @param strength the collation strength
* @return the compare mode * @return the compare mode
*/ */
public static synchronized CompareMode getInstance(String name, public static CompareMode getInstance(String name, int strength) {
int strength) {
return getInstance(name, strength, SysProperties.SORT_BINARY_UNSIGNED); return getInstance(name, strength, SysProperties.SORT_BINARY_UNSIGNED);
} }
...@@ -102,17 +101,18 @@ public class CompareMode { ...@@ -102,17 +101,18 @@ public class CompareMode {
* @param binaryUnsigned whether to compare binaries as unsigned * @param binaryUnsigned whether to compare binaries as unsigned
* @return the compare mode * @return the compare mode
*/ */
public static synchronized CompareMode getInstance(String name, public static CompareMode getInstance(String name, int strength, boolean binaryUnsigned) {
int strength, boolean binaryUnsigned) { CompareMode last;
if (lastUsed != null) {
if (StringUtils.equals(lastUsed.name, name) && if ((last = lastUsed) != null) {
lastUsed.strength == strength && if (StringUtils.equals(last.name, name) &&
lastUsed.binaryUnsigned == binaryUnsigned) { last.strength == strength &&
return lastUsed; last.binaryUnsigned == binaryUnsigned) {
return last;
} }
} }
if (name == null || name.equals(OFF)) { if (name == null || name.equals(OFF)) {
lastUsed = new CompareMode(name, strength, binaryUnsigned); lastUsed = last = new CompareMode(name, strength, binaryUnsigned);
} else { } else {
boolean useICU4J; boolean useICU4J;
if (name.startsWith(ICU4J)) { if (name.startsWith(ICU4J)) {
...@@ -125,12 +125,12 @@ public class CompareMode { ...@@ -125,12 +125,12 @@ public class CompareMode {
useICU4J = CAN_USE_ICU4J; useICU4J = CAN_USE_ICU4J;
} }
if (useICU4J) { if (useICU4J) {
lastUsed = new CompareModeIcu4J(name, strength, binaryUnsigned); lastUsed = last = new CompareModeIcu4J(name, strength, binaryUnsigned);
} else { } else {
lastUsed = new CompareModeDefault(name, strength, binaryUnsigned); lastUsed = last = new CompareModeDefault(name, strength, binaryUnsigned);
} }
} }
return lastUsed; return last;
} }
/** /**
......
...@@ -339,4 +339,8 @@ public class TestDataPage extends TestBase implements DataHandler { ...@@ -339,4 +339,8 @@ public class TestDataPage extends TestBase implements DataHandler {
return null; return null;
} }
@Override
public CompareMode getCompareMode() {
return compareMode;
}
} }
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
package org.h2.test.unit; package org.h2.test.unit;
import java.util.Random; import java.util.Random;
import org.h2.api.JavaObjectSerializer; import org.h2.api.JavaObjectSerializer;
import org.h2.store.DataHandler; import org.h2.store.DataHandler;
import org.h2.store.FileStore; import org.h2.store.FileStore;
...@@ -15,6 +14,7 @@ import org.h2.store.fs.FileUtils; ...@@ -15,6 +14,7 @@ import org.h2.store.fs.FileUtils;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.util.SmallLRUCache; import org.h2.util.SmallLRUCache;
import org.h2.util.TempFileDeleter; import org.h2.util.TempFileDeleter;
import org.h2.value.CompareMode;
/** /**
* Tests the in-memory file store. * Tests the in-memory file store.
...@@ -197,4 +197,8 @@ public class TestFile extends TestBase implements DataHandler { ...@@ -197,4 +197,8 @@ public class TestFile extends TestBase implements DataHandler {
return null; return null;
} }
@Override
public CompareMode getCompareMode() {
return CompareMode.getInstance(null, 0);
}
} }
...@@ -171,4 +171,9 @@ public class TestValueHashMap extends TestBase implements DataHandler { ...@@ -171,4 +171,9 @@ public class TestValueHashMap extends TestBase implements DataHandler {
public JavaObjectSerializer getJavaObjectSerializer() { public JavaObjectSerializer getJavaObjectSerializer() {
return null; return null;
} }
@Override
public CompareMode getCompareMode() {
return compareMode;
}
} }
...@@ -12,7 +12,6 @@ import java.sql.SQLException; ...@@ -12,7 +12,6 @@ import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.IdentityHashMap; import java.util.IdentityHashMap;
import java.util.Random; import java.util.Random;
import org.h2.api.JavaObjectSerializer; import org.h2.api.JavaObjectSerializer;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.store.DataHandler; import org.h2.store.DataHandler;
...@@ -24,6 +23,7 @@ import org.h2.tools.SimpleResultSet; ...@@ -24,6 +23,7 @@ import org.h2.tools.SimpleResultSet;
import org.h2.util.SmallLRUCache; import org.h2.util.SmallLRUCache;
import org.h2.util.TempFileDeleter; import org.h2.util.TempFileDeleter;
import org.h2.util.Utils; import org.h2.util.Utils;
import org.h2.value.CompareMode;
import org.h2.value.DataType; import org.h2.value.DataType;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueArray; import org.h2.value.ValueArray;
...@@ -288,4 +288,9 @@ public class TestValueMemory extends TestBase implements DataHandler { ...@@ -288,4 +288,9 @@ public class TestValueMemory extends TestBase implements DataHandler {
public JavaObjectSerializer getJavaObjectSerializer() { public JavaObjectSerializer getJavaObjectSerializer() {
return null; return null;
} }
@Override
public CompareMode getCompareMode() {
return CompareMode.getInstance(null, 0);
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论