Example usage for java.sql ResultSet CONCUR_READ_ONLY

List of usage examples for java.sql ResultSet CONCUR_READ_ONLY

Introduction

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

Prototype

int CONCUR_READ_ONLY

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

Click Source Link

Document

The constant indicating the concurrency mode for a ResultSet object that may NOT be updated.

Usage

From source file:it.cnr.icar.eric.server.persistence.rdb.AbstractDAO.java

/**
 * Executes a Select statment that has an IN clause while
 * taking care to execute it in chunks to avoid scalability limits
 * in some databases (Oracle 10g limits terms in IN clause to 1000)
 *
 * Note: Caller is responsible for closing statement associated with each resultSet
 * in resultSets. //  w w w .j av  a 2 s .  co  m
 *
 * @param selectStmtTemplate a string representing the SELECT statment in a parameterized format consistent withebRR parameterized queries.
 * @return a List of Objects
 */
public List<ResultSet> executeBufferedSelectWithINClause(String selectStmtTemplate, List<?> terms,
        int termLimit) throws RegistryException {
    ArrayList<ResultSet> resultSets = new ArrayList<ResultSet>();

    if (terms.size() == 0) {
        return resultSets;
    }

    Iterator<?> iter = terms.iterator();

    try {
        //We need to count the number of terms in "IN" list. 
        //We need to split the SQL Strings into chunks if there are too many terms. 
        //Reason is that some database such as Oracle, do not allow the IN list is too long
        int termCounter = 0;

        StringBuffer inTerms = new StringBuffer();
        while (iter.hasNext()) {
            String term = (String) iter.next();

            if (iter.hasNext() && (termCounter < termLimit)) {
                inTerms.append("'" + term + "',");
            } else {
                inTerms.append("'" + term + "' ");
                String sql = selectStmtTemplate.replaceAll("\\$InClauseTerms", inTerms.toString());

                // xxx 120216 pa allow scrollable resultset for jump to end with rs.last()
                Statement stmt = context.getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                        ResultSet.CONCUR_READ_ONLY);
                ResultSet rs = stmt.executeQuery(sql);
                resultSets.add(rs);

                termCounter = 0;
                inTerms = new StringBuffer();
            }

            termCounter++;
        }

    } catch (SQLException e) {
        throw new RegistryException(e);
    }

    return resultSets;
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccPgSql.CFAccPgSqlSchema.java

public boolean beginTransaction() {
    if (inTransaction) {
        return (false);
    }//from   w ww . j a  v  a 2s. c o m
    try {
        String sql = "begin transaction";
        Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        stmt.execute(sql);
        inTransaction = true;
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "beginTransaction", e);
    }
    return (inTransaction);
}

From source file:com.nridge.core.ds.rdbms.hsqldb.HDBSQLTable.java

/**
 * Returns a low-level JDBC <i>ResultSet</i> representation of all rows
 * fetched from the RDBMS table that match the SQL select statement
 * provided./*  www  .  j a va 2  s. com*/
 * <p>
 * <b>Note:</b> The developer is responsible for ensuring that the
 * SQL statement is properly formatted for the RDBMS vendor it will
 * be executed against.
 * </p>
 *
 * @param aSelectFromWhereStatement SQL select statement.
 *
 * @return JDBC result set instance.
 *
 * @throws NSException Catch-all exception for any SQL related issue.
 */
@Override
public ResultSet select(String aSelectFromWhereStatement) throws NSException {
    Logger appLogger = mAppMgr.getLogger(this, "select");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    ResultSet resultSet;
    appLogger.debug(aSelectFromWhereStatement);
    Connection jdbcConnection = mSQLConnection.getJDBCConnection();
    try {
        Statement stmtQuery = jdbcConnection.createStatement(ResultSet.TYPE_FORWARD_ONLY,
                ResultSet.CONCUR_READ_ONLY);
        stmtQuery.setEscapeProcessing(mSQLConnection.isStatementEscapingEnabled());
        mSQLConnection.setLastStatement(aSelectFromWhereStatement);
        resultSet = stmtQuery.executeQuery(aSelectFromWhereStatement);
    } catch (SQLException e) {
        throw new NSException("RDBMS Query Error: " + aSelectFromWhereStatement + " : " + e.getMessage(), e);
    }

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);

    return resultSet;
}

From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8ChainTable.java

