Example usage for java.sql ResultSet HOLD_CURSORS_OVER_COMMIT

List of usage examples for java.sql ResultSet HOLD_CURSORS_OVER_COMMIT

Introduction

In this page you can find the example usage for java.sql ResultSet HOLD_CURSORS_OVER_COMMIT.

Prototype

int HOLD_CURSORS_OVER_COMMIT

To view the source code for java.sql ResultSet HOLD_CURSORS_OVER_COMMIT.

Click Source Link

Document

The constant indicating that open ResultSet objects with this holdability will remain open when the current transaction is committed.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getConnection();

    DatabaseMetaData dbMeta = conn.getMetaData();
    if (dbMeta.supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT)) {
        System.out.println("this database hold cursors over commit");
    } else if (dbMeta.supportsResultSetHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT)) {
        System.out.println("this database close cursors at commit");
    }/*  w w  w.j av  a 2 s  .com*/
    conn.close();

}

From source file:com.alibaba.wasp.jdbc.TestJdbcStatement.java

@Test
public void testStatement() throws SQLException, IOException, InterruptedException {
    Statement stat = conn.createStatement();

    assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, conn.getHoldability());
    conn.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
    assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, conn.getHoldability());
    // ignored/*from   www .  ja v  a 2 s  .c  om*/
    stat.setCursorName("x");
    // fixed return value
    assertEquals(stat.getFetchDirection(), ResultSet.FETCH_FORWARD);
    // ignored
    stat.setFetchDirection(ResultSet.FETCH_REVERSE);
    // ignored
    stat.setMaxFieldSize(100);

    assertEquals(conf.getInt(FConstants.WASP_JDBC_FETCHSIZE, FConstants.DEFAULT_WASP_JDBC_FETCHSIZE),
            stat.getFetchSize());
    stat.setFetchSize(10);
    assertEquals(10, stat.getFetchSize());
    stat.setFetchSize(0);
    assertEquals(conf.getInt(FConstants.WASP_JDBC_FETCHSIZE, FConstants.DEFAULT_WASP_JDBC_FETCHSIZE),
            stat.getFetchSize());
    assertEquals(ResultSet.TYPE_FORWARD_ONLY, stat.getResultSetType());
    Statement stat2 = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY,
            ResultSet.HOLD_CURSORS_OVER_COMMIT);
    assertEquals(ResultSet.TYPE_SCROLL_SENSITIVE, stat2.getResultSetType());
    assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, stat2.getResultSetHoldability());
    assertEquals(ResultSet.CONCUR_READ_ONLY, stat2.getResultSetConcurrency());
    assertEquals(0, stat.getMaxFieldSize());
    assertTrue(!((JdbcStatement) stat2).isClosed());
    stat2.close();
    assertTrue(((JdbcStatement) stat2).isClosed());

    ResultSet rs;
    int count;
    boolean result;

    stat.execute("CREATE TABLE TEST {REQUIRED INT64 ID;" + "REQUIRED STRING VALUE; }PRIMARY KEY(ID), "
            + "ENTITY GROUP ROOT,ENTITY GROUP KEY(ID);");

    TEST_UTIL.waitTableEnabled(Bytes.toBytes("TEST"), 5000);

    ResultInHBasePrinter.printMETA(conf, LOG);
    ResultInHBasePrinter.printFMETA(conf, LOG);
    ResultInHBasePrinter.printTable("test", "WASP_ENTITY_TEST", conf, LOG);

    conn.getTypeMap();

    // this method should not throw an exception - if not supported, this
    // calls are ignored

    assertEquals(ResultSet.CONCUR_READ_ONLY, stat.getResultSetConcurrency());

    // stat.cancel();
    stat.setQueryTimeout(10);
    assertTrue(stat.getQueryTimeout() == 10);
    stat.setQueryTimeout(0);
    assertTrue(stat.getQueryTimeout() == 0);
    // assertThrows(SQLErrorCode.INVALID_VALUE_2, stat).setQueryTimeout(-1);
    assertTrue(stat.getQueryTimeout() == 0);
    trace("executeUpdate");
    count = stat.executeUpdate("INSERT INTO TEST (ID,VALUE) VALUES (1,'Hello')");
    assertEquals(1, count);
    count = stat.executeUpdate("INSERT INTO TEST (VALUE,ID) VALUES ('JDBC',2)");
    assertEquals(1, count);
    count = stat.executeUpdate("UPDATE TEST SET VALUE='LDBC' WHERE ID=1");
    assertEquals(1, count);

    count = stat.executeUpdate("DELETE FROM TEST WHERE ID=-1");
    assertEquals(0, count);
    count = stat.executeUpdate("DELETE FROM TEST WHERE ID=1");
    assertEquals(1, count);
    count = stat.executeUpdate("DELETE FROM TEST WHERE ID=2");
    assertEquals(1, count);

    result = stat.execute("INSERT INTO TEST(ID,VALUE) VALUES(1,'Hello')");
    assertTrue(!result);
    result = stat.execute("INSERT INTO TEST(VALUE,ID) VALUES('JDBC',2)");
    assertTrue(!result);
    result = stat.execute("UPDATE TEST SET VALUE='LDBC' WHERE ID=2");
    assertTrue(!result);
    result = stat.execute("DELETE FROM TEST WHERE ID=1");
    assertTrue(!result);
    result = stat.execute("DELETE FROM TEST WHERE ID=2");
    assertTrue(!result);
    result = stat.execute("DELETE FROM TEST WHERE ID=3");
    assertTrue(!result);

    // getMoreResults
    rs = stat.executeQuery("SELECT ID,VALUE FROM TEST WHERE ID=1");
    assertFalse(stat.getMoreResults());
    assertThrows(SQLErrorCode.OBJECT_CLOSED, rs).next();
    assertTrue(stat.getUpdateCount() == -1);
    count = stat.executeUpdate("DELETE FROM TEST WHERE ID=1");
    assertFalse(stat.getMoreResults());
    assertTrue(stat.getUpdateCount() == -1);

    WaspAdmin admin = new WaspAdmin(TEST_UTIL.getConfiguration());
    admin.disableTable("TEST");
    stat.execute("DROP TABLE TEST");
    admin.waitTableNotLocked("TEST".getBytes());
    stat.executeUpdate("DROP TABLE IF EXISTS TEST");

    assertTrue(stat.getWarnings() == null);
    stat.clearWarnings();
    assertTrue(stat.getWarnings() == null);
    assertTrue(conn == stat.getConnection());

    admin.close();
    stat.close();
}

