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:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8ChainTable.java

public MSSBamChainBuff[] readAllBuff(MSSBamAuthorization Authorization) {
    final String S_ProcName = "readAllBuff";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }//  w w w  .java  2s. co  m
    try {
        Connection cnx = schema.getCnx();
        String sql = S_sqlSelectChainBuff + "WHERE " + "anyo.ClassCode = 'CHN' " + "ORDER BY " + "anyo.Id ASC";
        Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        ResultSet resultSet = stmt.executeQuery(sql);
        List<MSSBamChainBuff> buffList = new ArrayList<MSSBamChainBuff>();
        while (resultSet.next()) {
            MSSBamChainBuff buff = unpackChainResultSetToBuff(resultSet);
            buffList.add(buff);
        }
        return (buffList.toArray(new MSSBamChainBuff[0]));
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    }
}

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

public void updateAddressTag(MSSBamAuthorization Authorization, MSSBamAddressTagBuff Buff) {
    final String S_ProcName = "updateAddressTag";
    try {//from ww w  . j a va 2  s  .c o  m
        Connection cnx = schema.getCnx();
        long AddressId = Buff.getRequiredAddressId();
        long TagId = Buff.getRequiredTagId();
        String TagValue = Buff.getRequiredTagValue();

        int Revision = Buff.getRequiredRevision();
        MSSBamAddressTagBuff readBuff = readBuffByIdIdx(Authorization, AddressId, TagId);
        int oldRevision = readBuff.getRequiredRevision();
        if (oldRevision != Revision) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), S_ProcName,
                    Buff);
        }
        int newRevision = Revision + 1;
        String sql = "UPDATE mssbam110.ctcaddr_tag " + "SET " + "AddressId = "
                + MSSBamPg8Schema.getInt64String(AddressId) + ", " + "TagId = "
                + MSSBamPg8Schema.getInt64String(TagId) + ", " + "TagValue = "
                + MSSBamPg8Schema.getQuotedString(TagValue) + ", " + "Revision = "
                + Integer.toString(newRevision) + " " + "WHERE " + "AddressId = " + Long.toString(AddressId)
                + " " + "AND " + "TagId = " + Long.toString(TagId) + " " + "AND " + "Revision = "
                + Integer.toString(Revision);
        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);
        }
        Buff.setRequiredRevision(newRevision);
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    }
}

From source file:edu.ku.brc.specify.conversion.IdHashMapper.java

public Integer get(final Integer oldId) {
    if (oldId == null) {
        return null;
    }/*from  w ww  .j  a va 2 s .  c o  m*/

    try {
        if (stmtNew == null) {
            stmtNew = oldConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        }

        Integer newId = null;

        ResultSet rs = stmtNew.executeQuery("SELECT NewID FROM " + mapTableName + " WHERE OldID = " + oldId);
        if (rs.next()) {
            newId = rs.getInt(1);

        } else {
            oldIdNullList.add(oldId);

            if (showLogErrors) {
                String msg = "********** Couldn't find old index [" + oldId + "] for " + mapTableName;
                log.error(msg);
                if (tblWriter != null)
                    tblWriter.logError(msg);
            }
            rs.close();
            return null;
        }
        rs.close();

        return newId;

    } catch (SQLException ex) {
        String msg = "Couldn't find old index [" + oldId + "] for " + mapTableName;
        if (tblWriter != null)
            tblWriter.logError(msg);

        edu.ku.brc.af.core.UsageTracker.incrSQLUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(IdHashMapper.class, ex);
        ex.printStackTrace();
        log.error(ex);
        throw new RuntimeException(msg);
    }
}

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

private static void checkResultSet(int resultSetType, int resultSetConcurrency)
        throws SQLFeatureNotSupportedException {
    if (resultSetType != ResultSet.TYPE_FORWARD_ONLY) {
        throw new SQLFeatureNotSupportedException("Result set type must be TYPE_FORWARD_ONLY");
    }//w  w  w . java  2s.  c  om
    if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) {
        throw new SQLFeatureNotSupportedException("Result set concurrency must be CONCUR_READ_ONLY");
    }
}

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

