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