use of org.h2.result.ResultInterface in project h2database by h2database.
the class Query method query.
/**
* Execute the query, writing the result to the target result.
*
* @param limit the maximum number of rows to return
* @param target the target result (null will return the result)
* @return the result set (if the target is not set).
*/
public final ResultInterface query(int limit, ResultTarget target) {
if (isUnion()) {
// right queries
return queryWithoutCacheLazyCheck(limit, target);
}
fireBeforeSelectTriggers();
if (noCache || !session.getDatabase().getOptimizeReuseResults() || session.isLazyQueryExecution()) {
return queryWithoutCacheLazyCheck(limit, target);
}
Value[] params = getParameterValues();
long now = session.getDatabase().getModificationDataId();
if (isEverything(ExpressionVisitor.DETERMINISTIC_VISITOR)) {
if (lastResult != null && !lastResult.isClosed() && limit == lastLimit) {
if (sameResultAsLast(session, params, lastParameters, lastEvaluated)) {
lastResult = lastResult.createShallowCopy(session);
if (lastResult != null) {
lastResult.reset();
return lastResult;
}
}
}
}
lastParameters = params;
closeLastResult();
ResultInterface r = queryWithoutCacheLazyCheck(limit, target);
lastResult = r;
this.lastEvaluated = now;
lastLimit = limit;
return r;
}
use of org.h2.result.ResultInterface in project h2database by h2database.
the class ScriptCommand method queryMeta.
@Override
public ResultInterface queryMeta() {
LocalResult r = createResult();
r.done();
return r;
}
use of org.h2.result.ResultInterface in project h2database by h2database.
the class SelectUnion method queryMeta.
@Override
public ResultInterface queryMeta() {
int columnCount = left.getColumnCount();
LocalResult result = new LocalResult(session, expressionArray, columnCount);
result.done();
return result;
}
use of org.h2.result.ResultInterface in project h2database by h2database.
the class SelectUnion method queryWithoutCache.
@Override
protected ResultInterface queryWithoutCache(int maxRows, ResultTarget target) {
if (maxRows != 0) {
// maxRows is set (maxRows 0 means no limit)
int l;
if (limitExpr == null) {
l = -1;
} else {
Value v = limitExpr.getValue(session);
l = v == ValueNull.INSTANCE ? -1 : v.getInt();
}
if (l < 0) {
// for limitExpr, 0 means no rows, and -1 means no limit
l = maxRows;
} else {
l = Math.min(l, maxRows);
}
limitExpr = ValueExpression.get(ValueInt.get(l));
}
if (session.getDatabase().getSettings().optimizeInsertFromSelect) {
if (unionType == UnionType.UNION_ALL && target != null) {
if (sort == null && !distinct && maxRows == 0 && offsetExpr == null && limitExpr == null) {
left.query(0, target);
right.query(0, target);
return null;
}
}
}
int columnCount = left.getColumnCount();
if (session.isLazyQueryExecution() && unionType == UnionType.UNION_ALL && !distinct && sort == null && !randomAccessResult && !isForUpdate && offsetExpr == null && isReadOnly()) {
int limit = -1;
if (limitExpr != null) {
Value v = limitExpr.getValue(session);
if (v != ValueNull.INSTANCE) {
limit = v.getInt();
}
}
// limit 0 means no rows
if (limit != 0) {
LazyResultUnion lazyResult = new LazyResultUnion(expressionArray, columnCount);
if (limit > 0) {
lazyResult.setLimit(limit);
}
return lazyResult;
}
}
LocalResult result = new LocalResult(session, expressionArray, columnCount);
if (sort != null) {
result.setSortOrder(sort);
}
if (distinct) {
left.setDistinct(true);
right.setDistinct(true);
result.setDistinct();
}
if (randomAccessResult) {
result.setRandomAccess();
}
switch(unionType) {
case UNION:
case EXCEPT:
left.setDistinct(true);
right.setDistinct(true);
result.setDistinct();
break;
case UNION_ALL:
break;
case INTERSECT:
left.setDistinct(true);
right.setDistinct(true);
break;
default:
DbException.throwInternalError("type=" + unionType);
}
ResultInterface l = left.query(0);
ResultInterface r = right.query(0);
l.reset();
r.reset();
switch(unionType) {
case UNION_ALL:
case UNION:
{
while (l.next()) {
result.addRow(convert(l.currentRow(), columnCount));
}
while (r.next()) {
result.addRow(convert(r.currentRow(), columnCount));
}
break;
}
case EXCEPT:
{
while (l.next()) {
result.addRow(convert(l.currentRow(), columnCount));
}
while (r.next()) {
result.removeDistinct(convert(r.currentRow(), columnCount));
}
break;
}
case INTERSECT:
{
LocalResult temp = new LocalResult(session, expressionArray, columnCount);
temp.setDistinct();
temp.setRandomAccess();
while (l.next()) {
temp.addRow(convert(l.currentRow(), columnCount));
}
while (r.next()) {
Value[] values = convert(r.currentRow(), columnCount);
if (temp.containsDistinct(values)) {
result.addRow(values);
}
}
temp.close();
break;
}
default:
DbException.throwInternalError("type=" + unionType);
}
if (offsetExpr != null) {
result.setOffset(offsetExpr.getValue(session).getInt());
}
if (limitExpr != null) {
Value v = limitExpr.getValue(session);
if (v != ValueNull.INSTANCE) {
result.setLimit(v.getInt());
}
}
l.close();
r.close();
result.done();
if (target != null) {
while (result.next()) {
target.addRow(result.currentRow());
}
result.close();
return null;
}
return result;
}
use of org.h2.result.ResultInterface in project h2database by h2database.
the class SessionRemote method readSerializationSettings.
/**
* Read the serializer name from the persistent database settings.
*
* @return the serializer
*/
private String readSerializationSettings() {
String javaObjectSerializerFQN = null;
CommandInterface ci = prepareCommand("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[0].getString();
}
} finally {
ci.close();
}
return javaObjectSerializerFQN;
}
Aggregations