Java Code Examples for java.sql.ResultSet#HOLD_CURSORS_OVER_COMMIT

The following examples show how to use java.sql.ResultSet#HOLD_CURSORS_OVER_COMMIT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JdbcFacade.java    From iaf with Apache License 2.0 6 votes vote down vote up
public String getDatasourceInfo() throws JdbcException {
	String dsinfo=null;
	try (Connection conn=getConnection()) {
		DatabaseMetaData md=conn.getMetaData();
		String product=md.getDatabaseProductName();
		String productVersion=md.getDatabaseProductVersion();
		String driver=md.getDriverName();
		String driverVersion=md.getDriverVersion();
		String url=md.getURL();
		String user=md.getUserName();
		if (getDatabaseType() == DbmsSupportFactory.DBMS_DB2 && "WAS".equals(IbisContext.getApplicationServerType()) && md.getResultSetHoldability() != ResultSet.HOLD_CURSORS_OVER_COMMIT) {
			// For (some?) combinations of WebShere and DB2 this seems to be
			// the default and result in the following exception when (for
			// example?) a ResultSetIteratingPipe is calling next() on the
			// ResultSet after it's sender has called a pipeline which
			// contains a GenericMessageSendingPipe using
			// transactionAttribute="NotSupported":
			//   com.ibm.websphere.ce.cm.ObjectClosedException: DSRA9110E: ResultSet is closed.
			ConfigurationWarnings.add(this, log, "The database's default holdability for ResultSet objects is " + md.getResultSetHoldability() + " instead of " + ResultSet.HOLD_CURSORS_OVER_COMMIT + " (ResultSet.HOLD_CURSORS_OVER_COMMIT)");
		}
		dsinfo ="user ["+user+"] url ["+url+"] product ["+product+"] version ["+productVersion+"] driver ["+driver+"] version ["+driverVersion+"]";
	} catch (SQLException e) {
		log.warn("Exception determining databaseinfo",e);
	}
	return dsinfo;
}
 
Example 2
Source File: DRDAStatement.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
private  void parsePkgidToFindHoldability()
{
	if (withHoldCursor != -1)
		return;
       
	//First, check if holdability was passed as a SQL attribute "WITH HOLD" for this prepare. If yes, then withHoldCursor
	//should not get overwritten by holdability from package name and that is why the check for -1
       String pkgid = pkgnamcsn.getPkgid();
	if (isDynamicPkgid(pkgid))
	{       
		if(pkgid.charAt(4) == 'N')
			withHoldCursor = ResultSet.CLOSE_CURSORS_AT_COMMIT;
		else  
			withHoldCursor = ResultSet.HOLD_CURSORS_OVER_COMMIT;
	}
	else 
	{            
		withHoldCursor = ResultSet.HOLD_CURSORS_OVER_COMMIT;
	
	}
}
 
Example 3
Source File: StatementPoolingTest.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Tests if the holdability settings is taking effect, and also that the
 * result set is closed when the connection is closed.
 *
 * @param holdability result set holdability as specfied by
 *      {@link java.sql.ResultSet}
 * @throws SQLException if something goes wrong...
 */
private void doTestResultSetCloseForHoldability(int holdability)
        throws SQLException {
    getConnection().setAutoCommit(false);
    PreparedStatement ps = prepareStatement(
            "select * from stmtpooltest order by val",
            ResultSet.TYPE_FORWARD_ONLY,
            ResultSet.CONCUR_READ_ONLY,
            holdability);
    ResultSet rs = ps.executeQuery();
    assertTrue(rs.next());
    assertEquals(1, rs.getInt(1));
    commit();
    if (holdability == ResultSet.HOLD_CURSORS_OVER_COMMIT) {
        assertTrue(rs.next());
        assertEquals(2, rs.getInt(1));
        rollback();
    }
    getConnection().close();
    try {
        rs.next();
        fail("Should have thrown exception");
    } catch (SQLException sqle) {
        assertSQLState("XCL16", sqle);
    }
}
 
Example 4
Source File: 1205753_EmbedPooledConnection_0_t.java    From coming with MIT License 5 votes vote down vote up
void resetRealConnection() throws SQLException {

		// ensure any outstanding changes from the previous
		// user are rolledback.
		realConnection.rollback();

		// clear any warnings that are left over
		realConnection.clearWarnings();

		// need to reset transaction isolation, autocommit, readonly, holdability states
		if (realConnection.getTransactionIsolation() != defaultIsolationLevel) {

			realConnection.setTransactionIsolation(defaultIsolationLevel);
		}

		if (!realConnection.getAutoCommit())
			realConnection.setAutoCommit(true);

		if (realConnection.isReadOnly() != defaultReadOnly)
			realConnection.setReadOnly(defaultReadOnly);

		if (realConnection.getHoldability() != ResultSet.HOLD_CURSORS_OVER_COMMIT)
			realConnection.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);

		// reset any remaining state of the connection
		realConnection.resetFromPool();
		if (SanityManager.DEBUG)
		{
			SanityManager.ASSERT(realConnection.transactionIsIdle(),
			"real connection should have been idle at this point"); 			
		}
	}
 
