import java.sql.*;
import java.io.InputStream;
import java.io.FileInputStream;
import java.util.Properties;
import java.util.Hashtable;
import oracle.jdbc.driver.*;
import oracle.dss.persistence.PSRConstants;
import oracle.dss.persistence.PSRUtilities;
import oracle.dss.security.DAD;
import oracle.dss.security.BISecurityException;
import oracle.dss.security.BISecurityConstants;
import oracle.dss.security.BIUser;
import oracle.dss.security.ConnectionProvider;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import oracle.jdbc.pool.OracleOCIConnectionPool;
import oracle.jdbc.pool.OracleConnectionCacheImpl;

public class OlapiPoolConnDriver implements ConnectionProvider
{

    public Object connect(Hashtable a_properties) throws BISecurityException
    {

        try
        {
            Context ctx = new InitialContext();
            System.out.println("Looking up JDBC connection pool for Catalog Connection");
           java.sql.Connection c= ((javax.sql.DataSource)ctx.lookup("jdbc/testtoolsCoreDS")).getConnection();
            return c;
        }
        // SQLException: most likely couldn't connect to the database.
        catch(SQLException sqle){
            String _msg = sqle.getLocalizedMessage();
            // if the exception's message starts with ORA-number, then
            // just pass it along. If the message doesn't have the vendor code in it,
            // query exception for the vendor code and append it to the message.
            if ((!_msg.startsWith("ORA-")) && (sqle.getErrorCode() != 0))
                    // make sure that the the length of the error code is at least 5 characters. Add leading zeros if necessary.
                    _msg = "ORA-" + PSRUtilities.padString(Integer.toString(sqle.getErrorCode()), '0', 5) + " " + _msg;
            throw new BISecurityException(_msg, sqle);
        }
        // catch any other general exception
        catch(Exception e) 
        {
            throw new BISecurityException(e.getLocalizedMessage(), e);
        }
    }
    public void disconnect(Object a_connection) throws BISecurityException
    {
        try {
            ((java.sql.Connection)a_connection).close();
        }
        catch(Exception e)
        {
            throw new BISecurityException(e.getLocalizedMessage(), null);
        }
    }

}