From source file:com.github.adejanovski.cassandra.jdbc.CassandraStatement.java

CassandraStatement(CassandraConnection con) throws SQLException {
    this(con, null, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
            ResultSet.HOLD_CURSORS_OVER_COMMIT);
}

From source file:com.github.adejanovski.cassandra.jdbc.CassandraStatement.java

CassandraStatement(CassandraConnection con, String cql) throws SQLException {
    this(con, cql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
}

From source file:com.github.adejanovski.cassandra.jdbc.CassandraStatement.java

CassandraStatement(CassandraConnection con, String cql, int resultSetType, int resultSetConcurrency)
        throws SQLException {
    this(con, cql, resultSetType, resultSetConcurrency, ResultSet.HOLD_CURSORS_OVER_COMMIT);
}

From source file:com.oracle.tutorial.jdbc.JDBCTutorialUtilities.java

public static void cursorHoldabilitySupport(Connection conn) throws SQLException {
    DatabaseMetaData dbMetaData = conn.getMetaData();
    System.out.println("ResultSet.HOLD_CURSORS_OVER_COMMIT = " + ResultSet.HOLD_CURSORS_OVER_COMMIT);
    System.out.println("ResultSet.CLOSE_CURSORS_AT_COMMIT = " + ResultSet.CLOSE_CURSORS_AT_COMMIT);
    System.out.println("Default cursor holdability: " + dbMetaData.getResultSetHoldability());
    System.out.println("Supports HOLD_CURSORS_OVER_COMMIT? "
            + dbMetaData.supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT));
    System.out.println("Supports CLOSE_CURSORS_AT_COMMIT? "
            + dbMetaData.supportsResultSetHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT));
}