Example 5
Source File: EmbedXAConnection.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
	Are held cursors allowed. If the connection is attached to
       a global transaction then downgrade the result set holdabilty
       to CLOSE_CURSORS_AT_COMMIT if downgrade is true, otherwise
       throw an exception.
       If the connection is in a local transaction then the
       passed in holdabilty is returned.
*/
public int  checkHoldCursors(int holdability, boolean downgrade)
       throws SQLException
   {
	if (holdability == ResultSet.HOLD_CURSORS_OVER_COMMIT) {		
		if (isGlobal()) {
               if (!downgrade)
                   throw Util.generateCsSQLException(SQLState.CANNOT_HOLD_CURSOR_XA);
               
               holdability = ResultSet.CLOSE_CURSORS_AT_COMMIT;
           }
	}

	return super.checkHoldCursors(holdability, downgrade);
}
 
Example 6
Source File: ClientDBMetaData.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int getResultSetHoldability() throws SQLException {
  this.conn.lock();
  try {
    initServiceMetaData();
    return this.serviceMetaData
        .isDefaultResultSetHoldabilityHoldCursorsOverCommit() ? ResultSet.HOLD_CURSORS_OVER_COMMIT
        : ResultSet.CLOSE_CURSORS_AT_COMMIT;
  } finally {
    this.conn.unlock();
  }
}
 
Example 7
Source File: 1205753_EmbedPooledConnection_0_s.java    From coming with MIT License 5 votes vote down vote up
void resetRealConnection() throws SQLException {

		// ensure any outstanding changes from the previous
		// user are rolledback.
		realConnection.rollback();

		// clear any warnings that are left over
		realConnection.clearWarnings();

		// need to reset transaction isolation, autocommit, readonly, holdability states
		if (realConnection.getTransactionIsolation() != defaultIsolationLevel) {

			realConnection.setTransactionIsolation(defaultIsolationLevel);
		}

		if (!realConnection.getAutoCommit())
			realConnection.setAutoCommit(true);

		if (realConnection.isReadOnly() != defaultReadOnly)
			realConnection.setReadOnly(defaultReadOnly);

		if (realConnection.getHoldability() != ResultSet.HOLD_CURSORS_OVER_COMMIT)
			realConnection.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);

		// reset any remaining state of the connection
		realConnection.resetFromPool();
		if (SanityManager.DEBUG)
		{
			SanityManager.ASSERT(realConnection.transactionIsIdle(),
			"real connection should have been idle at this point"); 			
		}
	}
 
Example 8
Source File: 1205753_EmbedPooledConnection_0_t.java    From coming with MIT License 5 votes vote down vote up
void resetRealConnection() throws SQLException {

		// ensure any outstanding changes from the previous
		// user are rolledback.
		realConnection.rollback();

		// clear any warnings that are left over
		realConnection.clearWarnings();

		// need to reset transaction isolation, autocommit, readonly, holdability states
		if (realConnection.getTransactionIsolation() != defaultIsolationLevel) {

			realConnection.setTransactionIsolation(defaultIsolationLevel);
		}

		if (!realConnection.getAutoCommit())
			realConnection.setAutoCommit(true);

		if (realConnection.isReadOnly() != defaultReadOnly)
			realConnection.setReadOnly(defaultReadOnly);

		if (realConnection.getHoldability() != ResultSet.HOLD_CURSORS_OVER_COMMIT)
			realConnection.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);

		// reset any remaining state of the connection
		realConnection.resetFromPool();
		if (SanityManager.DEBUG)
		{
			SanityManager.ASSERT(realConnection.transactionIsIdle(),
			"real connection should have been idle at this point"); 			
		}
	}
 
Example 9
Source File: StatementKeyFactoryTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testEqualityDefaultNoAutoGenKey() {
    int holdability = ResultSet.HOLD_CURSORS_OVER_COMMIT;
    StatementKey basicKey = StatementKeyFactory.newPrepared(
            "values 2", "APP", holdability);
    StatementKey simplifiedKey = StatementKeyFactory.newPrepared(
            "values 2", "APP", holdability, Statement.NO_GENERATED_KEYS);
    assertTrue(basicKey.equals(simplifiedKey));
    assertTrue(simplifiedKey.equals(basicKey));
}
 
