提交 0a211f76 authored 作者: Thomas Mueller's avatar Thomas Mueller

After re-connecting to a database, the database event listener (if set) is informed.

上级 7664a84f
......@@ -207,6 +207,13 @@ public class ConnectionInfo implements Cloneable {
}
}
/**
* Removes the database event listener object.
*/
void removeDatabaseEventListenerObject() {
prop.remove("DATABASE_EVENT_LISTENER_OBJECT");
}
/**
* Return the database event listener object set as a Java object. If the
* event listener is not set or set as a string (the class name), then this
......@@ -214,8 +221,8 @@ public class ConnectionInfo implements Cloneable {
*
* @return the database event listener object or null
*/
DatabaseEventListener removeDatabaseEventListenerObject() throws SQLException {
Object p = prop.remove("DATABASE_EVENT_LISTENER_OBJECT");
DatabaseEventListener getDatabaseEventListenerObject() throws SQLException {
Object p = prop.get("DATABASE_EVENT_LISTENER_OBJECT");
if (p == null) {
return null;
}
......
......@@ -181,16 +181,12 @@ public class Database implements DataHandler {
this.fileLockMethod = FileLock.getFileLockMethod(lockMethodName);
this.textStorage = ci.getTextStorage();
this.databaseURL = ci.getURL();
this.eventListener = ci.removeDatabaseEventListenerObject();
this.eventListener = ci.getDatabaseEventListenerObject();
ci.removeDatabaseEventListenerObject();
if (eventListener == null) {
String listener = ci.removeProperty("DATABASE_EVENT_LISTENER", null);
if (listener != null) {
if (listener.startsWith("'")) {
listener = listener.substring(1);
}
if (listener.endsWith("'")) {
listener = listener.substring(0, listener.length() - 1);
}
listener = StringUtils.trim(listener, true, true, "'");
setEventListenerClass(listener);
}
}
......
......@@ -8,6 +8,7 @@ package org.h2.engine;
import java.util.HashMap;
import org.h2.constant.SysProperties;
import org.h2.util.StringUtils;
/**
......@@ -93,16 +94,26 @@ public class Mode {
*/
public boolean supportOffsetFetch;
/**
* When enabled, aliased columns (as in SELECT ID AS I FROM TEST) return the
* alias (I in this case) in ResultSetMetaData.getColumnName() and 'null' in
* getTableName(). If disabled, the real column name (ID in this case) and
* table name is returned.
*/
public boolean aliasColumnName;
private String name;
static {
Mode mode = new Mode(REGULAR);
mode.aliasColumnName = SysProperties.ALIAS_COLUMN_NAME;
add(mode);
mode = new Mode("PostgreSQL");
mode.nullConcatIsNull = true;
mode.roundWhenConvertToLong = true;
mode.systemColumns = true;
mode.aliasColumnName = true;
add(mode);
mode = new Mode("MySQL");
......@@ -116,23 +127,28 @@ public class Mode {
mode.nullConcatIsNull = true;
mode.convertOnlyToSmallerScale = true;
mode.uniqueIndexSingleNull = true;
mode.aliasColumnName = true;
add(mode);
mode = new Mode("MSSQLServer");
mode.squareBracketQuotedNames = true;
mode.uniqueIndexSingleNull = true;
mode.aliasColumnName = true;
add(mode);
mode = new Mode("Derby");
mode.uniqueIndexSingleNull = true;
mode.aliasColumnName = true;
add(mode);
mode = new Mode("Oracle");
mode.uniqueIndexSingleNullExceptAllColumnsAreNull = true;
mode.aliasColumnName = true;
add(mode);
mode = new Mode("DB2");
mode.supportOffsetFetch = true;
mode.aliasColumnName = true;
add(mode);
}
......
......@@ -8,9 +8,12 @@ package org.h2.test.db;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import org.h2.engine.Constants;
import org.h2.test.TestBase;
/**
......@@ -20,10 +23,20 @@ public class TestCompatibility extends TestBase {
private Connection conn;
/**
* Run just this test.
*
* @param a ignored
*/
public static void main(String[] a) throws Exception {
TestBase.createCaller().init().test();
}
public void test() throws SQLException {
deleteDb("compatibility");
conn = getConnection("compatibility");
testColumnAlias();
testUniqueIndexSingleNull();
testUniqueIndexOracle();
testHsqlDb();
......@@ -33,6 +46,34 @@ public class TestCompatibility extends TestBase {
}
private void testColumnAlias() throws SQLException {
Statement stat = conn.createStatement();
String[] modes = new String[] { "PostgreSQL", "MySQL", "HSQLDB", "MSSQLServer", "Derby", "Oracle", "Regular" };
String columnAlias;
if (Constants.VERSION_MINOR == 0) {
columnAlias = "MySQL";
} else {
columnAlias = "MySQL,Regular";
}
stat.execute("CREATE TABLE TEST(ID INT)");
for (int i = 0; i < modes.length; i++) {
String mode = modes[i];
stat.execute("SET MODE " + mode);
ResultSet rs = stat.executeQuery("SELECT ID I FROM TEST");
ResultSetMetaData meta = rs.getMetaData();
String columnName = meta.getColumnName(1);
String tableName = meta.getTableName(1);
if ("ID".equals(columnName) && "TEST".equals(tableName)) {
assertTrue(mode + " mode should not support columnAlias", columnAlias.indexOf(mode) >= 0);
} else if ("I".equals(columnName) && tableName == null) {
assertTrue(mode + " mode should support columnAlias", columnAlias.indexOf(mode) < 0);
} else {
fail();
}
}
stat.execute("DROP TABLE TEST");
}
private void testUniqueIndexSingleNull() throws SQLException {
Statement stat = conn.createStatement();
String[] modes = new String[] { "PostgreSQL", "MySQL", "HSQLDB", "MSSQLServer", "Derby", "Oracle", "Regular" };
......
......@@ -23,6 +23,15 @@ import org.h2.tools.Server;
*/
public class TestPgServer extends TestBase {
/**
* Run just this test.
*
* @param a ignored
*/
public static void main(String[] a) throws Exception {
TestBase.createCaller().init().test();
}
public void test() throws SQLException {
deleteDb("test");
Server server = Server.createPgServer(new String[]{"-baseDir", baseDir, "-pgPort", "5535"});
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论