/*
 * Connection.java
 *
 * Created on August 1, 2007, 6:01 PM
 *
 */
package usda.weru.soil.arssql;

import java.sql.*;
import java.util.Map;
// LEW - JIm Ascough's programmers added this line to allow compilation/running under Java 7
import java.util.concurrent.Executor;

/**
 * This is a stripped implementation of the Connection interface. It is
 * intended to be used the ARS soap web service to obtain soil data.
 * Only calls that are actually used by WEPS are implemented.
 * @author wjr
 */
public class ConnectionARS implements java.sql.Connection {

    /**
     *
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        ConnectionARS cars = new ConnectionARS("SDMDataAccess.nrcs.usda.gov");
        StatementARS sars = (StatementARS) cars.createStatement();
        ResultSetARS rsars = sars.executeQuery("SELECT lkey,areasymbol,areaname FROM legend ORDER BY areasymbol");
        System.out.println("m: " + rsars);
        int index = 0;
        {
            rsars.next(); 
            String arname = rsars.getString("areaname");
            String arsym = rsars.getString("areasymbol");
            String lkey = rsars.getString("lkey");
            System.out.println(index ++);
            System.out.println("areaname = " + arname);
            System.out.println("areasymbol = " + arsym);
            System.out.println("lkey = " + lkey);
            ResultSetARS resSub = sars.executeQuery("SELECT mukey,musym,muname,lkey FROM mapunit WHERE lkey = '"
                        + lkey + "' ORDER BY muname");
            resSub.next();
            {
                String muname = resSub.getString("muname");
                String musym = resSub.getString("musym");
                String mukey = resSub.getString("mukey");
                String lkeySub = resSub.getString("lkey");
                System.out.println(index ++);
                System.out.println("muname = " + muname);
                System.out.println("musym = " + musym);
                System.out.println("mukey = " + mukey);
                System.out.println("lkey = " + lkeySub);
                ResultSetARS end = sars.executeQuery("SELECT cokey,comppct_r,compname,localphase,mukey FROM component WHERE mukey = '" + mukey + "' ORDER BY comppct_r");
                end.next();
                {
                    String compname = end.getString("compname");
                    String compsym = end.getString("comppct_r");
                    String cokey = end.getString("cokey");
                    String mukeySub = end.getString("mukey");
                    System.out.println(index ++);
                    System.out.println("compname = " + compname);
                    System.out.println("compsym = " + compsym);
                    System.out.println("cokey = " + cokey);
                    System.out.println("mukey = " + mukeySub);
                }
            }
        }
//        while(rsars.next()) 
//        {
//            String arname = rsars.getString("areaname");
//            String arsym = rsars.getString("areasymbol");
//            String lkey = rsars.getString("lkey");
//            System.out.println(index ++);
//            System.out.println("areaname = " + arname);
//            System.out.println("areasymbol = " + arsym);
//            System.out.println("lkey = " + lkey);
//            ResultSetARS resSub = sars.executeQuery("SELECT mukey,musym,muname,lkey FROM mapunit WHERE lkey = '"
//                        + lkey + "' ORDER BY muname");
//            while(resSub.next()) 
//            {
//                String muname = resSub.getString("muname");
//                String musym = resSub.getString("musym");
//                String mukey = resSub.getString("mukey");
//                String lkeySub = resSub.getString("lkey");
//                System.out.println(index ++);
//                System.out.println("muname = " + muname);
//                System.out.println("areasymbol = " + musym);
//                System.out.println("mukey = " + mukey);
//                System.out.println("lkey = " + lkeySub);
//            }
//        }
    }

    /** Creates a new instance of Connection */
    public ConnectionARS() {
    }
    String url;

    /**
     *
     * @param url
     */
    public ConnectionARS(String url) {
        this.url = url;
    }

    // todo: fix javadoc
//          Clears all warnings reported for this Connection object.
    /**
     *
     */
    @Override
    public void clearWarnings() {
    }

//          Releases this Connection object's database and JDBC resources immediately instead of waiting for them to be automatically released.
    /**
     *
     */
    @Override
    public void close() {
    }

//          Makes all changes made since the previous commit/rollback permanent and releases any database locks currently held by this Connection object.
    /**
     *
     */
    @Override
    public void commit() {
    }

//          Creates a Statement object for sending SQL statements to the database.
//			Used by WEPS -- creates new statement and passes URL to
//			statement.
    /**
     *
     * @return
     */
    @Override
    public Statement createStatement() {
        return new StatementARS(url);
    }

//          Creates a Statement object that will generate ResultSet objects with the given type and concurrency.public
    /**
     *
     * @param resultSetType
     * @param resultSetConcurrency
     * @return
     */
    @Override
    public Statement createStatement(int resultSetType, int resultSetConcurrency) {
        return null;
    }

//          Creates a Statement object that will generate ResultSet objects with the given type, concurrency, and holdability.
    /**
     *
     * @param resultSetType
     * @param resultSetConcurrency
     * @param resultSetHoldability
     * @return
     */
    @Override
    public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) {
        return null;
    }