Example 10
Source File: StatementKeyFactoryTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testCallableVsPrepared() {
    String sql = "select colA, colB from mytable";
    String schema = "SOMEAPP";
    int holdability = ResultSet.HOLD_CURSORS_OVER_COMMIT;
    StatementKey callable =
            StatementKeyFactory.newCallable(sql, schema, holdability);
    StatementKey prepared =
            StatementKeyFactory.newPrepared(sql, schema, holdability);
    assertFalse(callable.equals(prepared));
    assertFalse(prepared.equals(callable));
}
 
Example 11
Source File: AvaticaClosedStatementTest.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
@Override protected Statement newInstance() throws Exception {
  UnregisteredDriver driver = new TestDriver();
  AvaticaConnection connection = new AvaticaConnection(driver, driver.createFactory(),
      "jdbc:avatica", new Properties()) {
  };
  StatementHandle handle = mock(StatementHandle.class);
  AvaticaStatement statement = new AvaticaStatement(connection, handle,
      ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
      ResultSet.HOLD_CURSORS_OVER_COMMIT) {
  };
  statement.close();
  assertTrue("Statement is not closed", statement.isClosed());

  return statement;
}
 
Example 12
Source File: OOConnection.java    From jaybird with GNU Lesser General Public License v2.1 5 votes vote down vote up
public OOConnection(FBManagedConnection mc) {
    super(mc);
    try {
        super.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);
    } catch (SQLException e) {
        // ignore
        log.debug("Unexpected exception setting holdability", e);
    }
}
 
Example 13
Source File: 1205753_EmbedPooledConnection_0_s.java    From coming with MIT License 5 votes vote down vote up
void resetRealConnection() throws SQLException {

		// ensure any outstanding changes from the previous
		// user are rolledback.
		realConnection.rollback();

		// clear any warnings that are left over
		realConnection.clearWarnings();

		// need to reset transaction isolation, autocommit, readonly, holdability states
		if (realConnection.getTransactionIsolation() != defaultIsolationLevel) {

			realConnection.setTransactionIsolation(defaultIsolationLevel);
		}

		if (!realConnection.getAutoCommit())
			realConnection.setAutoCommit(true);

		if (realConnection.isReadOnly() != defaultReadOnly)
			realConnection.setReadOnly(defaultReadOnly);

		if (realConnection.getHoldability() != ResultSet.HOLD_CURSORS_OVER_COMMIT)
			realConnection.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);

		// reset any remaining state of the connection
		realConnection.resetFromPool();
		if (SanityManager.DEBUG)
		{
			SanityManager.ASSERT(realConnection.transactionIsIdle(),
			"real connection should have been idle at this point"); 			
		}
	}
 
Example 14
Source File: ShardingStatement.java    From sharding-jdbc-1.5.1 with Apache License 2.0 4 votes vote down vote up
public ShardingStatement(final ShardingConnection shardingConnection) {
    this(shardingConnection, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
}
 
Example 15
Source File: ShardingSphereStatement.java    From shardingsphere with Apache License 2.0 4 votes vote down vote up
public ShardingSphereStatement(final ShardingSphereConnection connection) {
    this(connection, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
}
 
Example 16
Source File: CassandraStatement.java    From cassandra-jdbc-wrapper with Apache License 2.0 4 votes vote down vote up
CassandraStatement(CassandraConnection con, String cql) throws SQLException
{
    this(con, cql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
}
 
Example 17
Source File: PrestoDatabaseMetaData.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public int getResultSetHoldability()
        throws SQLException
{
    return ResultSet.HOLD_CURSORS_OVER_COMMIT;
}
 
Example 18
Source File: CsvConnection.java    From jdbc-driver-csv with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public int getHoldability() throws SQLException {
    checkOpen();

    return ResultSet.HOLD_CURSORS_OVER_COMMIT;
}
 
Example 19
Source File: ShardingPreparedStatement.java    From sharding-jdbc-1.5.1 with Apache License 2.0 4 votes vote down vote up
public ShardingPreparedStatement(final ShardingConnection shardingConnection, final String sql) {
    this(shardingConnection, sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
}
 
Example 20
Source File: ShardingStatement.java    From sharding-jdbc-1.5.1 with Apache License 2.0 4 votes vote down vote up
public ShardingStatement(final ShardingConnection shardingConnection, final int resultSetType, final int resultSetConcurrency) {
    this(shardingConnection, resultSetType, resultSetConcurrency, ResultSet.HOLD_CURSORS_OVER_COMMIT);
}