com.ricebridge.csvman
Class CsvResultSet

java.lang.Object
  extended bycom.ricebridge.csvman.CsvResultSet
All Implemented Interfaces:
ResultSet

public class CsvResultSet
extends Object
implements ResultSet

Implementation of a ResultSet to present CSV data.

This ResultSet provides much the same interface as a database ResultSet. This implementation assumes that your data is fairly well behaved and attempts direct data type conversions for methods like getInt(java.lang.String). Bad data will cause an exception to be thrown. Refer to ResultSet for method documentation if none is given here.

The Source Code of this Java class is available under a BSD-style license.


Field Summary
protected  CsvResultSetMetaData iCsvRSMD
          ResultSetMetaData provider
protected  ArrayList iData
          Data as a List of String[] arrays.
protected  DateFormat iDateFormat
          Default data format for date parsing.
protected  String[] iLine
          Current line of data.
protected  long iLineIndex
          index of current line.
 
Fields inherited from interface java.sql.ResultSet
CLOSE_CURSORS_AT_COMMIT, CONCUR_READ_ONLY, CONCUR_UPDATABLE, FETCH_FORWARD, FETCH_REVERSE, FETCH_UNKNOWN, HOLD_CURSORS_OVER_COMMIT, TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE, TYPE_SCROLL_SENSITIVE
 
Constructor Summary
CsvResultSet()
          Create a new empty ResultSet.
CsvResultSet(ArrayList pData, boolean pHasHeaders, int pExpectedNumFields)
          Create a new ResultSet from CSV data.
 
