提交 7df1c533 authored 作者: S.Vladykin's avatar S.Vladykin

test and minor fixes

上级 e5b577fa
......@@ -6,7 +6,6 @@
package org.h2.command.dml;
import java.text.Collator;
import org.h2.api.ErrorCode;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared;
......@@ -20,9 +19,11 @@ import org.h2.expression.Expression;
import org.h2.expression.ValueExpression;
import org.h2.message.DbException;
import org.h2.result.ResultInterface;
import org.h2.result.RowFactory;
import org.h2.schema.Schema;
import org.h2.table.Table;
import org.h2.tools.CompressTool;
import org.h2.util.JdbcUtils;
import org.h2.util.StringUtils;
import org.h2.value.CompareMode;
import org.h2.value.ValueInt;
......@@ -483,6 +484,19 @@ public class Set extends Prepared {
addOrUpdateSetting(name, null, getIntValue());
break;
}
case SetTypes.ROW_FACTORY: {
session.getUser().checkAdmin();
String rowFactoryName = expression.getColumnName();
Class<RowFactory> rowFactoryClass = JdbcUtils.loadUserClass(rowFactoryName);
RowFactory rowFactory;
try {
rowFactory = rowFactoryClass.newInstance();
} catch (Exception e) {
throw DbException.convert(e);
}
database.setRowFactory(rowFactory);
break;
}
default:
DbException.throwInternalError("type="+type);
}
......
......@@ -223,6 +223,11 @@ public class SetTypes {
*/
public static final int QUERY_STATISTICS_MAX_ENTRIES = 42;
/**
* The type of a SET ROW_FACTORY statement.
*/
public static final int ROW_FACTORY = 43;
private static final ArrayList<String> TYPES = New.arrayList();
private SetTypes() {
......@@ -274,6 +279,7 @@ public class SetTypes {
list.add(RETENTION_TIME, "RETENTION_TIME");
list.add(QUERY_STATISTICS, "QUERY_STATISTICS");
list.add(QUERY_STATISTICS_MAX_ENTRIES, "QUERY_STATISTICS_MAX_ENTRIES");
list.add(ROW_FACTORY, "ROW_FACTORY");
}
/**
......
......@@ -192,7 +192,7 @@ public class Database implements DataHandler {
private boolean queryStatistics;
private int queryStatisticsMaxEntries = Constants.QUERY_STATISTICS_MAX_ENTRIES;
private QueryStatisticsData queryStatisticsData;
private final RowFactory rowFactory;
private RowFactory rowFactory = RowFactory.DEFAULT;
public Database(ConnectionInfo ci, String cipher) {
String name = ci.getName();
......@@ -251,17 +251,6 @@ public class Database implements DataHandler {
ci.getProperty("JAVA_OBJECT_SERIALIZER", null);
this.multiThreaded =
ci.getProperty("MULTI_THREADED", false);
String rowFactoryClassName = ci.getProperty("ROW_FACTORY");
if (rowFactoryClassName != null) {
Class<RowFactory> rowFactoryClass = JdbcUtils.loadUserClass(rowFactoryClassName);
try {
rowFactory = rowFactoryClass.newInstance();
} catch (Exception e) {
throw DbException.convert(e);
}
} else {
rowFactory = RowFactory.DEFAULT;
}
boolean closeAtVmShutdown =
dbSettings.dbCloseOnExit;
int traceLevelFile =
......@@ -321,6 +310,10 @@ public class Database implements DataHandler {
return rowFactory;
}
public void setRowFactory(RowFactory rowFactory) {
this.rowFactory = rowFactory;
}
public static void setInitialPowerOffCount(int count) {
initialPowerOffCount = count;
}
......
......@@ -42,7 +42,7 @@ public class FunctionCursorResultSet implements Cursor {
return null;
}
if (row == null) {
row = session.createRow(values, 1);
row = session.createRow(values, 1);
}
return row;
}
......
......@@ -7,16 +7,11 @@ import org.h2.value.Value;
*
* @author Sergi Vladykin
*/
public interface RowFactory {
public abstract class RowFactory {
/**
* Default implementation of row factory.
*/
RowFactory DEFAULT = new RowFactory() {
@Override
public Row createRow(Value[] data, int memory) {
return new RowImpl(data, memory);
}
};
public static final RowFactory DEFAULT = new DefaultRowFactory();
/**
* Create new row.
......@@ -25,5 +20,15 @@ public interface RowFactory {
* @param memory memory
* @return created row
*/
Row createRow(Value[] data, int memory);
public abstract Row createRow(Value[] data, int memory);
/**
* Default implementation of row factory.
*/
private static final class DefaultRowFactory extends RowFactory {
@Override
public Row createRow(Value[] data, int memory) {
return new RowImpl(data, memory);
}
}
}
......@@ -53,6 +53,7 @@ import org.h2.test.db.TestQueryCache;
import org.h2.test.db.TestReadOnly;
import org.h2.test.db.TestRecursiveQueries;
import org.h2.test.db.TestRights;
import org.h2.test.db.TestRowFactory;
import org.h2.test.db.TestRunscript;
import org.h2.test.db.TestSQLInjection;
import org.h2.test.db.TestScript;
......@@ -696,6 +697,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
addTest(new TestSpatial());
addTest(new TestSpeed());
addTest(new TestTableEngines());
addTest(new TestRowFactory());
addTest(new TestTempTables());
addTest(new TestTransaction());
addTest(new TestTriggersConstraints());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论