Package net.sourceforge.jtds.jdbc
Class MSCursorResultSet
java.lang.Object
net.sourceforge.jtds.jdbc.JtdsResultSet
net.sourceforge.jtds.jdbc.MSCursorResultSet
- All Implemented Interfaces:
AutoCloseable,ResultSet,Wrapper
This class extends the JtdsResultSet to support scrollable and or
updateable cursors on Microsoft servers.
The undocumented Microsoft sp_cursor procedures are used.
Implementation notes:
- All of Alin's cursor result set logic is incorporated here.
- This logic was originally implemented in the JtdsResultSet class but on reflection it seems that Alin's original approch of having a dedicated cursor class leads to a more flexible and maintainable design.
- Version:
- $Id: MSCursorResultSet.java,v 1.59 2007-07-11 20:02:45 bheineman Exp $
- Author:
- Alin Sinpalean, Mike Hutchinson
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanThe cursor is being built asynchronously.private static final intprivate static final intprivate static final intprivate static final intprivate static final Integerprivate static final Integerprivate static final Integerprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate intActual position of the cursor.private static final Integerprivate static final Integerprivate static final Integerprivate static final Integerprivate static final Integerprivate static final Integerprivate static final Integerprivate static final Integerprivate ParamInfo[]The "insert row".private booleanSet whenmoveToInsertRow()was called.private final ParamInfoCursor handle parameter.private final ParamInfosp_cursorfetchfetchtype parameter.private final ParamInfosp_cursorfetchnumrows IN parameter (for actual fetches).private final ParamInfosp_cursorfetchnumrows OUT parameter (for FETCH_INFO).private final ParamInfosp_cursoroptype parameter.private final ParamInfosp_cursorrownum parameter.private final ParamInfosp_cursorfetchrownum IN parameter (for actual fetches).private final ParamInfosp_cursorfetchrownum OUT parameter (for FETCH_INFO).private final ParamInfosp_cursortable parameter.private Object[][]The row cache used insteadJtdsResultSet.currentRow.private static final IntegerThe row has been deleted.private static final IntegerThe row is dirty and needs to be reloaded (internal state).private static final IntegerThe row is valid.private ParamInfo[]The "update row".Fields inherited from class net.sourceforge.jtds.jdbc.JtdsResultSet
cancelled, CLOSE_CURSORS_AT_COMMIT, closed, columnCount, columns, concurrency, currentRow, cursorName, direction, fetchDirection, fetchSize, HOLD_CURSORS_OVER_COMMIT, INITIAL_ROW_COUNT, pos, POS_AFTER_LAST, POS_BEFORE_FIRST, resultSetType, rowData, rowPtr, rowsInResult, statement, wasNullFields inherited from interface java.sql.ResultSet
CONCUR_READ_ONLY, CONCUR_UPDATABLE, FETCH_FORWARD, FETCH_REVERSE, FETCH_UNKNOWN, TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE, TYPE_SCROLL_SENSITIVE -
Constructor Summary
ConstructorsConstructorDescriptionMSCursorResultSet(JtdsStatement statement, String sql, String procName, ParamInfo[] procedureParams, int resultSetType, int concurrency) Construct a cursor result set using Microsoft sp_cursorcreate etc. -
Method Summary
Modifier and TypeMethodDescriptionbooleanabsolute(int row) voidvoidvoidvoidclose()private voidSupport general cursor operations such as delete, update etc.private voidClose a server side cursor.private voidcursorCreate(String sql, String procName, ParamInfo[] parameters) Create a new Cursor result set using the internal sp_cursoropen procedure.private booleancursorFetch(Integer fetchType, int rowNum) Fetch the next result row from a cursor using the internal sp_cursorfetch procedure.voidbooleanfirst()protected ObjectgetColumn(int index) Get the specified column's data item.protected Object[]Retrieve the current row data.(package private) static intgetCursorConcurrencyOpt(int resultSetConcurrency) Translates a JDBC result set concurrency into SQL Server native @ccOpt value for use with stored procedures such as sp_cursoropen, sp_cursorprepare or sp_cursorprepexec.(package private) static intgetCursorScrollOpt(int resultSetType, int resultSetConcurrency, boolean parameterized) Translates a JDBC result set type into SQL Server native @scrollOpt value for use with stored procedures such as sp_cursoropen, sp_cursorprepare or sp_cursorprepexec.voidbooleanisLast()booleanlast()voidvoidbooleannext()booleanprevious()private voidprocessOutput(TdsCore tds, boolean setMeta) Processes the output of a cursor open or fetch operation.voidbooleanrelative(int row) booleanbooleanbooleanprotected ObjectsetColValue(int colIndex, int jdbcType, Object value, int length) Set the specified column's data value.voidMethods inherited from class net.sourceforge.jtds.jdbc.JtdsResultSet
cacheResultSetRows, checkOpen, checkScrollable, checkUpdateable, clearWarnings, copyInfo, copyRow, findColumn, getArray, getArray, getAsciiStream, getAsciiStream, getBigDecimal, getBigDecimal, getBigDecimal, getBigDecimal, getBinaryStream, getBinaryStream, getBlob, getBlob, getBoolean, getBoolean, getByte, getByte, getBytes, getBytes, getCharacterStream, getCharacterStream, getClob, getClob, getColumnCount, getColumns, getConcurrency, getCursorName, getDate, getDate, getDate, getDate, getDouble, getDouble, getFetchDirection, getFetchSize, getFloat, getFloat, getHoldability, getInt, getInt, getLong, getLong, getMetaData, getNCharacterStream, getNCharacterStream, getNClob, getNClob, getNString, getNString, getObject, getObject, getObject, getObject, getObject, getObject, getRef, getRef, getRow, getRowId, getRowId, getShort, getShort, getSQLXML, getSQLXML, getStatement, getString, getString, getTime, getTime, getTime, getTime, getTimestamp, getTimestamp, getTimestamp, getTimestamp, getType, getUnicodeStream, getUnicodeStream, getURL, getURL, getWarnings, isAfterLast, isBeforeFirst, isClosed, isFirst, isWrapperFor, newRow, notImplemented, setColLabel, setColName, setColType, setColumnCount, setFetchDirection, setFetchSize, unwrap, updateArray, updateArray, updateAsciiStream, updateAsciiStream, updateAsciiStream, updateAsciiStream, updateAsciiStream, updateAsciiStream, updateBigDecimal, updateBigDecimal, updateBinaryStream, updateBinaryStream, updateBinaryStream, updateBinaryStream, updateBinaryStream, updateBinaryStream, updateBlob, updateBlob, updateBlob, updateBlob, updateBlob, updateBlob, updateBoolean, updateBoolean, updateByte, updateByte, updateBytes, updateBytes, updateCharacterStream, updateCharacterStream, updateCharacterStream, updateCharacterStream, updateCharacterStream, updateCharacterStream, updateClob, updateClob, updateClob, updateClob, updateClob, updateClob, updateDate, updateDate, updateDouble, updateDouble, updateFloat, updateFloat, updateInt, updateInt, updateLong, updateLong, updateNCharacterStream, updateNCharacterStream, updateNCharacterStream, updateNCharacterStream, updateNClob, updateNClob, updateNClob, updateNClob, updateNClob, updateNClob, updateNString, updateNString, updateNull, updateNull, updateObject, updateObject, updateObject, updateObject, updateRef, updateRef, updateRowId, updateRowId, updateShort, updateShort, updateSQLXML, updateSQLXML, updateString, updateString, updateTime, updateTime, updateTimestamp, updateTimestamp, wasNullMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.sql.ResultSet
updateObject, updateObject, updateObject, updateObject
-
Field Details
-
FETCH_FIRST
-
FETCH_NEXT
-
FETCH_PREVIOUS
-
FETCH_LAST
-
FETCH_ABSOLUTE
-
FETCH_RELATIVE
-
FETCH_REPEAT
-
FETCH_INFO
-
CURSOR_TYPE_KEYSET
private static final int CURSOR_TYPE_KEYSET- See Also:
-
CURSOR_TYPE_DYNAMIC
private static final int CURSOR_TYPE_DYNAMIC- See Also:
-
CURSOR_TYPE_FORWARD
private static final int CURSOR_TYPE_FORWARD- See Also:
-
CURSOR_TYPE_STATIC
private static final int CURSOR_TYPE_STATIC- See Also:
-
CURSOR_TYPE_FASTFORWARDONLY
private static final int CURSOR_TYPE_FASTFORWARDONLY- See Also:
-
CURSOR_TYPE_PARAMETERIZED
private static final int CURSOR_TYPE_PARAMETERIZED- See Also:
-
CURSOR_TYPE_AUTO_FETCH
private static final int CURSOR_TYPE_AUTO_FETCH- See Also:
-
CURSOR_CONCUR_READ_ONLY
private static final int CURSOR_CONCUR_READ_ONLY- See Also:
-
CURSOR_CONCUR_SCROLL_LOCKS
private static final int CURSOR_CONCUR_SCROLL_LOCKS- See Also:
-
CURSOR_CONCUR_OPTIMISTIC
private static final int CURSOR_CONCUR_OPTIMISTIC- See Also:
-
CURSOR_CONCUR_OPTIMISTIC_VALUES
private static final int CURSOR_CONCUR_OPTIMISTIC_VALUES- See Also:
-
CURSOR_OP_INSERT
-
CURSOR_OP_UPDATE
-
CURSOR_OP_DELETE
-
SQL_ROW_DIRTY
The row is dirty and needs to be reloaded (internal state). -
SQL_ROW_SUCCESS
The row is valid. -
SQL_ROW_DELETED
The row has been deleted. -
onInsertRow
private boolean onInsertRowSet whenmoveToInsertRow()was called. -
insertRow
The "insert row". -
updateRow
The "update row". -
rowCache
The row cache used insteadJtdsResultSet.currentRow. -
cursorPos
private int cursorPosActual position of the cursor. -
asyncCursor
private boolean asyncCursorThe cursor is being built asynchronously. -
PARAM_CURSOR_HANDLE
Cursor handle parameter. -
PARAM_FETCHTYPE
sp_cursorfetchfetchtype parameter. -
PARAM_ROWNUM_IN
sp_cursorfetchrownum IN parameter (for actual fetches). -
PARAM_NUMROWS_IN
sp_cursorfetchnumrows IN parameter (for actual fetches). -
PARAM_ROWNUM_OUT
sp_cursorfetchrownum OUT parameter (for FETCH_INFO). -
PARAM_NUMROWS_OUT
sp_cursorfetchnumrows OUT parameter (for FETCH_INFO). -
PARAM_OPTYPE
sp_cursoroptype parameter. -
PARAM_ROWNUM
sp_cursorrownum parameter. -
PARAM_TABLE
sp_cursortable parameter.
-
-
Constructor Details
-
MSCursorResultSet
MSCursorResultSet(JtdsStatement statement, String sql, String procName, ParamInfo[] procedureParams, int resultSetType, int concurrency) throws SQLException Construct a cursor result set using Microsoft sp_cursorcreate etc.- Parameters:
statement- The parent statement object or null.resultSetType- one of FORWARD_ONLY, SCROLL_INSENSITIVE, SCROLL_SENSITIVE.concurrency- One of CONCUR_READ_ONLY, CONCUR_UPDATE.- Throws:
SQLException
-
-
Method Details
-
setColValue
protected Object setColValue(int colIndex, int jdbcType, Object value, int length) throws SQLException Set the specified column's data value.- Overrides:
setColValuein classJtdsResultSet- Parameters:
colIndex- index of the columnvalue- new column valuelength- the length of a stream parameter- Returns:
- the value, possibly converted to an internal type
- Throws:
SQLException
-
getColumn
Get the specified column's data item.- Overrides:
getColumnin classJtdsResultSet- Parameters:
index- the column index in the row- Returns:
- the column value as an
Object - Throws:
SQLException- if the index is out of bounds or there is no current row
-
getCursorScrollOpt
static int getCursorScrollOpt(int resultSetType, int resultSetConcurrency, boolean parameterized) Translates a JDBC result set type into SQL Server native @scrollOpt value for use with stored procedures such as sp_cursoropen, sp_cursorprepare or sp_cursorprepexec.- Parameters:
resultSetType- JDBC result set type (one of theResultSet.TYPE_XXXvalues)resultSetConcurrency- JDBC result set concurrency (one of theResultSet.CONCUR_XXXvalues)- Returns:
- a value for the @scrollOpt parameter
-
getCursorConcurrencyOpt
static int getCursorConcurrencyOpt(int resultSetConcurrency) Translates a JDBC result set concurrency into SQL Server native @ccOpt value for use with stored procedures such as sp_cursoropen, sp_cursorprepare or sp_cursorprepexec.- Parameters:
resultSetConcurrency- JDBC result set concurrency (one of theResultSet.CONCUR_XXXvalues)- Returns:
- a value for the @scrollOpt parameter
-
cursorCreate
Create a new Cursor result set using the internal sp_cursoropen procedure.- Parameters:
sql- The SQL SELECT statement.procName- Optional procedure name for cursors based on a stored procedure.parameters- Optional stored procedure parameters.- Throws:
SQLException
-
cursorFetch
Fetch the next result row from a cursor using the internal sp_cursorfetch procedure.- Parameters:
fetchType- The type of fetch eg FETCH_ABSOLUTE.rowNum- The row number to fetch.- Returns:
booleantrue if a result set row is returned.- Throws:
SQLException
-
cursor
Support general cursor operations such as delete, update etc.- Parameters:
opType- the type of operation to performrow- the row number to update- Throws:
SQLException
-
cursorClose
Close a server side cursor.- Throws:
SQLException
-
processOutput
Processes the output of a cursor open or fetch operation. Fetches a batch of rows from theTdsCore, loading them into the row cache and optionally sets the column meta data (if called on cursor open). Consumes all the response and checks for server returned errors.- Parameters:
tds- theTdsCoreinstancesetMeta- whether column meta data needs to be loaded (cursor open)- Throws:
SQLException- if an error occurs or an error message is returned by the server
-
afterLast
- Specified by:
afterLastin interfaceResultSet- Overrides:
afterLastin classJtdsResultSet- Throws:
SQLException
-
beforeFirst
- Specified by:
beforeFirstin interfaceResultSet- Overrides:
beforeFirstin classJtdsResultSet- Throws:
SQLException
-
cancelRowUpdates
- Specified by:
cancelRowUpdatesin interfaceResultSet- Overrides:
cancelRowUpdatesin classJtdsResultSet- Throws:
SQLException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceResultSet- Overrides:
closein classJtdsResultSet- Throws:
SQLException
-
deleteRow
- Specified by:
deleteRowin interfaceResultSet- Overrides:
deleteRowin classJtdsResultSet- Throws:
SQLException
-
insertRow
- Specified by:
insertRowin interfaceResultSet- Overrides:
insertRowin classJtdsResultSet- Throws:
SQLException
-
moveToCurrentRow
- Specified by:
moveToCurrentRowin interfaceResultSet- Overrides:
moveToCurrentRowin classJtdsResultSet- Throws:
SQLException
-
moveToInsertRow
- Specified by:
moveToInsertRowin interfaceResultSet- Overrides:
moveToInsertRowin classJtdsResultSet- Throws:
SQLException
-
refreshRow
- Specified by:
refreshRowin interfaceResultSet- Overrides:
refreshRowin classJtdsResultSet- Throws:
SQLException
-
updateRow
- Specified by:
updateRowin interfaceResultSet- Overrides:
updateRowin classJtdsResultSet- Throws:
SQLException
-
first
- Specified by:
firstin interfaceResultSet- Overrides:
firstin classJtdsResultSet- Throws:
SQLException
-
isLast
- Specified by:
isLastin interfaceResultSet- Overrides:
isLastin classJtdsResultSet- Throws:
SQLException
-
last
- Specified by:
lastin interfaceResultSet- Overrides:
lastin classJtdsResultSet- Throws:
SQLException
-
next
- Specified by:
nextin interfaceResultSet- Overrides:
nextin classJtdsResultSet- Throws:
SQLException
-
previous
- Specified by:
previousin interfaceResultSet- Overrides:
previousin classJtdsResultSet- Throws:
SQLException
-
rowDeleted
- Specified by:
rowDeletedin interfaceResultSet- Overrides:
rowDeletedin classJtdsResultSet- Throws:
SQLException
-
rowInserted
- Specified by:
rowInsertedin interfaceResultSet- Overrides:
rowInsertedin classJtdsResultSet- Throws:
SQLException
-
rowUpdated
- Specified by:
rowUpdatedin interfaceResultSet- Overrides:
rowUpdatedin classJtdsResultSet- Throws:
SQLException
-
absolute
- Specified by:
absolutein interfaceResultSet- Overrides:
absolutein classJtdsResultSet- Throws:
SQLException
-
relative
- Specified by:
relativein interfaceResultSet- Overrides:
relativein classJtdsResultSet- Throws:
SQLException
-
getCurrentRow
Description copied from class:JtdsResultSetRetrieve the current row data.- Overrides:
getCurrentRowin classJtdsResultSet- Returns:
- The current row data as an
Object[].
-