提交 1094572f authored 作者: Thomas Mueller's avatar Thomas Mueller

Fulltext search (native): after re-opening the connection once the fulltext…

Fulltext search (native): after re-opening the connection once the fulltext index was created, transaction rollbacks did not roll back the modifications in the index.
上级 bfce01b2
......@@ -41,7 +41,7 @@ public interface Trigger {
* appropriate flags set. As an example, if the trigger is of type INSERT
* and UPDATE, then the parameter type is set to (INSERT | UPDATE).
*
* @param conn a connection to the database
* @param conn a connection to the database (a system connection)
* @param schemaName the name of the schema
* @param triggerName the name of the trigger used in the CREATE TRIGGER
* statement
......
......@@ -730,8 +730,10 @@ public class FullText {
stat.execute("DROP TRIGGER IF EXISTS " + trigger);
if (create) {
StringBuilder buff = new StringBuilder("CREATE TRIGGER IF NOT EXISTS ");
// needs to be called on rollback as well, because we use the init connection
// do to changes in the index (not the user connection)
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)).
......
......@@ -230,10 +230,8 @@ 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 because transaction rollback will not undo the changes in
// the Lucene index (but it will undo the changes in the native fulltext
// index, as those operations are part of the transaction)
// the trigger is also called on rollback because transaction rollback
// will not undo the changes in the Lucene index
buff.append(trigger).
append(" AFTER INSERT, UPDATE, DELETE, ROLLBACK ON ").
append(StringUtils.quoteIdentifier(schema)).
......
......@@ -59,11 +59,12 @@ public class TriggerObject extends SchemaObjectBase {
this.insteadOf = insteadOf;
}
private synchronized void load(Session session) {
private synchronized void load() {
if (triggerCallback != null) {
return;
}
try {
Session session = database.getSystemSession();
Connection c2 = session.createConnection(false);
Object obj = Utils.loadUserClass(triggerClassName).newInstance();
triggerCallback = (Trigger) obj;
......@@ -87,7 +88,7 @@ public class TriggerObject extends SchemaObjectBase {
public void setTriggerClassName(Session session, String triggerClassName, boolean force) {
this.triggerClassName = triggerClassName;
try {
load(session);
load();
} catch (DbException e) {
if (!force) {
throw e;
......@@ -108,7 +109,7 @@ public class TriggerObject extends SchemaObjectBase {
if (rowBased || before != beforeAction || (typeMask & type) == 0) {
return;
}
load(session);
load();
Connection c2 = session.createConnection(false);
boolean old = false;
if (type != Trigger.SELECT) {
......@@ -161,7 +162,7 @@ public class TriggerObject extends SchemaObjectBase {
if (rollback && !onRollback) {
return false;
}
load(session);
load();
Object[] oldList;
Object[] newList;
boolean fire = false;
......
......@@ -135,6 +135,9 @@ public class TestFullText extends TestBase {
rs = stat.executeQuery("SELECT * FROM FT_SEARCH('this', 0, 0)");
assertFalse(rs.next());
conn.close();
conn = getConnection("fullTextNative");
stat = conn.createStatement();
conn.setAutoCommit(false);
stat.execute("delete from test");
rs = stat.executeQuery("SELECT * FROM FT_SEARCH_DATA('Welcome', 0, 0)");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论