Method Summary
 boolean absolute(int pRow)
          As per ResultSet.absolute(int).
 void afterLast()
          As per ResultSet.afterLast().
 void beforeFirst()
          As per ResultSet.beforeFirst().
 void cancelRowUpdates()
          No action — see ResultSet.cancelRowUpdates().
 void clearWarnings()
          No action — see ResultSet.clearWarnings().
 void close()
          No action — see ResultSet.close().
 void deleteRow()
          No action — see ResultSet.deleteRow().
 int findColumn(String pColumnName)
          As per ResultSet.findColumn(java.lang.String).
 boolean first()
          As per ResultSet.first().
 Array getArray(int pIndex)
          Not supported.
 Array getArray(String pColName)
          Not supported.
 InputStream getAsciiStream(int pColumnIndex)
          As per ResultSet.getAsciiStream(int).
 InputStream getAsciiStream(String pColumnName)
          As per ResultSet.getAsciiStream(int).
 BigDecimal getBigDecimal(int pColumnIndex)
          As per ResultSet.getBigDecimal(int).
 BigDecimal getBigDecimal(int pColumnIndex, int pScale)
          As per ResultSet.getBigDecimal(int).
 BigDecimal getBigDecimal(String pColumnName)
          As per ResultSet.getBigDecimal(int).
 BigDecimal getBigDecimal(String pColumnName, int pScale)
          As per ResultSet.getBigDecimal(int).
 InputStream getBinaryStream(int pColumnIndex)
          As per ResultSet.getBinaryStream(int).
 InputStream getBinaryStream(String pColumnName)
          As per ResultSet.getBinaryStream(int).
 Blob getBlob(int pIndex)
          Not supported.
 Blob getBlob(String pColName)
          Not supported.
 boolean getBoolean(int pColumnIndex)
          As per ResultSet.getBoolean(int).
 boolean getBoolean(String pColumnName)
          As per ResultSet.getBoolean(int).
 byte getByte(int pColumnIndex)
          As per ResultSet.getByte(int).
 byte getByte(String pColumnName)
          As per ResultSet.getByte(int).
 byte[] getBytes(int pColumnIndex)
          As per ResultSet.getBytes(int).
 byte[] getBytes(String pColumnName)
          As per ResultSet.getBytes(int).
 Reader getCharacterStream(int pColumnIndex)
          As per ResultSet.getCharacterStream(int).
 Reader getCharacterStream(String pColumnName)
          As per ResultSet.getCharacterStream(int).
 Clob getClob(int pIndex)
          Not supported.
 Clob getClob(String pColName)
          Not supported.
 int getConcurrency()
          No action — see ResultSet.getConcurrency().
 String getCursorName()
          No action — see ResultSet.getCursorName().
 Date getDate(int pColumnIndex)
          As per ResultSet.getDate(int).
 Date getDate(int pColumnIndex, Calendar pCalendar)
          As per ResultSet.getDate(int).
 Date getDate(String pColumnName)
          As per ResultSet.getDate(int).
 Date getDate(String pColumnName, Calendar pCalendar)
          As per ResultSet.getDate(int).
 double getDouble(int pColumnIndex)
          As per ResultSet.getDouble(int).
 double getDouble(String pColumnName)
          As per ResultSet.getDouble(int).
 int getFetchDirection()
          No action — see ResultSet.getFetchDirection().
 int getFetchSize()
          No action — see ResultSet.getFetchSize().
 float getFloat(int pColumnIndex)
          As per ResultSet.getFloat(int).
 float getFloat(String pColumnName)
          As per ResultSet.getFloat(int).
 int getInt(int pColumnIndex)
          As per ResultSet.getInt(int).
 int getInt(String pColumnName)
          As per ResultSet.getInt(int).
 long getLong(int pColumnIndex)
          As per ResultSet.getLong(int).
 long getLong(String pColumnName)
          As per ResultSet.getLong(int).
 ResultSetMetaData getMetaData()
          As per ResultSet.getMetaData().
 Object getObject(int pColumnIndex)
          As per ResultSet.getObject(int).
 Object getObject(int pIndex, Map pMap)
          Not supported.
 Object getObject(String pColumnName)
          As per ResultSet.getObject(int).
 Object getObject(String pColName, Map pMap)
          Not supported.
 Ref getRef(int pIndex)
          Not supported.
 Ref getRef(String pColName)
          Not supported.
 int getRow()
          As per ResultSet.getRow().
 short getShort(int pColumnIndex)
          As per ResultSet.getShort(int).
 short getShort(String pColumnName)
          As per ResultSet.getShort(int).
 Statement getStatement()
          Not supported.
 String getString(int pColumnIndex)
          As per ResultSet.getString(int).
 String getString(String pColumnName)
          As per ResultSet.getString(int).
 Time getTime(int pColumnIndex)
          As per ResultSet.getTime(int).
 Time getTime(int pColumnIndex, Calendar pCalendar)
          As per ResultSet.getTime(int).
 Time getTime(String pColumnName)
          As per ResultSet.getTime(int).
 Time getTime(String pColumnName, Calendar pCalendar)
          As per ResultSet.getTime(int).
 Timestamp getTimestamp(int pColumnIndex)
          As per ResultSet.getTimestamp(int).
 Timestamp getTimestamp(int pColumnIndex, Calendar pCalendar)
          As per ResultSet.getTimestamp(int).
 Timestamp getTimestamp(String pColumnName)
          As per ResultSet.getTimestamp(int).
 Timestamp getTimestamp(String pColumnName, Calendar pCalendar)
          As per ResultSet.getTimestamp(int).
 int getType()
          No action — see ResultSet.getType().
 InputStream getUnicodeStream(int pColumnIndex)
          As per ResultSet.getUnicodeStream(int).
 InputStream getUnicodeStream(String pColumnName)
          As per ResultSet.getUnicodeStream(int).
 URL getURL(int pColumnIndex)
          As per ResultSet.getURL(int).
 URL getURL(String pColumnName)
          As per ResultSet.getURL(int).
 SQLWarning getWarnings()
          No action — see ResultSet.getWarnings().
 void insertRow()
          No action — see ResultSet.insertRow().
 boolean isAfterLast()
          As per ResultSet.isAfterLast().
 boolean isBeforeFirst()
          As per ResultSet.isBeforeFirst().
 boolean isFirst()
          As per ResultSet.isFirst().
 boolean isLast()
          As per ResultSet.isLast().
 boolean last()
          As per ResultSet.last().
 void moveToCurrentRow()
          No action — see ResultSet.moveToCurrentRow().
 void moveToInsertRow()
          No action — see ResultSet.moveToInsertRow().
