package usda.weru.weps.reports.query;

import java.io.InputStream;
import java.io.Reader;
import java.sql.NClob;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLXML;
import java.util.concurrent.Semaphore;
import org.h2.tools.SimpleResultSet;

/**
 *
 * @author joelevin
 */
public abstract class WepsResultSet extends SimpleResultSet {

    /**
     *
     * @throws SQLException
     */
    public abstract void fill() throws SQLException;

    /**
     *
     * @return
     */
    public abstract String getName();

    /**
     *
     */
    @Override
    public void close() {
        try {
            beforeFirst();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    /**
     *
     */
    public void dispose() {
        super.close();
    }

    /**
     * Creates a new Object array the size of the resultset getColumnCount().
     * @param add If true, the row will be added to the resultset
     * @return an empty object array.
     * @throws SQLException Upon an unexpected error. This should be very rare.
     */
    protected Object[] createNewRow(boolean add) throws SQLException {
        Object[] row = new Object[getColumnCount()];
        if (add) {
            addRow(row);
        }
        return row;
    }
    
    
    private boolean olderRunCheck = false;

    public void setOlderRunCheck(boolean b) {
        olderRunCheck = b;
    }

    public boolean getOlderRunCheck() {
        return olderRunCheck;
    }

    /**
     * Convinence method for adding values based on their column names. Slight
     * performance hit is to be expected, but helps prevent programming errors
     * due to future column reordering.
     * @param row
     * @param columnName column label to be resolved to the 0 based index.
     * @param value Object to store
     * @throws java.sql.SQLException
     */
    protected void setRowValue(Object[] row, String columnName, Object value) throws SQLException {
        int index = findColumn(columnName) - 1;
        row[index] = value;
    }

    /**
     *
     * @param <T>
     * @param row
     * @param columnName
     * @return
     * @throws SQLException
     */
    protected <T> T getRowValue(T[] row, String columnName) throws SQLException {
        int index = findColumn(columnName) - 1;
        return row[index];
    }

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

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

    /**
     *
     * @param columnIndex
     * @param x
     * @throws SQLException
     */
    @Override
    public void updateRowId(int columnIndex, RowId x) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnLabel
     * @param x
     * @throws SQLException
     */
    @Override
    public void updateRowId(String columnLabel, RowId x) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnIndex
     * @param nString
     * @throws SQLException
     */
    @Override
    public void updateNString(int columnIndex, String nString) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnLabel
     * @param nString
     * @throws SQLException
     */
    @Override
    public void updateNString(String columnLabel, String nString) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnIndex
     * @param nClob
     * @throws SQLException
     */
    @Override
    public void updateNClob(int columnIndex, NClob nClob) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnLabel
     * @param nClob
     * @throws SQLException
     */
    @Override
    public void updateNClob(String columnLabel, NClob nClob) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

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

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

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

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

    /**
     *
     * @param columnIndex
     * @param xmlObject
     * @throws SQLException
     */
    @Override
    public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnLabel
     * @param xmlObject
     * @throws SQLException
     */
    @Override
    public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

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

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

    /**
     *
     * @param columnIndex
     * @param x
     * @param length
     * @throws SQLException
     */
    @Override
    public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnLabel
     * @param reader
     * @param length
     * @throws SQLException
     */
    @Override
    public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnIndex
     * @param x
     * @param length
     * @throws SQLException
     */
    @Override
    public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnIndex
     * @param x
     * @param length
     * @throws SQLException
     */
    @Override
    public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnIndex
     * @param x
     * @param length
     * @throws SQLException
     */
    @Override
    public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnLabel
     * @param x
     * @param length
     * @throws SQLException
     */
    @Override
    public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnLabel
     * @param x
     * @param length
     * @throws SQLException
     */
    @Override
    public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnLabel
     * @param reader
     * @param length
     * @throws SQLException
     */
    @Override
    public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnIndex
     * @param inputStream
     * @param length
     * @throws SQLException
     */
    @Override
    public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnLabel
     * @param inputStream
     * @param length
     * @throws SQLException
     */
    @Override
    public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnIndex
     * @param reader
     * @param length
     * @throws SQLException
     */
    @Override
    public void updateClob(int columnIndex, Reader reader, long length) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnLabel
     * @param reader
     * @param length
     * @throws SQLException
     */
    @Override
    public void updateClob(String columnLabel, Reader reader, long length) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnIndex
     * @param reader
     * @param length
     * @throws SQLException
     */
    @Override
    public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnLabel
     * @param reader
     * @param length
     * @throws SQLException
     */
    @Override
    public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnIndex
     * @param x
     * @throws SQLException
     */
    @Override
    public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnLabel
     * @param reader
     * @throws SQLException
     */
    @Override
    public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnIndex
     * @param x
     * @throws SQLException
     */
    @Override
    public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnIndex
     * @param x
     * @throws SQLException
     */
    @Override
    public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnIndex
     * @param x
     * @throws SQLException
     */
    @Override
    public void updateCharacterStream(int columnIndex, Reader x) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnLabel
     * @param x
     * @throws SQLException
     */
    @Override
    public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnLabel
     * @param x
     * @throws SQLException
     */
    @Override
    public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnLabel
     * @param reader
     * @throws SQLException
     */
    @Override
    public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnIndex
     * @param inputStream
     * @throws SQLException
     */
    @Override
    public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnLabel
     * @param inputStream
     * @throws SQLException
     */
    @Override
    public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnIndex
     * @param reader
     * @throws SQLException
     */
    @Override
    public void updateClob(int columnIndex, Reader reader) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnLabel
     * @param reader
     * @throws SQLException
     */
    @Override
    public void updateClob(String columnLabel, Reader reader) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnIndex
     * @param reader
     * @throws SQLException
     */
    @Override
    public void updateNClob(int columnIndex, Reader reader) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param columnLabel
     * @param reader
     * @throws SQLException
     */
    @Override
    public void updateNClob(String columnLabel, Reader reader) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param <T>
     * @param iface
     * @return
     * @throws SQLException
     */
    @Override
    public <T> T unwrap(Class<T> iface) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     *
     * @param iface
     * @return
     * @throws SQLException
     */
    @Override
    public boolean isWrapperFor(Class<?> iface) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}
