/*
 *************************************************************************
 * 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.data.oda.adapter.dtp;

import java.math.BigDecimal;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;

import org.eclipse.datatools.connectivity.oda.IAdvancedQuery;
import org.eclipse.datatools.connectivity.oda.IBlob;
import org.eclipse.datatools.connectivity.oda.IClob;
import org.eclipse.datatools.connectivity.oda.IParameterRowSet;
import org.eclipse.datatools.connectivity.oda.IResultSet;
import org.eclipse.datatools.connectivity.oda.IResultSetMetaData;
import org.eclipse.datatools.connectivity.oda.OdaException;
import org.eclipse.datatools.connectivity.oda.SortSpec;

/**
 * AdvancedQuery is the DTP ODA adapter for the BIRT ODA driver interface IAdvancedQuery.
 */
public class AdvancedQuery extends Query implements IAdvancedQuery
{

    private org.eclipse.birt.data.oda.IAdvancedQuery m_birtAdvancedQuery = null;
    
    private AdvancedQuery() throws OdaException
    {
        super( null );
    }
    
    /**
     * Creates an AdvancedQuery adapter for the specified object.
     * @param birtAdvancedQuery	BIRT ODA IAdvancedQuery interface implementation.
     * @throws OdaException		if data source error occurs.
     */
    public AdvancedQuery( org.eclipse.birt.data.oda.IAdvancedQuery birtAdvancedQuery ) throws OdaException
    {
        super( birtAdvancedQuery );
        m_birtAdvancedQuery = birtAdvancedQuery;
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#execute()
     */
    public boolean execute() throws OdaException
    {
        try
        {
            return m_birtAdvancedQuery.execute();
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }             
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getResultSet()
     */
    public IResultSet getResultSet() throws OdaException
    {
        try
        {
            return new ResultSet( m_birtAdvancedQuery.getResultSet() );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }        
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getMoreResults()
     */
    public boolean getMoreResults() throws OdaException
    {
        try
        {
            return m_birtAdvancedQuery.getMoreResults();
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }          
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getResultSetNames()
     */
    public String[] getResultSetNames() throws OdaException
    {
        try
        {
            return m_birtAdvancedQuery.getResultSetNames();
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }          
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getMetaDataOf(java.lang.String)
     */
    public IResultSetMetaData getMetaDataOf( String resultSetName ) throws OdaException
    {
        try
        {
            return new ResultSetMetaData( m_birtAdvancedQuery.getMetaDataOf( resultSetName ) );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }          
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getResultSet(java.lang.String)
     */
    public IResultSet getResultSet( String resultSetName ) throws OdaException
    {
        try
        {
            return new ResultSet( m_birtAdvancedQuery.getResultSet( resultSetName ) );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#setNewRow(java.lang.String)
     */
    public IParameterRowSet setNewRow( String parameterName ) throws OdaException
    {
        try
        {
            return new ParameterRowSet( m_birtAdvancedQuery.setNewRow( parameterName ) );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }        
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#setNewRow(int)
     */
    public IParameterRowSet setNewRow( int parameterId ) throws OdaException
    {
        try
        {
            return new ParameterRowSet( m_birtAdvancedQuery.setNewRow( parameterId ) );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );           
        }        
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#setNewRowSet(java.lang.String)
     */
    public IParameterRowSet setNewRowSet( String parameterName ) throws OdaException
    {
        try
        {
            return new ParameterRowSet( m_birtAdvancedQuery.setNewRowSet( parameterName ) );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }        
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#setNewRowSet(int)
     */
    public IParameterRowSet setNewRowSet( int parameterId ) throws OdaException
    {
        try
        {
            return new ParameterRowSet( m_birtAdvancedQuery.setNewRowSet( parameterId ) );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }        
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getInt(java.lang.String)
     */
    public int getInt( String parameterName ) throws OdaException
    {
        try
        {
            return m_birtAdvancedQuery.getInt( parameterName );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }        
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getInt(int)
     */
    public int getInt( int parameterId ) throws OdaException
    {
        try
        {
            return m_birtAdvancedQuery.getInt( parameterId );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }        
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getDouble(java.lang.String)
     */
    public double getDouble( String parameterName ) throws OdaException
    {
        try
        {
            return m_birtAdvancedQuery.getDouble( parameterName );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }        
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getDouble(int)
     */
    public double getDouble( int parameterId ) throws OdaException
    {
        try
        {
            return m_birtAdvancedQuery.getDouble( parameterId );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }        
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getBigDecimal(java.lang.String)
     */
    public BigDecimal getBigDecimal( String parameterName ) throws OdaException
    {
        try
        {
            return m_birtAdvancedQuery.getBigDecimal( parameterName );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }        
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getBigDecimal(int)
     */
    public BigDecimal getBigDecimal( int parameterId ) throws OdaException
    {
        try
        {
            return m_birtAdvancedQuery.getBigDecimal( parameterId );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }        
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getString(java.lang.String)
     */
    public String getString( String parameterName ) throws OdaException
    {
        try
        {
            return m_birtAdvancedQuery.getString( parameterName );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }        
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getString(int)
     */
    public String getString( int parameterId ) throws OdaException
    {
        try
        {
            return m_birtAdvancedQuery.getString( parameterId );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }        
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getDate(java.lang.String)
     */
    public Date getDate( String parameterName ) throws OdaException
    {
        try
        {
            return m_birtAdvancedQuery.getDate( parameterName );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }        
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getDate(int)
     */
    public Date getDate( int parameterId ) throws OdaException
    {
        try
        {
            return m_birtAdvancedQuery.getDate( parameterId );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }        
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getTime(java.lang.String)
     */
    public Time getTime( String parameterName ) throws OdaException
    {
        try
        {
            return m_birtAdvancedQuery.getTime( parameterName );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }        
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getTime(int)
     */
    public Time getTime( int parameterId ) throws OdaException
    {
        try
        {
            return m_birtAdvancedQuery.getTime( parameterId );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }        
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getTimestamp(java.lang.String)
     */
    public Timestamp getTimestamp( String parameterName ) throws OdaException
    {
        try
        {
            return m_birtAdvancedQuery.getTimestamp( parameterName );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }        
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getTimestamp(int)
     */
    public Timestamp getTimestamp( int parameterId ) throws OdaException
    {
        try
        {
            return m_birtAdvancedQuery.getTimestamp( parameterId );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }        
    }
	
	/*
	 * (non-Javadoc)
	 * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getBlob(java.lang.String)
	 */
	public IBlob getBlob( String parameterName ) throws OdaException
	{
        throw new UnsupportedOperationException();	// not supported in pre-3.0 ODA
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getBlob(int)
	 */
	public IBlob getBlob( int parameterId ) throws OdaException
	{
        throw new UnsupportedOperationException();	// not supported in pre-3.0 ODA
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getClob(java.lang.String)
	 */
	public IClob getClob( String parameterName ) throws OdaException
	{
        throw new UnsupportedOperationException();	// not supported in pre-3.0 ODA
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getClob(int)
	 */
	public IClob getClob( int parameterId ) throws OdaException
	{
        throw new UnsupportedOperationException();	// not supported in pre-3.0 ODA
	}
	
    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getRow(java.lang.String)
     */
    public IParameterRowSet getRow( String parameterName ) throws OdaException
    {
        try
        {
            return new ParameterRowSet( m_birtAdvancedQuery.getRow( parameterName ) );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }        
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getRow(int)
     */
    public IParameterRowSet getRow( int parameterId ) throws OdaException
    {
        try
        {
            return new ParameterRowSet( m_birtAdvancedQuery.getRow( parameterId ) );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }        
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#findOutParameter(java.lang.String)
     */
    public int findOutParameter( String parameterName ) throws OdaException
    {
        try
        {
            return m_birtAdvancedQuery.findOutParameter( parameterName );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );            
        }        
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#wasNull()
     */
    public boolean wasNull() throws OdaException
    {
        try
        {
            return m_birtAdvancedQuery.wasNull();
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );
        }        
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#setSortSpec(java.lang.String, org.eclipse.datatools.connectivity.oda.SortSpec)
     */
    public void setSortSpec( String resultSetName, SortSpec sortBy ) throws OdaException
    {
        try
        {
            m_birtAdvancedQuery.setSortSpec( resultSetName, dtpToBirtSortSpec( sortBy ) );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );
        }   
    }

    /* (non-Javadoc)
     * @see org.eclipse.datatools.connectivity.oda.IAdvancedQuery#getSortSpec(java.lang.String)
     */
    public SortSpec getSortSpec( String resultSetName ) throws OdaException
    {
        try
        {
            return birtToDtpSortSpec( m_birtAdvancedQuery.getSortSpec( resultSetName ) );
        }
        catch( org.eclipse.birt.data.oda.OdaException e )
        {
            throw new OdaAdapterException( e );
        }        
    }
    
}
