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:no.polaric.aprsdb.MyDBSession.java

/**
 * Get list of signs in a specified geographic area and above a specified scale 
 *///from   ww w  .  ja va2  s  .  co  m
public DbList<Signs.Item> getSigns(long scale, Reference uleft, Reference lright) throws java.sql.SQLException {
    PreparedStatement stmt = getCon().prepareStatement(
            " SELECT s.id AS sid, position, maxscale, url, description, cl.name, s.icon AS sicon, cl.icon AS cicon "
                    + " FROM \"Signs\" s LEFT JOIN \"SignClass\" cl ON s.class=cl.id"
                    + " WHERE maxscale>=? AND position && ST_MakeEnvelope(?, ?, ?, ?, 4326) AND NOT s.hidden"
                    + " LIMIT 200",
            ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
    stmt.setLong(1, scale);
    LatLng ul = uleft.toLatLng();
    LatLng lr = lright.toLatLng();
    stmt.setDouble(2, ul.getLng());
    stmt.setDouble(3, ul.getLat());
    stmt.setDouble(4, lr.getLng());
    stmt.setDouble(5, lr.getLat());
    stmt.setMaxRows(200);

    return new DbList(stmt.executeQuery(), rs -> {
        String icon = rs.getString("sicon");
        if (icon == null)
            icon = rs.getString("cicon");

        // Item (Reference r, long sc, String ic, String url, String txt)
        return new Signs.Item(rs.getInt("sid"), getRef(rs, "position"), 0, icon, rs.getString("url"),
                rs.getString("description"));
    });
}

From source file:com.facebook.presto.jdbc.PrestoConnection.java

@Override
public void setHoldability(int holdability) throws SQLException {
    checkOpen();/*ww  w.jav a  2 s.c  o m*/
    if (holdability != ResultSet.HOLD_CURSORS_OVER_COMMIT) {
        throw new SQLFeatureNotSupportedException("Changing holdability not supported");
    }
}

From source file:com.facebook.presto.jdbc.PrestoConnection.java

@Override
public int getHoldability() throws SQLException {
    checkOpen();
    return ResultSet.HOLD_CURSORS_OVER_COMMIT;
}

From source file:org.apache.bigtop.itest.hive.TestJdbc.java

/**
 * Test simple DatabaseMetaData calls.  getColumns is tested elsewhere, as we need to call
 * that on a valid table.  Same with getFunctions.
 *
 * @throws SQLException//from  w w  w.j  a v a 2  s .  c  om
 */
@Test
public void databaseMetaDataCalls() throws SQLException {
    DatabaseMetaData md = conn.getMetaData();

    boolean boolrc = md.allTablesAreSelectable();
    LOG.debug("All tables are selectable? " + boolrc);

    String strrc = md.getCatalogSeparator();
    LOG.debug("Catalog separator " + strrc);

    strrc = md.getCatalogTerm();
    LOG.debug("Catalog term " + strrc);

    ResultSet rs = md.getCatalogs();
    while (rs.next()) {
        strrc = rs.getString(1);
        LOG.debug("Found catalog " + strrc);
    }

    Connection c = md.getConnection();

    int intrc = md.getDatabaseMajorVersion();
    LOG.debug("DB major version is " + intrc);

    intrc = md.getDatabaseMinorVersion();
    LOG.debug("DB minor version is " + intrc);

    strrc = md.getDatabaseProductName();
    LOG.debug("DB product name is " + strrc);

    strrc = md.getDatabaseProductVersion();
    LOG.debug("DB product version is " + strrc);

    intrc = md.getDefaultTransactionIsolation();
    LOG.debug("Default transaction isolation is " + intrc);

    intrc = md.getDriverMajorVersion();
    LOG.debug("Driver major version is " + intrc);

    intrc = md.getDriverMinorVersion();
    LOG.debug("Driver minor version is " + intrc);

    strrc = md.getDriverName();
    LOG.debug("Driver name is " + strrc);

    strrc = md.getDriverVersion();
    LOG.debug("Driver version is " + strrc);

    strrc = md.getExtraNameCharacters();
    LOG.debug("Extra name characters is " + strrc);

    strrc = md.getIdentifierQuoteString();
    LOG.debug("Identifier quote string is " + strrc);

    // In Hive 1.2 this always returns an empty RS
    rs = md.getImportedKeys("a", "b", "d");

    // In Hive 1.2 this always returns an empty RS
    rs = md.getIndexInfo("a", "b", "d", true, true);

    intrc = md.getJDBCMajorVersion();
    LOG.debug("JDBC major version is " + intrc);

    intrc = md.getJDBCMinorVersion();
    LOG.debug("JDBC minor version is " + intrc);

    intrc = md.getMaxColumnNameLength();
    LOG.debug("Maximum column name length is " + intrc);

    strrc = md.getNumericFunctions();
    LOG.debug("Numeric functions are " + strrc);

    // In Hive 1.2 this always returns an empty RS
    rs = md.getPrimaryKeys("a", "b", "d");

    // In Hive 1.2 this always returns an empty RS
    rs = md.getProcedureColumns("a", "b", "d", "e");

    strrc = md.getProcedureTerm();
    LOG.debug("Procedures are called " + strrc);

    // In Hive 1.2 this always returns an empty RS
    rs = md.getProcedures("a", "b", "d");

    strrc = md.getSchemaTerm();
    LOG.debug("Schemas are called " + strrc);

    rs = md.getSchemas();
    while (rs.next()) {
        strrc = rs.getString(1);
        LOG.debug("Found schema " + strrc);
    }

    strrc = md.getSearchStringEscape();
    LOG.debug("Search string escape is " + strrc);

    strrc = md.getStringFunctions();
    LOG.debug("String functions are " + strrc);

    strrc = md.getSystemFunctions();
    LOG.debug("System functions are " + strrc);

    rs = md.getTableTypes();
    while (rs.next()) {
        strrc = rs.getString(1);
        LOG.debug("Found table type " + strrc);
    }

    strrc = md.getTimeDateFunctions();
    LOG.debug("Time/date functions are " + strrc);

    rs = md.getTypeInfo();
    while (rs.next()) {
        strrc = rs.getString(1);
        LOG.debug("Found type " + strrc);
    }

    // In Hive 1.2 this always returns an empty RS
    rs = md.getUDTs("a", "b", "d", null);

    boolrc = md.supportsAlterTableWithAddColumn();
    LOG.debug("Supports alter table with add column? " + boolrc);

    boolrc = md.supportsAlterTableWithDropColumn();
    LOG.debug("Supports alter table with drop column? " + boolrc);

    boolrc = md.supportsBatchUpdates();
    LOG.debug("Supports batch updates? " + boolrc);

    boolrc = md.supportsCatalogsInDataManipulation();
    LOG.debug("Supports catalogs in data manipulation? " + boolrc);

    boolrc = md.supportsCatalogsInIndexDefinitions();
    LOG.debug("Supports catalogs in index definition? " + boolrc);

    boolrc = md.supportsCatalogsInPrivilegeDefinitions();
    LOG.debug("Supports catalogs in privilege definition? " + boolrc);

    boolrc = md.supportsCatalogsInProcedureCalls();
    LOG.debug("Supports catalogs in procedure calls? " + boolrc);

    boolrc = md.supportsCatalogsInTableDefinitions();
    LOG.debug("Supports catalogs in table definition? " + boolrc);

    boolrc = md.supportsColumnAliasing();
    LOG.debug("Supports column aliasing? " + boolrc);

    boolrc = md.supportsFullOuterJoins();
    LOG.debug("Supports full outer joins? " + boolrc);

    boolrc = md.supportsGroupBy();
    LOG.debug("Supports group by? " + boolrc);

    boolrc = md.supportsLimitedOuterJoins();
    LOG.debug("Supports limited outer joins? " + boolrc);

    boolrc = md.supportsMultipleResultSets();
    LOG.debug("Supports limited outer joins? " + boolrc);

    boolrc = md.supportsNonNullableColumns();
    LOG.debug("Supports non-nullable columns? " + boolrc);

    boolrc = md.supportsOuterJoins();
    LOG.debug("Supports outer joins? " + boolrc);

    boolrc = md.supportsPositionedDelete();
    LOG.debug("Supports positioned delete? " + boolrc);

    boolrc = md.supportsPositionedUpdate();
    LOG.debug("Supports positioned update? " + boolrc);

    boolrc = md.supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);
    LOG.debug("Supports result set holdability? " + boolrc);

    boolrc = md.supportsResultSetType(ResultSet.HOLD_CURSORS_OVER_COMMIT);
    LOG.debug("Supports result set type? " + boolrc);

    boolrc = md.supportsSavepoints();
    LOG.debug("Supports savepoints? " + boolrc);

    boolrc = md.supportsSchemasInDataManipulation();
    LOG.debug("Supports schemas in data manipulation? " + boolrc);

    boolrc = md.supportsSchemasInIndexDefinitions();
    LOG.debug("Supports schemas in index definitions? " + boolrc);

    boolrc = md.supportsSchemasInPrivilegeDefinitions();
    LOG.debug("Supports schemas in privilege definitions? " + boolrc);

    boolrc = md.supportsSchemasInProcedureCalls();
    LOG.debug("Supports schemas in procedure calls? " + boolrc);

    boolrc = md.supportsSchemasInTableDefinitions();
    LOG.debug("Supports schemas in table definitions? " + boolrc);

    boolrc = md.supportsSelectForUpdate();
    LOG.debug("Supports select for update? " + boolrc);

    boolrc = md.supportsStoredProcedures();
    LOG.debug("Supports stored procedures? " + boolrc);

    boolrc = md.supportsTransactions();
    LOG.debug("Supports transactions? " + boolrc);

    boolrc = md.supportsUnion();
    LOG.debug("Supports union? " + boolrc);

    boolrc = md.supportsUnionAll();
    LOG.debug("Supports union all? " + boolrc);

}

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

