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

Formatting, javadocs, cleanup

上级 0d27db6c
......@@ -26,7 +26,7 @@ Change Log
</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.
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.
</li><li>New feature from Davide Cavestro - allow using custom Java object serialization
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 {
int rowNumber = 0;
setCurrentRowNumber(0);
currentGroup = null;
Value[] previousKeyValues = null;
Value[] previousKeyValues = null;
while (topTableFilter.next()) {
setCurrentRowNumber(rowNumber + 1);
if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) {
......
......@@ -226,7 +226,7 @@ public class Set extends Prepared {
if (table != null) {
throw DbException.get(ErrorCode.JAVA_OBJECT_SERIALIZER_CHANGE_WITH_DATA_TABLE, table.getSQL());
}
database.setJavaObjectSerializerFQN (stringValue);
database.setJavaObjectSerializerName(stringValue);
addOrUpdateSetting(name, stringValue, 0);
break;
}
......
......@@ -179,7 +179,7 @@ public class Database implements DataHandler {
private DbException backgroundException;
private JavaObjectSerializer javaObjectSerializer;
private String javaObjectSerializerFQN;
private String javaObjectSerializerName;
private volatile boolean javaObjectSerializerInitialized;
public Database(ConnectionInfo ci, String cipher) {
......@@ -216,7 +216,7 @@ public class Database implements DataHandler {
}
this.multiVersion = ci.getProperty("MVCC", false);
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;
int traceLevelFile = ci.getIntProperty(SetTypes.TRACE_LEVEL_FILE, TraceSystem.DEFAULT_TRACE_LEVEL_FILE);
......@@ -2518,12 +2518,12 @@ public class Database implements DataHandler {
if (javaObjectSerializerInitialized) {
return;
}
String serializerFQN = javaObjectSerializerFQN;
if (serializerFQN != null) {
serializerFQN = serializerFQN.trim();
if (!serializerFQN.isEmpty() && !serializerFQN.equals("null")) {
String serializerName = javaObjectSerializerName;
if (serializerName != null) {
serializerName = serializerName.trim();
if (!serializerName.isEmpty() && !serializerName.equals("null")) {
try {
javaObjectSerializer = (JavaObjectSerializer) Utils.loadUserClass(serializerFQN).newInstance();
javaObjectSerializer = (JavaObjectSerializer) Utils.loadUserClass(serializerName).newInstance();
} catch (Exception e) {
throw DbException.convert(e);
}
......@@ -2532,11 +2532,11 @@ public class Database implements DataHandler {
javaObjectSerializerInitialized = true;
}
}
public void setJavaObjectSerializerFQN(String javaObjectSerializerFQN) {
this.javaObjectSerializerFQN = javaObjectSerializerFQN;
public void setJavaObjectSerializerName(String serializerName) {
synchronized (this) {
javaObjectSerializerInitialized = false;
javaObjectSerializerName = serializerName;
}
}
}
......@@ -760,7 +760,7 @@ public class SessionRemote extends SessionWithState implements DataHandler {
initJavaObjectSerializer();
return javaObjectSerializer;
}
private void initJavaObjectSerializer() {
if (javaObjectSerializerInitialized) {
return;
......@@ -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;
CommandInterface ci = prepareCommand(
"SELECT * FROM INFORMATION_SCHEMA.SETTINGS "+
"SELECT VALUE FROM INFORMATION_SCHEMA.SETTINGS "+
" WHERE NAME='JAVA_OBJECT_SERIALIZER'", Integer.MAX_VALUE);
try {
ResultInterface result = ci.executeQuery(0, false);
if (result.next()) {
Value[] row = result.currentRow();
javaObjectSerializerFQN = row[1].getString();
javaObjectSerializerFQN = row[0].getString();
}
} finally {
ci.close();
......
......@@ -21,7 +21,7 @@ import org.h2.value.Value;
/**
* A non-unique index based on an in-memory hash map.
*
*
* @author Sergi Vladykin
*/
public class NonUniqueHashIndex extends BaseIndex {
......
......@@ -159,6 +159,7 @@
90138=Neplatný název databáze: {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).
90141=#Serializer cannot be changed because there is a data table: {0}
HY000=Obecná chyba: {0}
HY004=Neznámý datový typ: {0}
HYC00=Vlastnost není podporována: {0}
......
......@@ -159,6 +159,7 @@
90138=Ungültiger Datenbank Name: {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).
90141=Serialisierer kann nicht geändert werden wenn eine Daten-Tabelle existiert: {0}
HY000=Allgemeiner Fehler: {0}
HY004=Unbekannter Datentyp: {0}
HYC00=Dieses Feature wird nicht unterstützt: {0}
......
......@@ -159,6 +159,7 @@
90138=Nombre de base de datos Invalido: {0}
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).
90141=#Serializer cannot be changed because there is a data table: {0}
HY000=Error General : {0}
HY004=Tipo de dato desconocido : {0}
HYC00=Caracteristica no soportada: {0}
......
......@@ -159,6 +159,7 @@
90138=不正なデータベース名: {0}
90139=public staticであるJavaメソッドが見つかりません: {0}
90140=リザルトセットは読み込み専用です。conn.createStatement(.., ResultSet.CONCUR_UPDATABLE) を使う必要があるかもしれません
90141=#Serializer cannot be changed because there is a data table: {0}
HY000=一般エラー: {0}
HY004=不明なデータ型: {0}
HYC00=機能はサポートされていません: {0}
......
......@@ -159,6 +159,7 @@
90138=#Invalid database name: {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).
90141=#Serializer cannot be changed because there is a data table: {0}
HY000=Blad ogolny: {0}
HY004=Nieznany typ danyche: {0}
HYC00=Cecha nie jest wspierana: {0}
......
......@@ -159,6 +159,7 @@
90138=#Invalid database name: {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).
90141=#Serializer cannot be changed because there is a data table: {0}
HY000=Erro geral: {0}
HY004=Tipo de dados desconhecido: {0}
HYC00=Recurso não suportado: {0}
......
......@@ -159,6 +159,7 @@
90138=Недопустимое имя базы данных: {0}
90139=public static Java метод не найден: {0}
90140=Набор записей не является обновляемым. Возможно необходимо использовать conn.createStatement(.., ResultSet.CONCUR_UPDATABLE).
90141=#Serializer cannot be changed because there is a data table: {0}
HY000=Внутренняя ошибка: {0}
HY004=Неизвестный тип данных: {0}
HYC00=Данная функция не поддерживается: {0}
......
......@@ -159,6 +159,7 @@
90138=Nesprávne meno databázy: {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).
90141=#Serializer cannot be changed because there is a data table: {0}
HY000=Všeobecná chyba: {0}
HY004=Neznámy dátový typ: {0}
HYC00=Vlastnosť nie je podporovaná: {0}
......
......@@ -159,6 +159,7 @@
90138=无效数据库名称: {0}
90139=找不到公用Java静态方法: {0}
90140=结果集是只读的. 你可以使用 conn.createStatement(.., ResultSet.CONCUR_UPDATABLE).
90141=#Serializer cannot be changed because there is a data table: {0}
HY000=常规错误: {0}
HY004=位置数据类型: {0}
HYC00=不支持的特性: {0}
......
......@@ -172,7 +172,7 @@ ON tableName ( indexColumn [,...] )
","
Creates a new index."
"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,
[ originalSchemaString, ] originalTableString ) [ EMIT UPDATES | READONLY ]
","
......
......@@ -628,7 +628,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
if (o == null || o instanceof byte[]) {
return (byte[]) o;
}
return Utils.serialize(o);
return Utils.serialize(o, null);
}
/**
......
......@@ -328,21 +328,8 @@ public class Utils {
}
/**
* Serialize the object to a byte array.
*
* @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.
* 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
* @param dataHandler provides the object serializer (may be null)
......@@ -350,12 +337,12 @@ public class Utils {
*/
public static byte[] serialize(Object obj, DataHandler dataHandler) {
try {
JavaObjectSerializer dbJavaObjectSerializer = null;
JavaObjectSerializer handlerSerializer = null;
if (dataHandler != null) {
dbJavaObjectSerializer = dataHandler.getJavaObjectSerializer();
handlerSerializer = dataHandler.getJavaObjectSerializer();
}
if (dbJavaObjectSerializer != null) {
return dbJavaObjectSerializer.serialize(obj);
if (handlerSerializer != null) {
return handlerSerializer.serialize(obj);
}
if (serializer != null) {
return serializer.serialize(obj);
......
......@@ -350,8 +350,6 @@ java org.h2.test.TestAll timer
private Server server;
public String javaObjectSerializer;
/**
* Run all tests.
*
......
......@@ -320,9 +320,6 @@ public abstract class TestBase {
if (config.nestedJoins) {
url = addOption(url, "NESTED_JOINS", "TRUE");
}
if (config.javaObjectSerializer!=null) {
url = addOption(url, "JAVA_OBJECT_SERIALIZER", config.javaObjectSerializer);
}
return "jdbc:h2:" + url;
}
......
......@@ -507,15 +507,16 @@ public class TestIndex extends TestBase {
private void testHashIndexOnMemoryTable() throws SQLException {
reconnect();
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)");
assertEquals(10, getValue("select count(*) from hash_index_test where data = 1"));
stat.execute("drop index idx2");
stat.execute("create unique hash index idx2 on hash_index_test(id)");
assertEquals(1, getValue("select count(*) from hash_index_test where id = 1"));
}
private int getValue(String sql) throws SQLException {
ResultSet rs = stat.executeQuery(sql);
rs.next();
......
......@@ -74,7 +74,7 @@ public class TestOptimizations extends TestBase {
testConvertOrToIn();
deleteDb("optimizations");
}
private void testGroupSubquery() throws Exception {
Connection conn = getConnection("optimizations");
Statement stat = conn.createStatement();
......@@ -84,7 +84,7 @@ public class TestOptimizations extends TestBase {
stat.execute("insert into t2 values(2), (3)");
stat.execute("create index t1id_index on t1(id)");
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");
rs.next();
assertEquals(2, rs.getInt(1));
......
......@@ -19,7 +19,7 @@ public class TestQueryCache extends TestBase {
/**
* Run just this test.
*
*
* @param a ignored
*/
public static void main(String... a) throws Exception {
......
......@@ -45,8 +45,8 @@ public class TestJavaObjectSerializer extends TestBase {
testDbLevelJavaObjectSerializer();
deleteDb("javaSerializer");
}
public void testStaticGlobalSerializer() throws Exception {
private void testStaticGlobalSerializer() throws Exception {
Utils.serializer = new JavaObjectSerializer() {
@Override
public byte[] serialize(Object obj) throws Exception {
......@@ -66,7 +66,7 @@ public class TestJavaObjectSerializer extends TestBase {
try {
deleteDb("javaSerializer");
Connection conn = getConnection("javaSerializer");
Statement stat = conn.createStatement();
stat.execute("create table t(id identity, val other)");
......@@ -91,11 +91,12 @@ public class TestJavaObjectSerializer extends TestBase {
}
/**
* Tests per-db {@link JavaObjectSerializer} when set through the related
* SET command.
*/
* Tests per-database serializer when set through the related SET command.
*/
public void testDbLevelJavaObjectSerializer() throws Exception {
DbLevelJavaObjectSerializer.testBaseRef = this;
try {
deleteDb("javaSerializer");
Connection conn = getConnection("javaSerializer");
......@@ -125,9 +126,15 @@ public class TestJavaObjectSerializer extends TestBase {
}
}
/**
* The serializer to use for this test.
*/
public static class DbLevelJavaObjectSerializer implements JavaObjectSerializer {
private static TestBase testBaseRef;
/**
* The test.
*/
static TestBase testBaseRef;
@Override
public byte[] serialize(Object obj) throws Exception {
......
/*
* Copyright 2004-2013 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.test.jdbc;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Types;
import org.h2.api.JavaObjectSerializer;
import org.h2.test.TestBase;
/**
* Tests per-db {@link JavaObjectSerializer} when set through the JDBC URL.
*
* @author Davide Cavestro
*/
public class TestUrlJavaObjectSerializer extends TestBase {
/**
* Run just this test.
*
* @param a ignored
*/
public static void main(String... a) throws Exception {
TestBase test = createCaller().init();
test.config.traceTest = true;
test.config.memory = true;
test.config.networked = true;
test.config.javaObjectSerializer = FakeJavaObjectSerializer.class.getName();
test.config.beforeTest();
test.test();
test.config.afterTest();
}
@Override
public void test() throws Exception {
FakeJavaObjectSerializer.testBaseRef = this;
try {
deleteDb("javaSerializer");
String fqn = FakeJavaObjectSerializer.class.getName();
Connection conn = getConnection("javaSerializer;JAVA_OBJECT_SERIALIZER='"+fqn+"'");
Statement stat = conn.createStatement();
stat.execute("create table t1(id identity, val other)");
PreparedStatement ins = conn.prepareStatement("insert into t1(val) values(?)");
ins.setObject(1, 100500, Types.JAVA_OBJECT);
assertEquals(1, ins.executeUpdate());
Statement s = conn.createStatement();
ResultSet rs = s.executeQuery("select val from t1");
assertTrue(rs.next());
assertEquals(100500, ((Integer) rs.getObject(1)).intValue());
assertEquals(new byte[] { 1, 2, 3 }, rs.getBytes(1));
conn.close();
deleteDb("javaSerializer");
} finally {
FakeJavaObjectSerializer.testBaseRef = null;
}
}
public static class FakeJavaObjectSerializer implements JavaObjectSerializer {
private static TestBase testBaseRef;
@Override
public byte[] serialize(Object obj) throws Exception {
testBaseRef.assertEquals(100500, ((Integer) obj).intValue());
return new byte[] { 1, 2, 3 };
}
@Override
public Object deserialize(byte[] bytes) throws Exception {
testBaseRef.assertEquals(new byte[] { 1, 2, 3 }, bytes);
return 100500;
}
}
}
/*
* Copyright 2004-2013 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.test.jdbc;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Types;
import org.h2.api.JavaObjectSerializer;
import org.h2.test.TestBase;
/**
* Tests per-db {@link JavaObjectSerializer} when set through the JDBC URL.
*
* @author Davide Cavestro
*/
public class TestUrlJavaObjectSerializer extends TestBase {
/**
* Run just this test.
*
* @param a ignored
*/
public static void main(String... a) throws Exception {
TestBase test = createCaller().init();
test.config.traceTest = true;
test.config.memory = true;
test.config.networked = true;
test.config.beforeTest();
test.test();
test.config.afterTest();
}
@Override
public void test() throws Exception {
FakeJavaObjectSerializer.testBaseRef = this;
try {
deleteDb("javaSerializer");
String fqn = FakeJavaObjectSerializer.class.getName();
Connection conn = getConnection("javaSerializer;JAVA_OBJECT_SERIALIZER='"+fqn+"'");
Statement stat = conn.createStatement();
stat.execute("create table t1(id identity, val other)");
PreparedStatement ins = conn.prepareStatement("insert into t1(val) values(?)");
ins.setObject(1, 100500, Types.JAVA_OBJECT);
assertEquals(1, ins.executeUpdate());
Statement s = conn.createStatement();
ResultSet rs = s.executeQuery("select val from t1");
assertTrue(rs.next());
assertEquals(100500, ((Integer) rs.getObject(1)).intValue());
assertEquals(new byte[] { 1, 2, 3 }, rs.getBytes(1));
conn.close();
deleteDb("javaSerializer");
} finally {
FakeJavaObjectSerializer.testBaseRef = null;
}
}
/**
* The serializer to use for this test.
*/
public static class FakeJavaObjectSerializer implements JavaObjectSerializer {
/**
* The test.
*/
static TestBase testBaseRef;
@Override
public byte[] serialize(Object obj) throws Exception {
testBaseRef.assertEquals(100500, ((Integer) obj).intValue());
return new byte[] { 1, 2, 3 };
}
@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
nico devel nicolas linestring atelier fortin cnrs tweet geospatialnews bundles
srid roads
overlaps anyhow poly
overlaps anyhow poly manifested cardinal invalidated
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论