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

import java.util.Map;

import org.eclipse.birt.data.engine.core.DataException;
import org.eclipse.birt.data.engine.impl.DataEngineSession;
import org.eclipse.birt.data.engine.odi.ICandidateQuery;
import org.eclipse.birt.data.engine.odi.IDataSource;
import org.eclipse.birt.data.engine.odi.IDataSourceQuery;

/**
 * In design time, this data source will generate propert query which will
 * retrieve data from cache.
 */
public class DataSource implements IDataSource
{

	private boolean isScriptedDataSource;

	private DataEngineSession session;
	/**
	 * 
	 * @param isScriptedDataSource
	 */
	public DataSource( boolean isScriptedDataSource, DataEngineSession session )
	{
		this.isScriptedDataSource = isScriptedDataSource;
		this.session = session;
	}

	/*
	 * @see org.eclipse.birt.data.engine.odi.IDataSource#addProperty(java.lang.String,
	 *      java.lang.String)
	 */
	public void addProperty( String name, String value ) throws DataException
	{
		// do nothing
	}

	/*
	 * @see org.eclipse.birt.data.engine.odi.IDataSource#setAppContext(java.util.Map)
	 */
	public void setAppContext( Map context ) throws DataException
	{
		// do nothing
	}

	/*
	 * @see org.eclipse.birt.data.engine.odi.IDataSource#newQuery(java.lang.String,
	 *      java.lang.String)
	 */
	public IDataSourceQuery newQuery( String queryType, String queryText )
			throws DataException
	{
		return new DataSourceQuery( session );
	}

	/*
	 * @see org.eclipse.birt.data.engine.odi.IDataSource#newCandidateQuery()
	 */
	public ICandidateQuery newCandidateQuery( )
	{
		if( this.isScriptedDataSource )
			return new org.eclipse.birt.data.engine.executor.dscache.CandidateQuery( session );
		else
			return new org.eclipse.birt.data.engine.executor.CandidateQuery( session );
	}

	/*
	 * @see org.eclipse.birt.data.engine.odi.IDataSource#open()
	 */
	public void open( ) throws DataException
	{
		// do nothing
	}

	/*
	 * @see org.eclipse.birt.data.engine.odi.IDataSource#canClose()
	 */
	public boolean canClose( )
	{
		return true;
	}

	/*
	 * @see org.eclipse.birt.data.engine.odi.IDataSource#close()
	 */
	public void close( )
	{
		// do nothing
	}

}
