Example usage for java.sql Connection getHoldability

List of usage examples for java.sql Connection getHoldability

Introduction

In this page you can find the example usage for java.sql Connection getHoldability.

Prototype

int getHoldability() throws SQLException;

Source Link

Document

Retrieves the current holdability of ResultSet objects created using this Connection object.

Usage

From source file:net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.java

protected static int getHoldability(String holdability, Connection connection) throws SQLException {
    if (HOLD_CURSORS_OVER_COMMIT.equals(holdability)) {
        return ResultSet.HOLD_CURSORS_OVER_COMMIT;
    } else if (CLOSE_CURSORS_AT_COMMIT.equals(holdability)) {
        return ResultSet.CLOSE_CURSORS_AT_COMMIT;
    }/*from  ww w. ja v  a 2  s.  c  o m*/

    return connection.getHoldability();
}

From source file:com.taobao.tddl.jdbc.group.TGroupStatement.java

/**
 * setBaseStatementStatement//from   w  ww.  j ava2s.com
 */
private Statement createStatementInternal(Connection conn, boolean isBatch) throws SQLException {
    Statement stmt;
    if (isBatch)
        stmt = conn.createStatement();
    else {
        int resultSetHoldability = this.resultSetHoldability;
        if (resultSetHoldability == -1) //setResultSetHoldability
            resultSetHoldability = conn.getHoldability();

        stmt = conn.createStatement(this.resultSetType, this.resultSetConcurrency, resultSetHoldability);
    }

    setBaseStatement(stmt); //Statement
    stmt.setQueryTimeout(queryTimeout); //
    stmt.setFetchSize(fetchSize);
    stmt.setMaxRows(maxRows);

    return stmt;
}

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.
 * //w  w  w  . j  a  v a 2  s  .  c  om
 * @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. ja v a  2 s  .c o m*/
 * 
 * @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.");
            }
        }
    }
}

From source file:com.taobao.tddl.jdbc.group.TGroupPreparedStatement.java

private PreparedStatement createPreparedStatementInternal(Connection conn, String sql) throws SQLException {
    PreparedStatement ps;/*  w w  w  . j  a  v  a2s  . c  o  m*/
    if (autoGeneratedKeys != -1) {
        ps = conn.prepareStatement(sql, autoGeneratedKeys);
    } else if (columnIndexes != null) {
        ps = conn.prepareStatement(sql, columnIndexes);
    } else if (columnNames != null) {
        ps = conn.prepareStatement(sql, columnNames);
    } else {
        int resultSetHoldability = this.resultSetHoldability;
        if (resultSetHoldability == -1) //setResultSetHoldability
            resultSetHoldability = conn.getHoldability();

        ps = conn.prepareStatement(sql, this.resultSetType, this.resultSetConcurrency, resultSetHoldability);
    }
    setBaseStatement(ps);
    ps.setQueryTimeout(queryTimeout); //setBaseStatement
    ps.setFetchSize(fetchSize);
    ps.setMaxRows(maxRows);

    return ps;
}

From source file:com.adaptris.jdbc.connection.FailoverDatasourceTest.java

@Test
public void testInfo() throws Exception {
    Connection conn = new MyProxy();

    try {/*w w w  .  j  av  a  2  s  .  com*/
        try {
            conn.getMetaData();
        } catch (SQLException e) {

        }
        try {
            conn.setCatalog(conn.getCatalog());
        } catch (SQLException e) {

        }
        try {
            conn.setReadOnly(conn.isReadOnly());
        } catch (SQLException e) {

        }
        try {
            conn.setTransactionIsolation(conn.getTransactionIsolation());
        } catch (SQLException e) {

        }
        try {
            conn.setTransactionIsolation(conn.getTransactionIsolation());
        } catch (SQLException e) {

        }
        try {
            conn.getWarnings();
        } catch (SQLException e) {

        }
        try {
            conn.clearWarnings();
        } catch (SQLException e) {

        }
        try {
            conn.setHoldability(conn.getHoldability());
        } catch (SQLException e) {

        }

        try {
            conn.setSchema(conn.getSchema());
        } catch (SQLException e) {

        }

    } finally {
        JdbcUtil.closeQuietly(conn);
    }

}

From source file:org.apache.openjpa.jdbc.sql.DBDictionary.java

/**
 * This method is called when the dictionary first sees any connection.
 * It is used to initialize dictionary metadata if needed. If you
 * override this method, be sure to call
 * <code>super.connectedConfiguration</code>.
 *//*from  w w w.jav a2s  .c  o  m*/
public void connectedConfiguration(Connection conn) throws SQLException {
    if (!connected) {
        DatabaseMetaData metaData = null;
        try {
            metaData = conn.getMetaData();

            databaseProductName = nullSafe(metaData.getDatabaseProductName());
            databaseProductVersion = nullSafe(metaData.getDatabaseProductVersion());
            setMajorVersion(metaData.getDatabaseMajorVersion());
            setMinorVersion(metaData.getDatabaseMinorVersion());
            try {
                // JDBC3-only method, so it might throw an
                // AbstractMethodError
                int JDBCMajorVersion = metaData.getJDBCMajorVersion();
                isJDBC3 = JDBCMajorVersion >= 3;
                isJDBC4 = JDBCMajorVersion >= 4;
            } catch (Throwable t) {
                // ignore if not JDBC3
            }
        } catch (Exception e) {
            if (log.isTraceEnabled())
                log.trace(e.toString(), e);
        }

        if (log.isTraceEnabled()) {
            log.trace(DBDictionaryFactory.toString(metaData));

            if (isJDBC3) {
                try {
                    log.trace(_loc.get("connection-defaults", new Object[] { conn.getAutoCommit(),
                            conn.getHoldability(), conn.getTransactionIsolation() }));
                } catch (Throwable t) {
                    log.trace("Unable to trace connection settings", t);
                }
            }
        }

        // Configure the naming utility
        if (supportsDelimitedIdentifiers == null) // not explicitly set
            configureNamingUtil(metaData);

        // Auto-detect generated keys retrieval support unless user specified it.
        if (supportsGetGeneratedKeys == null) {
            supportsGetGeneratedKeys = (isJDBC3) ? metaData.supportsGetGeneratedKeys() : false;
        }
        if (log.isInfoEnabled()) {
            log.info(_loc.get("dict-info", new Object[] { metaData.getDatabaseProductName(), getMajorVersion(),
                    getMinorVersion(), metaData.getDriverName(), metaData.getDriverVersion() }));
        }
    }
    connected = true;
}