public void updateChain(MSSBamAuthorization Authorization, MSSBamChainBuff Buff) {
    final String S_ProcName = "updateChain";
    try {/*from  w  ww  .  jav  a2 s .c o  m*/
        Connection cnx = schema.getCnx();
        long Id = Buff.getRequiredId();
        long TableId = Buff.getRequiredTableId();
        String Suffix = Buff.getOptionalSuffix();
        Long PrevRelationId = Buff.getOptionalPrevRelationId();
        Long NextRelationId = Buff.getOptionalNextRelationId();

        String sql = "UPDATE mssbam110.chain_def " + "SET " + "Id = " + MSSBamPg8Schema.getInt64String(Id)
                + ", " + "TableId = " + MSSBamPg8Schema.getInt64String(TableId) + ", " + "Suffix = "
                + ((Suffix != null) ? MSSBamPg8Schema.getQuotedString(Suffix) : "null") + ", "
                + "PrevRelationId = "
                + ((PrevRelationId != null) ? MSSBamPg8Schema.getInt64String(PrevRelationId) : "null") + ", "
                + "NextRelationId = "
                + ((NextRelationId != null) ? MSSBamPg8Schema.getInt64String(NextRelationId) : "null") + " "
                + "WHERE " + "Id = " + Long.toString(Id) + " ";
        Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        int rowsAffected = stmt.executeUpdate(sql);
        if (rowsAffected != 1) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Expected 1 row to be affected by update, not " + rowsAffected);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    }
}

From source file:jp.mathes.databaseWiki.db.postgres.PostgresBackend.java

@Override
public List<String> getTables(final String user, final String password, final String db)
        throws BackendException {
    Statement st = null;// www .j  a  v a  2 s .  c o  m
    Connection conn = null;
    ResultSet rs = null;
    String query = String.format("select table_name from information_schema.tables where table_schema='%s'",
            this.getSchemaName("", db));
    List<String> result = new LinkedList<String>();
    try {
        conn = this.connectToDB(user, password, db);
        st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.logString(query.trim(), user);
        rs = st.executeQuery(query.trim());
        while (rs.next()) {
            result.add(rs.getString(1));
        }
    } catch (SQLException e) {
        throw new BackendException(e);
    } catch (ClassNotFoundException e) {
        throw new BackendException(e);
    } finally {
        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(st);
        DbUtils.closeQuietly(conn);
    }
    return result;
}

From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8BoolDefTable.java

public MSSBamBoolDefBuff[] readDerivedByAuthorIdx(MSSBamAuthorization Authorization, Long AuthorId) {
    final String S_ProcName = "readDerivedByAuthorIdx";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }/*from w w w . j a  v a2s.c  om*/
    ArrayList<String> classCodeList = new ArrayList<String>();
    String classCode;
    try {
        Connection cnx = schema.getCnx();
        String sql = S_sqlSelectBoolDefDistinctClassCode + "WHERE "
                + ((AuthorId == null) ? "anyo.AuthorId is null "
                        : "anyo.AuthorId = " + AuthorId.toString() + " ");
        Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        ResultSet resultSet = stmt.executeQuery(sql);
        while (resultSet.next()) {
            classCode = resultSet.getString(1);
            classCodeList.add(classCode);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    }
    ArrayList<MSSBamBoolDefBuff> resultList = new ArrayList<MSSBamBoolDefBuff>();
    ListIterator<String> classCodeIter = classCodeList.listIterator();
    while (classCodeIter.hasNext()) {
        classCode = classCodeIter.next();
        if (classCode.equals("BLN")) {
            MSSBamBoolDefBuff[] subList = readBuffByAuthorIdx(Authorization, AuthorId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("TBLN")) {
            MSSBamTableBoolBuff[] subList = schema.getTableTableBool().readBuffByAuthorIdx(Authorization,
                    AuthorId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("SBLN")) {
            MSSBamSchemaBoolBuff[] subList = schema.getTableSchemaBool().readBuffByAuthorIdx(Authorization,
                    AuthorId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Did not expect ClassCode \"" + classCode + "\"");
        }
    }
    return (resultList.toArray(new MSSBamBoolDefBuff[0]));

}

From source file:com.taobao.tdhs.jdbc.TDHSStatement.java

public int getResultSetConcurrency() throws SQLException {
    return ResultSet.CONCUR_READ_ONLY;
}

From source file:com.couchbase.CBConnection.java

/**
 * Creates a <code>Statement</code> object that will generate
 * <code>ResultSet</code> objects with the given type and concurrency.
 * This method is the same as the <code>createStatement</code> method
 * above, but it allows the default result set
 * type and concurrency to be overridden.
 * The holdability of the created result sets can be determined by
 * calling {@link #getHoldability}.//w ww .ja va  2  s.  c o m
 *
 * @param resultSetType        a result set type; one of
 *                             <code>ResultSet.TYPE_FORWARD_ONLY</code>,
 *                             <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
 *                             <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
 * @param resultSetConcurrency a concurrency type; one of
 *                             <code>ResultSet.CONCUR_READ_ONLY</code> or
 *                             <code>ResultSet.CONCUR_UPDATABLE</code>
 * @return a new <code>Statement</code> object that will generate
 * <code>ResultSet</code> objects with the given type and
 * concurrency
 * @throws java.sql.SQLException           if a database access error occurs, this
 *                                         method is called on a closed connection
 *                                         or the given parameters are not <code>ResultSet</code>
 *                                         constants indicating type and concurrency
 * @throws java.sql.SQLFeatureNotSupportedException if the JDBC driver does not support
 *                                         this method or this method is not supported for the specified result
 *                                         set type and result set concurrency.
 * @since 1.2
 */
@Override
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
    checkClosed();
    if (resultSetType == ResultSet.TYPE_FORWARD_ONLY && resultSetConcurrency == ResultSet.CONCUR_READ_ONLY)
        return createStatement();
    else
        throw CBDriver.notImplemented(CBConnection.class, "createStatement");

}

From source file:com.toxind.benchmark.thrid.ibatis.sqlmap.engine.execution.SqlExecutor.java

private PreparedStatement prepareStatement(SessionScope sessionScope, Connection conn, String sql,
        Integer rsType) throws SQLException {
    SqlMapExecutorDelegate delegate = ((SqlMapClientImpl) sessionScope.getSqlMapExecutor()).getDelegate();
    if (sessionScope.hasPreparedStatementFor(sql)) {
        return sessionScope.getPreparedStatement((sql));
    } else {//from   w  w w .j  a  va 2  s  . c  o  m
        PreparedStatement ps = conn.prepareStatement(sql, rsType.intValue(), ResultSet.CONCUR_READ_ONLY);
        sessionScope.putPreparedStatement(delegate, sql, ps);
        return ps;
    }
}

From source file:gobblin.source.extractor.extract.jdbc.JdbcExtractor.java

/**
 * Execute query using JDBC PreparedStatement to pass query parameters Set
 * fetch size//from   w  w  w  .  j av  a  2s .c  om
 *
 * @param cmds commands - query, fetch size, query parameters
 * @return JDBC ResultSet
 * @throws Exception
 */
private CommandOutput<?, ?> executePreparedSql(List<Command> cmds) {
    String query = null;
    List<String> queryParameters = null;
    int fetchSize = 0;

    for (Command cmd : cmds) {
        if (cmd instanceof JdbcCommand) {
            JdbcCommandType type = (JdbcCommandType) cmd.getCommandType();
            switch (type) {
            case QUERY:
                query = cmd.getParams().get(0);
                break;
            case QUERYPARAMS:
                queryParameters = cmd.getParams();
                break;
            case FETCHSIZE:
                fetchSize = Integer.parseInt(cmd.getParams().get(0));
                break;
            default:
                this.log.error("Command " + type.toString() + " not recognized");
                break;
            }
        }
    }

    this.log.info("Executing query:" + query);
    ResultSet resultSet = null;
    try {
        this.jdbcSource = createJdbcSource();
        this.dataConnection = this.jdbcSource.getConnection();

        PreparedStatement statement = this.dataConnection.prepareStatement(query, ResultSet.TYPE_FORWARD_ONLY,
                ResultSet.CONCUR_READ_ONLY);

        int parameterPosition = 1;
        if (queryParameters != null && queryParameters.size() > 0) {
            for (String parameter : queryParameters) {
                statement.setString(parameterPosition, parameter);
                parameterPosition++;
            }
        }
        if (fetchSize != 0) {
            statement.setFetchSize(fetchSize);
        }
        final boolean status = statement.execute();
        if (status == false) {
            this.log.error("Failed to execute sql:" + query);
        }
        resultSet = statement.getResultSet();

    } catch (Exception e) {
        this.log.error("Failed to execute sql:" + query + " ;error-" + e.getMessage(), e);
    }

    CommandOutput<JdbcCommand, ResultSet> output = new JdbcCommandOutput();
    output.put((JdbcCommand) cmds.get(0), resultSet);
    return output;
}