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

The methods of the CloseListener are added to the Trigger interface. The…

The methods of the CloseListener are added to the Trigger interface. The interface CloseListener is removed.
上级 b985f204
...@@ -18,7 +18,9 @@ Change Log ...@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>Converting a UUID to bytes was incorrect. Because of that, updatable result sets on <ul><li>The methods of the CloseListener are added to the Trigger interface.
The interface CloseListener is removed.
</li><li>Converting a UUID to bytes was incorrect. Because of that, updatable result sets on
tables with UUID primary key did not work. tables with UUID primary key did not work.
</li><li>The database URL property DATABASE_EVENT_LISTENER_OBJECT is no longer supported </li><li>The database URL property DATABASE_EVENT_LISTENER_OBJECT is no longer supported
(there are problems passing objects when the PostgreSQL driver is installed as well). (there are problems passing objects when the PostgreSQL driver is installed as well).
......
/*
* Copyright 2004-2010 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;
/**
* This method is called when the trigger is dropped.
*
* @throws SQLException
*/
void remove() throws SQLException;
}
...@@ -36,7 +36,8 @@ public interface Trigger { ...@@ -36,7 +36,8 @@ public interface Trigger {
/** /**
* This method is called by the database engine once when initializing the * This method is called by the database engine once when initializing the
* trigger. * trigger. It is called when the trigger is created, as well as when the
* database is opened.
* *
* @param conn a connection to the database * @param conn a connection to the database
* @param schemaName the name of the schema * @param schemaName the name of the schema
...@@ -67,4 +68,20 @@ public interface Trigger { ...@@ -67,4 +68,20 @@ public interface Trigger {
*/ */
void fire(Connection conn, Object[] oldRow, Object[] newRow) throws SQLException; void fire(Connection conn, Object[] oldRow, Object[] newRow) throws SQLException;
/**
* 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;
/**
* This method is called when the trigger is dropped.
*
* @throws SQLException
*/
void remove() throws SQLException;
} }
...@@ -23,7 +23,6 @@ import java.util.HashMap; ...@@ -23,7 +23,6 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import org.h2.api.CloseListener;
import org.h2.api.Trigger; import org.h2.api.Trigger;
import org.h2.command.Parser; import org.h2.command.Parser;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -773,7 +772,7 @@ public class FullText { ...@@ -773,7 +772,7 @@ public class FullText {
/** /**
* Trigger updates the index when a inserting, updating, or deleting a row. * Trigger updates the index when a inserting, updating, or deleting a row.
*/ */
public static class FullTextTrigger implements Trigger, CloseListener { public static class FullTextTrigger implements Trigger {
protected FullTextSettings setting; protected FullTextSettings setting;
protected IndexInfo index; protected IndexInfo index;
......
...@@ -30,7 +30,6 @@ import org.apache.lucene.search.Hits; ...@@ -30,7 +30,6 @@ import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
import org.apache.lucene.search.Searcher; import org.apache.lucene.search.Searcher;
import org.h2.api.CloseListener;
import org.h2.api.Trigger; import org.h2.api.Trigger;
import org.h2.command.Parser; import org.h2.command.Parser;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -410,7 +409,7 @@ public class FullTextLucene extends FullText { ...@@ -410,7 +409,7 @@ public class FullTextLucene extends FullText {
*/ */
public static class FullTextTrigger public static class FullTextTrigger
//## Java 1.4 begin ## //## Java 1.4 begin ##
implements Trigger, CloseListener implements Trigger
//## Java 1.4 end ## //## Java 1.4 end ##
{ {
......
...@@ -8,8 +8,6 @@ package org.h2.schema; ...@@ -8,8 +8,6 @@ package org.h2.schema;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.api.CloseListener;
import org.h2.api.Trigger; import org.h2.api.Trigger;
import org.h2.command.Parser; import org.h2.command.Parser;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
...@@ -324,9 +322,7 @@ public class TriggerObject extends SchemaObjectBase { ...@@ -324,9 +322,7 @@ public class TriggerObject extends SchemaObjectBase {
table.removeTrigger(this); table.removeTrigger(this);
database.removeMeta(session, getId()); database.removeMeta(session, getId());
if (triggerCallback != null) { if (triggerCallback != null) {
if (triggerCallback instanceof CloseListener) { triggerCallback.remove();
((CloseListener) triggerCallback).remove();
}
} }
table = null; table = null;
triggerClassName = null; triggerClassName = null;
...@@ -370,9 +366,7 @@ public class TriggerObject extends SchemaObjectBase { ...@@ -370,9 +366,7 @@ public class TriggerObject extends SchemaObjectBase {
*/ */
public void close() throws SQLException { public void close() throws SQLException {
if (triggerCallback != null) { if (triggerCallback != null) {
if (triggerCallback instanceof CloseListener) { triggerCallback.close();
((CloseListener) triggerCallback).close();
}
} }
} }
......
...@@ -58,6 +58,14 @@ public class TriggerPassData implements Trigger { ...@@ -58,6 +58,14 @@ public class TriggerPassData implements Trigger {
System.out.println(triggerData + ": " + row[0]); System.out.println(triggerData + ": " + row[0]);
} }
public void close() {
// ignore
}
public void remove() {
// ignore
}
/** /**
* Call this method to change a specific trigger. * Call this method to change a specific trigger.
* *
......
...@@ -95,6 +95,15 @@ public class TriggerSample { ...@@ -95,6 +95,15 @@ public class TriggerSample {
prep.setBigDecimal(1, diff); prep.setBigDecimal(1, diff);
prep.execute(); prep.execute();
} }
public void close() {
// ignore
}
public void remove() {
// ignore
}
} }
} }
...@@ -287,7 +287,9 @@ java org.h2.test.TestAll timer ...@@ -287,7 +287,9 @@ java org.h2.test.TestAll timer
System.setProperty("h2.check2", "true"); System.setProperty("h2.check2", "true");
/* /*
Row.getMemorySize
FileStore.sync, Database.sync() (CHECKPOINT SYNC) FileStore.sync, Database.sync() (CHECKPOINT SYNC)
document in performance section: document in performance section:
PreparedStatement prep = conn.prepareStatement( PreparedStatement prep = conn.prepareStatement(
"select * from table(x int = ?) t inner join test on t.x = test.id"); "select * from table(x int = ?) t inner join test on t.x = test.id");
...@@ -296,7 +298,6 @@ ResultSet rs = prep.executeQuery(); ...@@ -296,7 +298,6 @@ ResultSet rs = prep.executeQuery();
review package and class level javadocs review package and class level javadocs
TestAll deleteIndex TestAll deleteIndex
use RuntimeException internally
document FETCH FIRST document FETCH FIRST
......
...@@ -139,4 +139,12 @@ public class TestRunscript extends TestBase implements Trigger { ...@@ -139,4 +139,12 @@ public class TestRunscript extends TestBase implements Trigger {
// nothing to do // nothing to do
} }
public void close() {
// ignore
}
public void remove() {
// ignore
}
} }
...@@ -85,6 +85,14 @@ public class TestTriggersConstraints extends TestBase implements Trigger { ...@@ -85,6 +85,14 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
prepInsert.execute(); prepInsert.execute();
} }
public void close() {
// ignore
}
public void remove() {
// ignore
}
} }
private void testTriggerBeforeSelect() throws SQLException { private void testTriggerBeforeSelect() throws SQLException {
...@@ -137,6 +145,14 @@ public class TestTriggersConstraints extends TestBase implements Trigger { ...@@ -137,6 +145,14 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
prepMeta.execute(); prepMeta.execute();
} }
public void close() {
// ignore
}
public void remove() {
// ignore
}
} }
/** /**
...@@ -152,6 +168,15 @@ public class TestTriggersConstraints extends TestBase implements Trigger { ...@@ -152,6 +168,15 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
int type) { int type) {
// nothing to do // nothing to do
} }
public void close() {
// ignore
}
public void remove() {
// ignore
}
} }
private void testTriggerAlterTable() throws SQLException { private void testTriggerAlterTable() throws SQLException {
...@@ -290,6 +315,14 @@ public class TestTriggersConstraints extends TestBase implements Trigger { ...@@ -290,6 +315,14 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
} }
} }
public void close() {
// ignore
}
public void remove() {
// ignore
}
private void checkCommit(Connection conn) { private void checkCommit(Connection conn) {
try { try {
conn.commit(); conn.commit();
......
...@@ -346,6 +346,14 @@ public class TestPreparedStatement extends TestBase { ...@@ -346,6 +346,14 @@ public class TestPreparedStatement extends TestBase {
// ignore // ignore
} }
public void close() {
// ignore
}
public void remove() {
// ignore
}
} }
private void testScopedGeneratedKey(Connection conn) throws SQLException { private void testScopedGeneratedKey(Connection conn) throws SQLException {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论