ClassCastException fixed for UUID primary keys

上级 06e97e0e
...@@ -23,6 +23,7 @@ import java.util.HashMap; ...@@ -23,6 +23,7 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.UUID;
import org.h2.api.Trigger; import org.h2.api.Trigger;
import org.h2.command.Parser; import org.h2.command.Parser;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -490,6 +491,9 @@ public class FullText { ...@@ -490,6 +491,9 @@ public class FullText {
case Types.VARBINARY: case Types.VARBINARY:
case Types.LONGVARBINARY: case Types.LONGVARBINARY:
case Types.BINARY: case Types.BINARY:
if (data instanceof UUID) {
return "'" + data.toString() + "'";
}
return "'" + StringUtils.convertBytesToHex((byte[]) data) + "'"; return "'" + StringUtils.convertBytesToHex((byte[]) data) + "'";
case Types.CLOB: case Types.CLOB:
case Types.JAVA_OBJECT: case Types.JAVA_OBJECT:
......
...@@ -14,6 +14,7 @@ import java.sql.SQLException; ...@@ -14,6 +14,7 @@ import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.Random; import java.util.Random;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.UUID;
import org.h2.fulltext.FullText; import org.h2.fulltext.FullText;
import org.h2.store.fs.FileUtils; import org.h2.store.fs.FileUtils;
import org.h2.test.TestBase; import org.h2.test.TestBase;
...@@ -39,6 +40,7 @@ public class TestFullText extends TestBase { ...@@ -39,6 +40,7 @@ public class TestFullText extends TestBase {
} }
public void test() throws Exception { public void test() throws Exception {
testUuidPrimaryKey(false);
testAutoAnalyze(); testAutoAnalyze();
testNativeFeatures(); testNativeFeatures();
testTransaction(false); testTransaction(false);
...@@ -54,6 +56,7 @@ public class TestFullText extends TestBase { ...@@ -54,6 +56,7 @@ public class TestFullText extends TestBase {
String luceneFullTextClassName = "org.h2.fulltext.FullTextLucene"; String luceneFullTextClassName = "org.h2.fulltext.FullTextLucene";
try { try {
Class.forName(luceneFullTextClassName); Class.forName(luceneFullTextClassName);
testUuidPrimaryKey(true);
testMultiThreaded(true); testMultiThreaded(true);
testMultiThreaded(false); testMultiThreaded(false);
testTransaction(true); testTransaction(true);
...@@ -149,6 +152,31 @@ public class TestFullText extends TestBase { ...@@ -149,6 +152,31 @@ public class TestFullText extends TestBase {
conn.close(); conn.close();
} }
private void testUuidPrimaryKey(boolean lucene) throws SQLException {
deleteDb("fullText");
Connection conn = getConnection("fullText");
Statement stat = conn.createStatement();
String prefix = lucene ? "FTL" : "FT";
String className = lucene ? "FullTextLucene" : "FullText";
stat.execute("CREATE ALIAS IF NOT EXISTS " + prefix + "_INIT FOR \"org.h2.fulltext." + className + ".init\"");
stat.execute("CALL " + prefix + "_INIT()");
stat.execute("CREATE TABLE TEST(ID UUID PRIMARY KEY, NAME VARCHAR)");
String id = UUID.randomUUID().toString();
stat.execute("INSERT INTO TEST VALUES('"+ id +"', 'Hello World')");
stat.execute("CALL " + prefix + "_CREATE_INDEX('PUBLIC', 'TEST', 'NAME')");
ResultSet rs = stat.executeQuery("SELECT * FROM " + prefix + "_SEARCH('Hello', 0, 0)");
assertTrue(rs.next());
stat.execute("UPDATE TEST SET NAME=NULL WHERE ID='" + id + "'");
rs = stat.executeQuery("SELECT * FROM " + prefix + "_SEARCH('Hello', 0, 0)");
assertFalse(rs.next());
stat.execute("UPDATE TEST SET NAME='Good Bye' WHERE ID='" + id + "'");
rs = stat.executeQuery("SELECT * FROM " + prefix + "_SEARCH('bye', 0, 0)");
assertTrue(rs.next());
FullText.dropAll(conn);
conn.close();
deleteDb("fullText");
}
private void testTransaction(boolean lucene) throws SQLException { private void testTransaction(boolean lucene) throws SQLException {
if (config.memory) { if (config.memory) {
return; return;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论