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.MSSBamPg8BaseDomainTable.java

public MSSBamBaseDomainBuff[] readDerivedByTenantIdx(MSSBamAuthorization Authorization, long TenantId) {
    final String S_ProcName = "readDerivedByTenantIdx";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }/*from  w  ww.j  ava 2s.c  om*/
    ArrayList<String> classCodeList = new ArrayList<String>();
    String classCode;
    try {
        Connection cnx = schema.getCnx();
        String sql = S_sqlSelectBaseDomainDistinctClassCode + "WHERE " + "anyo.TenantId = "
                + Long.toString(TenantId) + " ";
        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<MSSBamBaseDomainBuff> resultList = new ArrayList<MSSBamBaseDomainBuff>();
    ListIterator<String> classCodeIter = classCodeList.listIterator();
    while (classCodeIter.hasNext()) {
        classCode = classCodeIter.next();
        if (classCode.equals("BDM")) {
            MSSBamBaseDomainBuff[] subList = readBuffByTenantIdx(Authorization, TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("DOM")) {
            MSSBamDomainBuff[] subList = schema.getTableDomain().readBuffByTenantIdx(Authorization, TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("LENT")) {
            MSSBamLegalEntityBuff[] subList = schema.getTableLegalEntity().readBuffByTenantIdx(Authorization,
                    TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("COM")) {
            MSSBamCompanyBuff[] subList = schema.getTableCompany().readBuffByTenantIdx(Authorization, TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("USR")) {
            MSSBamUserBuff[] subList = schema.getTableUser().readBuffByTenantIdx(Authorization, TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("PRJ")) {
            MSSBamProjectBuff[] subList = schema.getTableProject().readBuffByTenantIdx(Authorization, TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("VER")) {
            MSSBamVersionBuff[] subList = schema.getTableVersion().readBuffByTenantIdx(Authorization, TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("MJV")) {
            MSSBamMajorVersionBuff[] subList = schema.getTableMajorVersion().readBuffByTenantIdx(Authorization,
                    TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("MNV")) {
            MSSBamMinorVersionBuff[] subList = schema.getTableMinorVersion().readBuffByTenantIdx(Authorization,
                    TenantId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("TLD")) {
            MSSBamTLDBuff[] subList = schema.getTableTLD().readBuffByTenantIdx(Authorization, TenantId);
            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 MSSBamBaseDomainBuff[0]));

}

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

public void updateAttachment(MSSBamAuthorization Authorization, MSSBamAttachmentBuff Buff) {
    final String S_ProcName = "updateAttachment";
    try {/*from  w  w  w  . j  av  a2 s  .c  o m*/
        Connection cnx = schema.getCnx();
        long AttachmentId = Buff.getRequiredAttachmentId();
        long ContactId = Buff.getRequiredContactId();
        String Description = Buff.getRequiredDescription();
        Short MimeTypeId = Buff.getOptionalMimeTypeId();
        String Attachment = Buff.getRequiredAttachment();

        int Revision = Buff.getRequiredRevision();
        MSSBamAttachmentBuff readBuff = readBuffByIdIdx(Authorization, AttachmentId);
        int oldRevision = readBuff.getRequiredRevision();
        if (oldRevision != Revision) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), S_ProcName,
                    Buff);
        }
        int newRevision = Revision + 1;
        String sql = "UPDATE mssbam110.Attachment " + "SET " + "AttachmentId = "
                + MSSBamPg8Schema.getInt64String(AttachmentId) + ", " + "ContactId = "
                + MSSBamPg8Schema.getInt64String(ContactId) + ", " + "Description = "
                + MSSBamPg8Schema.getQuotedString(Description) + ", " + "MimeTypeId = "
                + ((MimeTypeId != null) ? MSSBamPg8Schema.getInt16String(MimeTypeId) : "null") + ", "
                + "Attachment = " + MSSBamPg8Schema.getQuotedString(Attachment) + ", " + "Revision = "
                + Integer.toString(newRevision) + " " + "WHERE " + "AttachmentId = "
                + Long.toString(AttachmentId) + " " + "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.MSSBamPg8ChainTable.java

public MSSBamChainBuff[] readBuffByScopeIdx(MSSBamAuthorization Authorization, Long ScopeId) {
    final String S_ProcName = "readBuffByScopeIdx";
    try {//from   ww w . ja  v  a  2 s.  c  o m
        Connection cnx = schema.getCnx();
        String sql = S_sqlSelectChainBuff + "WHERE "
                + ((ScopeId == null) ? "anyo.ScopeId is null " : "anyo.ScopeId = " + ScopeId.toString() + " ")
                + "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.MSSBamPg8BoolDefTable.java

public MSSBamBoolDefBuff readDerivedByIdIdx(MSSBamAuthorization Authorization, long Id) {
    final String S_ProcName = "MSSBamPg8BoolDefTable.readDerivedByIdIdx() ";
    MSSBamBoolDefBuff buff;//from ww w . ja  va  2  s  .  c  o m
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }
    String classCode;
    try {
        Connection cnx = schema.getCnx();
        String sql = S_sqlSelectBoolDefDistinctClassCode + "WHERE " + "anyo.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("BLN")) {
        buff = readBuffByIdIdx(Authorization, Id);
    } else if (classCode.equals("TBLN")) {
        buff = schema.getTableTableBool().readBuffByIdIdx(Authorization, Id);
    } else if (classCode.equals("SBLN")) {
        buff = schema.getTableSchemaBool().readBuffByIdIdx(Authorization, Id);
    } else {
        throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                "Did not expect ClassCode \"" + classCode + "\"");
    }
    return (buff);
}

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

public void updateAddress(MSSBamAuthorization Authorization, MSSBamAddressBuff Buff) {
    final String S_ProcName = "updateAddress";
    try {/*from  www  . j  a va  2 s  .  c  om*/
        Connection cnx = schema.getCnx();
        long AddressId = Buff.getRequiredAddressId();
        long ContactId = Buff.getRequiredContactId();
        String Description = Buff.getRequiredDescription();
        String AddrLine1 = Buff.getOptionalAddrLine1();
        String AddrLine2 = Buff.getOptionalAddrLine2();
        String City = Buff.getOptionalCity();
        String State = Buff.getOptionalState();
        String Country = Buff.getOptionalCountry();
        String PostalCode = Buff.getOptionalPostalCode();

        int Revision = Buff.getRequiredRevision();
        MSSBamAddressBuff readBuff = readBuffByIdIdx(Authorization, AddressId);
        int oldRevision = readBuff.getRequiredRevision();
        if (oldRevision != Revision) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), S_ProcName,
                    Buff);
        }
        int newRevision = Revision + 1;
        String sql = "UPDATE mssbam110.Address " + "SET " + "AddressId = "
                + MSSBamPg8Schema.getInt64String(AddressId) + ", " + "ContactId = "
                + MSSBamPg8Schema.getInt64String(ContactId) + ", " + "Description = "
                + MSSBamPg8Schema.getQuotedString(Description) + ", " + "AddrLine1 = "
                + ((AddrLine1 != null) ? MSSBamPg8Schema.getQuotedString(AddrLine1) : "null") + ", "
                + "AddrLine2 = " + ((AddrLine2 != null) ? MSSBamPg8Schema.getQuotedString(AddrLine2) : "null")
                + ", " + "City = " + ((City != null) ? MSSBamPg8Schema.getQuotedString(City) : "null") + ", "
                + "State = " + ((State != null) ? MSSBamPg8Schema.getQuotedString(State) : "null") + ", "
                + "Country = " + ((Country != null) ? MSSBamPg8Schema.getQuotedString(Country) : "null") + ", "
                + "PostalCode = "
                + ((PostalCode != null) ? MSSBamPg8Schema.getQuotedString(PostalCode) : "null") + ", "
                + "Revision = " + Integer.toString(newRevision) + " " + "WHERE " + "AddressId = "
                + Long.toString(AddressId) + " " + "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:com.cloudera.sqoop.manager.OracleManager.java

/**
 * The concept of database in Oracle is mapped to schemas. Each schema
 * is identified by the corresponding username.
 *///from  w  w  w.j  a  v a  2  s.  com
@Override
public String[] listDatabases() {
    Connection conn = null;
    Statement stmt = null;
    ResultSet rset = null;
    List<String> databases = new ArrayList<String>();

    try {
        conn = getConnection();
        stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        rset = stmt.executeQuery(QUERY_LIST_DATABASES);

        while (rset.next()) {
            databases.add(rset.getString(1));
        }
        conn.commit();
    } catch (SQLException e) {
        try {
            conn.rollback();
        } catch (Exception ex) {
            LOG.error("Failed to rollback transaction", ex);
        }

        if (e.getErrorCode() == ERROR_TABLE_OR_VIEW_DOES_NOT_EXIST) {
            LOG.error("The catalog view DBA_USERS was not found. "
                    + "This may happen if the user does not have DBA privileges. "
                    + "Please check privileges and try again.");
            LOG.debug("Full trace for ORA-00942 exception", e);
        } else {
            LOG.error("Failed to list databases", e);
        }
    } finally {
        if (rset != null) {
            try {
                rset.close();
            } catch (SQLException ex) {
                LOG.error("Failed to close resultset", ex);
            }
        }
        if (stmt != null) {
            try {
                stmt.close();
            } catch (Exception ex) {
                LOG.error("Failed to close statement", ex);
            }
        }

        try {
            close();
        } catch (SQLException ex) {
            LOG.error("Unable to discard connection", ex);
        }
    }

    return databases.toArray(new String[databases.size()]);
}

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

public MSSBamChainBuff[] readBuffByAuthorIdx(MSSBamAuthorization Authorization, Long AuthorId) {
    final String S_ProcName = "readBuffByAuthorIdx";
    try {//from   w  ww .  ja  va  2 s. c o  m
        Connection cnx = schema.getCnx();
        String sql = S_sqlSelectChainBuff + "WHERE " + ((AuthorId == null) ? "anyo.AuthorId is null "
                : "anyo.AuthorId = " + AuthorId.toString() + " ") + "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:edu.ku.brc.specify.conversion.StratToGTP.java

/**
 * @throws SQLException//  w ww.  j  a  va 2  s .c o m
 */
public void convertStratToGTPKUIVP() 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                           System        Series       Stage
        String sql = "SELECT s.StratigraphyID, s.Formation, s.SuperGroup, s.Text1 FROM stratigraphy s ORDER BY s.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 system = rs.getString(2);
            String series = rs.getString(3);
            String stage = rs.getString(4);

            if (StringUtils.isNotEmpty(stage)) {
                if (StringUtils.isNotEmpty(series)) {
                    series += ' ' + stage;

                } else {
                    series = stage;
                }
            }

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

            // create a new Geography object from the old data
            GeologicTimePeriod newStrat = convertOldStratRecord(localSession, eraNode, null, null, null, system,
                    series, stage);

            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

}

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

public MSSBamBlobDefBuff readDerivedByIdIdx(MSSBamAuthorization Authorization, long Id) {
    final String S_ProcName = "MSSBamPg8BlobDefTable.readDerivedByIdIdx() ";
    MSSBamBlobDefBuff buff;//from ww w. ja va 2s .c o m
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }
    String classCode;
    try {
        Connection cnx = schema.getCnx();
        String sql = S_sqlSelectBlobDefDistinctClassCode + "WHERE " + "anyo.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 = readBuffByIdIdx(Authorization, Id);
    } else if (classCode.equals("TBLB")) {
        buff = schema.getTableTableBlob().readBuffByIdIdx(Authorization, Id);
    } else if (classCode.equals("SBLB")) {
        buff = schema.getTableSchemaBlob().readBuffByIdIdx(Authorization, Id);
    } else {
        throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                "Did not expect ClassCode \"" + classCode + "\"");
    }
    return (buff);
}

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

public void deleteAttachment(MSSBamAuthorization Authorization, MSSBamAttachmentBuff Buff) {
    final String S_ProcName = "deleteAttachment";
    try {/*from  w  w  w.  j  a v a2  s . c  o  m*/
        Connection cnx = schema.getCnx();
        long AttachmentId = Buff.getRequiredAttachmentId();
        long ContactId = Buff.getRequiredContactId();
        String Description = Buff.getRequiredDescription();
        Short MimeTypeId = Buff.getOptionalMimeTypeId();
        String Attachment = Buff.getRequiredAttachment();

        int Revision = Buff.getRequiredRevision();
        MSSBamAttachmentBuff readBuff = readBuffByIdIdx(Authorization, AttachmentId);
        int oldRevision = readBuff.getRequiredRevision();
        if (oldRevision != Revision) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), S_ProcName,
                    Buff);
        }
        String sql = "DELETE FROM mssbam110.Attachment " + "WHERE " + "AttachmentId = "
                + Long.toString(AttachmentId) + " " + "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 delete, not " + rowsAffected);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    }
}