//          Retrieves the current auto-commit mode for this Connection object.
    /**
     *
     * @return
     */
    @Override
    public boolean getAutoCommit() {
        return false;
    }

//          Retrieves this Connection object's current catalog name.
    /**
     *
     * @return
     */
    @Override
    public String getCatalog() {
        return null;
    }

//          Retrieves the current holdability of ResultSet objects created using this Connection object.
    /**
     *
     * @return
     */
    @Override
    public int getHoldability() {
        return -1;
    }

//          Retrieves a DatabaseMetaData object that contains metadata about the database to which this Connection object represents a connection.
    /**
     *
     * @return
     */
    @Override
    public DatabaseMetaData getMetaData() {
        return null;
    }

//          Retrieves this Connection object's current transaction isolation level.
    /**
     *
     * @return
     */
    @Override
    public int getTransactionIsolation() {
        return -1;
    }

//          Retrieves the Map object associated with this Connection object.
    /**
     *
     * @return
     */
    @Override
    public Map<String, Class<?>> getTypeMap() {
        return null;
    }

//          Retrieves the first warning reported by calls on this Connection object.
//			Used by WEPS -- returns null to indicate no warnings.
//			(probably will need to be fixed later)
    /**
     *
     * @return
     */
    @Override
    public SQLWarning getWarnings() {
        return null;
    }

//          Retrieves whether this Connection object has been closed.
    /**
     *
     * @return
     */
    @Override
    public boolean isClosed() {
        return false;
    }

//          Retrieves whether this Connection object is in read-only mode.
    /**
     *
     * @return
     */
    @Override
    public boolean isReadOnly() {
        return true;
    }

//          Converts the given SQL statement into the system's native SQL grammar.
    /**
     *
     * @param sql
     * @return
     */
    @Override
    public String nativeSQL(String sql) {
        return sql;
    }

//          Creates a CallableStatement object for calling database stored procedures.
    /**
     *
     * @param sql
     * @return
     */
    @Override
    public CallableStatement prepareCall(String sql) {
        return null;
    }

//          Creates a CallableStatement object that will generate ResultSet objects with the given type and concurrency.
    /**
     *
     * @param sql
     * @param resultSetType
     * @param resultSetConcurrency
     * @return
     */
    @Override
    public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) {
        return null;
    }

//          Creates a CallableStatement object that will generate ResultSet objects with the given type and concurrency.
    /**
     *
     * @param sql
     * @param resultSetType
     * @param resultSetConcurrency
     * @param resultSetHoldability
     * @return
     */
    @Override
    public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) {
        return null;
    }

//          Creates a PreparedStatement object for sending parameterized SQL statements to the database.
    /**
     *
     * @param sql
     * @return
     */
    @Override
    public PreparedStatement prepareStatement(String sql) {
        return null;
    }

//          Creates a default PreparedStatement object that has the capability to retrieve auto-generated keys.
    /**
     *
     * @param sql
     * @param autoGeneratedKeys
     * @return
     */
    @Override
    public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) {
        return null;
    }

//          Creates a default PreparedStatement object capable of returning the auto-generated keys designated by the given array.
    /**
     *
     * @param sql
     * @param columnIndexes
     * @return
     */
    @Override
    public PreparedStatement prepareStatement(String sql, int[] columnIndexes) {
        return null;
    }

//          Creates a PreparedStatement object that will generate ResultSet objects with the given type and concurrency.
    /**
     *
     * @param sql
     * @param resultSetType
     * @param resultSetConcurrency
     * @return
     */
    @Override
    public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) {
        return null;
    }

//          Creates a PreparedStatement object that will generate ResultSet objects with the given type, concurrency, and holdability.
    /**
     *
     * @param sql
     * @param resultSetType
     * @param resultSetConcurrency
     * @param resultSetHoldability
     * @return
     */
    @Override
    public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) {
        return null;
    }

//          Creates a default PreparedStatement object capable of returning the auto-generated keys designated by the given array.
    /**
     *
     * @param sql
     * @param columnNames
     * @return
     */
    @Override
    public PreparedStatement prepareStatement(String sql, String[] columnNames) {
        return null;
    }

