Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
08ef0d6f
提交
08ef0d6f
authored
1月 04, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
The Lucene fulltext search ignored transaction rollback. Fixed using a trigger on rollback.
上级
8926f35e
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
61 行增加
和
9 行删除
+61
-9
FullText.java
h2/src/main/org/h2/fulltext/FullText.java
+15
-4
FullTextLucene.java
h2/src/main/org/h2/fulltext/FullTextLucene.java
+5
-4
FullTextSettings.java
h2/src/main/org/h2/fulltext/FullTextSettings.java
+1
-1
TestFullText.java
h2/src/test/org/h2/test/db/TestFullText.java
+40
-0
没有找到文件。
h2/src/main/org/h2/fulltext/FullText.java
浏览文件 @
08ef0d6f
...
...
@@ -364,7 +364,7 @@ public class FullText {
case
Types
.
ARRAY
:
case
DataType
.
TYPE_DATALINK
:
case
Types
.
DISTINCT
:
throw
new
SQLException
(
"FULLTEXT"
,
"Unsupported column data type: "
+
type
);
throw
throwException
(
"Unsupported column data type: "
+
type
);
default
:
return
""
;
}
...
...
@@ -462,7 +462,7 @@ public class FullText {
case
Types
.
ARRAY
:
case
DataType
.
TYPE_DATALINK
:
case
Types
.
DISTINCT
:
throw
new
SQLException
(
"FULLTEXT"
,
"Unsupported key data type: "
+
type
);
throw
throwException
(
"Unsupported key data type: "
+
type
);
default
:
return
""
;
}
...
...
@@ -506,7 +506,7 @@ public class FullText {
}
}
if
(
found
<
0
)
{
throw
new
SQLException
(
"FULLTEXT"
,
"Column not found: "
+
key
);
throw
throwException
(
"Column not found: "
+
key
);
}
index
[
i
]
=
found
;
}
...
...
@@ -823,7 +823,7 @@ public class FullText {
}
}
if
(
keyList
.
size
()
==
0
)
{
throw
new
SQL
Exception
(
"No primary key for table "
+
tableName
);
throw
throw
Exception
(
"No primary key for table "
+
tableName
);
}
ArrayList
<
String
>
indexList
=
New
.
arrayList
();
PreparedStatement
prep
=
conn
.
prepareStatement
(
...
...
@@ -1017,4 +1017,15 @@ public class FullText {
FullTextSettings
.
closeAll
();
}
/**
* Throw a SQLException with the given message.
*
* @param message the message
* @return never returns normally
* @throws SQLException the exception
*/
protected
static
SQLException
throwException
(
String
message
)
throws
SQLException
{
throw
new
SQLException
(
message
,
"FULLTEXT"
);
}
}
h2/src/main/org/h2/fulltext/FullTextLucene.java
浏览文件 @
08ef0d6f
...
...
@@ -217,7 +217,7 @@ public class FullTextLucene extends FullText {
* @return the converted SQL exception
*/
protected
static
SQLException
convertException
(
Exception
e
)
{
SQLException
e2
=
new
SQLException
(
"
FULLTEXT"
,
"Error while indexing document
"
);
SQLException
e2
=
new
SQLException
(
"
Error while indexing document"
,
"FULLTEXT
"
);
e2
.
initCause
(
e
);
return
e2
;
}
...
...
@@ -234,8 +234,9 @@ public class FullTextLucene extends FullText {
String
trigger
=
StringUtils
.
quoteIdentifier
(
schema
)
+
"."
+
StringUtils
.
quoteIdentifier
(
TRIGGER_PREFIX
+
table
);
stat
.
execute
(
"DROP TRIGGER IF EXISTS "
+
trigger
);
StringBuilder
buff
=
new
StringBuilder
(
"CREATE TRIGGER IF NOT EXISTS "
);
// unlike the native fulltext search, the trigger is also called on rollback
buff
.
append
(
trigger
).
append
(
" AFTER INSERT, UPDATE, DELETE ON "
).
append
(
" AFTER INSERT, UPDATE, DELETE
, ROLLBACK
ON "
).
append
(
StringUtils
.
quoteIdentifier
(
schema
)).
append
(
'.'
).
append
(
StringUtils
.
quoteIdentifier
(
table
)).
...
...
@@ -282,7 +283,7 @@ public class FullTextLucene extends FullText {
rs
.
next
();
String
path
=
rs
.
getString
(
1
);
if
(
path
==
null
)
{
throw
new
SQLException
(
"FULLTEXT"
,
"Fulltext search for in-memory databases is not supported."
);
throw
throwException
(
"Fulltext search for in-memory databases is not supported."
);
}
rs
.
close
();
return
path
;
...
...
@@ -463,7 +464,7 @@ public class FullTextLucene extends FullText {
}
}
if
(
keyList
.
size
()
==
0
)
{
throw
new
SQL
Exception
(
"No primary key for table "
+
tableName
);
throw
throw
Exception
(
"No primary key for table "
+
tableName
);
}
ArrayList
<
String
>
indexList
=
New
.
arrayList
();
PreparedStatement
prep
=
conn
.
prepareStatement
(
...
...
h2/src/main/org/h2/fulltext/FullTextSettings.java
浏览文件 @
08ef0d6f
...
...
@@ -139,7 +139,7 @@ public class FullTextSettings {
rs
.
next
();
String
path
=
rs
.
getString
(
1
);
if
(
"MEM:UNNAMED"
.
equals
(
path
))
{
throw
new
SQLException
(
"FULLTEXT"
,
"Fulltext search for private (unnamed) in-memory databases is not supported."
);
throw
FullText
.
throwException
(
"Fulltext search for private (unnamed) in-memory databases is not supported."
);
}
rs
.
close
();
return
path
;
...
...
h2/src/test/org/h2/test/db/TestFullText.java
浏览文件 @
08ef0d6f
...
...
@@ -33,6 +33,8 @@ public class TestFullText extends TestBase {
}
public
void
test
()
throws
Exception
{
testTransaction
(
false
);
testTransaction
(
true
);
testCreateDrop
();
if
(
config
.
memory
)
{
return
;
...
...
@@ -62,6 +64,38 @@ public class TestFullText extends TestBase {
deleteDb
(
"fullTextReopen"
);
}
private
void
testTransaction
(
boolean
lucene
)
throws
SQLException
{
if
(
config
.
memory
)
{
return
;
}
String
prefix
=
lucene
?
"FTL"
:
"FT"
;
deleteDb
(
"fullTextTransaction"
);
FileSystem
.
getInstance
(
baseDir
).
deleteRecursive
(
baseDir
+
"/fullTextTransaction"
,
false
);
Connection
conn
=
getConnection
(
"fullTextTransaction"
);
Statement
stat
=
conn
.
createStatement
();
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 INT PRIMARY KEY, NAME VARCHAR)"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1, 'Hello World')"
);
stat
.
execute
(
"CALL "
+
prefix
+
"_CREATE_INDEX('PUBLIC', 'TEST', NULL)"
);
stat
.
execute
(
"UPDATE TEST SET NAME=NULL WHERE ID=1"
);
stat
.
execute
(
"UPDATE TEST SET NAME='Hello World' WHERE ID=1"
);
conn
.
setAutoCommit
(
false
);
stat
.
execute
(
"insert into test values(2, 'Hello Moon!')"
);
conn
.
rollback
();
conn
.
close
();
conn
=
getConnection
(
"fullTextTransaction"
);
stat
=
conn
.
createStatement
();
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"_SEARCH('Hello', 0, 0)"
);
assertTrue
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"_SEARCH('Moon', 0, 0)"
);
assertFalse
(
rs
.
next
());
FullText
.
dropAll
(
conn
);
conn
.
close
();
deleteDb
(
"fullTextTransaction"
);
}
private
void
testMultiThreaded
()
throws
Exception
{
deleteDb
(
"fullText"
);
final
boolean
[]
stop
=
new
boolean
[
1
];
...
...
@@ -125,6 +159,10 @@ public class TestFullText extends TestBase {
stat
.
execute
(
"CREATE ALIAS IF NOT EXISTS FT_INIT FOR \"org.h2.fulltext.FullText.init\""
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, DATA CLOB)"
);
FullText
.
createIndex
(
conn
,
"PUBLIC"
,
"TEST"
,
null
);
conn
.
setAutoCommit
(
false
);
stat
.
execute
(
"insert into test values(1, 'Hello Moon!')"
);
conn
.
rollback
();
conn
.
setAutoCommit
(
true
);
stat
.
execute
(
"insert into test values(0, 'Hello World!')"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"insert into test values(1, ?)"
);
final
int
length
=
1024
*
1024
;
...
...
@@ -145,6 +183,8 @@ public class TestFullText extends TestBase {
prep
.
execute
();
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM FT_SEARCH('World', 0, 0)"
);
assertTrue
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"SELECT * FROM FT_SEARCH('Moon', 0, 0)"
);
assertFalse
(
rs
.
next
());
FullText
.
dropAll
(
conn
);
conn
.
close
();
deleteDb
(
"fullText"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论