下面列出了java.sql.ResultSet#TYPE_SCROLL_INSENSITIVE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
CassandraStatement(CassandraConnection con, String cql, int resultSetType, int resultSetConcurrency,
int resultSetHoldability) throws SQLException
{
this.connection = con;
this.cql = cql;
this.batchQueries = Lists.newArrayList();
this.consistencyLevel = con.defaultConsistencyLevel;
if (!(resultSetType == ResultSet.TYPE_FORWARD_ONLY
|| resultSetType == ResultSet.TYPE_SCROLL_INSENSITIVE
|| resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE)) throw new SQLSyntaxErrorException(BAD_TYPE_RSET);
this.resultSetType = resultSetType;
if (!(resultSetConcurrency == ResultSet.CONCUR_READ_ONLY
|| resultSetConcurrency == ResultSet.CONCUR_UPDATABLE)) throw new SQLSyntaxErrorException(BAD_TYPE_RSET);
this.resultSetConcurrency = resultSetConcurrency;
if (!(resultSetHoldability == ResultSet.HOLD_CURSORS_OVER_COMMIT
|| resultSetHoldability == ResultSet.CLOSE_CURSORS_AT_COMMIT))
throw new SQLSyntaxErrorException(BAD_HOLD_RSET);
this.resultSetHoldability = resultSetHoldability;
}
/**
* Returns the resultType if set if not set returns the default
* java.sql.ResultSet.TYPE_FORWARD_ONLY
*/
static int getResultType(StatementAttrs attrs) {
int rsType;
if (attrs != null && attrs.isSetResultSetType()) {
rsType = attrs.getResultSetType();
}
else {
rsType = gfxdConstants.DEFAULT_RESULTSET_TYPE;
}
switch (rsType) {
case gfxdConstants.RESULTSET_TYPE_FORWARD_ONLY:
return ResultSet.TYPE_FORWARD_ONLY;
case gfxdConstants.RESULTSET_TYPE_INSENSITIVE:
return ResultSet.TYPE_SCROLL_INSENSITIVE;
case gfxdConstants.RESULTSET_TYPE_SENSITIVE:
return ResultSet.TYPE_SCROLL_SENSITIVE;
default:
throw new InternalGemFireError("unknown resultSet type "
+ attrs.getResultSetType());
}
}
public int getBestResultSetType( final DataRow dataRow ) throws SQLException {
if ( globalConfig != null && "simple".equalsIgnoreCase( globalConfig.getConfigProperty( //$NON-NLS-1$
ResultSetTableModelFactory.RESULTSET_FACTORY_MODE ) ) ) { //$NON-NLS-1$
return ResultSet.TYPE_FORWARD_ONLY;
}
final Connection connection = getConnection( dataRow );
final boolean supportsScrollInsensitive =
connection.getMetaData().supportsResultSetType( ResultSet.TYPE_SCROLL_INSENSITIVE );
final boolean supportsScrollSensitive =
connection.getMetaData().supportsResultSetType( ResultSet.TYPE_SCROLL_SENSITIVE );
if ( supportsScrollInsensitive ) {
return ResultSet.TYPE_SCROLL_INSENSITIVE;
}
if ( supportsScrollSensitive ) {
return ResultSet.TYPE_SCROLL_SENSITIVE;
}
return ResultSet.TYPE_FORWARD_ONLY;
}
/**
* Returns the resultType if set if not set returns the default
* java.sql.ResultSet.TYPE_FORWARD_ONLY
*/
static int getResultType(StatementAttrs attrs) {
int rsType;
if (attrs != null && attrs.isSetResultSetType()) {
rsType = attrs.getResultSetType();
}
else {
rsType = gfxdConstants.DEFAULT_RESULTSET_TYPE;
}
switch (rsType) {
case gfxdConstants.RESULTSET_TYPE_FORWARD_ONLY:
return ResultSet.TYPE_FORWARD_ONLY;
case gfxdConstants.RESULTSET_TYPE_INSENSITIVE:
return ResultSet.TYPE_SCROLL_INSENSITIVE;
case gfxdConstants.RESULTSET_TYPE_SENSITIVE:
return ResultSet.TYPE_SCROLL_SENSITIVE;
default:
throw new InternalGemFireError("unknown resultSet type "
+ attrs.getResultSetType());
}
}
@DataProvider(name = "rowSetScrollTypes")
protected Object[][] rowSetScrollTypes() throws Exception {
RowSet rs = newInstance();
return new Object[][]{
{rs, ResultSet.TYPE_FORWARD_ONLY},
{rs, ResultSet.TYPE_SCROLL_INSENSITIVE},
{rs, ResultSet.TYPE_SCROLL_SENSITIVE}
};
}
@DataProvider(name = "rowSetScrollTypes")
protected Object[][] rowSetScrollTypes() throws Exception {
RowSet rs = newInstance();
return new Object[][]{
{rs, ResultSet.TYPE_FORWARD_ONLY},
{rs, ResultSet.TYPE_SCROLL_INSENSITIVE},
{rs, ResultSet.TYPE_SCROLL_SENSITIVE}
};
}
private int setResultSetType(int resultSetType) {
/* Add warning if scroll sensitive cursor
* and downgrade to scroll insensitive cursor.
*/
if (resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE)
{
addWarning(SQLWarningFactory.newSQLWarning(SQLState.NO_SCROLL_SENSITIVE_CURSORS));
resultSetType = ResultSet.TYPE_SCROLL_INSENSITIVE;
}
return resultSetType;
}
@DataProvider(name = "rowSetScrollTypes")
protected Object[][] rowSetScrollTypes() throws Exception {
RowSet rs = newInstance();
return new Object[][]{
{rs, ResultSet.TYPE_FORWARD_ONLY},
{rs, ResultSet.TYPE_SCROLL_INSENSITIVE},
{rs, ResultSet.TYPE_SCROLL_SENSITIVE}
};
}
/**
* Determine if DBMS/Driver supports scrollable resultsets to be able to
* determine complete row count for a given SQL.
*
* @param conn established JDBC connection
* @param dc connection information
* @param sql the sql to be executed
*/
private void updateScrollableSupport(Connection conn, DatabaseConnection dc,
String sql) {
useScrollableCursors = dc.isUseScrollableCursors();
if (!useScrollableCursors) {
return;
}
String driverName = dc.getDriverClass();
/* Derby fails to support scrollable cursors when invoking 'stored procedures'
which return resultsets - it fails hard: not throwing a SQLException,
but terminating the connection - so don't try to use scrollable cursor
on derby, for "non"-selects */
if (driverName != null && driverName.startsWith("org.apache.derby")) { //NOI18N
if (!isSelectStatement(sql)) {
resultSetScrollType = ResultSet.TYPE_FORWARD_ONLY;
return;
}
}
/* Try to get a "good" scrollable ResultSet and follow the DBs support */
try {
if (conn.getMetaData().supportsResultSetType(
ResultSet.TYPE_SCROLL_INSENSITIVE)) {
resultSetScrollType = ResultSet.TYPE_SCROLL_INSENSITIVE;
} else if (conn.getMetaData().supportsResultSetType(
ResultSet.TYPE_SCROLL_SENSITIVE)) {
resultSetScrollType = ResultSet.TYPE_SCROLL_SENSITIVE;
}
} catch (Exception ex) {
LOGGER.log(Level.WARNING, "Exception while querying" //NOI18N
+ " database for scrollable resultset support"); //NOI18N
}
}
/**
* JDBC 2.0
*
* Determine whether or not a visible row update can be detected by
* calling ResultSet.rowUpdated().
*
* @param type result set type, i.e. ResultSet.TYPE_XXX
* @return true if updates are detected by the resultset type
*/
public boolean updatesAreDetected(int type) {
if (type == ResultSet.TYPE_SCROLL_INSENSITIVE) {
return true;
} else {
// For forward only resultsets, we move to before the next
// row after a update and that is why updatesAreDetected
// returns false.
return false;
}
}
@DataProvider(name = "rowSetScrollTypes")
protected Object[][] rowSetScrollTypes() throws Exception {
RowSet rs = newInstance();
return new Object[][]{
{rs, ResultSet.TYPE_FORWARD_ONLY},
{rs, ResultSet.TYPE_SCROLL_INSENSITIVE},
{rs, ResultSet.TYPE_SCROLL_SENSITIVE}
};
}
public static int getThriftResultSetType(int jdbcType) {
switch (jdbcType) {
case ResultSet.TYPE_FORWARD_ONLY:
return gfxdConstants.RESULTSET_TYPE_FORWARD_ONLY;
case ResultSet.TYPE_SCROLL_INSENSITIVE:
return gfxdConstants.RESULTSET_TYPE_INSENSITIVE;
case ResultSet.TYPE_SCROLL_SENSITIVE:
return gfxdConstants.RESULTSET_TYPE_SENSITIVE;
default:
return gfxdConstants.RESULTSET_TYPE_UNKNOWN;
}
}
private static int getResultSetType(RuntimeProperties props) throws BarleyDBQueryException {
if (props.getScrollType() == null) {
return ResultSet.TYPE_FORWARD_ONLY;
}
switch(props.getScrollType()) {
case FORWARD_ONLY:
return ResultSet.TYPE_FORWARD_ONLY;
case SCROLL_INSENSITIVE:
return ResultSet.TYPE_SCROLL_INSENSITIVE;
case SCROLL_SENSITIVE:
return ResultSet.TYPE_SCROLL_SENSITIVE;
default:
throw new IllegalQueryStateException("Unknown scroll type '" + props.getScrollType() + "'");
}
}
/**
* JDBC 2.0
*
* Determine whether or not a visible row update can be detected by
* calling ResultSet.rowUpdated().
*
* @param type result set type, i.e. ResultSet.TYPE_XXX
* @return true if updates are detected by the resultset type
*/
public boolean updatesAreDetected(int type) {
if (type == ResultSet.TYPE_SCROLL_INSENSITIVE) {
return true;
} else {
// For forward only resultsets, we move to before the next
// row after a update and that is why updatesAreDetected
// returns false.
return false;
}
}
private int setResultSetType(int resultSetType) {
/* Add warning if scroll sensitive cursor
* and downgrade to scroll insensitive cursor.
*/
if (resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE)
{
addWarning(SQLWarningFactory.newSQLWarning(SQLState.NO_SCROLL_SENSITIVE_CURSORS));
resultSetType = ResultSet.TYPE_SCROLL_INSENSITIVE;
}
return resultSetType;
}
@Override
public int getType() throws SQLException {
return ResultSet.TYPE_SCROLL_INSENSITIVE;
}
/**
* JDBC 2.0
*
* Determine whether a result set's updates are visible.
*
* @param type result set type, i.e. ResultSet.TYPE_XXX
* @return true if updates are visible for the result set type
*/
public boolean ownUpdatesAreVisible(int type) {
if (type == ResultSet.TYPE_SCROLL_INSENSITIVE) {
return true;
} else {
return false;
}
}
/**
* JDBC 2.0
*
* Does the database support the given result set type?
*
* @param type defined in java.sql.ResultSet
* @return true if so
* @see Connection
*/
public boolean supportsResultSetType(int type) {
if ((type == ResultSet.TYPE_FORWARD_ONLY) ||
(type == ResultSet.TYPE_SCROLL_INSENSITIVE)) {
return true;
}
//we don't support TYPE_SCROLL_SENSITIVE yet.
return false;
}
/**
* JDBC 2.0
*
* Does the database support the given result set type?
*
* @param type defined in java.sql.ResultSet
* @return true if so
* @see Connection
*/
public boolean supportsResultSetType(int type) {
if ((type == ResultSet.TYPE_FORWARD_ONLY) ||
(type == ResultSet.TYPE_SCROLL_INSENSITIVE)) {
return true;
}
//we don't support TYPE_SCROLL_SENSITIVE yet.
return false;
}
/**
* Retrieves the type of this <code>ResultSet</code> object.
* The type is determined by the <code>Statement</code> object
* that created the result set.
*
* @return <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>,
* or <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @exception SQLException if a database access error occurs
* @since 1.2
*/
public int getType() throws SQLException {
return ResultSet.TYPE_SCROLL_INSENSITIVE;
}