下面列出了java.sql.ResultSet#CONCUR_UPDATABLE 实例代码,或者点击链接到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;
}
/**
* {@inheritDoc}
*/
@Override
public boolean supportsResultSetConcurrency(int type, int concurrency)
throws SQLException {
this.conn.lock();
try {
initServiceMetaData();
List<Integer> supportedRSTypes;
switch (concurrency) {
case ResultSet.CONCUR_READ_ONLY:
supportedRSTypes = this.serviceMetaData.getFeaturesWithParams().get(
ServiceFeatureParameterized.RESULTSET_CONCURRENCY_READ_ONLY);
break;
case ResultSet.CONCUR_UPDATABLE:
supportedRSTypes = this.serviceMetaData.getFeaturesWithParams().get(
ServiceFeatureParameterized.RESULTSET_CONCURRENCY_UPDATABLE);
break;
default:
return false;
}
return supportedRSTypes != null
&& supportedRSTypes.contains(Converters.getThriftResultSetType(type));
} finally {
this.conn.unlock();
}
}
@DataProvider(name = "rowSetConcurrencyTypes")
protected Object[][] rowSetConcurrencyTypes() throws Exception {
RowSet rs = newInstance();
return new Object[][]{
{rs, ResultSet.CONCUR_READ_ONLY},
{rs, ResultSet.CONCUR_UPDATABLE}
};
}
@DataProvider(name = "rowSetConcurrencyTypes")
protected Object[][] rowSetConcurrencyTypes() throws Exception {
RowSet rs = newInstance();
return new Object[][]{
{rs, ResultSet.CONCUR_READ_ONLY},
{rs, ResultSet.CONCUR_UPDATABLE}
};
}
@DataProvider(name = "rowSetConcurrencyTypes")
protected Object[][] rowSetConcurrencyTypes() throws Exception {
RowSet rs = newInstance();
return new Object[][]{
{rs, ResultSet.CONCUR_READ_ONLY},
{rs, ResultSet.CONCUR_UPDATABLE}
};
}
@DataProvider(name = "rowSetConcurrencyTypes")
protected Object[][] rowSetConcurrencyTypes() throws Exception {
RowSet rs = newInstance();
return new Object[][]{
{rs, ResultSet.CONCUR_READ_ONLY},
{rs, ResultSet.CONCUR_UPDATABLE}
};
}
@DataProvider(name = "rowSetConcurrencyTypes")
protected Object[][] rowSetConcurrencyTypes() throws Exception {
RowSet rs = newInstance();
return new Object[][]{
{rs, ResultSet.CONCUR_READ_ONLY},
{rs, ResultSet.CONCUR_UPDATABLE}
};
}
ClientStatement(ClientConnection conn, int rsType, int rsConcurrency,
int rsHoldability) {
this(conn, conn.getHoldability());
this.attrs.setResultSetType((byte)Converters
.getThriftResultSetType(rsType));
if (rsConcurrency == ResultSet.CONCUR_UPDATABLE) {
this.attrs.setUpdatable(true);
}
this.isOpen = true;
}
/**
* Constructs a cached result set based on locally generated data.
*
* @param statement the parent statement object
* @param colName array of column names
* @param colType array of corresponding data types
* @exception SQLException if an error occurs
*/
CachedResultSet(JtdsStatement statement,
String[] colName, int[] colType) throws SQLException {
super(statement, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE, null);
//
// Construct the column descriptor array
//
columns = new ColInfo[colName.length];
for (int i = 0; i < colName.length; i++) {
ColInfo ci = new ColInfo();
ci.name = colName[i];
ci.realName = colName[i];
ci.jdbcType = colType[i];
ci.isCaseSensitive = false;
ci.isIdentity = false;
ci.isWriteable = false;
ci.nullable = 2;
ci.scale = 0;
TdsData.fillInType(ci);
columns[i] = ci;
}
columnCount = getColumnCount(columns);
rowData = new ArrayList(INITIAL_ROW_COUNT);
rowsInResult = 0;
pos = POS_BEFORE_FIRST;
tempResultSet = true;
cursorName = null;
procName = null;
procedureParams = null;
}
public void testUnequalityVarious() {
String sql = "select * from sys.systables";
String schema = "APP";
int rsh = ResultSet.HOLD_CURSORS_OVER_COMMIT;
int rst = ResultSet.TYPE_SCROLL_INSENSITIVE;
int rsc = ResultSet.CONCUR_UPDATABLE;
int auto = Statement.RETURN_GENERATED_KEYS;
// Create a one key of each type, all different from each other.
StatementKey[] keys = new StatementKey[] {
StatementKeyFactory.newPrepared(sql, schema, rsh),
StatementKeyFactory.newPrepared(sql, schema, rsh, auto),
StatementKeyFactory.newPrepared(sql, schema, rst, rsc, rsh),
StatementKeyFactory.newCallable(sql, schema, rsh),
StatementKeyFactory.newCallable(sql, schema, rst, rsc, rsh)};
for (int outer=0; outer < keys.length; outer++) {
StatementKey current = keys[outer];
for (int inner=0; inner < keys.length; inner++) {
if (outer != inner) {
if (current.equals(keys[inner])) {
fail("[" + current.toString() + "] should not equal [" +
keys[inner].toString() + "]");
}
} else {
// Should equal itself.
assertTrue(current.equals(keys[inner]));
}
}
}
}
private static int getResultSetConcurrency(RuntimeProperties props) throws BarleyDBQueryException {
if (props == null) {
return ResultSet.CONCUR_READ_ONLY;
}
switch (props.getConcurrency()) {
case READ_ONLY:
return ResultSet.CONCUR_READ_ONLY;
case UPDATABLE:
return ResultSet.CONCUR_UPDATABLE;
default:
throw new IllegalQueryStateException("Unknown concurrency '" + props.getConcurrency() + "'");
}
}
ClientStatement(ClientConnection conn, int rsType, int rsConcurrency,
int rsHoldability) {
this(conn, conn.getHoldability());
this.attrs.setResultSetType((byte)Converters
.getThriftResultSetType(rsType));
if (rsConcurrency == ResultSet.CONCUR_UPDATABLE) {
this.attrs.setUpdatable(true);
}
this.isOpen = true;
}
/**
* Get the ResultSetMetaData for the class/object. We first look for
* the optional static method which has the same signature as the constructor.
* If it doesn't exist, then we instantiate an object and get the ResultSetMetaData
* from that object.
*
* @return The ResultSetMetaData from the class/object.
*
* @exception StandardException Thrown on error
*/
public ResultSetMetaData getResultSetMetaData()
throws StandardException
{
// Get the actual
ResultSetMetaData rsmd = null;
try
{
if (version2)
{
ps = (PreparedStatement) getNewInstance();
if (ps.getResultSetConcurrency() != ResultSet.CONCUR_UPDATABLE)
{
throw StandardException.newException(SQLState.LANG_UPDATABLE_VTI_NON_UPDATABLE_RS,
getVTIName());
}
rsmd = ps.getMetaData();
controlsDeferral = (ps instanceof DeferModification);
/* See if the result set is known to be insensitive or not.
*
* Some older VTI implementations do not implement getResultSetType(). UpdatableVTITemplate
* does not implement it at all. UpdatableVTITemplate.getResultSetType throws an
* exception. In either of these cases make the conservative assumption that the result set is sensitive.
*/
try
{
resultSetType = ps.getResultSetType();
}
catch( SQLException sqle){}
catch( java.lang.AbstractMethodError ame){}
catch( java.lang.NoSuchMethodError nsme){}
isInsensitive = (resultSetType == ResultSet.TYPE_SCROLL_INSENSITIVE);
if (!implementsVTICosting) {
ps.close();
ps = null;
}
}
else
{
rs = (ResultSet) getNewInstance();
rsmd = rs.getMetaData();
if (!implementsVTICosting) {
rs.close();
rs = null;
}
}
}
catch(Throwable t)
{
throw StandardException.unexpectedUserException(t);
}
return rsmd;
}
/**
* Test SUR properties of the query
*/
public void runTest()
throws SQLException
{
println(query);
DatabaseMetaData dbMeta = getConnection().getMetaData();
if (dbMeta.ownDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)) {
checkRowDeleted = true;
}
Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
s.setCursorName(cursorName);
ResultSet rs = s.executeQuery(query);
checkRowUpdated = dbMeta.ownUpdatesAreVisible(rs.getType());
checkRowDeleted = dbMeta.ownDeletesAreVisible(rs.getType());
// Create map with rows
Map rows = createRowMap(rs);
// Set of rows which are updated (contains Integer with position in RS)
final Set updatedRows = new HashSet();
// Set of rows which are deleted (contains Integer with position in RS)
final Set deletedRows = new HashSet();
// Test navigation
testNavigation(rs, rows, updatedRows, deletedRows);
// Only test updatability if the ResultSet is updatable:
// (Note: this enables the test do run successfully even if
// scrollable updatable resultsets are not implemented.
// If SUR is not implemented, a well behaved JDBC driver will
// downgrade the concurrency mode to READ_ONLY).
// SUR may be implemented incrementally, i.e first in embedded mode
// then in the network driver.)
if (rs.getConcurrency()==ResultSet.CONCUR_UPDATABLE) {
// update a random sample of 2 records
updateRandomSampleOfNRecords(rs, rows, updatedRows, 2);
testNavigation(rs, rows, updatedRows, deletedRows);
// update a random sample of 5 records
updateRandomSampleOfNRecords(rs, rows, updatedRows, 5);
testNavigation(rs, rows, updatedRows, deletedRows);
// update a random sample of 10 records
updateRandomSampleOfNRecords(rs, rows, updatedRows, 10);
testNavigation(rs, rows, updatedRows, deletedRows);
// delete a random sample of 2 records
deleteRandomSampleOfNRecords(rs, rows, deletedRows, 2);
testNavigation(rs, rows, updatedRows, deletedRows);
// delete a random sample of 5 records
deleteRandomSampleOfNRecords(rs, rows, deletedRows, 5);
testNavigation(rs, rows, updatedRows, deletedRows);
// delete a random sample of 10 records
deleteRandomSampleOfNRecords(rs, rows, deletedRows, 10);
testNavigation(rs, rows, updatedRows, deletedRows);
} else {
assertTrue("ResultSet concurrency downgraded to CONCUR_READ_ONLY",
false);
}
rs.close();
s.close();
}
/**
* Test SUR properties of the query
*/
public void runTest()
throws SQLException
{
println(query);
DatabaseMetaData dbMeta = getConnection().getMetaData();
if (dbMeta.ownDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)) {
checkRowDeleted = true;
}
Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
s.setCursorName(cursorName);
ResultSet rs = s.executeQuery(query);
checkRowUpdated = dbMeta.ownUpdatesAreVisible(rs.getType());
checkRowDeleted = dbMeta.ownDeletesAreVisible(rs.getType());
// Create map with rows
Map rows = createRowMap(rs);
// Set of rows which are updated (contains Integer with position in RS)
final Set updatedRows = new HashSet();
// Set of rows which are deleted (contains Integer with position in RS)
final Set deletedRows = new HashSet();
// Test navigation
testNavigation(rs, rows, updatedRows, deletedRows);
// Only test updatability if the ResultSet is updatable:
// (Note: this enables the test do run successfully even if
// scrollable updatable resultsets are not implemented.
// If SUR is not implemented, a well behaved JDBC driver will
// downgrade the concurrency mode to READ_ONLY).
// SUR may be implemented incrementally, i.e first in embedded mode
// then in the network driver.)
if (rs.getConcurrency()==ResultSet.CONCUR_UPDATABLE) {
// update a random sample of 2 records
updateRandomSampleOfNRecords(rs, rows, updatedRows, 2);
testNavigation(rs, rows, updatedRows, deletedRows);
// update a random sample of 5 records
updateRandomSampleOfNRecords(rs, rows, updatedRows, 5);
testNavigation(rs, rows, updatedRows, deletedRows);
// update a random sample of 10 records
updateRandomSampleOfNRecords(rs, rows, updatedRows, 10);
testNavigation(rs, rows, updatedRows, deletedRows);
// delete a random sample of 2 records
deleteRandomSampleOfNRecords(rs, rows, deletedRows, 2);
testNavigation(rs, rows, updatedRows, deletedRows);
// delete a random sample of 5 records
deleteRandomSampleOfNRecords(rs, rows, deletedRows, 5);
testNavigation(rs, rows, updatedRows, deletedRows);
// delete a random sample of 10 records
deleteRandomSampleOfNRecords(rs, rows, deletedRows, 10);
testNavigation(rs, rows, updatedRows, deletedRows);
} else {
assertTrue("ResultSet concurrency downgraded to CONCUR_READ_ONLY",
false);
}
rs.close();
s.close();
}
/**
* Test SUR properties of the query
*/
public void runTest()
throws SQLException
{
println(query);
DatabaseMetaData dbMeta = getConnection().getMetaData();
if (dbMeta.ownDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)) {
checkRowDeleted = true;
}
Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
s.setCursorName(cursorName);
ResultSet rs = s.executeQuery(query);
checkRowUpdated = dbMeta.ownUpdatesAreVisible(rs.getType());
checkRowDeleted = dbMeta.ownDeletesAreVisible(rs.getType());
// Create map with rows
Map rows = createRowMap(rs);
// Set of rows which are updated (contains Integer with position in RS)
final Set updatedRows = new HashSet();
// Set of rows which are deleted (contains Integer with position in RS)
final Set deletedRows = new HashSet();
// Test navigation
testNavigation(rs, rows, updatedRows, deletedRows);
// Only test updatability if the ResultSet is updatable:
// (Note: this enables the test do run successfully even if
// scrollable updatable resultsets are not implemented.
// If SUR is not implemented, a well behaved JDBC driver will
// downgrade the concurrency mode to READ_ONLY).
// SUR may be implemented incrementally, i.e first in embedded mode
// then in the network driver.)
if (rs.getConcurrency()==ResultSet.CONCUR_UPDATABLE) {
// update a random sample of 2 records
updateRandomSampleOfNRecords(rs, rows, updatedRows, 2);
testNavigation(rs, rows, updatedRows, deletedRows);
// update a random sample of 5 records
updateRandomSampleOfNRecords(rs, rows, updatedRows, 5);
testNavigation(rs, rows, updatedRows, deletedRows);
// update a random sample of 10 records
updateRandomSampleOfNRecords(rs, rows, updatedRows, 10);
testNavigation(rs, rows, updatedRows, deletedRows);
// delete a random sample of 2 records
deleteRandomSampleOfNRecords(rs, rows, deletedRows, 2);
testNavigation(rs, rows, updatedRows, deletedRows);
// delete a random sample of 5 records
deleteRandomSampleOfNRecords(rs, rows, deletedRows, 5);
testNavigation(rs, rows, updatedRows, deletedRows);
// delete a random sample of 10 records
deleteRandomSampleOfNRecords(rs, rows, deletedRows, 10);
testNavigation(rs, rows, updatedRows, deletedRows);
} else {
assertTrue("ResultSet concurrency downgraded to CONCUR_READ_ONLY",
false);
}
rs.close();
s.close();
}
/**
* {@inheritDoc}
*/
@Override
public int getResultSetConcurrency() throws SQLException {
return this.attrs.isSetUpdatable() && this.attrs.isUpdatable()
? ResultSet.CONCUR_UPDATABLE : ResultSet.CONCUR_READ_ONLY;
}
/**
* @see java.sql.Statement
*
* @exception SQLException on unexpected JDBC error
*/
public int getResultSetConcurrency() throws SQLException
{
return ResultSet.CONCUR_UPDATABLE;
}
/**
* Returns the Concurrency associated with the statement if set the the input
* object if not set by default returns java.sql.ResultSet.CONCUR_READ_ONLY
*
* @param attrs
* @return
*/
static int getResultSetConcurrency(StatementAttrs attrs) {
return attrs != null && attrs.isSetUpdatable() && attrs.isUpdatable()
? ResultSet.CONCUR_UPDATABLE : ResultSet.CONCUR_READ_ONLY;
}
/**
* @see java.sql.Statement
*
* @exception SQLException on unexpected JDBC error
*/
public int getResultSetConcurrency() throws SQLException
{
return ResultSet.CONCUR_UPDATABLE;
}