protected  boolean moveToLine()
          Move to correct data line.
 boolean next()
          As per ResultSet.next().
 boolean previous()
          As per ResultSet.previous().
 void refreshRow()
          No action — see ResultSet.refreshRow().
 boolean relative(int pRows)
          As per ResultSet.relative(int).
 boolean rowDeleted()
          No action — see ResultSet.rowDeleted().
 boolean rowInserted()
          No action — see ResultSet.rowInserted().
 boolean rowUpdated()
          No action — see ResultSet.rowUpdated().
 void setData(ArrayList pData, boolean pHasHeaders, int pExpectedNumFields)
          Set data for ResultSet.
 void setDateFormat(DateFormat pDateFormat)
          Specify custom date format.
 void setFetchDirection(int pDirection)
          No action — see ResultSet.setFetchDirection(int).
 void setFetchSize(int pRows)
          No action — see ResultSet.setFetchSize(int).
 void updateArray(int pColumnIndex, Array pArray)
          No action — see ResultSet.updateArray(int, java.sql.Array).
 void updateArray(String pColumnName, Array pArray)
          No action — see ResultSet.updateArray(int, java.sql.Array).
 void updateAsciiStream(int pColumnIndex, InputStream pInputStream, int pLength)
          No action — see ResultSet.updateAsciiStream(int, java.io.InputStream, int).
 void updateAsciiStream(String pColumnName, InputStream pInputStream, int pLength)
          No action — see ResultSet.updateAsciiStream(int, java.io.InputStream, int).
 void updateBigDecimal(int pColumnIndex, BigDecimal pBigDecimal)
          No action — see ResultSet.updateBigDecimal(int, java.math.BigDecimal).
 void updateBigDecimal(String pColumnName, BigDecimal pBigDecimal)
          No action — see ResultSet.updateBigDecimal(int, java.math.BigDecimal).
 void updateBinaryStream(int pColumnIndex, InputStream pInputStream, int pLength)
          No action — see ResultSet.updateBinaryStream(int, java.io.InputStream, int).
 void updateBinaryStream(String pColumnName, InputStream pInputStream, int pLength)
          No action — see ResultSet.updateBinaryStream(int, java.io.InputStream, int).
 void updateBlob(int pColumnIndex, Blob pBlob)
          No action — see ResultSet.updateBlob(int, java.sql.Blob).
 void updateBlob(String pColumnName, Blob pBlob)
          No action — see ResultSet.updateBlob(int, java.sql.Blob).
 void updateBoolean(int pColumnIndex, boolean pValue)
          No action — see ResultSet.updateBoolean(int, boolean).
 void updateBoolean(String pColumnName, boolean pValue)
          No action — see ResultSet.updateBoolean(int, boolean).
 void updateByte(int pColumnIndex, byte pValue)
          No action — see ResultSet.updateByte(int, byte).
 void updateByte(String pColumnName, byte pValue)
          No action — see ResultSet.updateByte(int, byte).
 void updateBytes(int pColumnIndex, byte[] pBytes)
          No action — see ResultSet.updateBytes(int, byte[]).
 void updateBytes(String pColumnName, byte[] pBytes)
          No action — see ResultSet.updateBytes(int, byte[]).
 void updateCharacterStream(int pColumnIndex, Reader pReader, int pLength)
          No action — see ResultSet.updateCharacterStream(int, java.io.Reader, int).
 void updateCharacterStream(String pColumnName, Reader pReader, int pLength)
          No action — see ResultSet.updateCharacterStream(int, java.io.Reader, int).
 void updateClob(int pColumnIndex, Clob pValue)
          No action — see ResultSet.updateClob(int, java.sql.Clob).
 void updateClob(String pColumnName, Clob pValue)
          No action — see ResultSet.updateClob(int, java.sql.Clob).
 void updateDate(int pColumnIndex, Date pValue)
          No action — see ResultSet.updateDate(int, java.sql.Date).
 void updateDate(String pColumnName, Date pValue)
          No action — see ResultSet.updateDate(int, java.sql.Date).
 void updateDouble(int pColumnIndex, double pValue)
          No action — see ResultSet.updateDouble(int, double).
 void updateDouble(String pColumnName, double pValue)
          No action — see ResultSet.updateDouble(int, double).
 void updateFloat(int pColumnIndex, float pValue)
          No action — see ResultSet.updateFloat(int, float).
 void updateFloat(String pColumnName, float pValue)
          No action — see ResultSet.updateFloat(int, float).
 void updateInt(int pColumnIndex, int pValue)
          No action — see ResultSet.updateInt(int, int).
 void updateInt(String pColumnName, int pValue)
          No action — see ResultSet.updateInt(int, int).
 void updateLong(int pColumnIndex, long pValue)
          No action — see ResultSet.updateLong(int, long).
 void updateLong(String pColumnName, long pValue)
          No action — see ResultSet.updateLong(int, long).
 void updateNull(int pColumnIndex)
          No action — see ResultSet.updateNull(int).
 void updateNull(String pColumnName)
          No action — see ResultSet.updateNull(int).
 void updateObject(int pColumnIndex, Object pValue)
          No action — see ResultSet.updateObject(int, java.lang.Object).
 void updateObject(int pColumnIndex, Object pValue, int pScale)
          No action — see ResultSet.updateObject(int, java.lang.Object).
 void updateObject(String pColumnName, Object pValue)
          No action — see ResultSet.updateObject(int, java.lang.Object).
 void updateObject(String pColumnName, Object pValue, int pScale)
          No action — see ResultSet.updateObject(int, java.lang.Object).
 void updateRef(int pColumnIndex, Ref pValue)
          No action — see ResultSet.updateRef(int, java.sql.Ref).
 void updateRef(String pColumnName, Ref pValue)
          No action — see ResultSet.updateRef(int, java.sql.Ref).
 void updateRow()
          No action — see ResultSet.updateRow().
 void updateShort(int pColumnIndex, short pValue)
          No action — see ResultSet.updateShort(int, short).
 void updateShort(String pColumnName, short pValue)
          No action — see ResultSet.updateShort(int, short).
 void updateString(int pColumnIndex, String pValue)
          No action — see ResultSet.updateString(int, java.lang.String).
 void updateString(String pColumnName, String pValue)
          No action — see ResultSet.updateString(int, java.lang.String).
 void updateTime(int pColumnIndex, Time pValue)
          No action — see ResultSet.updateTime(int, java.sql.Time).
 void updateTime(String pColumnName, Time pValue)
          No action — see ResultSet.updateTime(int, java.sql.Time).
 void updateTimestamp(int pColumnIndex, Timestamp pValue)
          No action — see ResultSet.updateTimestamp(int, java.sql.Timestamp).
 void updateTimestamp(String pColumnName, Timestamp pValue)
          No action — see ResultSet.updateTimestamp(int, java.sql.Timestamp).
 boolean wasNull()
          No action — see ResultSet.wasNull().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

