Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
// Contributors:
// Oracle - initial API and implementation from Oracle TopLink
package org.eclipse.persistence.queries;
import java.util.*;
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.exceptions.*;
import org.eclipse.persistence.expressions.*;
import org.eclipse.persistence.internal.queries.*;
import org.eclipse.persistence.internal.sessions.AbstractRecord;
import org.eclipse.persistence.internal.expressions.*;
import org.eclipse.persistence.internal.databaseaccess.*;
import org.eclipse.persistence.internal.helper.*;
/**
*
Purpose:
* Stream class which is used to deal with large collections returned
* from TOPLink queries more efficiently.
*
*
Responsibilities:
* Wraps a database result set cursor to provide a stream on the resulting selected objects.
*
* @author Yvon Lavoie
* @since TOPLink/Java 1.0
*/
public class CursoredStream extends Cursor {
/** Marker for backing up. */
protected int marker;
/**
* INTERNAL:
* Initialize the state of the stream
*/
public CursoredStream() {
super();
}
/**
* INTERNAL:
* Initialize the state of the stream
*/
public CursoredStream(DatabaseCall call, CursoredStreamPolicy policy) {
super(call, policy);
// Must close on exception as stream will not be returned to user.
try {
setLimits();
} catch (RuntimeException exception) {
try {
close();
} catch (RuntimeException ignore) {
}
throw exception;
}
}
/**
* PUBLIC:
* Return whether the cursored stream is at its end.
*/
public boolean atEnd() throws DatabaseException {
if ((this.position + 1) <= this.objectCollection.size()) {
return false;
}
if (this.nextRow != null) {
return false;
}
if (isClosed()) {
return true;
}
int oldSize = this.objectCollection.size();
retrieveNextPage();
return this.objectCollection.size() == oldSize;
}
/**
* PUBLIC:
* Returns the number of objects that can be read from this input without blocking.
*/
public int available() throws DatabaseException {
//For CR#2570/CR#2571.
return this.objectCollection.size() - this.position;
}
/**
* INTERNAL:
* Must build the count on the primary key fields, not * as * is not allowed if there was a distinct.
* This require a manually defined operator.
* added for CR 2900
*/
public Expression buildCountDistinctExpression(List includeFields, ExpressionBuilder builder) {
ExpressionOperator countOperator = new ExpressionOperator();
countOperator.setType(ExpressionOperator.AggregateOperator);
Vector databaseStrings = new Vector();
databaseStrings.add("COUNT(DISTINCT ");
databaseStrings.add(")");
countOperator.printsAs(databaseStrings);
countOperator.bePrefix();
countOperator.setNodeClass(ClassConstants.FunctionExpression_Class);
Expression firstFieldExpression = builder.getField(((DatabaseField)includeFields.get(0)).getQualifiedName());
return countOperator.expressionForArguments(firstFieldExpression, new ArrayList(0));
}
/**
* INTERNAL:
* Answer a list of the elements of the receiver's collection from startIndex to endIndex.
*/
protected List