提交 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 { ...@@ -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 * 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 * event listener is not set or set as a string (the class name), then this
...@@ -214,8 +221,8 @@ public class ConnectionInfo implements Cloneable { ...@@ -214,8 +221,8 @@ public class ConnectionInfo implements Cloneable {
* *
* @return the database event listener object or null * @return the database event listener object or null
*/ */
DatabaseEventListener removeDatabaseEventListenerObject() throws SQLException { DatabaseEventListener getDatabaseEventListenerObject() throws SQLException {
Object p = prop.remove("DATABASE_EVENT_LISTENER_OBJECT"); Object p = prop.get("DATABASE_EVENT_LISTENER_OBJECT");
if (p == null) { if (p == null) {
return null; return null;
} }
......
...@@ -181,16 +181,12 @@ public class Database implements DataHandler { ...@@ -181,16 +181,12 @@ public class Database implements DataHandler {
this.fileLockMethod = FileLock.getFileLockMethod(lockMethodName); this.fileLockMethod = FileLock.getFileLockMethod(lockMethodName);
this.textStorage = ci.getTextStorage(); this.textStorage = ci.getTextStorage();
this.databaseURL = ci.getURL(); this.databaseURL = ci.getURL();
this.eventListener = ci.removeDatabaseEventListenerObject(); this.eventListener = ci.getDatabaseEventListenerObject();
ci.removeDatabaseEventListenerObject();
if (eventListener == null) { if (eventListener == null) {
String listener = ci.removeProperty("DATABASE_EVENT_LISTENER", null); String listener = ci.removeProperty("DATABASE_EVENT_LISTENER", null);
if (listener != null) { if (listener != null) {
if (listener.startsWith("'")) { listener = StringUtils.trim(listener, true, true, "'");
listener = listener.substring(1);
}
if (listener.endsWith("'")) {
listener = listener.substring(0, listener.length() - 1);
}
setEventListenerClass(listener); setEventListenerClass(listener);
} }
} }
......
...@@ -8,6 +8,7 @@ package org.h2.engine; ...@@ -8,6 +8,7 @@ package org.h2.engine;
import java.util.HashMap; import java.util.HashMap;
import org.h2.constant.SysProperties;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
/** /**
...@@ -93,16 +94,26 @@ public class Mode { ...@@ -93,16 +94,26 @@ public class Mode {
*/ */
public boolean supportOffsetFetch; 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; private String name;
static { static {
Mode mode = new Mode(REGULAR); Mode mode = new Mode(REGULAR);
mode.aliasColumnName = SysProperties.ALIAS_COLUMN_NAME;
add(mode); add(mode);
mode = new Mode("PostgreSQL"); mode = new Mode("PostgreSQL");
mode.nullConcatIsNull = true; mode.nullConcatIsNull = true;
mode.roundWhenConvertToLong = true; mode.roundWhenConvertToLong = true;
mode.systemColumns = true; mode.systemColumns = true;
mode.aliasColumnName = true;
add(mode); add(mode);
mode = new Mode("MySQL"); mode = new Mode("MySQL");
...@@ -116,23 +127,28 @@ public class Mode { ...@@ -116,23 +127,28 @@ public class Mode {
mode.nullConcatIsNull = true; mode.nullConcatIsNull = true;
mode.convertOnlyToSmallerScale = true; mode.convertOnlyToSmallerScale = true;
mode.uniqueIndexSingleNull = true; mode.uniqueIndexSingleNull = true;
mode.aliasColumnName = true;
add(mode); add(mode);
mode = new Mode("MSSQLServer"); mode = new Mode("MSSQLServer");
mode.squareBracketQuotedNames = true; mode.squareBracketQuotedNames = true;
mode.uniqueIndexSingleNull = true; mode.uniqueIndexSingleNull = true;
mode.aliasColumnName = true;
add(mode); add(mode);
mode = new Mode("Derby"); mode = new Mode("Derby");
mode.uniqueIndexSingleNull = true; mode.uniqueIndexSingleNull = true;
mode.aliasColumnName = true;
add(mode); add(mode);
mode = new Mode("Oracle"); mode = new Mode("Oracle");
mode.uniqueIndexSingleNullExceptAllColumnsAreNull = true; mode.uniqueIndexSingleNullExceptAllColumnsAreNull = true;
mode.aliasColumnName = true;
add(mode); add(mode);
mode = new Mode("DB2"); mode = new Mode("DB2");
mode.supportOffsetFetch = true; mode.supportOffsetFetch = true;
mode.aliasColumnName = true;
add(mode); add(mode);
} }
......
...@@ -8,9 +8,12 @@ package org.h2.test.db; ...@@ -8,9 +8,12 @@ package org.h2.test.db;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import org.h2.engine.Constants;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/** /**
...@@ -20,10 +23,20 @@ public class TestCompatibility extends TestBase { ...@@ -20,10 +23,20 @@ public class TestCompatibility extends TestBase {
private Connection conn; 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 { public void test() throws SQLException {
deleteDb("compatibility"); deleteDb("compatibility");
conn = getConnection("compatibility"); conn = getConnection("compatibility");
testColumnAlias();
testUniqueIndexSingleNull(); testUniqueIndexSingleNull();
testUniqueIndexOracle(); testUniqueIndexOracle();
testHsqlDb(); testHsqlDb();
...@@ -33,6 +46,34 @@ public class TestCompatibility extends TestBase { ...@@ -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 { private void testUniqueIndexSingleNull() throws SQLException {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
String[] modes = new String[] { "PostgreSQL", "MySQL", "HSQLDB", "MSSQLServer", "Derby", "Oracle", "Regular" }; String[] modes = new String[] { "PostgreSQL", "MySQL", "HSQLDB", "MSSQLServer", "Derby", "Oracle", "Regular" };
......
...@@ -23,6 +23,15 @@ import org.h2.tools.Server; ...@@ -23,6 +23,15 @@ import org.h2.tools.Server;
*/ */
public class TestPgServer extends TestBase { 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 { public void test() throws SQLException {
deleteDb("test"); deleteDb("test");
Server server = Server.createPgServer(new String[]{"-baseDir", baseDir, "-pgPort", "5535"}); Server server = Server.createPgServer(new String[]{"-baseDir", baseDir, "-pgPort", "5535"});
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论