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 boolean
The cursor is being built asynchronously.private static final int
private static final int
private static final int
private static final int
private static final Integer
private static final Integer
private static final Integer
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private int
Actual position of the cursor.private static final Integer
private static final Integer
private static final Integer
private static final Integer
private static final Integer
private static final Integer
private static final Integer
private static final Integer
private ParamInfo[]
The "insert row".private boolean
Set whenmoveToInsertRow()
was called.private final ParamInfo
Cursor handle parameter.private final ParamInfo
sp_cursorfetch
fetchtype parameter.private final ParamInfo
sp_cursorfetch
numrows IN parameter (for actual fetches).private final ParamInfo
sp_cursorfetch
numrows OUT parameter (for FETCH_INFO).private final ParamInfo
sp_cursor
optype parameter.private final ParamInfo
sp_cursor
rownum parameter.private final ParamInfo
sp_cursorfetch
rownum IN parameter (for actual fetches).private final ParamInfo
sp_cursorfetch
rownum OUT parameter (for FETCH_INFO).private final ParamInfo
sp_cursor
table parameter.private Object[][]
The row cache used insteadJtdsResultSet.currentRow
.private static final Integer
The row has been deleted.private static final Integer
The row is dirty and needs to be reloaded (internal state).private static final Integer
The 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, wasNull
Fields 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 TypeMethodDescriptionboolean
absolute
(int row) void
void
void
void
close()
private void
Support general cursor operations such as delete, update etc.private void
Close a server side cursor.private void
cursorCreate
(String sql, String procName, ParamInfo[] parameters) Create a new Cursor result set using the internal sp_cursoropen procedure.private boolean
cursorFetch
(Integer fetchType, int rowNum) Fetch the next result row from a cursor using the internal sp_cursorfetch procedure.void
boolean
first()
protected Object
getColumn
(int index) Get the specified column's data item.protected Object[]
Retrieve the current row data.(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.(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.void
boolean
isLast()
boolean
last()
void
void
boolean
next()
boolean
previous()
private void
processOutput
(TdsCore tds, boolean setMeta) Processes the output of a cursor open or fetch operation.void
boolean
relative
(int row) boolean
boolean
boolean
protected Object
setColValue
(int colIndex, int jdbcType, Object value, int length) Set the specified column's data value.void
Methods 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, wasNull
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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_cursorfetch
fetchtype parameter. -
PARAM_ROWNUM_IN
sp_cursorfetch
rownum IN parameter (for actual fetches). -
PARAM_NUMROWS_IN
sp_cursorfetch
numrows IN parameter (for actual fetches). -
PARAM_ROWNUM_OUT
sp_cursorfetch
rownum OUT parameter (for FETCH_INFO). -
PARAM_NUMROWS_OUT
sp_cursorfetch
numrows OUT parameter (for FETCH_INFO). -
PARAM_OPTYPE
sp_cursor
optype parameter. -
PARAM_ROWNUM
sp_cursor
rownum parameter. -
PARAM_TABLE
sp_cursor
table 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:
setColValue
in 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:
getColumn
in 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_XXX
values)resultSetConcurrency
- JDBC result set concurrency (one of theResultSet.CONCUR_XXX
values)- 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_XXX
values)- 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:
boolean
true 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
- theTdsCore
instancesetMeta
- 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:
afterLast
in interfaceResultSet
- Overrides:
afterLast
in classJtdsResultSet
- Throws:
SQLException
-
beforeFirst
- Specified by:
beforeFirst
in interfaceResultSet
- Overrides:
beforeFirst
in classJtdsResultSet
- Throws:
SQLException
-
cancelRowUpdates
- Specified by:
cancelRowUpdates
in interfaceResultSet
- Overrides:
cancelRowUpdates
in classJtdsResultSet
- Throws:
SQLException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceResultSet
- Overrides:
close
in classJtdsResultSet
- Throws:
SQLException
-
deleteRow
- Specified by:
deleteRow
in interfaceResultSet
- Overrides:
deleteRow
in classJtdsResultSet
- Throws:
SQLException
-
insertRow
- Specified by:
insertRow
in interfaceResultSet
- Overrides:
insertRow
in classJtdsResultSet
- Throws:
SQLException
-
moveToCurrentRow
- Specified by:
moveToCurrentRow
in interfaceResultSet
- Overrides:
moveToCurrentRow
in classJtdsResultSet
- Throws:
SQLException
-
moveToInsertRow
- Specified by:
moveToInsertRow
in interfaceResultSet
- Overrides:
moveToInsertRow
in classJtdsResultSet
- Throws:
SQLException
-
refreshRow
- Specified by:
refreshRow
in interfaceResultSet
- Overrides:
refreshRow
in classJtdsResultSet
- Throws:
SQLException
-
updateRow
- Specified by:
updateRow
in interfaceResultSet
- Overrides:
updateRow
in classJtdsResultSet
- Throws:
SQLException
-
first
- Specified by:
first
in interfaceResultSet
- Overrides:
first
in classJtdsResultSet
- Throws:
SQLException
-
isLast
- Specified by:
isLast
in interfaceResultSet
- Overrides:
isLast
in classJtdsResultSet
- Throws:
SQLException
-
last
- Specified by:
last
in interfaceResultSet
- Overrides:
last
in classJtdsResultSet
- Throws:
SQLException
-
next
- Specified by:
next
in interfaceResultSet
- Overrides:
next
in classJtdsResultSet
- Throws:
SQLException
-
previous
- Specified by:
previous
in interfaceResultSet
- Overrides:
previous
in classJtdsResultSet
- Throws:
SQLException
-
rowDeleted
- Specified by:
rowDeleted
in interfaceResultSet
- Overrides:
rowDeleted
in classJtdsResultSet
- Throws:
SQLException
-
rowInserted
- Specified by:
rowInserted
in interfaceResultSet
- Overrides:
rowInserted
in classJtdsResultSet
- Throws:
SQLException
-
rowUpdated
- Specified by:
rowUpdated
in interfaceResultSet
- Overrides:
rowUpdated
in classJtdsResultSet
- Throws:
SQLException
-
absolute
- Specified by:
absolute
in interfaceResultSet
- Overrides:
absolute
in classJtdsResultSet
- Throws:
SQLException
-
relative
- Specified by:
relative
in interfaceResultSet
- Overrides:
relative
in classJtdsResultSet
- Throws:
SQLException
-
getCurrentRow
Description copied from class:JtdsResultSet
Retrieve the current row data.- Overrides:
getCurrentRow
in classJtdsResultSet
- Returns:
- The current row data as an
Object[]
.
-