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