public int getResultSetHoldability() throws SQLException {
    checkNotClosed();/*from   w ww  . j a v a2s  .c o m*/
    // the Cassandra implementations does not support commits so this is the closest match
    return ResultSet.HOLD_CURSORS_OVER_COMMIT;
}

From source file:org.pentaho.di.core.jdbc.ThinResultSet.java

@Override
public int getHoldability() throws SQLException {
    return ResultSet.HOLD_CURSORS_OVER_COMMIT;
}

From source file:com.facebook.presto.jdbc.PrestoConnection.java

private static void checkHoldability(int resultSetHoldability) throws SQLFeatureNotSupportedException {
    if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT) {
        throw new SQLFeatureNotSupportedException("Result set holdability must be HOLD_CURSORS_OVER_COMMIT");
    }/* w ww  . j a va2s . c  o  m*/
}

From source file:com.cloud.utils.db.Transaction.java

protected void closePreviousStatement() {
    if (_stmt != null) {
        try {/* w w w . ja va2 s  . c o  m*/
            if (s_stmtLogger.isTraceEnabled()) {
                s_stmtLogger.trace("Closing: " + _stmt.toString());
            }
            try {
                ResultSet rs = _stmt.getResultSet();
                if (rs != null && _stmt.getResultSetHoldability() != ResultSet.HOLD_CURSORS_OVER_COMMIT) {
                    rs.close();
                }
            } catch (SQLException e) {
                s_stmtLogger.trace("Unable to close resultset");
            }
            _stmt.close();
        } catch (final SQLException e) {
            s_stmtLogger.trace("Unable to close statement: " + _stmt.toString());
        } finally {
            _stmt = null;
        }
    }
}

