提交 34e8b659 authored 作者: Thomas Mueller's avatar Thomas Mueller

Formatting, javadocs, cleanup

上级 0d27db6c
...@@ -26,7 +26,7 @@ Change Log ...@@ -26,7 +26,7 @@ Change Log
</li><li>Fix bug in unique and non-unique hash indexes which manifested as incorrect results </li><li>Fix bug in unique and non-unique hash indexes which manifested as incorrect results
when the search key was a different cardinal type from the table index key. when the search key was a different cardinal type from the table index key.
e.g. where the one was INT and the other was LONG e.g. where the one was INT and the other was LONG
</li><li>Bug: Changes to the database structure did not result </li><li>Bug: Changes to the database structure did not result
in the Session query cache being invalidated. in the Session query cache being invalidated.
</li><li>New feature from Davide Cavestro - allow using custom Java object serialization </li><li>New feature from Davide Cavestro - allow using custom Java object serialization
engines on a per-DB basis. engines on a per-DB basis.
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -161,7 +161,7 @@ public class Select extends Query { ...@@ -161,7 +161,7 @@ public class Select extends Query {
int rowNumber = 0; int rowNumber = 0;
setCurrentRowNumber(0); setCurrentRowNumber(0);
currentGroup = null; currentGroup = null;
Value[] previousKeyValues = null; Value[] previousKeyValues = null;
while (topTableFilter.next()) { while (topTableFilter.next()) {
setCurrentRowNumber(rowNumber + 1); setCurrentRowNumber(rowNumber + 1);
if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) { if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) {
......
...@@ -226,7 +226,7 @@ public class Set extends Prepared { ...@@ -226,7 +226,7 @@ public class Set extends Prepared {
if (table != null) { if (table != null) {
throw DbException.get(ErrorCode.JAVA_OBJECT_SERIALIZER_CHANGE_WITH_DATA_TABLE, table.getSQL()); throw DbException.get(ErrorCode.JAVA_OBJECT_SERIALIZER_CHANGE_WITH_DATA_TABLE, table.getSQL());
} }
database.setJavaObjectSerializerFQN (stringValue); database.setJavaObjectSerializerName(stringValue);
addOrUpdateSetting(name, stringValue, 0); addOrUpdateSetting(name, stringValue, 0);
break; break;
} }
......
...@@ -179,7 +179,7 @@ public class Database implements DataHandler { ...@@ -179,7 +179,7 @@ public class Database implements DataHandler {
private DbException backgroundException; private DbException backgroundException;
private JavaObjectSerializer javaObjectSerializer; private JavaObjectSerializer javaObjectSerializer;
private String javaObjectSerializerFQN; private String javaObjectSerializerName;
private volatile boolean javaObjectSerializerInitialized; private volatile boolean javaObjectSerializerInitialized;
public Database(ConnectionInfo ci, String cipher) { public Database(ConnectionInfo ci, String cipher) {
...@@ -216,7 +216,7 @@ public class Database implements DataHandler { ...@@ -216,7 +216,7 @@ public class Database implements DataHandler {
} }
this.multiVersion = ci.getProperty("MVCC", false); this.multiVersion = ci.getProperty("MVCC", false);
this.logMode = ci.getProperty("LOG", PageStore.LOG_MODE_SYNC); this.logMode = ci.getProperty("LOG", PageStore.LOG_MODE_SYNC);
this.javaObjectSerializerFQN = ci.getProperty("JAVA_OBJECT_SERIALIZER", null); this.javaObjectSerializerName = ci.getProperty("JAVA_OBJECT_SERIALIZER", null);
boolean closeAtVmShutdown = dbSettings.dbCloseOnExit; boolean closeAtVmShutdown = dbSettings.dbCloseOnExit;
int traceLevelFile = ci.getIntProperty(SetTypes.TRACE_LEVEL_FILE, TraceSystem.DEFAULT_TRACE_LEVEL_FILE); int traceLevelFile = ci.getIntProperty(SetTypes.TRACE_LEVEL_FILE, TraceSystem.DEFAULT_TRACE_LEVEL_FILE);
...@@ -2518,12 +2518,12 @@ public class Database implements DataHandler { ...@@ -2518,12 +2518,12 @@ public class Database implements DataHandler {
if (javaObjectSerializerInitialized) { if (javaObjectSerializerInitialized) {
return; return;
} }
String serializerFQN = javaObjectSerializerFQN; String serializerName = javaObjectSerializerName;
if (serializerFQN != null) { if (serializerName != null) {
serializerFQN = serializerFQN.trim(); serializerName = serializerName.trim();
if (!serializerFQN.isEmpty() && !serializerFQN.equals("null")) { if (!serializerName.isEmpty() && !serializerName.equals("null")) {
try { try {
javaObjectSerializer = (JavaObjectSerializer) Utils.loadUserClass(serializerFQN).newInstance(); javaObjectSerializer = (JavaObjectSerializer) Utils.loadUserClass(serializerName).newInstance();
} catch (Exception e) { } catch (Exception e) {
throw DbException.convert(e); throw DbException.convert(e);
} }
...@@ -2532,11 +2532,11 @@ public class Database implements DataHandler { ...@@ -2532,11 +2532,11 @@ public class Database implements DataHandler {
javaObjectSerializerInitialized = true; javaObjectSerializerInitialized = true;
} }
} }
public void setJavaObjectSerializerFQN(String javaObjectSerializerFQN) { public void setJavaObjectSerializerName(String serializerName) {
this.javaObjectSerializerFQN = javaObjectSerializerFQN;
synchronized (this) { synchronized (this) {
javaObjectSerializerInitialized = false; javaObjectSerializerInitialized = false;
javaObjectSerializerName = serializerName;
} }
} }
} }
...@@ -760,7 +760,7 @@ public class SessionRemote extends SessionWithState implements DataHandler { ...@@ -760,7 +760,7 @@ public class SessionRemote extends SessionWithState implements DataHandler {
initJavaObjectSerializer(); initJavaObjectSerializer();
return javaObjectSerializer; return javaObjectSerializer;
} }
private void initJavaObjectSerializer() { private void initJavaObjectSerializer() {
if (javaObjectSerializerInitialized) { if (javaObjectSerializerInitialized) {
return; return;
...@@ -785,18 +785,20 @@ public class SessionRemote extends SessionWithState implements DataHandler { ...@@ -785,18 +785,20 @@ public class SessionRemote extends SessionWithState implements DataHandler {
} }
/** /**
* Read needed persistent db settings * Read the serializer name from the persistent database settings.
*
* @return the serializer
*/ */
private String readSerializationSettings () { private String readSerializationSettings() {
String javaObjectSerializerFQN = null; String javaObjectSerializerFQN = null;
CommandInterface ci = prepareCommand( CommandInterface ci = prepareCommand(
"SELECT * FROM INFORMATION_SCHEMA.SETTINGS "+ "SELECT VALUE FROM INFORMATION_SCHEMA.SETTINGS "+
" WHERE NAME='JAVA_OBJECT_SERIALIZER'", Integer.MAX_VALUE); " WHERE NAME='JAVA_OBJECT_SERIALIZER'", Integer.MAX_VALUE);
try { try {
ResultInterface result = ci.executeQuery(0, false); ResultInterface result = ci.executeQuery(0, false);
if (result.next()) { if (result.next()) {
Value[] row = result.currentRow(); Value[] row = result.currentRow();
javaObjectSerializerFQN = row[1].getString(); javaObjectSerializerFQN = row[0].getString();
} }
} finally { } finally {
ci.close(); ci.close();
......
...@@ -21,7 +21,7 @@ import org.h2.value.Value; ...@@ -21,7 +21,7 @@ import org.h2.value.Value;
/** /**
* A non-unique index based on an in-memory hash map. * A non-unique index based on an in-memory hash map.
* *
* @author Sergi Vladykin * @author Sergi Vladykin
*/ */
public class NonUniqueHashIndex extends BaseIndex { public class NonUniqueHashIndex extends BaseIndex {
......
...@@ -159,6 +159,7 @@ ...@@ -159,6 +159,7 @@
90138=Neplatný název databáze: {0} 90138=Neplatný název databáze: {0}
90139=Nenalezena veřejná statická Java metoda: {0} 90139=Nenalezena veřejná statická Java metoda: {0}
90140=Vrácený výsledek je pouze pro čtení. Možná budete muset použít conn.createStatement(..., ResultSet.CONCUR_UPDATABLE). 90140=Vrácený výsledek je pouze pro čtení. Možná budete muset použít conn.createStatement(..., ResultSet.CONCUR_UPDATABLE).
90141=#Serializer cannot be changed because there is a data table: {0}
HY000=Obecná chyba: {0} HY000=Obecná chyba: {0}
HY004=Neznámý datový typ: {0} HY004=Neznámý datový typ: {0}
HYC00=Vlastnost není podporována: {0} HYC00=Vlastnost není podporována: {0}
......
...@@ -159,6 +159,7 @@ ...@@ -159,6 +159,7 @@
90138=Ungültiger Datenbank Name: {0} 90138=Ungültiger Datenbank Name: {0}
90139=Die (public static) Java Funktion wurde nicht gefunden: {0} 90139=Die (public static) Java Funktion wurde nicht gefunden: {0}
90140=Die Resultat-Zeilen können nicht verändert werden. Mögliche Lösung: conn.createStatement(.., ResultSet.CONCUR_UPDATABLE). 90140=Die Resultat-Zeilen können nicht verändert werden. Mögliche Lösung: conn.createStatement(.., ResultSet.CONCUR_UPDATABLE).
90141=Serialisierer kann nicht geändert werden wenn eine Daten-Tabelle existiert: {0}
HY000=Allgemeiner Fehler: {0} HY000=Allgemeiner Fehler: {0}
HY004=Unbekannter Datentyp: {0} HY004=Unbekannter Datentyp: {0}
HYC00=Dieses Feature wird nicht unterstützt: {0} HYC00=Dieses Feature wird nicht unterstützt: {0}
......
...@@ -159,6 +159,7 @@ ...@@ -159,6 +159,7 @@
90138=Nombre de base de datos Invalido: {0} 90138=Nombre de base de datos Invalido: {0}
90139=El metodo Java (publico y estatico) : {0} no fue encontrado 90139=El metodo Java (publico y estatico) : {0} no fue encontrado
90140=El conjunto de resultados es de solo lectura. Puede ser necesario usar conn.createStatement(.., ResultSet.CONCUR_UPDATABLE). 90140=El conjunto de resultados es de solo lectura. Puede ser necesario usar conn.createStatement(.., ResultSet.CONCUR_UPDATABLE).
90141=#Serializer cannot be changed because there is a data table: {0}
HY000=Error General : {0} HY000=Error General : {0}
HY004=Tipo de dato desconocido : {0} HY004=Tipo de dato desconocido : {0}
HYC00=Caracteristica no soportada: {0} HYC00=Caracteristica no soportada: {0}
......
...@@ -159,6 +159,7 @@ ...@@ -159,6 +159,7 @@
90138=不正なデータベース名: {0} 90138=不正なデータベース名: {0}
90139=public staticであるJavaメソッドが見つかりません: {0} 90139=public staticであるJavaメソッドが見つかりません: {0}
90140=リザルトセットは読み込み専用です。conn.createStatement(.., ResultSet.CONCUR_UPDATABLE) を使う必要があるかもしれません 90140=リザルトセットは読み込み専用です。conn.createStatement(.., ResultSet.CONCUR_UPDATABLE) を使う必要があるかもしれません
90141=#Serializer cannot be changed because there is a data table: {0}
HY000=一般エラー: {0} HY000=一般エラー: {0}
HY004=不明なデータ型: {0} HY004=不明なデータ型: {0}
HYC00=機能はサポートされていません: {0} HYC00=機能はサポートされていません: {0}
......
...@@ -159,6 +159,7 @@ ...@@ -159,6 +159,7 @@
90138=#Invalid database name: {0} 90138=#Invalid database name: {0}
90139=#The public static Java method was not found: {0} 90139=#The public static Java method was not found: {0}
90140=#The result set is readonly. You may need to use conn.createStatement(.., ResultSet.CONCUR_UPDATABLE). 90140=#The result set is readonly. You may need to use conn.createStatement(.., ResultSet.CONCUR_UPDATABLE).
90141=#Serializer cannot be changed because there is a data table: {0}
HY000=Blad ogolny: {0} HY000=Blad ogolny: {0}
HY004=Nieznany typ danyche: {0} HY004=Nieznany typ danyche: {0}
HYC00=Cecha nie jest wspierana: {0} HYC00=Cecha nie jest wspierana: {0}
......
...@@ -159,6 +159,7 @@ ...@@ -159,6 +159,7 @@
90138=#Invalid database name: {0} 90138=#Invalid database name: {0}
90139=#The public static Java method was not found: {0} 90139=#The public static Java method was not found: {0}
90140=#The result set is readonly. You may need to use conn.createStatement(.., ResultSet.CONCUR_UPDATABLE). 90140=#The result set is readonly. You may need to use conn.createStatement(.., ResultSet.CONCUR_UPDATABLE).
90141=#Serializer cannot be changed because there is a data table: {0}
HY000=Erro geral: {0} HY000=Erro geral: {0}
HY004=Tipo de dados desconhecido: {0} HY004=Tipo de dados desconhecido: {0}
HYC00=Recurso não suportado: {0} HYC00=Recurso não suportado: {0}
......
...@@ -159,6 +159,7 @@ ...@@ -159,6 +159,7 @@
90138=Недопустимое имя базы данных: {0} 90138=Недопустимое имя базы данных: {0}
90139=public static Java метод не найден: {0} 90139=public static Java метод не найден: {0}
90140=Набор записей не является обновляемым. Возможно необходимо использовать conn.createStatement(.., ResultSet.CONCUR_UPDATABLE). 90140=Набор записей не является обновляемым. Возможно необходимо использовать conn.createStatement(.., ResultSet.CONCUR_UPDATABLE).
90141=#Serializer cannot be changed because there is a data table: {0}
HY000=Внутренняя ошибка: {0} HY000=Внутренняя ошибка: {0}
HY004=Неизвестный тип данных: {0} HY004=Неизвестный тип данных: {0}
HYC00=Данная функция не поддерживается: {0} HYC00=Данная функция не поддерживается: {0}
......
...@@ -159,6 +159,7 @@ ...@@ -159,6 +159,7 @@
90138=Nesprávne meno databázy: {0} 90138=Nesprávne meno databázy: {0}
90139=Verejná statická Java metóda nebola nájdená: {0} 90139=Verejná statická Java metóda nebola nájdená: {0}
90140=Výsledok (result set) je iba na čítanie. Je potrebné použiť conn.createStatement(.., ResultSet.CONCUR_UPDATABLE). 90140=Výsledok (result set) je iba na čítanie. Je potrebné použiť conn.createStatement(.., ResultSet.CONCUR_UPDATABLE).
90141=#Serializer cannot be changed because there is a data table: {0}
HY000=Všeobecná chyba: {0} HY000=Všeobecná chyba: {0}
HY004=Neznámy dátový typ: {0} HY004=Neznámy dátový typ: {0}
HYC00=Vlastnosť nie je podporovaná: {0} HYC00=Vlastnosť nie je podporovaná: {0}
......
...@@ -159,6 +159,7 @@ ...@@ -159,6 +159,7 @@
90138=无效数据库名称: {0} 90138=无效数据库名称: {0}
90139=找不到公用Java静态方法: {0} 90139=找不到公用Java静态方法: {0}
90140=结果集是只读的. 你可以使用 conn.createStatement(.., ResultSet.CONCUR_UPDATABLE). 90140=结果集是只读的. 你可以使用 conn.createStatement(.., ResultSet.CONCUR_UPDATABLE).
90141=#Serializer cannot be changed because there is a data table: {0}
HY000=常规错误: {0} HY000=常规错误: {0}
HY004=位置数据类型: {0} HY004=位置数据类型: {0}
HYC00=不支持的特性: {0} HYC00=不支持的特性: {0}
......
...@@ -172,7 +172,7 @@ ON tableName ( indexColumn [,...] ) ...@@ -172,7 +172,7 @@ ON tableName ( indexColumn [,...] )
"," ","
Creates a new index." Creates a new index."
"Commands (DDL)","CREATE LINKED TABLE"," "Commands (DDL)","CREATE LINKED TABLE","
CREATE [ [ GLOBAL | LOCAL ] TEMPORARY ] LINKED TABLE [ IF NOT EXISTS ] CREATE [ FORCE ] [ [ GLOBAL | LOCAL ] TEMPORARY ] LINKED TABLE [ IF NOT EXISTS ]
name ( driverString, urlString, userString, passwordString, name ( driverString, urlString, userString, passwordString,
[ originalSchemaString, ] originalTableString ) [ EMIT UPDATES | READONLY ] [ originalSchemaString, ] originalTableString ) [ EMIT UPDATES | READONLY ]
"," ","
......
...@@ -628,7 +628,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData { ...@@ -628,7 +628,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
if (o == null || o instanceof byte[]) { if (o == null || o instanceof byte[]) {
return (byte[]) o; return (byte[]) o;
} }
return Utils.serialize(o); return Utils.serialize(o, null);
} }
/** /**
......
...@@ -328,21 +328,8 @@ public class Utils { ...@@ -328,21 +328,8 @@ public class Utils {
} }
/** /**
* Serialize the object to a byte array. * Serialize the object to a byte array, using the serializer specified by
* * the connection info if set, or the default serializer.
* @param obj the object to serialize
* @return the byte array
*
* @deprecated use {@link #serialize(Object, DataHandler)} instead
*/
@Deprecated
public static byte[] serialize(Object obj) {
return serialize(obj, null);
}
/**
* Serialize the object to a byte array, eventually using the serializer
* specified by the connection info.
* *
* @param obj the object to serialize * @param obj the object to serialize
* @param dataHandler provides the object serializer (may be null) * @param dataHandler provides the object serializer (may be null)
...@@ -350,12 +337,12 @@ public class Utils { ...@@ -350,12 +337,12 @@ public class Utils {
*/ */
public static byte[] serialize(Object obj, DataHandler dataHandler) { public static byte[] serialize(Object obj, DataHandler dataHandler) {
try { try {
JavaObjectSerializer dbJavaObjectSerializer = null; JavaObjectSerializer handlerSerializer = null;
if (dataHandler != null) { if (dataHandler != null) {
dbJavaObjectSerializer = dataHandler.getJavaObjectSerializer(); handlerSerializer = dataHandler.getJavaObjectSerializer();
} }
if (dbJavaObjectSerializer != null) { if (handlerSerializer != null) {
return dbJavaObjectSerializer.serialize(obj); return handlerSerializer.serialize(obj);
} }
if (serializer != null) { if (serializer != null) {
return serializer.serialize(obj); return serializer.serialize(obj);
......
...@@ -350,8 +350,6 @@ java org.h2.test.TestAll timer ...@@ -350,8 +350,6 @@ java org.h2.test.TestAll timer
private Server server; private Server server;
public String javaObjectSerializer;
/** /**
* Run all tests. * Run all tests.
* *
......
...@@ -320,9 +320,6 @@ public abstract class TestBase { ...@@ -320,9 +320,6 @@ public abstract class TestBase {
if (config.nestedJoins) { if (config.nestedJoins) {
url = addOption(url, "NESTED_JOINS", "TRUE"); url = addOption(url, "NESTED_JOINS", "TRUE");
} }
if (config.javaObjectSerializer!=null) {
url = addOption(url, "JAVA_OBJECT_SERIALIZER", config.javaObjectSerializer);
}
return "jdbc:h2:" + url; return "jdbc:h2:" + url;
} }
......
...@@ -507,15 +507,16 @@ public class TestIndex extends TestBase { ...@@ -507,15 +507,16 @@ public class TestIndex extends TestBase {
private void testHashIndexOnMemoryTable() throws SQLException { private void testHashIndexOnMemoryTable() throws SQLException {
reconnect(); reconnect();
stat.execute("drop table if exists hash_index_test"); stat.execute("drop table if exists hash_index_test");
stat.execute("create memory table hash_index_test as select x as id, x % 10 as data from (select * from system_range(1, 100))"); stat.execute("create memory table hash_index_test as " +
"select x as id, x % 10 as data from (select * from system_range(1, 100))");
stat.execute("create hash index idx2 on hash_index_test(data)"); stat.execute("create hash index idx2 on hash_index_test(data)");
assertEquals(10, getValue("select count(*) from hash_index_test where data = 1")); assertEquals(10, getValue("select count(*) from hash_index_test where data = 1"));
stat.execute("drop index idx2"); stat.execute("drop index idx2");
stat.execute("create unique hash index idx2 on hash_index_test(id)"); stat.execute("create unique hash index idx2 on hash_index_test(id)");
assertEquals(1, getValue("select count(*) from hash_index_test where id = 1")); assertEquals(1, getValue("select count(*) from hash_index_test where id = 1"));
} }
private int getValue(String sql) throws SQLException { private int getValue(String sql) throws SQLException {
ResultSet rs = stat.executeQuery(sql); ResultSet rs = stat.executeQuery(sql);
rs.next(); rs.next();
......
...@@ -74,7 +74,7 @@ public class TestOptimizations extends TestBase { ...@@ -74,7 +74,7 @@ public class TestOptimizations extends TestBase {
testConvertOrToIn(); testConvertOrToIn();
deleteDb("optimizations"); deleteDb("optimizations");
} }
private void testGroupSubquery() throws Exception { private void testGroupSubquery() throws Exception {
Connection conn = getConnection("optimizations"); Connection conn = getConnection("optimizations");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
...@@ -84,7 +84,7 @@ public class TestOptimizations extends TestBase { ...@@ -84,7 +84,7 @@ public class TestOptimizations extends TestBase {
stat.execute("insert into t2 values(2), (3)"); stat.execute("insert into t2 values(2), (3)");
stat.execute("create index t1id_index on t1(id)"); stat.execute("create index t1id_index on t1(id)");
ResultSet rs; ResultSet rs;
rs = stat.executeQuery("select id, (select count(*) from t2 " + rs = stat.executeQuery("select id, (select count(*) from t2 " +
"where t2.id = t1.id) cc from t1 group by id order by id"); "where t2.id = t1.id) cc from t1 group by id order by id");
rs.next(); rs.next();
assertEquals(2, rs.getInt(1)); assertEquals(2, rs.getInt(1));
......
...@@ -19,7 +19,7 @@ public class TestQueryCache extends TestBase { ...@@ -19,7 +19,7 @@ public class TestQueryCache extends TestBase {
/** /**
* Run just this test. * Run just this test.
* *
* @param a ignored * @param a ignored
*/ */
public static void main(String... a) throws Exception { public static void main(String... a) throws Exception {
......
...@@ -45,8 +45,8 @@ public class TestJavaObjectSerializer extends TestBase { ...@@ -45,8 +45,8 @@ public class TestJavaObjectSerializer extends TestBase {
testDbLevelJavaObjectSerializer(); testDbLevelJavaObjectSerializer();
deleteDb("javaSerializer"); deleteDb("javaSerializer");
} }
public void testStaticGlobalSerializer() throws Exception { private void testStaticGlobalSerializer() throws Exception {
Utils.serializer = new JavaObjectSerializer() { Utils.serializer = new JavaObjectSerializer() {
@Override @Override
public byte[] serialize(Object obj) throws Exception { public byte[] serialize(Object obj) throws Exception {
...@@ -66,7 +66,7 @@ public class TestJavaObjectSerializer extends TestBase { ...@@ -66,7 +66,7 @@ public class TestJavaObjectSerializer extends TestBase {
try { try {
deleteDb("javaSerializer"); deleteDb("javaSerializer");
Connection conn = getConnection("javaSerializer"); Connection conn = getConnection("javaSerializer");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("create table t(id identity, val other)"); stat.execute("create table t(id identity, val other)");
...@@ -91,11 +91,12 @@ public class TestJavaObjectSerializer extends TestBase { ...@@ -91,11 +91,12 @@ public class TestJavaObjectSerializer extends TestBase {
} }
/** /**
* Tests per-db {@link JavaObjectSerializer} when set through the related * Tests per-database serializer when set through the related SET command.
* SET command. */
*/
public void testDbLevelJavaObjectSerializer() throws Exception { public void testDbLevelJavaObjectSerializer() throws Exception {
DbLevelJavaObjectSerializer.testBaseRef = this; DbLevelJavaObjectSerializer.testBaseRef = this;
try { try {
deleteDb("javaSerializer"); deleteDb("javaSerializer");
Connection conn = getConnection("javaSerializer"); Connection conn = getConnection("javaSerializer");
...@@ -125,9 +126,15 @@ public class TestJavaObjectSerializer extends TestBase { ...@@ -125,9 +126,15 @@ public class TestJavaObjectSerializer extends TestBase {
} }
} }
/**
* The serializer to use for this test.
*/
public static class DbLevelJavaObjectSerializer implements JavaObjectSerializer { public static class DbLevelJavaObjectSerializer implements JavaObjectSerializer {
private static TestBase testBaseRef; /**
* The test.
*/
static TestBase testBaseRef;
@Override @Override
public byte[] serialize(Object obj) throws Exception { public byte[] serialize(Object obj) throws Exception {
......
/* /*
* Copyright 2004-2013 H2 Group. Multiple-Licensed under the H2 License, * Copyright 2004-2013 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0 * Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html). * (http://h2database.com/html/license.html).
* Initial Developer: H2 Group * Initial Developer: H2 Group
*/ */
package org.h2.test.jdbc; package org.h2.test.jdbc;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.Statement; import java.sql.Statement;
import java.sql.Types; import java.sql.Types;
import org.h2.api.JavaObjectSerializer; import org.h2.api.JavaObjectSerializer;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/** /**
* Tests per-db {@link JavaObjectSerializer} when set through the JDBC URL. * Tests per-db {@link JavaObjectSerializer} when set through the JDBC URL.
* *
* @author Davide Cavestro * @author Davide Cavestro
*/ */
public class TestUrlJavaObjectSerializer extends TestBase { public class TestUrlJavaObjectSerializer extends TestBase {
/** /**
* Run just this test. * Run just this test.
* *
* @param a ignored * @param a ignored
*/ */
public static void main(String... a) throws Exception { public static void main(String... a) throws Exception {
TestBase test = createCaller().init(); TestBase test = createCaller().init();
test.config.traceTest = true; test.config.traceTest = true;
test.config.memory = true; test.config.memory = true;
test.config.networked = true; test.config.networked = true;
test.config.javaObjectSerializer = FakeJavaObjectSerializer.class.getName(); test.config.beforeTest();
test.config.beforeTest(); test.test();
test.test(); test.config.afterTest();
test.config.afterTest(); }
}
@Override
@Override public void test() throws Exception {
public void test() throws Exception { FakeJavaObjectSerializer.testBaseRef = this;
FakeJavaObjectSerializer.testBaseRef = this; try {
try { deleteDb("javaSerializer");
deleteDb("javaSerializer"); String fqn = FakeJavaObjectSerializer.class.getName();
String fqn = FakeJavaObjectSerializer.class.getName(); Connection conn = getConnection("javaSerializer;JAVA_OBJECT_SERIALIZER='"+fqn+"'");
Connection conn = getConnection("javaSerializer;JAVA_OBJECT_SERIALIZER='"+fqn+"'");
Statement stat = conn.createStatement();
Statement stat = conn.createStatement(); stat.execute("create table t1(id identity, val other)");
stat.execute("create table t1(id identity, val other)");
PreparedStatement ins = conn.prepareStatement("insert into t1(val) values(?)");
PreparedStatement ins = conn.prepareStatement("insert into t1(val) values(?)");
ins.setObject(1, 100500, Types.JAVA_OBJECT);
ins.setObject(1, 100500, Types.JAVA_OBJECT); assertEquals(1, ins.executeUpdate());
assertEquals(1, ins.executeUpdate());
Statement s = conn.createStatement();
Statement s = conn.createStatement(); ResultSet rs = s.executeQuery("select val from t1");
ResultSet rs = s.executeQuery("select val from t1");
assertTrue(rs.next());
assertTrue(rs.next());
assertEquals(100500, ((Integer) rs.getObject(1)).intValue());
assertEquals(100500, ((Integer) rs.getObject(1)).intValue()); assertEquals(new byte[] { 1, 2, 3 }, rs.getBytes(1));
assertEquals(new byte[] { 1, 2, 3 }, rs.getBytes(1));
conn.close();
conn.close(); deleteDb("javaSerializer");
deleteDb("javaSerializer"); } finally {
} finally { FakeJavaObjectSerializer.testBaseRef = null;
FakeJavaObjectSerializer.testBaseRef = null; }
} }
}
/**
public static class FakeJavaObjectSerializer implements JavaObjectSerializer { * The serializer to use for this test.
*/
private static TestBase testBaseRef; public static class FakeJavaObjectSerializer implements JavaObjectSerializer {
@Override /**
public byte[] serialize(Object obj) throws Exception { * The test.
testBaseRef.assertEquals(100500, ((Integer) obj).intValue()); */
static TestBase testBaseRef;
return new byte[] { 1, 2, 3 };
} @Override
public byte[] serialize(Object obj) throws Exception {
@Override testBaseRef.assertEquals(100500, ((Integer) obj).intValue());
public Object deserialize(byte[] bytes) throws Exception {
testBaseRef.assertEquals(new byte[] { 1, 2, 3 }, bytes); return new byte[] { 1, 2, 3 };
}
return 100500;
} @Override
public Object deserialize(byte[] bytes) throws Exception {
} testBaseRef.assertEquals(new byte[] { 1, 2, 3 }, bytes);
}
return 100500;
}
}
}
...@@ -735,4 +735,4 @@ mgcodeact cumer reach notably computation varies smuggled stderr sees messes ...@@ -735,4 +735,4 @@ mgcodeact cumer reach notably computation varies smuggled stderr sees messes
nico devel nicolas linestring atelier fortin cnrs tweet geospatialnews bundles nico devel nicolas linestring atelier fortin cnrs tweet geospatialnews bundles
srid roads srid roads
overlaps anyhow poly overlaps anyhow poly manifested cardinal invalidated
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论