提交 c7ab9de0 authored 作者: Thomas Mueller's avatar Thomas Mueller

The native fulltext index kept a reference to a database after the database was closed.

上级 45d8571a
......@@ -51,6 +51,8 @@ public class FullText {
private static final String TRIGGER_PREFIX = "FT_";
private static final String SCHEMA = "FT";
private static final String SELECT_MAP_BY_WORD_ID = "SELECT ROWID FROM " + SCHEMA + ".MAP WHERE WORDID=?";
private static final String SELECT_ROW_BY_ID = "SELECT KEY, INDEXID FROM " + SCHEMA + ".ROWS WHERE ID=?";
/**
* A column name of the result set returned by the searchData method.
......@@ -517,7 +519,7 @@ public class FullText {
HashSet<Integer> rIds = null, lastRowIds = null;
HashMap<String, Integer> allWords = setting.getWordList();
PreparedStatement prepSelectMapByWordId = setting.getPrepSelectMapByWordId();
PreparedStatement prepSelectMapByWordId = setting.prepare(conn, SELECT_MAP_BY_WORD_ID);
for (String word : words) {
lastRowIds = rIds;
rIds = New.hashSet();
......@@ -537,7 +539,7 @@ public class FullText {
if (rIds == null || rIds.size() == 0) {
return result;
}
PreparedStatement prepSelectRowById = setting.getPrepSelectRowById();
PreparedStatement prepSelectRowById = setting.prepare(conn, SELECT_ROW_BY_ID);
int rowCount = 0;
for (int rowId : rIds) {
prepSelectRowById.setInt(1, rowId);
......@@ -787,13 +789,6 @@ public class FullText {
"DELETE FROM " + SCHEMA + ".MAP WHERE ROWID=? AND WORDID=?");
prepSelectRow = conn.prepareStatement(
"SELECT ID FROM " + SCHEMA + ".ROWS WHERE HASH=? AND INDEXID=? AND KEY=?");
PreparedStatement prepSelectMapByWordId = conn.prepareStatement(
"SELECT ROWID FROM " + SCHEMA + ".MAP WHERE WORDID=?");
PreparedStatement prepSelectRowById = conn.prepareStatement(
"SELECT KEY, INDEXID FROM " + SCHEMA + ".ROWS WHERE ID=?");
setting.setPrepSelectMapByWordId(prepSelectMapByWordId);
setting.setPrepSelectRowById(prepSelectRowById);
}
/**
......
......@@ -14,6 +14,7 @@ import java.sql.Statement;
import java.util.HashMap;
import java.util.HashSet;
import org.h2.util.New;
import org.h2.util.SoftHashMap;
/**
* The global settings of a full text search.
......@@ -26,8 +27,7 @@ class FullTextSettings {
private HashSet<String> ignoreList = New.hashSet();
private HashMap<String, Integer> words = New.hashMap();
private HashMap<Integer, IndexInfo> indexes = New.hashMap();
private PreparedStatement prepSelectMapByWordId;
private PreparedStatement prepSelectRowById;
private SoftHashMap<String, PreparedStatement> cache = new SoftHashMap<String, PreparedStatement>();
private FullTextSettings() {
// don't allow construction
......@@ -104,20 +104,16 @@ class FullTextSettings {
return path;
}
PreparedStatement getPrepSelectMapByWordId() {
return prepSelectMapByWordId;
}
void setPrepSelectMapByWordId(PreparedStatement prepSelectMapByWordId) {
this.prepSelectMapByWordId = prepSelectMapByWordId;
}
PreparedStatement getPrepSelectRowById() {
return prepSelectRowById;
}
void setPrepSelectRowById(PreparedStatement prepSelectRowById) {
this.prepSelectRowById = prepSelectRowById;
synchronized PreparedStatement prepare(Connection conn, String sql) throws SQLException {
PreparedStatement prep = cache.get(sql);
if (prep != null && prep.getConnection().isClosed()) {
prep = null;
}
if (prep == null) {
prep = conn.prepareStatement(sql);
cache.put(sql, prep);
}
return prep;
}
/**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论