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.
CURSOR_CONCUR_OPTIMISTIC
private static final int CURSOR_CONCUR_OPTIMISTIC
CURSOR_CONCUR_OPTIMISTIC_VALUES
private static final int CURSOR_CONCUR_OPTIMISTIC_VALUES
CURSOR_CONCUR_READ_ONLY
private static final int CURSOR_CONCUR_READ_ONLY
CURSOR_CONCUR_SCROLL_LOCKS
private static final int CURSOR_CONCUR_SCROLL_LOCKS
CURSOR_OP_DELETE
private static final Integer CURSOR_OP_DELETE
CURSOR_OP_INSERT
private static final Integer CURSOR_OP_INSERT
CURSOR_OP_UPDATE
private static final Integer CURSOR_OP_UPDATE
CURSOR_TYPE_AUTO_FETCH
private static final int CURSOR_TYPE_AUTO_FETCH
CURSOR_TYPE_DYNAMIC
private static final int CURSOR_TYPE_DYNAMIC
CURSOR_TYPE_FASTFORWARDONLY
private static final int CURSOR_TYPE_FASTFORWARDONLY
CURSOR_TYPE_FORWARD
private static final int CURSOR_TYPE_FORWARD
CURSOR_TYPE_KEYSET
private static final int CURSOR_TYPE_KEYSET
CURSOR_TYPE_PARAMETERIZED
private static final int CURSOR_TYPE_PARAMETERIZED
CURSOR_TYPE_STATIC
private static final int CURSOR_TYPE_STATIC
FETCH_ABSOLUTE
private static final Integer FETCH_ABSOLUTE
FETCH_FIRST
private static final Integer FETCH_FIRST
FETCH_INFO
private static final Integer FETCH_INFO
FETCH_LAST
private static final Integer FETCH_LAST
FETCH_NEXT
private static final Integer FETCH_NEXT
FETCH_PREVIOUS
private static final Integer FETCH_PREVIOUS
FETCH_RELATIVE
private static final Integer FETCH_RELATIVE
FETCH_REPEAT
private static final Integer FETCH_REPEAT
PARAM_CURSOR_HANDLE
private final ParamInfo PARAM_CURSOR_HANDLE
Cursor handle parameter.
PARAM_FETCHTYPE
private final ParamInfo PARAM_FETCHTYPE
sp_cursorfetch
fetchtype parameter.
PARAM_NUMROWS_IN
private final ParamInfo PARAM_NUMROWS_IN
sp_cursorfetch
numrows IN parameter (for actual fetches).
PARAM_NUMROWS_OUT
private final ParamInfo PARAM_NUMROWS_OUT
sp_cursorfetch
numrows OUT parameter (for FETCH_INFO).
PARAM_OPTYPE
private final ParamInfo PARAM_OPTYPE
sp_cursor
optype parameter.
PARAM_ROWNUM
private final ParamInfo PARAM_ROWNUM
sp_cursor
rownum parameter.
PARAM_ROWNUM_IN
private final ParamInfo PARAM_ROWNUM_IN
sp_cursorfetch
rownum IN parameter (for actual fetches).
PARAM_ROWNUM_OUT
private final ParamInfo PARAM_ROWNUM_OUT
sp_cursorfetch
rownum OUT parameter (for FETCH_INFO).
PARAM_TABLE
private final ParamInfo PARAM_TABLE
sp_cursor
table parameter.
SQL_ROW_DELETED
private static final Integer SQL_ROW_DELETED
The row has been deleted.
SQL_ROW_DIRTY
private static final Integer SQL_ROW_DIRTY
The row is dirty and needs to be reloaded (internal state).
SQL_ROW_SUCCESS
private static final Integer SQL_ROW_SUCCESS
The row is valid.
asyncCursor
private boolean asyncCursor
The cursor is being built asynchronously.
cursorPos
private int cursorPos
Actual position of the cursor.
insertRow
private ParamInfo[] insertRow
The "insert row".
onInsertRow
private boolean onInsertRow
Set when moveToInsertRow()
was called.
rowCache
private Object[][] rowCache
updateRow
private ParamInfo[] updateRow
The "update row".
cursor
private void cursor(Integer opType,
ParamInfo[] row)
throws SQLException
Support general cursor operations such as delete, update etc.
opType
- the type of operation to performrow
- the row number to update
cursorClose
private void cursorClose()
throws SQLException
Close a server side cursor.
cursorCreate
private void cursorCreate(String sql,
String procName,
ParamInfo[] parameters)
throws SQLException
Create a new Cursor result set using the internal sp_cursoropen procedure.
sql
- The SQL SELECT statement.procName
- Optional procedure name for cursors based on a stored procedure.parameters
- Optional stored procedure parameters.
cursorFetch
private boolean cursorFetch(Integer fetchType,
int rowNum)
throws SQLException
Fetch the next result row from a cursor using the internal sp_cursorfetch procedure.
fetchType
- The type of fetch eg FETCH_ABSOLUTE.rowNum
- The row number to fetch.
boolean
true if a result set row is returned.
getColumn
protected Object getColumn(int index)
throws SQLException
Get the specified column's data item.
- getColumn in interface JtdsResultSet
index
- the column index in the row
- the column value as an
Object
getCurrentRow
protected Object[] getCurrentRow()
Retrieve the current row data.
- getCurrentRow in interface JtdsResultSet
- The current row data as an
Object[]
.
getCursorConcurrencyOpt
(package private) 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.
resultSetConcurrency
- JDBC result set concurrency (one of the
ResultSet.CONCUR_XXX
values)
- a value for the @scrollOpt parameter
getCursorScrollOpt
(package private) 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.
resultSetType
- JDBC result set type (one of the
ResultSet.TYPE_XXX
values)resultSetConcurrency
- JDBC result set concurrency (one of the
ResultSet.CONCUR_XXX
values)
- a value for the @scrollOpt parameter
processOutput
private void processOutput(TdsCore tds,
boolean setMeta)
throws SQLException
Processes the output of a cursor open or fetch operation. Fetches a
batch of rows from the TdsCore
, 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.
tds
- the TdsCore
instancesetMeta
- whether column meta data needs to be loaded (cursor open)
setColValue
protected Object setColValue(int colIndex,
int jdbcType,
Object value,
int length)
throws SQLException
Set the specified column's data value.
- setColValue in interface JtdsResultSet
colIndex
- index of the columnvalue
- new column value
- the value, possibly converted to an internal type