public MSSBamAddressBuff readBuffByUDescrIdx(MSSBamAuthorization Authorization, long ContactId,
        String Description) {//from w  ww . j av a  2s .  co  m
    final String S_ProcName = "readBuffByUDescrIdx";
    try {
        Connection cnx = schema.getCnx();
        String sql = S_sqlSelectAddressBuff + "WHERE " + "adr.ContactId = " + Long.toString(ContactId) + " "
                + "AND " + "adr.Description = " + MSSBamPg8Schema.getQuotedString(Description) + " ";
        Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        ResultSet resultSet = stmt.executeQuery(sql);
        if (resultSet.next()) {
            MSSBamAddressBuff buff = unpackAddressResultSetToBuff(resultSet);
            if (resultSet.next()) {
                resultSet.last();
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Did not expect multi-buff response, " + resultSet.getRow() + " rows selected");
            }
            return (buff);
        } else {
            return (null);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    }
}

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

public void updateAttachmentTag(MSSBamAuthorization Authorization, MSSBamAttachmentTagBuff Buff) {
    final String S_ProcName = "updateAttachmentTag";
    try {/* w  w  w.  ja  v  a  2s.  c  o  m*/
        Connection cnx = schema.getCnx();
        long AttachmentId = Buff.getRequiredAttachmentId();
        long TagId = Buff.getRequiredTagId();
        String TagValue = Buff.getRequiredTagValue();

        int Revision = Buff.getRequiredRevision();
        MSSBamAttachmentTagBuff readBuff = readBuffByIdIdx(Authorization, AttachmentId, TagId);
        int oldRevision = readBuff.getRequiredRevision();
        if (oldRevision != Revision) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), S_ProcName,
                    Buff);
        }
        int newRevision = Revision + 1;
        String sql = "UPDATE mssbam110.ctcattch_tag " + "SET " + "AttachmentId = "
                + MSSBamPg8Schema.getInt64String(AttachmentId) + ", " + "TagId = "
                + MSSBamPg8Schema.getInt64String(TagId) + ", " + "TagValue = "
                + MSSBamPg8Schema.getQuotedString(TagValue) + ", " + "Revision = "
                + Integer.toString(newRevision) + " " + "WHERE " + "AttachmentId = "
                + Long.toString(AttachmentId) + " " + "AND " + "TagId = " + Long.toString(TagId) + " " + "AND "
                + "Revision = " + Integer.toString(Revision);
        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);
        }
        Buff.setRequiredRevision(newRevision);
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    }
}

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

public MSSBamBlobDefBuff readDerived(MSSBamAuthorization Authorization, MSSBamAnyObjPKey PKey) {
    final String S_ProcName = "readDerived()";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }/*from   w  w  w  .  jav a 2 s. c o  m*/
    MSSBamBlobDefBuff buff;
    long Id = PKey.getRequiredId();
    String classCode;
    try {
        Connection cnx = schema.getCnx();
        String sql = S_sqlSelectBlobDefDistinctClassCode + "WHERE " + "blb.Id = " + Long.toString(Id) + " ";
        Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        ResultSet resultSet = stmt.executeQuery(sql);
        if (resultSet.next()) {
            classCode = resultSet.getString(1);
            if (resultSet.next()) {
                resultSet.last();
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Did not expect multi-buff response, " + resultSet.getRow() + " rows selected");
            }
        } else {
            return (null);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    }
    if (classCode.equals("BLB")) {
        buff = readBuff(Authorization, PKey);
    } else if (classCode.equals("TBLB")) {
        buff = schema.getTableTableBlob().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SBLB")) {
        buff = schema.getTableSchemaBlob().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else {
        throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                "Did not expect ClassCode \"" + classCode + "\"");
    }
    return (buff);
}

From source file:de.innovationgate.webgate.api.jdbc.custom.JDBCSource.java

public Map find(String type, String query, Map parameters) throws WGQueryException {

    if (type == null || type.equals("native")) {
        type = "sql";
    }//from   w  w  w .  ja  v  a2 s  .co  m

    List nativeOptions = new ArrayList();
    String nativeOptionsString = (String) parameters.get(WGDatabase.QUERYOPTION_NATIVEOPTIONS);
    if (nativeOptionsString != null) {
        nativeOptions.addAll(WGUtils.deserializeCollection(nativeOptionsString.toLowerCase(), ",", true));
    }

    ResultSet resultSet = null;
    String table = null;
    PreparedStatement stmt;
    Boolean resetAutocommit = null;
    Connection connection = null;
    try {

        // Create statement
        connection = getConnection();
        boolean isUpdate = nativeOptions.contains("update");
        if (isUpdate && !connection.getAutoCommit()) {
            resetAutocommit = connection.getAutoCommit();
            connection.setAutoCommit(true);
        }

        if (type.equals("sql")) {

            stmt = connection.prepareStatement(query, ResultSet.TYPE_FORWARD_ONLY,
                    (isUpdate ? ResultSet.CONCUR_UPDATABLE : ResultSet.CONCUR_READ_ONLY));

        } else if (type.startsWith("table:")) {

            table = type.substring(6).trim();
            if (!_tables.keySet().contains(table.toLowerCase())) {
                throw new WGQueryException(query, "Table '" + table + "' does not exist or has no primary key");
            }

            if (query != null && !query.trim().equals("")) {
                query = "SELECT * FROM " + table + " WHERE " + query;
            } else {
                query = "SELECT * FROM " + table;
            }
            stmt = connection.prepareStatement(query, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);

        } else {
            throw new WGQueryException(query, "Unknown query type: " + type);
        }

        // Apply parameters
        if (parameters.containsKey(WGDatabase.QUERYOPTION_MAXRESULTS)) {
            stmt.setMaxRows(((Number) parameters.get(WGDatabase.QUERYOPTION_MAXRESULTS)).intValue());
        }

        applyQueryParameters(parameters, stmt, query);

        // Execute and extract data
        stmt.execute();
        resultSet = stmt.getResultSet();
        Map results;
        if (resultSet != null) {
            results = extractRowResults(resultSet, table);
        } else {
            results = new HashMap();
        }

        return results;

    } catch (SQLException e) {
        throw new WGQueryException(query, e.getMessage(), e);
    } finally {
        if (connection != null && resetAutocommit != null) {
            try {
                connection.setAutoCommit(resetAutocommit);
            } catch (SQLException e) {
                throw new WGQueryException(query, "Exception resetting autocommit", e);
            }
        }
        closeResultSet(resultSet);
    }
}

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

