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

Pass database instead of session to MVTempResult

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