//          Removes the given Savepoint object from the current transaction.
    /**
     *
     * @param savepoint
     */
    @Override
    public void releaseSavepoint(Savepoint savepoint) {
    }

//          Undoes all changes made in the current transaction and releases any database locks currently held by this Connection object.
    /**
     *
     */
    @Override
    public void rollback() {
    }

//          Undoes all changes made after the given Savepoint object was set.
    /**
     *
     * @param savepoint
     */
    @Override
    public void rollback(Savepoint savepoint) {
    }

//          Sets this connection's auto-commit mode to the given state.
    /**
     *
     * @param autoCommit
     */
    @Override
    public void setAutoCommit(boolean autoCommit) {
    }

//          Sets the given catalog name in order to select a subspace of this Connection object's database in which to work.
    /**
     *
     * @param catalog
     */
    @Override
    public void setCatalog(String catalog) {
    }

//          Changes the holdability of ResultSet objects created using this Connection object to the given holdability.
    /**
     *
     * @param holdability
     */
    @Override
    public void setHoldability(int holdability) {
    }

//          Puts this connection in read-only mode as a hint to the driver to enable database optimizations.
    /**
     *
     * @param readOnly
     */
    @Override
    public void setReadOnly(boolean readOnly) {
    }

//          Creates an unnamed savepoint in the current transaction and returns the new Savepoint object that represents it.
    /**
     *
     * @return
     */
    @Override
    public Savepoint setSavepoint() {
        return null;
    }

//          Creates a savepoint with the given name in the current transaction and returns the new Savepoint object that represents it.
    /**
     *
     * @param name
     * @return
     */
    @Override
    public Savepoint setSavepoint(String name) {
        return null;
    }

//          Attempts to change the transaction isolation level for this Connection object to the one given.
    /**
     *
     * @param level
     */
    @Override
    public void setTransactionIsolation(int level) {
    }

//			Installs the given TypeMap object as the type map for this Connection object.
    /**
     *
     * @param map
     */
    @Override
    public void setTypeMap(Map<String, Class<?>> map) {
    }

    /**
     *
     * @param s
     * @param oa
     * @return
     */
    @Override
    public Struct createStruct(String s, Object[] oa) {
        return null;
    }

    /**
     *
     * @param s
     * @param oa
     * @return
     */
    @Override
    public Array createArrayOf(String s, Object[] oa) {
        return null;
    }

    /**
     *
     * @return
     */
    @Override
    public java.util.Properties getClientInfo() {
        return null;
    }

    /**
     *
     * @param s
     * @return
     */
    @Override
    public String getClientInfo(String s) {
        return null;
    }

    /**
     *
     * @param p
     */
    @Override
    public void setClientInfo(java.util.Properties p) {
    }

    /**
     *
     * @param s1
     * @param s2
     */
    @Override
    public void setClientInfo(String s1, String s2) {
    }

    /**
     *
     * @param i
     * @return
     */
    @Override
    public boolean isValid(int i) {
        return false;
    }

    /**
     *
     * @return
     */
    @Override
    public SQLXML createSQLXML() {
        return null;
    }

    /**
     *
     * @return
     */
    @Override
    public NClob createNClob() {
        return null;
    }

    /**
     *
     * @return
     */
    @Override
    public Blob createBlob() {
        return null;
    }

    /**
     *
     * @return
     */
    @Override
    public Clob createClob() {
        return null;
    }

    /**
     *
     * @param c
     * @return
     */
    @Override
    public boolean isWrapperFor(Class<?> c) {
        return false;
    }

    /**
     *
     * @param <T>
     * @param t
     * @return
     */
    @Override
    public <T> T unwrap(Class<T> t) {
        return null;
    }
    // LEW - JIm Ascough's programmers added these lines to allow compilation/running under Java 7
    //@Override

    /**
     *
     * @param schema
     * @throws SQLException
     */
    @Override
    public void setSchema(String schema) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

	//@Override
    /**
     *
     * @return
     * @throws SQLException
     */
    @Override
    public String getSchema() throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

	//@Override
    /**
     *
     * @param executor
     * @throws SQLException
     */
    @Override
    public void abort(Executor executor) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

	//@Override
    /**
     *
     * @param executor
     * @param milliseconds
     * @throws SQLException
     */
    @Override
    public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

	//@Override
    /**
     *
     * @return
     * @throws SQLException
     */
    @Override
    public int getNetworkTimeout() throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