public MSSBamAttachmentBuff[] readBuffByMimeTypeIdx(MSSBamAuthorization Authorization, Short MimeTypeId) {
    final String S_ProcName = "readBuffByMimeTypeIdx";
    try {//from   w w  w  . ja va 2  s  .co  m
        Connection cnx = schema.getCnx();
        String sql = S_sqlSelectAttachmentBuff + "WHERE "
                + ((MimeTypeId == null) ? "attc.MimeTypeId is null "
                        : "attc.MimeTypeId = " + MimeTypeId.toString() + " ")
                + "ORDER BY " + "attc.AttachmentId ASC";
        Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        ResultSet resultSet = stmt.executeQuery(sql);
        List<MSSBamAttachmentBuff> buffList = new ArrayList<MSSBamAttachmentBuff>();
        while (resultSet.next()) {
            MSSBamAttachmentBuff buff = unpackAttachmentResultSetToBuff(resultSet);
            buffList.add(buff);
        }
        return (buffList.toArray(new MSSBamAttachmentBuff[0]));
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    }
}

From source file:edu.ku.brc.specify.conversion.StratToGTP.java

/**
 * @throws SQLException/*  www  . ja v a  2  s  .co m*/
 */
public void convertStratToGTPNDGS() throws SQLException {
    Statement stmt = null;
    ResultSet rs = null;

    try {
        // get a Hibernate session for saving the new records
        Session localSession = HibernateUtil.getCurrentSession();
        HibernateUtil.beginTransaction();

        int count = BasicSQLUtils.getCountAsInt(oldDBConn, "SELECT COUNT(*) FROM stratigraphy");
        if (count < 1)
            return;

        if (hasFrame) {
            setProcess(0, count);
        }

        IdTableMapper gtpIdMapper = IdMapperMgr.getInstance().addTableMapper("geologictimeperiod",
                "GeologicTimePeriodID");

        Hashtable<Integer, Integer> ceToNewStratIdHash = new Hashtable<Integer, Integer>();

        IdMapperIFace ceMapper = IdMapperMgr.getInstance().get("collectingevent", "CollectingEventID");

        // get all of the old records
        //  Future GTP                           Period         Epoch         Age   
        String sql = "SELECT StratigraphyID, 'Placeholder',  SuperGroup,  `Group` FROM stratigraphy ORDER BY StratigraphyID";

        stmt = oldDBConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        rs = stmt.executeQuery(sql);

        int counter = 0;
        // for each old record, convert the record
        while (rs.next()) {
            if (counter % 500 == 0) {
                if (hasFrame) {
                    setProcess(counter);

                } else {
                    log.info("Converted " + counter + " Stratigraphy records");
                }
            }

            // grab the important data fields from the old record
            int oldStratId = rs.getInt(1);
            String period = rs.getString(2);
            String epoch = rs.getString(3);
            String age = rs.getString(4);

            if (StringUtils.isEmpty(epoch)) {
                epoch = "(Empty)";
            }

            // create a new Geography object from the old data
            GeologicTimePeriod newStrat = convertOldStratRecord(localSession, eraNode, null, null, null, period,
                    epoch, age);

            counter++;

            // Map Old GeologicTimePeriod ID to the new Tree Id
            gtpIdMapper.put(oldStratId, newStrat.getGeologicTimePeriodId());

            // Convert Old CEId to new CEId, then map the new CEId -> new StratId
            Integer ceId = ceMapper.get(oldStratId);
            if (ceId != null) {
                ceToNewStratIdHash.put(ceId, newStrat.getGeologicTimePeriodId());
            } else {
                String msg = String.format("No CE mapping for Old StratId %d, when they are a one-to-one.",
                        oldStratId);
                tblWriter.logError(msg);
                log.error(msg);
            }
        }
        stmt.close();

        if (hasFrame) {
            setProcess(counter);

        } else {
            log.info("Converted " + counter + " Stratigraphy records");
        }

        TreeHelper.fixFullnameForNodeAndDescendants(eraNode);
        eraNode.setNodeNumber(1);
        fixNodeNumbersFromRoot(eraNode);
        rs.close();

        HibernateUtil.commitTransaction();
        log.info("Converted " + counter + " Stratigraphy records");

    } catch (Exception ex) {
        ex.printStackTrace();
    }

    // Now in this Step we Add the PaleoContext to the Collecting Events

}