gt: 			Binding result = new Binding( structure.getName( ) );
context: /*******************************************************************************
   * Copyright (c) 2004, 2005 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.report.data.adapter.impl;
  
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  import org.eclipse.birt.core.data.ExpressionUtil;
  import org.eclipse.birt.core.exception.BirtException;
  import org.eclipse.birt.data.engine.api.DataEngine;
  import org.eclipse.birt.data.engine.api.IBaseDataSetDesign;
  import org.eclipse.birt.data.engine.api.IBinding;
  import org.eclipse.birt.data.engine.api.IComputedColumn;
  import org.eclipse.birt.data.engine.api.IFilterDefinition;
  import org.eclipse.birt.data.engine.api.IQueryDefinition;
  import org.eclipse.birt.data.engine.api.IQueryResults;
  import org.eclipse.birt.data.engine.api.querydefn.Binding;
  import org.eclipse.birt.data.engine.api.querydefn.ComputedColumn;
  import org.eclipse.birt.data.engine.api.querydefn.InputParameterBinding;
  import org.eclipse.birt.data.engine.api.querydefn.ScriptExpression;
  import org.eclipse.birt.data.engine.core.DataException;
  import org.eclipse.birt.data.engine.impl.DataEngineImpl;
  import org.eclipse.birt.report.data.adapter.api.AdapterException;
  import org.eclipse.birt.report.data.adapter.api.DataRequestSession;
  import org.eclipse.birt.report.data.adapter.api.DataSessionContext;
  import org.eclipse.birt.report.data.adapter.api.IDataSetInterceptor;
  import org.eclipse.birt.report.data.adapter.api.IDataSetInterceptorContext;
  import org.eclipse.birt.report.data.adapter.api.IModelAdapter;
  import org.eclipse.birt.report.model.api.ComputedColumnHandle;
  import org.eclipse.birt.report.model.api.DataSetHandle;
  import org.eclipse.birt.report.model.api.DerivedDataSetHandle;
  import org.eclipse.birt.report.model.api.Expression;
  import org.eclipse.birt.report.model.api.ExpressionHandle;
  import org.eclipse.birt.report.model.api.FilterConditionHandle;
  import org.eclipse.birt.report.model.api.JointDataSetHandle;
  import org.eclipse.birt.report.model.api.ModuleHandle;
  import org.eclipse.birt.report.model.api.OdaDataSetParameterHandle;
  import org.eclipse.birt.report.model.api.ParamBindingHandle;
  import org.eclipse.birt.report.model.api.elements.structures.DataSetParameter;
  import org.mozilla.javascript.Scriptable;
  
  /**
   * 
   */
  class QueryExecutionHelper
  {
  
  	//
  	private DataEngine dataEngine;
  	private IModelAdapter modelAdaptor;
  	private DataSessionContext sessionContext;
  	
  	private boolean useResultHints;
  	
  	//The major data set handle this QueryExecutionHelper deal with.
  	private DataSetHandle major;
  	private DataRequestSession session;
  
  	/**
  	 * @param dataEngine
  	 * @param modelAdaptor
  	 * @param moduleHandle
  	 */
  	QueryExecutionHelper( DataEngine dataEngine, IModelAdapter modelAdaptor,
  			DataSessionContext sessionContext, DataRequestSession session )
  	{
  		this( dataEngine, modelAdaptor, sessionContext, true, session );
  	}
  	
  	/**
  	 * @param dataEngine
  	 * @param modelAdaptor
  	 * @param moduleHandle
  	 * @param useResultHints
  	 */
  	QueryExecutionHelper( DataEngine dataEngine, IModelAdapter modelAdaptor,
  			DataSessionContext sessionContext, boolean useResultHints, DataRequestSession session )
  	{
  		this.dataEngine = dataEngine;
  		this.modelAdaptor = modelAdaptor;
  		this.sessionContext = sessionContext;
  		this.useResultHints = useResultHints;
  		this.session = session;
  	}
  
  	/**
  	 * @param queryDefn
  	 * @return
  	 * @throws BirtException
  	 */
  	IQueryResults executeQuery( IQueryDefinition queryDefn, IDataSetInterceptorContext context )
  			throws BirtException
  	{
  		return executeQuery( queryDefn, null, null, null, null , context );
  	}
  	
  	/**
  	 * 
  	 * @param queryDefn
  	 * @param paramBindingIt
  	 * @param filterIt
  	 * @param bindingIt
  	 * @return
  	 * @throws BirtException
  	 */
  	IQueryResults executeQuery( IQueryDefinition queryDefn,
  			Iterator paramBindingIt, Iterator filterIt, Iterator bindingIt, Scriptable scope, IDataSetInterceptorContext interceptorContext )
  			throws BirtException
  	{
  		return executeQuery( queryDefn,
  				paramBindingIt,
  				filterIt,
  				bindingIt,
  				true,
  				false,
  				scope, interceptorContext );
  	}
  
  	IQueryResults executeQuery( IQueryDefinition queryDefn,
  			Iterator paramBindingIt, Iterator filterIt, Iterator bindingIt,
  			boolean keepDataSetFilter, boolean disAllowAggregation, Scriptable scope, IDataSetInterceptorContext interceptorContext ) throws BirtException
  	{
  		populateQueryDefn( queryDefn, paramBindingIt, filterIt, bindingIt, disAllowAggregation );
  
  		defineDataSourceDataSet( queryDefn, keepDataSetFilter, disAllowAggregation, interceptorContext );
  
  		return dataEngine.prepare( queryDefn, sessionContext.getAppContext( ) )
  				.execute( scope );
  	}
  	
  	/**
  	 * @param queryDefn
  	 * @throws AdapterException
  	 * @throws BirtException
  	 */
  	private void defineDataSourceDataSet( IQueryDefinition queryDefn, boolean keepDataSetFilter, boolean allowAggregation, IDataSetInterceptorContext interceptorContext  )
  			throws AdapterException, BirtException
  	{
  		String dataSetName = queryDefn.getDataSetName( );
  
  		ModuleHandle module = sessionContext.getModuleHandle();
  		if ( module != null  )
  		{
  			List l = module.getAllDataSets( );
  			DataSetHandle handle = null;
  			for ( int i = 0; i < l.size( ); i++ )
  			{
  				if ( ( (DataSetHandle) l.get( i ) ).getQualifiedName( ) != null
  						&& ( (DataSetHandle) l.get( i ) ).getQualifiedName( )
  								.equals( dataSetName ) )
  				{
  					handle = (DataSetHandle) l.get( i );
  					break;
  				}
  			}
  			major = handle;
  			defineDataSet( handle, new DataSetHandleProcessContext(major, useResultHints, keepDataSetFilter, allowAggregation) );
  			if ( interceptorContext != null )
  				DefineDataSourceSetUtil.prepareForTransientQuery( sessionContext, (DataEngineImpl)dataEngine, 
  						handle, queryDefn, null, interceptorContext );
  		}
  	}
  
  	/**
  	 * @param queryDefn
  	 * @param paramBindingIt
  	 * @param filterIt
  	 * @param bindingIt
  	 * @throws AdapterException 
  	 */
  	private void populateQueryDefn( IQueryDefinition queryDefn,
  			Iterator paramBindingIt, Iterator filterIt, Iterator bindingIt, boolean disAllowAggregation ) throws AdapterException
  	{
  		try
  		{
  			while ( bindingIt != null && bindingIt.hasNext( ) )
  			{
  				Object computedBinding = bindingIt.next( );
  				IBinding binding = null;
  				if ( computedBinding instanceof ComputedColumnHandle )
  				{
  					binding = this.modelAdaptor.adaptBinding( (ComputedColumnHandle) computedBinding );
  				}
  				else if ( computedBinding instanceof org.eclipse.birt.report.model.api.elements.structures.ComputedColumn )
  				{
  					binding = adaptBinding( (org.eclipse.birt.report.model.api.elements.structures.ComputedColumn) computedBinding );
  				}
  				if ( binding == null
  						|| ( disAllowAggregation && binding.getAggrFunction( ) != null ) )
  					continue;
  				queryDefn.addBinding( binding );
  			}
  
  			List parameterBindings = convertParamterBindings( paramBindingIt );
  
  			// add parameter binding
  			if ( parameterBindings != null )
  				queryDefn.getInputParamBindings( ).addAll( parameterBindings );
  
  			// add filter
  			List filters = convertFilters( filterIt );
  			if ( filters != null )
  				queryDefn.getFilters( ).addAll( filters );
  		}
  		catch ( DataException e )
  		{
  			throw new AdapterException( e.getLocalizedMessage( ), e );
  		}
  	}
  
  	/**
  	 * NOTE: This binding is the temp binding, it would not be aggregation. The
  	 * binding is used when select value list for filter expression.
  	 * 
  	 * @param structure
  	 * @return
  	 */
  	private IBinding adaptBinding(
  			org.eclipse.birt.report.model.api.elements.structures.ComputedColumn structure )
  	{
  		try
  		{
  			if ( structure == null )
  				return null;
  