From source file:com.novartis.opensource.yada.QueryManager.java

/**
 * Executes a query-level commit on the connection stored in the YADAQuery
 * referenced by the parameter. If the connection object returned by the query
 * is not a JDBC connection, but, for instance, a SOAPConnection, the error
 * will be caught and handled gracefully.
 * //  www .j a  va 2s .  c  o  m
 * @param yq
 *          the query containing the statements to commit
 * @throws YADAConnectionException
 *           when the commit fails
 */
public void commit(YADAQuery yq) throws YADAConnectionException {
    try {
        if (this.requiredCommits.contains(yq.getSource())) {
            Connection connection = (Connection) yq.getConnection();
            if (connection.getHoldability() == ResultSet.HOLD_CURSORS_OVER_COMMIT) {
                connection.commit();
                int count = yq.getResult().getTotalResultCount();
                String rows = count == 1 ? "row" : "rows";
                String msg = "\n------------------------------------------------------------\n";
                msg += "   Commit successful on connection to [" + yq.getSource() + "] (" + count + " " + rows
                        + ")\n";
                msg += "------------------------------------------------------------\n";
                l.debug(msg);
            } else {
                deferCommit(yq.getSource());
            }
        }
    } catch (SQLException e) {
        String msg = "Unable to commit transaction on [" + yq.getSource() + "].";
        throw new YADAConnectionException(msg, e);
    } catch (ClassCastException e) {
        l.info("Connection to [" + yq.getSource()
                + "] is not a JDBC connection (it's probably SOAP.) No commit was attempted.");
    }
}

From source file:com.novartis.opensource.yada.QueryManager.java

/**
 * Executes a commit on all connections created during processing of the
 * current request./*  w ww  . j  a v  a  2 s.com*/
 * 
 * @throws YADAConnectionException
 *           when the commit fails
 */
public void commit() throws YADAConnectionException {
    if (this.connectionMap != null && this.connectionMap.keySet().size() > 0) {
        //TODO         int    totalCount = 0;
        String source = "";
        for (Iterator<String> iterator = this.requiredCommits.iterator(); iterator.hasNext();) {
            try {
                source = iterator.next();
                Connection connection = (Connection) this.connectionMap.get(source);
                if (connection.getHoldability() == ResultSet.HOLD_CURSORS_OVER_COMMIT) {
                    connection.commit();
                    String msg = "\n------------------------------------------------------------\n";
                    msg += "   Commit successful on [" + source + "].\n";
                    msg += "------------------------------------------------------------\n";
                    l.info(msg);
                } else {
                    deferCommit(source);
                }
            } catch (SQLException e) {
                String msg = "Unable to commit transaction on [" + source + "].";
                throw new YADAConnectionException(msg, e);
            } catch (ClassCastException e) {
                l.info("Connection to [" + source
                        + "] is not a JDBC connection (it's probably SOAP.)  No commit was attempted.");
            }
        }
    }
}