提交 01b617c3 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Pass database instead of session to MVTempResult

上级 cea2572e
......@@ -6,7 +6,6 @@
package org.h2.mvstore.db;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.expression.Expression;
import org.h2.message.DbException;
import org.h2.mvstore.Cursor;
......@@ -65,16 +64,15 @@ class MVPlainTempResult extends MVTempResult {
/**
* Creates a new plain temporary result.
*
* @param session
* database session.
* @param database
* database
* @param expressions
* column expressions
*/
MVPlainTempResult(Session session, Expression[] expressions) {
super(session);
Database db = session.getDatabase();
MVPlainTempResult(Database database, Expression[] expressions) {
super(database);
ValueDataType keyType = new ValueDataType(null, null, null);
valueType = new ValueDataType(db.getCompareMode(), db, new int[expressions.length]);
valueType = new ValueDataType(database.getCompareMode(), database, new int[expressions.length]);
Builder<ValueLong, ValueArray> builder = new MVMap.Builder<ValueLong, ValueArray>().keyType(keyType)
.valueType(valueType);
map = store.openMap("tmp", builder);
......
......@@ -8,7 +8,6 @@ package org.h2.mvstore.db;
import java.util.BitSet;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.expression.Expression;
import org.h2.mvstore.Cursor;
import org.h2.mvstore.MVMap;
......@@ -78,8 +77,8 @@ class MVSortedTempResult extends MVTempResult {
/**
* Creates a new sorted temporary result.
*
* @param session
* database session
* @param database
* database
* @param expressions
* column expressions
* @param distinct
......@@ -88,10 +87,9 @@ class MVSortedTempResult extends MVTempResult {
* sort order, or {@code null} if this result does not
* need any sorting
*/
MVSortedTempResult(Session session, Expression[] expressions, boolean distinct, SortOrder sort) {
super(session);
MVSortedTempResult(Database database, Expression[] expressions, boolean distinct, SortOrder sort) {
super(database);
this.distinct = distinct;
Database db = session.getDatabase();
int length = expressions.length;
int[] sortTypes = new int[length];
int[] indexes;
......@@ -146,7 +144,7 @@ class MVSortedTempResult extends MVTempResult {
indexes = null;
}
this.indexes = indexes;
ValueDataType keyType = new ValueDataType(db.getCompareMode(), db, sortTypes);
ValueDataType keyType = new ValueDataType(database.getCompareMode(), database, sortTypes);
Builder<ValueArray, Long> builder = new MVMap.Builder<ValueArray, Long>().keyType(keyType);
map = store.openMap("tmp", builder);
}
......
......@@ -10,7 +10,7 @@ import java.lang.ref.Reference;
import java.util.ArrayList;
import org.h2.engine.Constants;
import org.h2.engine.Session;
import org.h2.engine.Database;
import org.h2.expression.Expression;
import org.h2.message.DbException;
import org.h2.mvstore.MVStore;
......@@ -60,8 +60,8 @@ public abstract class MVTempResult implements ResultExternal {
/**
* Creates MVStore-based temporary result.
*
* @param session
* session
* @param database
* database
* @param expressions
* expressions
* @param distinct
......@@ -70,9 +70,9 @@ public abstract class MVTempResult implements ResultExternal {
* sort order, or {@code null}
* @return temporary result
*/
public static ResultExternal of(Session session, Expression[] expressions, boolean distinct, SortOrder sort) {
return distinct || sort != null ? new MVSortedTempResult(session, expressions, distinct, sort)
: new MVPlainTempResult(session, expressions);
public static ResultExternal of(Database database, Expression[] expressions, boolean distinct, SortOrder sort) {
return distinct || sort != null ? new MVSortedTempResult(database, expressions, distinct, sort)
: new MVPlainTempResult(database, expressions);
}
/**
......@@ -132,19 +132,19 @@ public abstract class MVTempResult implements ResultExternal {
/**
* Creates a new temporary result.
*
* @param session
* database session
* @param database
* database
*/
MVTempResult(Session session) {
MVTempResult(Database database) {
try {
String fileName = FileUtils.createTempFile("h2tmp", Constants.SUFFIX_TEMP_FILE, false, true);
Builder builder = new MVStore.Builder().fileName(fileName);
byte[] key = session.getDatabase().getFileEncryptionKey();
byte[] key = database.getFileEncryptionKey();
if (key != null) {
builder.encryptionKey(MVTableEngine.decodePassword(key));
}
store = builder.open();
tempFileDeleter = session.getDatabase().getTempFileDeleter();
tempFileDeleter = database.getTempFileDeleter();
closeable = new CloseImpl(store, fileName);
fileRef = tempFileDeleter.addFile(closeable, this);
} catch (IOException e) {
......
......@@ -291,8 +291,9 @@ public class LocalResult implements ResultInterface, ResultTarget {
}
private void createExternalResult() {
external = session.getDatabase().getMvStore() != null
? MVTempResult.of(session, expressions, distinct, sort)
Database database = session.getDatabase();
external = database.getMvStore() != null
? MVTempResult.of(database, expressions, distinct, sort)
: new ResultTempTable(session, expressions, distinct, sort);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论