From source file:org.xenei.jdbc4sparql.J4SConnection.java

public J4SConnection(final J4SDriver driver, final J4SUrl url, final Properties properties)
        throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException,
        MissingAnnotation, SQLException {
    if (properties == null) {
        throw new IllegalArgumentException("Properties may not be null");
    }//  w ww .  j  a  va 2 s. c  o m
    this.properties = properties;

    this.catalogMap = new HashMap<String, Catalog>();
    this.sqlWarnings = null;
    this.driver = driver;
    this.url = url;
    this.clientInfo = new Properties();

    this.holdability = ResultSet.HOLD_CURSORS_OVER_COMMIT;

    // create the SPARQLParser
    this.sparqlParser = url.getParser() != null ? url.getParser() : SparqlParser.Util.getDefaultParser();

    // default catalog name is set here and catalog schema is set here
    mergeProperties(url.getProperties());

    // make sure the dataset producer class is set.
    if (!properties.containsKey(J4SPropertyNames.DATASET_PRODUCER)) {
        properties.setProperty(J4SPropertyNames.DATASET_PRODUCER, MemDatasetProducer.class.getCanonicalName());
    }

    configureCatalogMap();

    if (catalogMap.get(MetaCatalogBuilder.LOCAL_NAME) == null) {
        dsProducer.getMetaDataModel(MetaCatalogBuilder.LOCAL_NAME);
        final Catalog c = MetaCatalogBuilder.getInstance(dsProducer);
        catalogMap.put(c.getName().getShortName(), c);
    }
    if (StringUtils.isNotEmpty(getCatalog()) && (catalogMap.get(getCatalog()) == null)) {
        throw new IllegalArgumentException(
                String.format("Catalog '%s' not found in catalog map", getCatalog()));
    }

    catalogMap.put(VirtualCatalog.NAME, new VirtualCatalog());

}

From source file:com.github.adejanovski.cassandra.jdbc.CassandraStatement.java

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;
}

From source file:com.github.woonsan.jdbc.jcr.impl.JcrJdbcResultSetTest.java

@Test
public void testExecuteSQLQuery() throws Exception {
    Statement statement = getConnection().createStatement();
    ResultSet rs = statement.executeQuery(SQL_EMPS);
    assertSame(statement, rs.getStatement());

    assertEquals(ResultSet.TYPE_FORWARD_ONLY, rs.getType());
    assertEquals(ResultSet.CONCUR_READ_ONLY, rs.getConcurrency());
    assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, rs.getHoldability());

    assertFalse(rs.isClosed());/* w w  w. j  ava 2  s .  com*/
    assertTrue(rs.isBeforeFirst());
    assertFalse(rs.isAfterLast());

    assertEquals(1, rs.findColumn("empno"));
    assertEquals(2, rs.findColumn("ename"));
    assertEquals(3, rs.findColumn("salary"));
    assertEquals(4, rs.findColumn("hiredate"));

    int count = printResultSet(rs);

    assertEquals(getEmpRowCount(), count);
    assertFalse(rs.isBeforeFirst());
    assertTrue(rs.isAfterLast());
    rs.close();
    assertTrue(rs.isClosed());

    statement.close();
    assertTrue(statement.isClosed());
}

From source file:nl.nn.adapterframework.jdbc.JdbcFacade.java

public String getDatasourceInfo() throws JdbcException {
    String dsinfo = null;// ww w.  ja v  a 2 s  .c om
    Connection conn = null;
    try {
        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 configWarnings = ConfigurationWarnings.getInstance();
            configWarnings.add(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);
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e1) {
                log.warn("exception closing connection for metadata", e1);
            }
        }
    }
    return dsinfo;
}