package com.ricebridge.csvman;
import org.jostraca.util.Internal;
import java.sql.*;
import java.io.InputStream;
import java.io.Reader;
import java.net.URL;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.util.Map;
import java.util.Calendar;
import java.util.ArrayList;
public class CsvResultSet implements ResultSet {
public Array
getArray( String pColName ) throws SQLException { throw new UnsupportedOperationException(); }
public Array
getArray( int pIndex ) throws SQLException { throw new UnsupportedOperationException(); }
public Blob
getBlob( String pColName ) throws SQLException { throw new UnsupportedOperationException(); }
public Blob
getBlob( int pIndex ) throws SQLException { throw new UnsupportedOperationException(); }
public Clob
getClob( String pColName ) throws SQLException { throw new UnsupportedOperationException(); }
public Clob
getClob( int pIndex ) throws SQLException { throw new UnsupportedOperationException(); }
public Object
getObject( String pColName, Map pMap ) throws SQLException { throw new UnsupportedOperationException(); }
public Object
getObject( int pIndex, Map pMap ) throws SQLException { throw new UnsupportedOperationException(); }
public Ref
getRef( String pColName ) throws SQLException { throw new UnsupportedOperationException(); }
public Ref
getRef( int pIndex ) throws SQLException { throw new UnsupportedOperationException(); }
public Statement
getStatement() throws SQLException { throw new UnsupportedOperationException(); }
public SQLWarning
getWarnings() throws SQLException { return null; }
public String
getCursorName() throws SQLException { return ""; }
public boolean
rowDeleted( ) throws SQLException { return false; }
public boolean
rowInserted( ) throws SQLException { return false; }
public boolean
rowUpdated( ) throws SQLException { return false; }
public boolean
wasNull( ) throws SQLException { return false; }
public int
getFetchDirection( ) throws SQLException { return FETCH_FORWARD; }
public void
setFetchDirection( int pDirection ) throws SQLException { }
public int
getFetchSize( ) throws SQLException { return 0; }
public void
setFetchSize( int pRows ) throws SQLException { }
public int
getConcurrency( ) throws SQLException { return CONCUR_READ_ONLY; }
public int
getType( ) throws SQLException { return TYPE_FORWARD_ONLY; }
public void
cancelRowUpdates( ) throws SQLException {}
public void
clearWarnings( ) throws SQLException {}
public void
close( ) throws SQLException {}
public void
deleteRow( ) throws SQLException {}
public void
insertRow( ) throws SQLException {}
public void
moveToCurrentRow( ) throws SQLException {}
public void
moveToInsertRow( ) throws SQLException {}
public void
refreshRow( ) throws SQLException {}
public void
updateArray( String pColumnName, Array pArray ) throws SQLException {}
public void
updateArray( int pColumnIndex, Array pArray ) throws SQLException {}
public void
updateAsciiStream( String pColumnName, InputStream pInputStream, int pLength ) throws SQLException {}
public void
updateAsciiStream( int pColumnIndex, InputStream pInputStream, int pLength ) throws SQLException {}
public void
updateBigDecimal( String pColumnName, BigDecimal pBigDecimal ) throws SQLException {}
public void
updateBigDecimal( int pColumnIndex, BigDecimal pBigDecimal ) throws SQLException {}
public void
updateBinaryStream( String pColumnName, InputStream pInputStream, int pLength ) throws SQLException {}
public void
updateBinaryStream( int pColumnIndex, InputStream pInputStream, int pLength ) throws SQLException {}
public void
updateBlob( String pColumnName, Blob pBlob ) throws SQLException {}
public void
updateBlob( int pColumnIndex, Blob pBlob ) throws SQLException {}
public void
updateBoolean( String pColumnName, boolean pValue ) throws SQLException {}
public void
updateBoolean( int pColumnIndex, boolean pValue ) throws SQLException {}
public void
updateByte( String pColumnName, byte pValue ) throws SQLException {}
public void
updateByte( int pColumnIndex, byte pValue ) throws SQLException {}
public void
updateBytes( String pColumnName, byte pBytes[] ) throws SQLException {}
public void
updateBytes( int pColumnIndex, byte pBytes[] ) throws SQLException {}
public void
updateCharacterStream( String pColumnName, Reader pReader, int pLength ) throws SQLException {}
public void
updateCharacterStream( int pColumnIndex, Reader pReader, int pLength ) throws SQLException {}
public void
updateClob( String pColumnName, Clob pValue ) throws SQLException {}
public void
updateClob( int pColumnIndex, Clob pValue ) throws SQLException {}
public void
updateDate( String pColumnName, Date pValue ) throws SQLException {}
public void
updateDate( int pColumnIndex, Date pValue ) throws SQLException {}
public void
updateDouble( String pColumnName, double pValue ) throws SQLException {}
public void
updateDouble( int pColumnIndex, double pValue ) throws SQLException {}
public void
updateFloat( String pColumnName, float pValue ) throws SQLException {}
public void
updateFloat( int pColumnIndex, float pValue ) throws SQLException {}
public void
updateInt( String pColumnName, int pValue ) throws SQLException {}
public void
updateInt( int pColumnIndex, int pValue ) throws SQLException {}
public void
updateLong( String pColumnName, long pValue ) throws SQLException {}
public void
updateLong( int pColumnIndex, long pValue ) throws SQLException {}
public void
updateNull( String pColumnName ) throws SQLException {}
public void
updateNull( int pColumnIndex ) throws SQLException {}
public void
updateObject( String pColumnName, Object pValue ) throws SQLException {}
public void
updateObject( String pColumnName, Object pValue, int pScale ) throws SQLException {}
public void
updateObject( int pColumnIndex, Object pValue ) throws SQLException {}
public void
updateObject( int pColumnIndex, Object pValue, int pScale ) throws SQLException {}
public void
updateRef( String pColumnName, Ref pValue ) throws SQLException {}
public void
updateRef( int pColumnIndex, Ref pValue ) throws SQLException {}
public void
updateRow( ) throws SQLException {}
public void
updateShort( String pColumnName, short pValue ) throws SQLException {}
public void
updateShort( int pColumnIndex, short pValue ) throws SQLException {}
public void
updateString( String pColumnName, String pValue ) throws SQLException {}
public void
updateString( int pColumnIndex, String pValue ) throws SQLException {}
public void
updateTime( String pColumnName, Time pValue ) throws SQLException {}
public void
updateTime( int pColumnIndex, Time pValue ) throws SQLException {}
public void
updateTimestamp( String pColumnName, Timestamp pValue ) throws SQLException {}
public void
updateTimestamp( int pColumnIndex, Timestamp pValue ) throws SQLException {}
protected ArrayList iData = new ArrayList();
protected String[] iLine = null;
protected long iLineIndex = -1;
protected DateFormat iDateFormat = DateFormat.getDateInstance();
protected CsvResultSetMetaData iCsvRSMD = null;
public CsvResultSet( ArrayList pData, boolean pHasHeaders, int pExpectedNumFields ) {
setData( pData, pHasHeaders, pExpectedNumFields );
}
public CsvResultSet() {
}
public void setData( ArrayList pData, boolean pHasHeaders, int pExpectedNumFields ) {
iData = (ArrayList) Internal.null_arg( pData );
if( 0 < iData.size() ) {
if( pHasHeaders ) {
iCsvRSMD = new CsvResultSetMetaData( (String[]) iData.get(0) );
iData.remove(0);
}
else {
int numfields = ((String[]) iData.get(0)).length;
iCsvRSMD = new CsvResultSetMetaData( new String[ numfields ] );
}
}
else {
iCsvRSMD = new CsvResultSetMetaData( new String[pExpectedNumFields] );
}
}
public ResultSetMetaData getMetaData( ) throws SQLException {
return iCsvRSMD;
}
public int findColumn( String pColumnName ) throws SQLException {
return iCsvRSMD.findColumn( pColumnName );
}
public boolean absolute( int pRow ) throws SQLException {
if( pRow > -1 ) {
iLineIndex = pRow - 1;
}
else {
iLineIndex = iData.size() + pRow;
}
return moveToLine();
}
public boolean first( ) throws SQLException {
return absolute(0);
}
public boolean last( ) throws SQLException {
return absolute(-1);
}
public boolean isAfterLast( ) throws SQLException {
return iLineIndex >= iData.size();
}
public boolean isBeforeFirst( ) throws SQLException {
return iLineIndex <= -1;
}
public boolean isFirst( ) throws SQLException {
return 0 == iLineIndex;
}
public boolean isLast( ) throws SQLException {
return iData.size() - 1 == iLineIndex;
}
public boolean next( ) throws SQLException {
return relative(1);
}
public boolean previous( ) throws SQLException {
return relative(-1);
}
public boolean relative( int pRows ) throws SQLException {
iLineIndex += pRows;
return moveToLine();
}
public int getRow( ) throws SQLException {
return (int) iLineIndex+1;
}
public void afterLast( ) throws SQLException {
iLineIndex = iData.size();
}
public void beforeFirst( ) throws SQLException {
iLineIndex = -1;
}
public BigDecimal getBigDecimal( String pColumnName ) throws SQLException {
return getBigDecimal( findColumn(pColumnName) );
}
public BigDecimal getBigDecimal( String pColumnName, int pScale ) throws SQLException {
return getBigDecimal( findColumn(pColumnName), pScale );
}
public BigDecimal getBigDecimal( int pColumnIndex ) throws SQLException {
return new BigDecimal( iLine[pColumnIndex-1] );
}
public BigDecimal getBigDecimal( int pColumnIndex, int pScale ) throws SQLException {
return new BigDecimal( iLine[pColumnIndex-1] ).setScale( pScale );
}
public Object getObject( String pColumnName ) throws SQLException {
return getObject(findColumn(pColumnName));
}
public Object getObject( int pColumnIndex ) throws SQLException {
return iLine[pColumnIndex-1];
}
public String getString( String pColumnName ) throws SQLException {
return getString(findColumn(pColumnName));
}
public String getString( int pColumnIndex ) throws SQLException {
return iLine[pColumnIndex-1];
}
public boolean getBoolean( String pColumnName ) throws SQLException {
return getBoolean( findColumn(pColumnName ) );
}
public boolean getBoolean( int pColumnIndex ) throws SQLException {
return new Boolean( iLine[pColumnIndex-1] ).booleanValue();
}
public byte getByte( String pColumnName ) throws SQLException {
return getByte( findColumn(pColumnName) );
}
public byte getByte( int pColumnIndex ) throws SQLException {
return iLine[pColumnIndex-1].getBytes()[0];
}
public byte[] getBytes( String pColumnName ) throws SQLException {
return getBytes(findColumn(pColumnName));
}
public byte[] getBytes( int pColumnIndex ) throws SQLException {
return iLine[pColumnIndex-1].getBytes();
}
public double getDouble( String pColumnName ) throws SQLException {
return getDouble(findColumn(pColumnName));
}
public double getDouble( int pColumnIndex ) throws SQLException {
return Double.parseDouble(iLine[pColumnIndex-1]);
}
public float getFloat( String pColumnName ) throws SQLException {
return getFloat(findColumn(pColumnName));
}
public float getFloat( int pColumnIndex ) throws SQLException {
return Float.parseFloat(iLine[pColumnIndex-1]);
}
public int getInt( String pColumnName ) throws SQLException {
return getInt(findColumn(pColumnName));
}
public int getInt( int pColumnIndex ) throws SQLException {
return Integer.parseInt(iLine[pColumnIndex-1]);
}
public InputStream getAsciiStream( String pColumnName ) throws SQLException {
return null;
}
public InputStream getAsciiStream( int pColumnIndex ) throws SQLException {
return null;
}
public InputStream getBinaryStream( String pColumnName ) throws SQLException {
return null;
}
public InputStream getBinaryStream( int pColumnIndex ) throws SQLException {
return null;
}
public InputStream getUnicodeStream( String pColumnName ) throws SQLException {
return null;
}
public InputStream getUnicodeStream( int pColumnIndex ) throws SQLException {
return null;
}
public Reader getCharacterStream( String pColumnName ) throws SQLException {
return null;
}
public Reader getCharacterStream( int pColumnIndex ) throws SQLException {
return null;
}
public URL getURL( String pColumnName ) throws SQLException {
return getURL( findColumn(pColumnName) );
}
public URL getURL( int pColumnIndex ) throws SQLException {
try {
return new URL( iLine[pColumnIndex-1] );
}
catch( Exception e ) {
throw new SQLException( e.getMessage() );
}
}
public Date getDate( String pColumnName ) throws SQLException {
return getDate( findColumn(pColumnName) );
}
public Date getDate( String pColumnName, Calendar pCalendar ) throws SQLException {
return getDate( findColumn(pColumnName), pCalendar );
}
public Date getDate( int pColumnIndex ) throws SQLException {
return getDate( pColumnIndex, null );
}
public Date getDate( int pColumnIndex, Calendar pCalendar ) throws SQLException {
try {
java.util.Date d = iDateFormat.parse( iLine[pColumnIndex-1] );
return new Date( d.getTime() );
}
catch( Exception e ) {
throw new SQLException( e.getMessage() );
}
}
public Time getTime( String pColumnName ) throws SQLException {
return getTime(findColumn(pColumnName));
}
public Time getTime( String pColumnName, Calendar pCalendar ) throws SQLException {
return getTime(findColumn(pColumnName), null );
}
public Time getTime( int pColumnIndex ) throws SQLException {
return getTime( pColumnIndex, null );
}
public Time getTime( int pColumnIndex, Calendar pCalendar ) throws SQLException {
return new Time( getLong(pColumnIndex) );
}
public Timestamp getTimestamp( String pColumnName ) throws SQLException {
return getTimestamp(findColumn(pColumnName));
}
public Timestamp getTimestamp( String pColumnName, Calendar pCalendar ) throws SQLException {
return getTimestamp(findColumn(pColumnName),null);
}
public Timestamp getTimestamp( int pColumnIndex ) throws SQLException {
return getTimestamp(pColumnIndex,null);
}
public Timestamp getTimestamp( int pColumnIndex, Calendar pCalendar ) throws SQLException {
try {
java.util.Date d = iDateFormat.parse( iLine[pColumnIndex-1] );
return new Timestamp( d.getTime() );
}
catch( Exception e ) {
throw new SQLException( e.getMessage() );
}
}
public long getLong( String pColumnName ) throws SQLException {
return getLong(findColumn(pColumnName));
}
public long getLong( int pColumnIndex ) throws SQLException {
return Long.parseLong( iLine[pColumnIndex-1] );
}
public short getShort( String pColumnName ) throws SQLException {
return getShort(findColumn(pColumnName));
}
public short getShort( int pColumnIndex ) throws SQLException {
return Short.parseShort( iLine[pColumnIndex-1] );
}
public void setDateFormat( DateFormat pDateFormat ) {
iDateFormat = (DateFormat) Internal.null_arg( pDateFormat );
}
protected boolean moveToLine() {
boolean inside = -1 < iLineIndex && iLineIndex < iData.size();
if( inside ) {
iLine = (String[]) iData.get( (int) iLineIndex );
}
return inside;
}
}