iData

protected ArrayList iData
Data as a List of String[] arrays.


iLine

protected String[] iLine
Current line of data.


iLineIndex

protected long iLineIndex
index of current line.


iDateFormat

protected DateFormat iDateFormat
Default data format for date parsing.


iCsvRSMD

protected CsvResultSetMetaData iCsvRSMD
ResultSetMetaData provider

Constructor Detail

CsvResultSet

public CsvResultSet(ArrayList pData,
                    boolean pHasHeaders,
                    int pExpectedNumFields)
Create a new ResultSet from CSV data.

When pHasHeaders is true, the first line of data is used as the names of the columns and getMetaData() will return these column names.

When pHasHeaders is false, default names of the form Column X are generated.

Parameters:
pData - List of String[]
pHasHeaders - first row is headers

CsvResultSet

public CsvResultSet()
Create a new empty ResultSet.

Initialise with setData(java.util.ArrayList, boolean, int)

Method Detail

getArray

public Array getArray(String pColName)
               throws SQLException
Not supported.

Specified by:
getArray in interface ResultSet
Throws:
SQLException

getArray

public Array getArray(int pIndex)
               throws SQLException
Not supported.

Specified by:
getArray in interface ResultSet
Throws:
SQLException

getBlob

public Blob getBlob(String pColName)
             throws SQLException
Not supported.

Specified by:
getBlob in interface ResultSet
Throws:
SQLException

getBlob

public Blob getBlob(int pIndex)
             throws SQLException
Not supported.

Specified by:
getBlob in interface ResultSet
Throws:
SQLException

getClob

public Clob getClob(String pColName)
             throws SQLException
Not supported.

Specified by:
getClob in interface ResultSet
Throws:
SQLException

getClob

public Clob getClob(int pIndex)
             throws SQLException
Not supported.

Specified by:
getClob in interface ResultSet
Throws:
SQLException

getObject

public Object getObject(String pColName,
                        Map pMap)
                 throws SQLException
Not supported.

Specified by:
getObject in interface ResultSet
Throws:
SQLException

getObject

public Object getObject(int pIndex,
                        Map pMap)
                 throws SQLException
Not supported.

Specified by:
getObject in interface ResultSet
Throws:
SQLException

getRef

public Ref getRef(String pColName)
           throws SQLException
Not supported.

Specified by:
getRef in interface ResultSet
Throws:
SQLException

getRef

public Ref getRef(int pIndex)
           throws SQLException
Not supported.

Specified by:
getRef in interface ResultSet
Throws:
SQLException

getStatement

public Statement getStatement()
                       throws SQLException
Not supported.

Specified by:
getStatement in interface ResultSet
Throws:
SQLException

getWarnings

public SQLWarning getWarnings()
                       throws SQLException
No action — see ResultSet.getWarnings().

Specified by:
getWarnings in interface ResultSet
Throws:
SQLException

getCursorName

public String getCursorName()
                     throws SQLException
No action — see ResultSet.getCursorName().

Specified by:
getCursorName in interface ResultSet
Throws:
SQLException

rowDeleted

public boolean rowDeleted()
                   throws SQLException
No action — see ResultSet.rowDeleted().

Specified by:
rowDeleted in interface ResultSet
Throws:
SQLException

rowInserted

public boolean rowInserted()
                    throws SQLException
No action — see ResultSet.rowInserted().

Specified by:
rowInserted in interface ResultSet
Throws:
SQLException

rowUpdated

public boolean rowUpdated()
                   throws SQLException
No action — see ResultSet.rowUpdated().

Specified by:
rowUpdated in interface ResultSet
Throws:
SQLException

wasNull

public boolean wasNull()
                throws SQLException
No action — see