/*
 *************************************************************************
 * Copyright (c) 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.engine.odaconsumer.birtdriver;

import java.util.Properties;

import org.eclipse.birt.data.oda.OdaException;
import org.eclipse.birt.data.oda.impl.SimpleConnection;

/**
 * A test ODA connection that implements the deprecated BIRT ODA run-time interfaces.
 * This is used to test the DTP-to-BIRT ODA driver adapter and
 * its backward compatibility support.
 */
public class TestBirtConnectionImpl extends SimpleConnection
{
    private int m_maxQueries = 0;
    
    /* (non-Javadoc)
     * @see org.eclipse.birt.data.oda.IConnection#open(java.util.Properties)
     */
    public void open( Properties connProperties ) throws OdaException
    {
        try
        {
            super.open( connProperties );
        }
        catch( UnsupportedOperationException e )
        {
            // override base class exception
        }
        
        if( connProperties == null )
            return;		// do nothing

        // key used in BirtOdaAdapter junit test case
        Object value = connProperties.get( "MaxQueries" );
        if( value != null && value instanceof Integer )
            m_maxQueries = ((Integer) value).intValue();
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.birt.data.oda.IConnection#getMaxQueries()
     */
    public int getMaxQueries() throws OdaException
    {
        // number passed in via connection properties
        // for checking by junit test case
        return m_maxQueries;
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.birt.data.oda.IConnection#close()
     */
    public void close() throws OdaException
    {
        try
        {
            super.close();
        }
        catch( UnsupportedOperationException e )
        {
            // override base class exception
        }
        
        // reset member variable to default
        m_maxQueries = 0;
    }
}
