<commit_before>/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/
package org.eclipse.birt.data.engine.impl;

import java.util.logging.Logger;

import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.data.engine.core.DataException;
import org.eclipse.birt.data.engine.i18n.ResourceConstants;
import org.eclipse.birt.data.engine.odi.IResultObject;
import org.mozilla.javascript.Scriptable;

/**
 * When useDetails==false, this class is used.
 */
class ResultIterator2 extends ResultIterator
{
	// the value of lower group level
	private int lowestGroupLevel;
	
	private int currRowIndex;
	
	private int cachedRowId;

	private static Logger logger = Logger.getLogger( ResultIterator2.class.getName( ) );

	/**
	 * @param context
	 * @param queryResults
	 * @param queryResultID
	 * @param useDetails
	 * @param lowestGroupLevel
	 * @throws DataException
	 */
	ResultIterator2( IServiceForResultSet rService,
			org.eclipse.birt.data.engine.odi.IResultIterator odiResult,
			Scriptable scope, int rawIdStartingValue ) throws DataException
	{
		super( rService, odiResult, scope, rawIdStartingValue );
		Object[] params = {
				rService, odiResult, scope
		};
		logger.entering( ResultIterator2.class.getName( ),
				"ResultIterator2",
				params );

		this.lowestGroupLevel = rService.getQueryDefn( ).getGroups( ).size( );
		this.currRowIndex = -1;
		this.cachedRowId = 0;
		logger.exiting( ResultIterator2.class.getName( ), "ResultIterator2" );
	}

	/*
	 * @see org.eclipse.birt.data.engine.impl.ResultIterator#next()
	 */
	public boolean next( ) throws BirtException
	{
		boolean hasNext = super.next( );
		if ( hasNext )
			currRowIndex++;
		return hasNext;
	}
	
	/*
	 * @see org.eclipse.birt.data.engine.impl.ResultIterator#hasNextRow()
	 */
	protected boolean hasNextRow( ) throws DataException
	{
		boolean result = false;
		boolean shouldMoveForward = false;
	
		int index = this.odiResult.getCurrentResultIndex( );

		this.odiResult.last( lowestGroupLevel );

		if ( index != this.odiResult.getCurrentResultIndex( ) )
		{
			result = odiResult.getCurrentResult( ) == null ? false : true;
			shouldMoveForward = false;
		}
		else
		{
			shouldMoveForward = true;
		}
	
		
		if( shouldMoveForward )
		{
			result = this.odiResult.next( );
		}<commit_msg>CheckIn:Fix TED 14338 "Cannot load query " error for certain report<commit_after>/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/
package org.eclipse.birt.data.engine.impl;

import java.util.logging.Logger;

import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.data.engine.core.DataException;
import org.eclipse.birt.data.engine.i18n.ResourceConstants;
import org.eclipse.birt.data.engine.odi.IResultObject;
import org.mozilla.javascript.Scriptable;

/**
 * When useDetails==false, this class is used.
 */
class ResultIterator2 extends ResultIterator
{
	// the value of lower group level
	private int lowestGroupLevel;
	
	private int currRowIndex;
	
	private int cachedRowId;

	private static Logger logger = Logger.getLogger( ResultIterator2.class.getName( ) );

	/**
	 * @param context
	 * @param queryResults
	 * @param queryResultID
	 * @param useDetails
	 * @param lowestGroupLevel
	 * @throws DataException
	 */
	ResultIterator2( IServiceForResultSet rService,
			org.eclipse.birt.data.engine.odi.IResultIterator odiResult,
			Scriptable scope, int rawIdStartingValue ) throws DataException
	{
		super( rService, odiResult, scope, rawIdStartingValue );
		Object[] params = {
				rService, odiResult, scope
		};
		logger.entering( ResultIterator2.class.getName( ),
				"ResultIterator2",
				params );

		this.lowestGroupLevel = rService.getQueryDefn( ).getGroups( ).size( );
		this.currRowIndex = -1;
		this.cachedRowId = 0;
		logger.exiting( ResultIterator2.class.getName( ), "ResultIterator2" );
	}

	/*
	 * @see org.eclipse.birt.data.engine.impl.ResultIterator#next()
	 */
	public boolean next( ) throws BirtException
	{
		boolean hasNext = super.next( );
		if ( hasNext )
			currRowIndex++;
		else if ( currRowIndex == -1)
		{
			//If empty result set, the cachedRowId should be -1.
			this.cachedRowId = -1;
		}
		return hasNext;
	}
	
	/*
	 * @see org.eclipse.birt.data.engine.impl.ResultIterator#hasNextRow()
	 */
	protected boolean hasNextRow( ) throws DataException
	{
		boolean result = false;
		boolean shouldMoveForward = false;
	
		int index = this.odiResult.getCurrentResultIndex( );

		this.odiResult.last( lowestGroupLevel );

		if ( index != this.odiResult.getCurrentResultIndex( ) )
		{
			result = odiResult.getCurrentResult( ) == null ? false : true;
			shouldMoveForward = false;
		}
		else
		{
			shouldMoveForward = true;
		}
	
		
		if( shouldMoveForward )
		{
			result = this.odiResult.next( );
		}
{'fraction_non_alphanumeric': 0.15723822909346452, 'fraction_numerical': 0.008081517919887562, 'mean_word_length': 4.194343065693431, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5531652', 'n_tokens_mistral': 1838, 'n_tokens_neox': 1646, 'n_words': 397}