/*******************************************************************************
 * 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.executor.cache;

import org.eclipse.birt.data.engine.core.DataException;
import org.eclipse.birt.data.engine.executor.ResultObject;
import org.eclipse.birt.data.engine.odi.IResultClass;
import org.eclipse.birt.data.engine.odi.IResultObject;

/**
 * This class implements IRowResultSet and delegate the behavior of class
 * RowResultSet, besides that it can adjust the IResultObject instance return
 * by its "next()" method according to the given metadata in a limited way.
 */
class ExpandableRowResultSet implements IRowResultSet
{
	// result meta data
	private IResultClass resultClass;
	
	// 
	private RowResultSet rowResultSet;

	/**
	 * Construction
	 * 
	 * @param query
	 * @param odaResultSet
	 * @param resultClass
	 */
	ExpandableRowResultSet( SmartCacheRequest smartCacheRequest )
	{
		this.resultClass = smartCacheRequest.getResultClass( );

		this.rowResultSet = new RowResultSet( smartCacheRequest );
	}

	/**
	 * @return result meta data
	 */
	public IResultClass getMetaData( )
	{
		return resultClass;
	}
	
	/**
	 * Notice the return value of this function is IResultObject. The null value
	 * indicates the cursor exceeds the end of result set.
	 * 
	 * @return next result data
	 * @throws DataException
	 */
	public IResultObject next( ) throws DataException
	{
		IResultObject ro = this.rowResultSet.next( );
		if( ro == null )
			return null;
		Object[] objs = new Object[this.resultClass.getFieldCount( )];
		int roFieldCount = ro.getResultClass( ).getFieldCount( );
		for( int i = 0; i < objs.length; i++)
		{
			if( i+1 <= roFieldCount )
				objs[i] = ro.getFieldValue( i+1 );
			else
				objs[i] = null;
		}
		return new ResultObject( resultClass, objs);
	}
}
@@ -1991,16 +1991,46 @@
 nt( )%5D;%0A
+%09%09if ( objs.length %3E 0 )%0A%09%09%7B%0A%09
 %09%09int ro
@@ -2085,13 +2085,15 @@
  );%0A
+%09
 %09%09for
+ 
 ( in
@@ -2125,23 +2125,29 @@
  i++
+ 
 )%0A
+%09
 %09%09%7B%0A
+%09
 %09%09%09if
+ 
 ( i
-+
+ + 
 1 %3C=
@@ -2162,16 +2162,17 @@
 Count )%0A
+%09
 %09%09%09%09objs
@@ -2200,22 +2200,25 @@
 e( i
-+
+ + 
 1 );%0A
+%09
 %09%09%09else%0A
 %09%09%09%09
@@ -2213,16 +2213,17 @@
 %09%09%09else%0A
+%09
 %09%09%09%09objs
@@ -2234,16 +2234,21 @@
 = null;%0A
+%09%09%09%7D%0A
 %09%09%7D%0A%09%09re
@@ -2287,15 +2287,16 @@
 ss, objs
+ 
 );%0A%09%7D%0A%7D

Fix a minor bug in ExpandableRowResultSet