提交 2a83a1ba authored 作者: Thomas Mueller's avatar Thomas Mueller

the lucene index was always recreated and never closed

上级 4ba52d30
/*
* Copyright 2004-2008 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.api;
import java.sql.SQLException;
/**
* A trigger that implements this interface will be notified when the database
* is closed.
*/
public interface CloseListener {
/**
* This method is called when the database is closed.
* If the method throws an exception, it will be logged, but
* closing the database will continue.
*
* @throws SQLException
*/
void close() throws SQLException;
}
......@@ -63,5 +63,5 @@ public interface Trigger {
* if the operation must be undone
*/
void fire(Connection conn, Object[] oldRow, Object[] newRow) throws SQLException;
}
......@@ -34,6 +34,7 @@ import org.h2.result.SearchRow;
import org.h2.schema.Schema;
import org.h2.schema.SchemaObject;
import org.h2.schema.Sequence;
import org.h2.schema.TriggerObject;
import org.h2.store.DataHandler;
import org.h2.store.DataPage;
import org.h2.store.DiskFile;
......@@ -1043,6 +1044,11 @@ public class Database implements DataHandler {
Sequence sequence = (Sequence) sequences.get(i);
sequence.close();
}
ObjectArray triggers = getAllSchemaObjects(DbObject.TRIGGER);
for (int i = 0; i < triggers.size(); i++) {
TriggerObject trigger = (TriggerObject) triggers.get(i);
trigger.close();
}
meta.close(systemSession);
systemSession.commit(true);
indexSummaryValid = true;
......
......@@ -32,6 +32,7 @@ import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Searcher;
import org.h2.api.CloseListener;
import org.h2.api.Trigger;
import org.h2.command.Parser;
import org.h2.engine.Session;
......@@ -50,7 +51,7 @@ import org.h2.util.StringUtils;
*/
public class FullTextLucene extends FullText
//## Java 1.4 begin ##
implements Trigger
implements Trigger, CloseListener
//## Java 1.4 end ##
{
......@@ -574,8 +575,9 @@ implements Trigger
synchronized (indexers) {
indexer = (IndexModifier) indexers.get(path);
if (indexer == null) {
// TODO: create flag = true means re-create
indexer = new IndexModifier(path, new StandardAnalyzer(), true);
Analyzer analyzer = new StandardAnalyzer();
boolean create = !IndexReader.indexExists(path);
indexer = new IndexModifier(path, analyzer, create);
indexers.put(path, indexer);
}
}
......@@ -613,6 +615,18 @@ implements Trigger
index[i] = found;
}
}
public void close() throws SQLException {
try {
if (indexer != null) {
indexer.flush();
indexer.close();
indexer = null;
}
} catch (Exception e) {
throw convertException(e);
}
}
//## Java 1.4 end ##
}
......@@ -9,6 +9,7 @@ package org.h2.schema;
import java.sql.Connection;
import java.sql.SQLException;
import org.h2.api.CloseListener;
import org.h2.api.Trigger;
import org.h2.command.Parser;
import org.h2.constant.ErrorCode;
......@@ -313,7 +314,7 @@ public class TriggerObject extends SchemaObjectBase {
}
/**
* Get the trigger class name
* Get the trigger class name.
*
* @return the class name
*/
......@@ -321,4 +322,15 @@ public class TriggerObject extends SchemaObjectBase {
return triggerClassName;
}
/**
* Close the trigger.
*/
public void close() throws SQLException {
if (triggerCallback != null) {
if (triggerCallback instanceof CloseListener) {
((CloseListener) triggerCallback).close();
}
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论