提交 f7bac66f authored 作者: Thomas Mueller's avatar Thomas Mueller

Use the result interface instead of the class (prepare for server side cursors).

上级 ef9a67cb
......@@ -7,7 +7,6 @@
package org.h2.command;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.engine.Constants;
import org.h2.engine.Database;
......@@ -16,7 +15,6 @@ import org.h2.expression.ParameterInterface;
import org.h2.message.Message;
import org.h2.message.Trace;
import org.h2.message.TraceObject;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.util.MemoryUtils;
import org.h2.util.ObjectArray;
......@@ -88,7 +86,7 @@ public abstract class Command implements CommandInterface {
*
* @return an empty result set
*/
public abstract LocalResult queryMeta() throws SQLException;
public abstract ResultInterface queryMeta() throws SQLException;
/**
* Execute an updating statement, if this is possible.
......@@ -107,30 +105,23 @@ public abstract class Command implements CommandInterface {
* @return the local result set
* @throws SQLException if the command is not a query
*/
public LocalResult query(int maxrows) throws SQLException {
public ResultInterface query(int maxrows) throws SQLException {
throw Message.getSQLException(ErrorCode.METHOD_ONLY_ALLOWED_FOR_QUERY);
}
public final LocalResult getMetaDataLocal() throws SQLException {
return queryMeta();
}
public final ResultInterface getMetaData() throws SQLException {
return queryMeta();
}
public ResultInterface executeQuery(int maxrows, boolean scrollable) throws SQLException {
return executeQueryLocal(maxrows);
}
/**
* Execute a query and return a local result set.
* Execute a query and return the result.
* This method prepares everything and calls {@link #query(int)} finally.
*
* @param maxrows the maximum number of rows to return
* @return the local result set
* @param scrollable if the result set must be scrollable (ignored)
* @return the result set
*/
public LocalResult executeQueryLocal(int maxrows) throws SQLException {
public ResultInterface executeQuery(int maxrows, boolean scrollable) throws SQLException {
startTime = System.currentTimeMillis();
Database database = session.getDatabase();
Object sync = database.isMultiThreaded() ? (Object) session : (Object) database;
......@@ -190,7 +181,6 @@ public abstract class Command implements CommandInterface {
trace.info("slow query: " + time);
}
}
session.getDatabase().afterWriting();
}
public int executeUpdate() throws SQLException {
......@@ -199,6 +189,8 @@ public abstract class Command implements CommandInterface {
MemoryUtils.allocateReserveMemory();
Object sync = database.isMultiThreaded() ? (Object) session : (Object) database;
session.waitIfExclusiveModeEnabled();
boolean callStop = true;
session.getDatabase().beforeWriting();
synchronized (sync) {
int rollback = session.getLogId();
session.setCurrentCommand(this, startTime);
......@@ -238,26 +230,26 @@ public abstract class Command implements CommandInterface {
if (e.getErrorCode() == ErrorCode.DEADLOCK_1) {
session.rollback();
} else if (e.getErrorCode() == ErrorCode.OUT_OF_MEMORY) {
// try to rollback, saving memory
try {
session.rollbackTo(rollback, true);
} catch (SQLException e2) {
if (e2.getErrorCode() == ErrorCode.OUT_OF_MEMORY) {
// if rollback didn't work, there is a serious problem:
// there is a serious problem:
// the transaction may be applied partially
// in this case we need to panic:
// close the database
callStop = false;
session.getDatabase().shutdownImmediately();
}
throw e2;
}
throw e;
} else {
session.rollbackTo(rollback, false);
}
throw e;
} finally {
try {
if (callStop) {
stop();
}
} finally {
session.getDatabase().afterWriting();
}
}
}
}
......
......@@ -7,10 +7,9 @@
package org.h2.command;
import java.sql.SQLException;
import org.h2.expression.Parameter;
import org.h2.expression.ParameterInterface;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.util.ObjectArray;
import org.h2.value.Value;
......@@ -74,12 +73,12 @@ public class CommandContainer extends Command {
return updateCount;
}
public LocalResult query(int maxrows) throws SQLException {
public ResultInterface query(int maxrows) throws SQLException {
recompileIfRequired();
// TODO query time: should keep lock time separate from running time
start();
prepared.checkParameters();
LocalResult result = prepared.query(maxrows);
ResultInterface result = prepared.query(maxrows);
prepared.trace(startTime, result.getRowCount());
return result;
}
......@@ -88,7 +87,7 @@ public class CommandContainer extends Command {
return prepared.isReadOnly();
}
public LocalResult queryMeta() throws SQLException {
public ResultInterface queryMeta() throws SQLException {
return prepared.queryMeta();
}
......
......@@ -7,9 +7,8 @@
package org.h2.command;
import java.sql.SQLException;
import org.h2.expression.ParameterInterface;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.util.ObjectArray;
/**
......@@ -45,8 +44,8 @@ public class CommandList extends Command {
return updateCount;
}
public LocalResult query(int maxrows) throws SQLException {
LocalResult result = command.query(maxrows);
public ResultInterface query(int maxrows) throws SQLException {
ResultInterface result = command.query(maxrows);
executeRemaining();
return result;
}
......@@ -63,7 +62,7 @@ public class CommandList extends Command {
return false;
}
public LocalResult queryMeta() throws SQLException {
public ResultInterface queryMeta() throws SQLException {
return command.queryMeta();
}
......
......@@ -7,7 +7,6 @@
package org.h2.command;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.engine.Database;
......@@ -17,7 +16,7 @@ import org.h2.expression.Parameter;
import org.h2.index.Index;
import org.h2.jdbc.JdbcSQLException;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.util.ObjectArray;
import org.h2.util.StatementBuilder;
import org.h2.value.Value;
......@@ -81,9 +80,9 @@ public abstract class Prepared {
/**
* Get an empty result set containing the meta data.
*
* @return an empty result set
* @return the result set
*/
public abstract LocalResult queryMeta() throws SQLException;
public abstract ResultInterface queryMeta() throws SQLException;
/**
* Check if this command is read only.
......@@ -202,7 +201,7 @@ public abstract class Prepared {
* @return the result set
* @throws SQLException if it is not a query
*/
public LocalResult query(int maxrows) throws SQLException {
public ResultInterface query(int maxrows) throws SQLException {
throw Message.getSQLException(ErrorCode.METHOD_ONLY_ALLOWED_FOR_QUERY);
}
......
......@@ -7,7 +7,6 @@
package org.h2.command.ddl;
import java.sql.SQLException;
import org.h2.command.Parser;
import org.h2.command.Prepared;
import org.h2.constant.ErrorCode;
......@@ -21,7 +20,7 @@ import org.h2.expression.Expression;
import org.h2.index.Index;
import org.h2.index.IndexType;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.schema.Schema;
import org.h2.schema.SchemaObject;
import org.h2.schema.Sequence;
......@@ -412,7 +411,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
private void checkNoNullValues() throws SQLException {
String sql = "SELECT COUNT(*) FROM " + table.getSQL() + " WHERE " + oldColumn.getSQL() + " IS NULL";
Prepared command = session.prepare(sql);
LocalResult result = command.query(0);
ResultInterface result = command.query(0);
result.next();
if (result.currentRow()[0].getInt() > 0) {
throw Message.getSQLException(ErrorCode.COLUMN_CONTAINS_NULL_VALUES_1, oldColumn.getSQL());
......
......@@ -11,7 +11,7 @@ import org.h2.command.Prepared;
import org.h2.engine.Constants;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.table.Column;
import org.h2.table.Table;
import org.h2.table.TableData;
......@@ -50,7 +50,7 @@ public class Analyze extends DefineCommand {
}
String sql = buff.toString();
Prepared command = session.prepare(sql);
LocalResult result = command.query(0);
ResultInterface result = command.query(0);
result.next();
for (int j = 0; j < columns.length; j++) {
int selectivity = result.currentRow()[j].getInt();
......
......@@ -8,7 +8,7 @@ package org.h2.command.ddl;
import org.h2.command.Prepared;
import org.h2.engine.Session;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
/**
* This class represents a non-transaction statement, for example a CREATE or
......@@ -33,7 +33,7 @@ public abstract class DefineCommand extends Prepared {
return false;
}
public LocalResult queryMeta() {
public ResultInterface queryMeta() {
return null;
}
......
......@@ -23,7 +23,7 @@ import org.h2.expression.Expression;
import org.h2.log.LogFile;
import org.h2.log.LogSystem;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.store.DiskFile;
import org.h2.store.FileLister;
import org.h2.store.PageStore;
......@@ -179,7 +179,7 @@ public class BackupCommand extends Prepared {
return false;
}
public LocalResult queryMeta() {
public ResultInterface queryMeta() {
return null;
}
......
......@@ -8,13 +8,13 @@ package org.h2.command.dml;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.h2.command.Prepared;
import org.h2.engine.Session;
import org.h2.expression.Expression;
import org.h2.expression.ExpressionColumn;
import org.h2.expression.ExpressionVisitor;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.table.Column;
import org.h2.util.ObjectArray;
import org.h2.value.Value;
......@@ -33,7 +33,7 @@ public class Call extends Prepared {
super(session);
}
public LocalResult queryMeta() throws SQLException {
public ResultInterface queryMeta() throws SQLException {
LocalResult result = new LocalResult(session, expressions, 1);
result.done();
return result;
......@@ -56,7 +56,7 @@ public class Call extends Prepared {
}
}
public LocalResult query(int maxrows) throws SQLException {
public ResultInterface query(int maxrows) throws SQLException {
setCurrentRowNumber(1);
Value v = value.getValue(session);
if (v.getType() == Value.RESULT_SET) {
......
......@@ -7,13 +7,12 @@
package org.h2.command.dml;
import java.sql.SQLException;
import org.h2.command.Prepared;
import org.h2.engine.Right;
import org.h2.engine.Session;
import org.h2.expression.Expression;
import org.h2.log.UndoLogRecord;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.result.Row;
import org.h2.result.RowList;
import org.h2.table.PlanItem;
......@@ -108,7 +107,7 @@ public class Delete extends Prepared {
return true;
}
public LocalResult queryMeta() {
public ResultInterface queryMeta() {
return null;
}
......
......@@ -7,13 +7,12 @@
package org.h2.command.dml;
import java.sql.SQLException;
import org.h2.command.Prepared;
import org.h2.engine.Procedure;
import org.h2.engine.Session;
import org.h2.expression.Expression;
import org.h2.expression.Parameter;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.util.ObjectArray;
/**
......@@ -64,7 +63,7 @@ public class ExecuteProcedure extends Prepared {
return prepared.update();
}
public final LocalResult query(int limit) throws SQLException {
public ResultInterface query(int limit) throws SQLException {
setParameters();
Prepared prepared = procedure.getPrepared();
return prepared.query(limit);
......@@ -74,7 +73,7 @@ public class ExecuteProcedure extends Prepared {
return true;
}
public LocalResult queryMeta() throws SQLException {
public ResultInterface queryMeta() throws SQLException {
Prepared prepared = procedure.getPrepared();
return prepared.queryMeta();
}
......
......@@ -7,12 +7,12 @@
package org.h2.command.dml;
import java.sql.SQLException;
import org.h2.command.Prepared;
import org.h2.engine.Session;
import org.h2.expression.Expression;
import org.h2.expression.ExpressionColumn;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.table.Column;
import org.h2.value.Value;
import org.h2.value.ValueString;
......@@ -38,11 +38,11 @@ public class ExplainPlan extends Prepared {
command.prepare();
}
public LocalResult queryMeta() throws SQLException {
public ResultInterface queryMeta() throws SQLException {
return query(-1);
}
public LocalResult query(int maxrows) throws SQLException {
public ResultInterface query(int maxrows) throws SQLException {
Column column = new Column("PLAN", Value.STRING);
ExpressionColumn expr = new ExpressionColumn(session.getDatabase(), column);
Expression[] expressions = new Expression[] {
......
......@@ -7,7 +7,6 @@
package org.h2.command.dml;
import java.sql.SQLException;
import org.h2.command.Command;
import org.h2.command.Prepared;
import org.h2.constant.ErrorCode;
......@@ -19,7 +18,7 @@ import org.h2.expression.Parameter;
import org.h2.index.PageIndex;
import org.h2.log.UndoLogRecord;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.result.Row;
import org.h2.table.Column;
import org.h2.table.Table;
......@@ -123,7 +122,7 @@ public class Insert extends Prepared {
count++;
}
} else {
LocalResult rows = query.query(0);
ResultInterface rows = query.query(0);
count = 0;
table.fireBefore(session);
table.lock(session, true, false);
......@@ -225,7 +224,7 @@ public class Insert extends Prepared {
return true;
}
public LocalResult queryMeta() {
public ResultInterface queryMeta() {
return null;
}
......
......@@ -7,7 +7,6 @@
package org.h2.command.dml;
import java.sql.SQLException;
import org.h2.command.Command;
import org.h2.command.Prepared;
import org.h2.constant.ErrorCode;
......@@ -18,7 +17,7 @@ import org.h2.expression.Parameter;
import org.h2.index.Index;
import org.h2.log.UndoLogRecord;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.result.Row;
import org.h2.table.Column;
import org.h2.table.Table;
......@@ -127,7 +126,7 @@ public class Merge extends Prepared {
count++;
}
} else {
LocalResult rows = query.query(0);
ResultInterface rows = query.query(0);
count = 0;
table.fireBefore(session);
table.lock(session, true, false);
......@@ -269,7 +268,7 @@ public class Merge extends Prepared {
return true;
}
public LocalResult queryMeta() {
public ResultInterface queryMeta() {
return null;
}
......
......@@ -8,7 +8,7 @@ package org.h2.command.dml;
import org.h2.command.Prepared;
import org.h2.engine.Session;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
/**
* Represents an empty statement or a statement that has no effect.
......@@ -39,7 +39,7 @@ public class NoOperation extends Prepared {
return true;
}
public LocalResult queryMeta() {
public ResultInterface queryMeta() {
return null;
}
......
......@@ -21,6 +21,7 @@ import org.h2.expression.Parameter;
import org.h2.expression.ValueExpression;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.result.SortOrder;
import org.h2.table.ColumnResolver;
import org.h2.table.Table;
......@@ -214,7 +215,7 @@ public abstract class Query extends Prepared {
return params;
}
public LocalResult query(int limit) throws SQLException {
public ResultInterface query(int limit) throws SQLException {
if (!session.getDatabase().getOptimizeReuseResults()) {
return queryWithoutCache(limit);
}
......
......@@ -14,7 +14,7 @@ import org.h2.command.Prepared;
import org.h2.constant.SysProperties;
import org.h2.engine.Session;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.util.ScriptReader;
/**
......@@ -73,7 +73,7 @@ public class RunScriptCommand extends ScriptBase {
this.charset = charset;
}
public LocalResult queryMeta() {
public ResultInterface queryMeta() {
return null;
}
......
......@@ -36,6 +36,7 @@ import org.h2.index.Cursor;
import org.h2.index.Index;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.result.Row;
import org.h2.schema.Constant;
import org.h2.schema.Schema;
......@@ -103,7 +104,7 @@ public class ScriptCommand extends ScriptBase {
this.drop = drop;
}
public LocalResult queryMeta() throws SQLException {
public ResultInterface queryMeta() throws SQLException {
LocalResult r = createResult();
r.done();
return r;
......@@ -115,7 +116,7 @@ public class ScriptCommand extends ScriptBase {
return new LocalResult(session, expressions, 1);
}
public LocalResult query(int maxrows) throws SQLException {
public ResultInterface query(int maxrows) throws SQLException {
session.getUser().checkAdmin();
reset();
try {
......@@ -318,7 +319,8 @@ public class ScriptCommand extends ScriptBase {
private int writeLobStream(ValueLob v) throws IOException, SQLException {
if (!tempLobTableCreated) {
add("CREATE TABLE IF NOT EXISTS SYSTEM_LOB_STREAM(ID INT, PART INT, CDATA VARCHAR, BDATA BINARY, PRIMARY KEY(ID, PART))", true);
add("CREATE TABLE IF NOT EXISTS SYSTEM_LOB_STREAM(ID INT NOT NULL, PART INT NOT NULL, CDATA VARCHAR, BDATA BINARY)", true);
add("CREATE PRIMARY KEY SYSTEM_LOB_STREAM_PRIMARY_KEY ON SYSTEM_LOB_STREAM(ID, PART)", true);
add("CREATE ALIAS IF NOT EXISTS SYSTEM_COMBINE_CLOB FOR \"" + this.getClass().getName() + ".combineClob\"", true);
add("CREATE ALIAS IF NOT EXISTS SYSTEM_COMBINE_BLOB FOR \"" + this.getClass().getName() + ".combineBlob\"", true);
tempLobTableCreated = true;
......
......@@ -28,6 +28,7 @@ import org.h2.index.Index;
import org.h2.index.IndexType;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.result.SearchRow;
import org.h2.result.SortOrder;
import org.h2.table.Column;
......@@ -515,7 +516,7 @@ public class Select extends Query {
result.addRow(row);
}
public LocalResult queryMeta() throws SQLException {
public ResultInterface queryMeta() throws SQLException {
LocalResult result = new LocalResult(session, expressions, visibleColumnCount);
result.done();
return result;
......
......@@ -19,6 +19,7 @@ import org.h2.expression.Parameter;
import org.h2.expression.ValueExpression;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.result.SortOrder;
import org.h2.table.Column;
import org.h2.table.ColumnResolver;
......@@ -92,7 +93,7 @@ public class SelectUnion extends Query {
return values;
}
public LocalResult queryMeta() throws SQLException {
public ResultInterface queryMeta() throws SQLException {
ObjectArray<Expression> leftExpressions = left.getExpressions();
int columnCount = left.getColumnCount();
LocalResult result = new LocalResult(session, leftExpressions, columnCount);
......@@ -131,8 +132,8 @@ public class SelectUnion extends Query {
default:
Message.throwInternalError("type=" + unionType);
}
LocalResult l = left.query(0);
LocalResult r = right.query(0);
ResultInterface l = left.query(0);
ResultInterface r = right.query(0);
l.reset();
r.reset();
switch (unionType) {
......@@ -330,7 +331,7 @@ public class SelectUnion extends Query {
return buff.toString();
}
public LocalResult query(int limit) throws SQLException {
public ResultInterface query(int limit) throws SQLException {
// union doesn't always know the parameter list of the left and right queries
return queryWithoutCache(limit);
}
......
......@@ -8,7 +8,6 @@ package org.h2.command.dml;
import java.sql.SQLException;
import java.text.Collator;
import org.h2.command.Prepared;
import org.h2.compress.Compressor;
import org.h2.constant.ErrorCode;
......@@ -19,7 +18,7 @@ import org.h2.engine.Setting;
import org.h2.expression.Expression;
import org.h2.expression.ValueExpression;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.schema.Schema;
import org.h2.table.Table;
import org.h2.tools.CompressTool;
......@@ -370,7 +369,7 @@ public class Set extends Prepared {
return false;
}
public LocalResult queryMeta() {
public ResultInterface queryMeta() {
return null;
}
......
......@@ -7,13 +7,12 @@
package org.h2.command.dml;
import java.sql.SQLException;
import org.h2.command.Prepared;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.log.LogSystem;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
/**
* Represents a transactional statement.
......@@ -207,7 +206,7 @@ public class TransactionCommand extends Prepared {
this.transactionName = string;
}
public LocalResult queryMeta() {
public ResultInterface queryMeta() {
return null;
}
......
......@@ -7,7 +7,6 @@
package org.h2.command.dml;
import java.sql.SQLException;
import org.h2.command.Prepared;
import org.h2.constant.ErrorCode;
import org.h2.engine.Right;
......@@ -16,7 +15,7 @@ import org.h2.expression.Expression;
import org.h2.expression.Parameter;
import org.h2.expression.ValueExpression;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.result.Row;
import org.h2.result.RowList;
import org.h2.table.Column;
......@@ -177,7 +176,7 @@ public class Update extends Prepared {
return true;
}
public LocalResult queryMeta() {
public ResultInterface queryMeta() {
return null;
}
......
......@@ -7,13 +7,12 @@
package org.h2.constraint;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.engine.Session;
import org.h2.expression.Expression;
import org.h2.index.Index;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.result.Row;
import org.h2.schema.Schema;
import org.h2.table.Column;
......@@ -117,7 +116,7 @@ public class ConstraintCheck extends Constraint {
return;
}
String sql = "SELECT 1 FROM " + filter.getTable().getSQL() + " WHERE NOT(" + expr.getSQL() + ")";
LocalResult r = session.prepare(sql).query(1);
ResultInterface r = session.prepare(sql).query(1);
if (r.next()) {
throw Message.getSQLException(ErrorCode.CHECK_CONSTRAINT_VIOLATED_1, getName());
}
......
......@@ -7,7 +7,6 @@
package org.h2.constraint;
import java.sql.SQLException;
import org.h2.command.Parser;
import org.h2.command.Prepared;
import org.h2.constant.ErrorCode;
......@@ -17,7 +16,7 @@ import org.h2.expression.Parameter;
import org.h2.index.Cursor;
import org.h2.index.Index;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.result.Row;
import org.h2.result.SearchRow;
import org.h2.schema.Schema;
......@@ -627,7 +626,7 @@ public class ConstraintReferential extends Constraint {
}
buff.append(')');
String sql = buff.toString();
LocalResult r = session.prepare(sql).query(1);
ResultInterface r = session.prepare(sql).query(1);
if (r.next()) {
throw Message.getSQLException(ErrorCode.REFERENTIAL_INTEGRITY_VIOLATED_PARENT_MISSING_1,
getShortDescription());
......
......@@ -7,10 +7,9 @@
package org.h2.expression;
import java.sql.SQLException;
import org.h2.command.dml.Query;
import org.h2.engine.Session;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter;
import org.h2.value.Value;
......@@ -29,7 +28,7 @@ public class ConditionExists extends Condition {
public Value getValue(Session session) throws SQLException {
query.setSession(session);
LocalResult result = query.query(1);
ResultInterface result = query.query(1);
session.addTemporaryResult(result);
boolean r = result.getRowCount() > 0;
return ValueBoolean.get(r);
......
......@@ -7,7 +7,6 @@
package org.h2.expression;
import java.sql.SQLException;
import org.h2.command.dml.Query;
import org.h2.command.dml.Select;
import org.h2.constant.ErrorCode;
......@@ -17,7 +16,7 @@ import org.h2.engine.Session;
import org.h2.index.Index;
import org.h2.index.IndexCondition;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter;
import org.h2.table.TableView;
......@@ -46,7 +45,7 @@ public class ConditionInSelect extends Condition {
public Value getValue(Session session) throws SQLException {
query.setSession(session);
LocalResult rows = query.query(0);
ResultInterface rows = query.query(0);
session.addTemporaryResult(rows);
boolean hasNull = false;
boolean result = all;
......
......@@ -7,12 +7,11 @@
package org.h2.expression;
import java.sql.SQLException;
import org.h2.command.dml.Query;
import org.h2.constant.ErrorCode;
import org.h2.engine.Session;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter;
import org.h2.value.Value;
......@@ -33,7 +32,7 @@ public class Subquery extends Expression {
public Value getValue(Session session) throws SQLException {
query.setSession(session);
LocalResult result = query.query(2);
ResultInterface result = query.query(2);
try {
int rowcount = result.getRowCount();
if (rowcount > 1) {
......
......@@ -13,6 +13,7 @@ import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.table.Column;
import org.h2.tools.SimpleResultSet;
import org.h2.util.MathUtils;
......@@ -124,7 +125,7 @@ public class TableFunction extends Function {
return vr;
}
private SimpleResultSet getSimpleResultSet(LocalResult rs, int maxrows) throws SQLException {
private SimpleResultSet getSimpleResultSet(ResultInterface rs, int maxrows) throws SQLException {
int columnCount = rs.getVisibleColumnCount();
SimpleResultSet simple = new SimpleResultSet();
for (int i = 0; i < columnCount; i++) {
......
......@@ -7,9 +7,8 @@
package org.h2.index;
import java.sql.SQLException;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.result.Row;
import org.h2.result.SearchRow;
import org.h2.value.Value;
......@@ -19,11 +18,11 @@ import org.h2.value.Value;
*/
public class FunctionCursor implements Cursor {
private LocalResult result;
private ResultInterface result;
private Value[] values;
private Row row;
FunctionCursor(LocalResult result) {
FunctionCursor(ResultInterface result) {
this.result = result;
}
......
......@@ -7,11 +7,10 @@
package org.h2.index;
import java.sql.SQLException;
import org.h2.constant.SysProperties;
import org.h2.engine.Session;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.result.Row;
import org.h2.result.SearchRow;
import org.h2.table.FunctionTable;
......@@ -24,7 +23,7 @@ import org.h2.table.IndexColumn;
public class FunctionIndex extends BaseIndex {
private FunctionTable functionTable;
private LocalResult result;
private ResultInterface result;
public FunctionIndex(FunctionTable functionTable, IndexColumn[] columns) {
initBaseIndex(functionTable, 0, null, columns, IndexType.createNonUnique(true));
......
......@@ -17,7 +17,7 @@ import org.h2.expression.Expression;
import org.h2.expression.ExpressionColumn;
import org.h2.expression.ExpressionVisitor;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.table.Column;
import org.h2.util.ObjectArray;
import org.h2.util.StatementBuilder;
......@@ -155,7 +155,7 @@ public class IndexCondition {
* @param session the session
* @return the result
*/
public LocalResult getCurrentResult(Session session) throws SQLException {
public ResultInterface getCurrentResult(Session session) throws SQLException {
return expressionQuery.query(0);
}
......
......@@ -11,7 +11,7 @@ import java.util.HashSet;
import org.h2.engine.Session;
import org.h2.expression.Comparison;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.result.Row;
import org.h2.result.SearchRow;
import org.h2.result.SortOrder;
......@@ -37,7 +37,7 @@ public class IndexCursor implements Cursor {
private Column inColumn;
private int inListIndex;
private Value[] inList;
private LocalResult inResult;
private ResultInterface inResult;
private HashSet<Value> inResultTested;
public void setIndex(Index index) {
......
......@@ -7,9 +7,8 @@
package org.h2.index;
import java.sql.SQLException;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.result.Row;
import org.h2.result.SearchRow;
import org.h2.table.Table;
......@@ -22,10 +21,10 @@ import org.h2.value.ValueNull;
public class ViewCursor implements Cursor {
private Table table;
private LocalResult result;
private ResultInterface result;
private Row current;
ViewCursor(Table table, LocalResult result) {
ViewCursor(Table table, ResultInterface result) {
this.table = table;
this.result = result;
}
......
......@@ -13,7 +13,7 @@ import org.h2.engine.Session;
import org.h2.expression.Comparison;
import org.h2.expression.Parameter;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.result.Row;
import org.h2.result.SearchRow;
import org.h2.table.Column;
......@@ -189,7 +189,7 @@ public class ViewIndex extends BaseIndex {
}
}
}
LocalResult result = query.query(0);
ResultInterface result = query.query(0);
return new ViewCursor(table, result);
}
......
......@@ -367,11 +367,6 @@ public class LocalResult implements ResultInterface {
}
}
/**
* Check if this result set is buffered using a temporary file.
*
* @return true if it is
*/
public boolean needToClose() {
return disk != null;
}
......
......@@ -59,6 +59,14 @@ public interface ResultInterface {
*/
int getRowCount();
/**
* Check if this result set should be closed, for example because it is
* buffered using a temporary file.
*
* @return true if close should be called.
*/
boolean needToClose();
/**
* Close the result and delete any temporary files
*/
......
......@@ -248,4 +248,8 @@ public class ResultRemote implements ResultInterface {
this.fetchSize = fetchSize;
}
public boolean needToClose() {
return true;
}
}
......@@ -11,7 +11,6 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.Socket;
import java.sql.SQLException;
import org.h2.command.Command;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
......@@ -25,8 +24,8 @@ import org.h2.expression.ParameterInterface;
import org.h2.expression.ParameterRemote;
import org.h2.jdbc.JdbcSQLException;
import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultColumn;
import org.h2.result.ResultInterface;
import org.h2.util.ObjectArray;
import org.h2.util.SmallMap;
import org.h2.util.StringUtils;
......@@ -263,7 +262,7 @@ public class TcpServerThread implements Runnable {
int id = transfer.readInt();
int objectId = transfer.readInt();
Command command = (Command) cache.getObject(id, false);
LocalResult result = command.getMetaDataLocal();
ResultInterface result = command.getMetaData();
cache.addObject(objectId, result);
int columnCount = result.getVisibleColumnCount();
transfer.writeInt(SessionRemote.STATUS_OK).writeInt(columnCount).writeInt(0);
......@@ -281,7 +280,7 @@ public class TcpServerThread implements Runnable {
Command command = (Command) cache.getObject(id, false);
setParameters(command);
int old = session.getModificationId();
LocalResult result = command.executeQueryLocal(maxRows);
ResultInterface result = command.executeQuery(maxRows, false);
cache.addObject(objectId, result);
int columnCount = result.getVisibleColumnCount();
int state = getState(old);
......@@ -326,7 +325,7 @@ public class TcpServerThread implements Runnable {
case SessionRemote.RESULT_FETCH_ROWS: {
int id = transfer.readInt();
int count = transfer.readInt();
LocalResult result = (LocalResult) cache.getObject(id, false);
ResultInterface result = (ResultInterface) cache.getObject(id, false);
transfer.writeInt(SessionRemote.STATUS_OK);
for (int i = 0; i < count; i++) {
sendRow(result);
......@@ -336,13 +335,13 @@ public class TcpServerThread implements Runnable {
}
case SessionRemote.RESULT_RESET: {
int id = transfer.readInt();
LocalResult result = (LocalResult) cache.getObject(id, false);
ResultInterface result = (ResultInterface) cache.getObject(id, false);
result.reset();
break;
}
case SessionRemote.RESULT_CLOSE: {
int id = transfer.readInt();
LocalResult result = (LocalResult) cache.getObject(id, true);
ResultInterface result = (ResultInterface) cache.getObject(id, true);
if (result != null) {
result.close();
cache.freeObject(id);
......@@ -376,7 +375,7 @@ public class TcpServerThread implements Runnable {
return SessionRemote.STATUS_OK_STATE_CHANGED;
}
private void sendRow(LocalResult result) throws IOException, SQLException {
private void sendRow(ResultInterface result) throws IOException, SQLException {
if (result.next()) {
transfer.writeBoolean(true);
Value[] v = result.currentRow();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论