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:fr.bird.bloom.model.GeographicTreatment.java

/**
 * Select wrong coordinates and write in a file:
 * latitude = 0 ; <-90 ; >90/*from  w w  w . ja  v a 2s  .c  om*/
 * longitude = 0 ; <-180 ; >180
 * 
 * @return File wrong coordinates
 */
public List<String> deleteWrongCoordinates() {
    Statement statement = null;
    try {
        statement = ConnectionDatabase.getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                ResultSet.CONCUR_READ_ONLY);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    DatabaseTreatment newConnection = new DatabaseTreatment(statement);

    List<String> messages = new ArrayList<>();
    messages.add("\n--- Select wrong coordinates ---");

    String sqlRetrieveWrongCoord = "SELECT abstract_,acceptedNameUsage_,acceptedNameUsageID_,accessRights_,accrualMethod_,accrualPeriodicity_,accrualPolicy_,alternative_,associatedMedia_,associatedOccurrences_,associatedOrganisms_,associatedReferences_,associatedSequences_,associatedTaxa_,audience_,available_,basisOfRecord_,bed_,behavior_,bibliographicCitation_,catalogNumber_,class_,classKey_,collectionCode_,collectionID_,conformsTo_,continent_,contributor_,coordinateAccuracy_,coordinatePrecision_,coordinateUncertaintyInMeters_,country_,countryCode_,county_,coverage_,created_,creator_,dataGeneralizations_,datasetID_,datasetKey_,datasetName_,date_,dateAccepted_,dateCopyrighted_,dateIdentified_,dateSubmitted_,day_,decimalLatitude_,decimalLongitude_,depth_,depthAccuracy_,description_,disposition_,distanceAboveSurface_,distanceAboveSurfaceAccuracy_,dynamicProperties_,earliestAgeOrLowestStage_,earliestEonOrLowestEonothem_,earliestEpochOrLowestSeries_,earliestEraOrLowestErathem_,earliestPeriodOrLowestSystem_,educationLevel_,elevation_,elevationAccuracy_,endDayOfYear_,establishmentMeans_,event_,eventDate_,eventID_,eventRemarks_,eventTime_,extent_,family_,familyKey_,fieldNotes_,fieldNumber_,footprintSpatialFit_,footprintSRS_,footprintWKT_,format_,formation_,gbifID_,genericName_,genus_,genusKey_,geodeticDatum_,geologicalContext_,geologicalContextID_,georeferencedBy_,georeferencedDate_,georeferenceProtocol_,georeferenceRemarks_,georeferenceSources_,georeferenceVerificationStatus_,group_,habitat_,hasCoordinate_,hasFormat_,hasGeospatialIssues_,hasPart_,hasVersion_,higherClassification_,higherGeography_,higherGeographyID_,highestBiostratigraphicZone_,identification_,identificationID_,identificationQualifier_,identificationReferences_,identificationRemarks_,identificationVerificationStatus_,identifiedBy_,identifier_,idFile_,individualCount_,individualID_,informationWithheld_,infraspecificEpithet_,institutionCode_,institutionID_,instructionalMethod_,isFormatOf_,island_,islandGroup_,isPartOf_,isReferencedBy_,isReplacedBy_,isRequiredBy_,issue_,issued_,isVersionOf_,kingdom_,kingdomKey_,language_,lastCrawled_,lastInterpreted_,lastParsed_,latestAgeOrHighestStage_,latestEonOrHighestEonothem_,latestEpochOrHighestSeries_,latestEraOrHighestErathem_,latestPeriodOrHighestSystem_,license_,lifeStage_,lithostratigraphicTerms_,livingSpecimen_,locality_,locationAccordingTo_,locationID_,locationRemarks_,lowestBiostratigraphicZone_,machineObservation_,materialSample_,materialSampleID_,maximumDepthinMeters_,maximumDistanceAboveSurfaceInMeters_,maximumElevationInMeters_,measurementAccuracy_,measurementDeterminedBy_,measurementDeterminedDate_,measurementID_,measurementMethod_,measurementOrFact_,measurementRemarks_,measurementType_,measurementUnit_,mediator_,mediaType_,medium_,member_,minimumDepthinMeters_,minimumDistanceAboveSurfaceInMeters_,minimumElevationInMeters_,modified_,month_,municipality_,nameAccordingTo_,nameAccordingToID_,namePublishedIn_,namePublishedInID_,namePublishedInYear_,nomenclaturalCode_,nomenclaturalStatus_,occurrence_,occurrenceDetails_,occurrenceID_,occurrenceRemarks_,occurrenceStatus_,order_,orderKey_,organism_,organismID_,organismName_,organismRemarks_,organismScope_,originalNameUsage_,originalNameUsageID_,otherCatalogNumbers_,ownerInstitutionCode_,parentNameUsage_,parentNameUsageID_,phylum_,phylumKey_,pointRadiusSpatialFit_,preparations_,preservedSpecimen_,previousIdentifications_,protocol_,provenance_,publisher_,publishingCountry_,recordedBy_,recordNumber_,references_,relatedResourceID_,relationshipAccordingTo_,relationshipEstablishedDate_,relationshipRemarks_,relation_,replaces_,reproductiveCondition_,requires_,resourceID_,resourceRelationship_,resourceRelationshipID_,rights_,rightsHolder_,samplingEffort_,samplingProtocol_,scientificName_,scientificNameAuthorship_,scientificNameID_,sex_,source_,spatial_,species_,speciesKey_,specificEpithet_,startDayOfYear_,stateProvince_,subgenus_,subgenusKey_,subject_,tableOfContents_,taxon_,taxonConceptID_,taxonID_,taxonKey_,taxonomicStatus_,taxonRank_,taxonRemarks_,temporal_,title_,type_,typeStatus_,typifiedName_,valid_,verbatimCoordinates_,verbatimCoordinateSystem_,verbatimDate_,verbatimDepth_,verbatimElevation_,verbatimEventDate_,verbatimLatitude_,verbatimLocality_,verbatimLongitude_,verbatimSRS_,verbatimTaxonRank_,vernacularName_,waterBody_,year_ FROM Workflow.DarwinCoreInput WHERE (UUID_=\""
            + this.getUuid()
            + "\") AND (decimalLatitude_=0 OR decimalLatitude_>90 OR decimalLatitude_<-90 OR decimalLongitude_=0 OR decimalLongitude_>180 OR decimalLongitude_<-180);";
    messages.addAll(newConnection.executeSQLcommand("executeQuery", sqlRetrieveWrongCoord));
    List<String> resultatSelect = newConnection.getResultatSelect();
    messages.add("nb lignes affectes :" + Integer.toString(resultatSelect.size() - 1));

    if (!new File(BloomConfig.getDirectoryPath() + "temp/" + this.getUuid() + "/wrong/").exists()) {
        BloomUtils.createDirectory(BloomConfig.getDirectoryPath() + "temp/" + this.getUuid() + "/wrong/");
    }

    for (int j = 0; j < messages.size(); j++) {
        if (messages.get(j).contains("nb lignes affectes")) {
            this.setNbWrongCoordinates(Integer.parseInt(messages.get(j).split(":")[1]));
        }
        System.out.println(messages.get(j));
    }

    this.setNbWrongCoordinates(resultatSelect.size() - 1);

    return resultatSelect;
}

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

/** =============================================================================
 *                      Convert Taxon// w  w  w . jav a  2 s  .  com
 *  =============================================================================
 */
private void convertTaxonRecords() {
    txMapper = IdMapperMgr.getInstance().get("taxonname", "TaxonNameID");
    txTypMapper = IdMapperMgr.getInstance().get("TaxonomyType", "TaxonomyTypeID");
    txUnitTypMapper = IdMapperMgr.getInstance().get("TaxonomicUnitType", "TaxonomicUnitTypeID");
    mappers = new IdMapperIFace[] { txMapper, txMapper, txTypMapper, txMapper, txUnitTypMapper };

    IdHashMapper.setTblWriter(tblWriter);

    newToOldColMap.put("TaxonID", "TaxonNameID");
    newToOldColMap.put("ParentID", "ParentTaxonNameID");
    newToOldColMap.put("TaxonTreeDefID", "TaxonomyTypeID");
    newToOldColMap.put("TaxonTreeDefItemID", "TaxonomicUnitTypeID");
    newToOldColMap.put("Name", "TaxonName");
    newToOldColMap.put("FullName", "FullTaxonName");
    newToOldColMap.put("IsAccepted", "Accepted");

    oldToNewColMap.put("TaxonNameID", "TaxonID");
    oldToNewColMap.put("ParentTaxonNameID", "ParentID");
    oldToNewColMap.put("TaxonomyTypeID", "TaxonTreeDefID");
    oldToNewColMap.put("TaxonomicUnitTypeID", "TaxonTreeDefItemID");
    oldToNewColMap.put("TaxonName", "Name");
    oldToNewColMap.put("FullTaxonName", "FullName");
    oldToNewColMap.put("Accepted", "IsAccepted");

    // Ignore new fields
    // These were added for supporting the new security model and hybrids
    /*String[] ignoredFields = { "GUID", "Visibility", "VisibilitySetBy", "IsHybrid",
                            "HybridParent1ID", "HybridParent2ID", "EsaStatus", "CitesStatus", "UsfwsCode",
                            "IsisNumber", "Text1", "Text2", "NcbiTaxonNumber", "Number1", "Number2",
                            "CreatedByAgentID", "ModifiedByAgentID", "Version", "CultivarName", "LabelFormat", 
                            "COLStatus", "VisibilitySetByID"};
    */

    StringBuilder newSB = new StringBuilder();
    StringBuilder vl = new StringBuilder();
    for (int i = 0; i < cols.length; i++) {
        fieldToColHash.put(cols[i], i + 1);
        colToFieldHash.put(i + 1, cols[i]);

        if (newSB.length() > 0)
            newSB.append(", ");
        newSB.append(cols[i]);

        if (vl.length() > 0)
            vl.append(',');
        vl.append('?');
    }

    StringBuilder oldSB = new StringBuilder();
    for (int i = 0; i < oldCols.length; i++) {
        oldFieldToColHash.put(oldCols[i], i + 1);
        if (oldSB.length() > 0)
            oldSB.append(", ");
        oldSB.append("tx.");
        oldSB.append(oldCols[i]);
    }

    rankIdOldDBInx = oldFieldToColHash.get("RankID");

    String sqlStr = String.format("SELECT %s FROM taxon", newSB.toString());
    log.debug(sqlStr);

    String sql = String.format("SELECT %s %s", oldSB.toString(), taxonFromClause);
    log.debug(sql);

    String cntSQL = String.format("SELECT COUNT(*) %s", taxonFromClause);
    log.debug(cntSQL);
    int txCnt = BasicSQLUtils.getCountAsInt(oldDBConn, cntSQL);
    if (frame != null) {
        frame.setProcess(0, txCnt);
    }

    String pStr = String.format("INSERT INTO taxon (%s) VALUES (%s)", newSB.toString(), vl.toString());
    log.debug(pStr);

    try {
        stmtTx = newDBConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        ResultSet rs1 = stmtTx.executeQuery(sqlStr);
        ResultSetMetaData rsmd1 = rs1.getMetaData();
        colTypes = new int[rsmd1.getColumnCount()];
        colSizes = new int[rsmd1.getColumnCount()];
        for (int i = 0; i < colTypes.length; i++) {
            colTypes[i] = rsmd1.getColumnType(i + 1);
            colSizes[i] = rsmd1.getPrecision(i + 1);
        }
        rs1.close();
        stmtTx.close();

        missingParentList.clear();
        strandedFixedHash.clear();

        lastEditedByInx = oldFieldToColHash.get("LastEditedBy");
        modifiedByAgentInx = fieldToColHash.get("ModifiedByAgentID");
        stmtTx = oldDBConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        pStmtTx = newDBConn.prepareStatement(pStr);

        mappers[1].setShowLogErrors(false);

        int cnt = 0;
        ResultSet rs = stmtTx.executeQuery(sql);
        ResultSetMetaData rsmd = rs.getMetaData();
        while (rs.next()) {
            processRow(rs, rsmd, null);

            cnt++;
            if (cnt % 1000 == 0) {
                log.debug(cnt);
                if (frame != null) {
                    frame.setProcess(cnt);
                }
            }
        }
        rs.close();

        if (frame != null) {
            frame.setProcess(txCnt, txCnt);
        }

        if (missingParentList.size() > 0) {
            fixStrandedTaxon(oldSB);

            tblWriter.setHasLines();

            tblWriter.startTable("Stranded Taxon (no parent): " + missingParentList.size());
            tblWriter.logHdr("Full Name", "RankID", "Sp5 RecordID", "Was Re-parented", "Description");
            for (Pair<Integer, String> p : missingParentList) {
                tblWriter.append("<TR>");
                Object[] row = BasicSQLUtils.queryForRow(oldDBConn,
                        "SELECT FullTaxonName, RankID, TaxonNameID FROM taxonname WHERE TaxonNameID = "
                                + p.first);
                for (Object obj : row) {
                    tblWriter.append("<TD>");
                    tblWriter.append(obj != null ? obj.toString() : "null");
                    tblWriter.append("</TD>");
                }
                tblWriter.append("<TD>");
                tblWriter.append(strandedFixedHash.contains(p.first) ? "Yes" : "No");
                tblWriter.append("</TD><TD>");
                tblWriter.append(p.second);
                tblWriter.append("</TD></TR>");
            }
            tblWriter.endTable();
            tblWriter.append("<BR>");

            frame.setDesc("Renumbering the tree nodes, this may take a while...");

            HashSet<Integer> ttdHash = new HashSet<Integer>();
            for (CollectionInfo colInfo : CollectionInfo.getFilteredCollectionInfoList()) {
                if (!ttdHash.contains(colInfo.getTaxonTreeDef().getId())) {
                    DataProviderSessionIFace session = null;
                    try {
                        session = DataProviderFactory.getInstance().createSession();

                        TaxonTreeDef taxonTreeDef = colInfo.getTaxonTreeDef();
                        taxonTreeDef = (TaxonTreeDef) session
                                .getData("FROM TaxonTreeDef WHERE id = " + taxonTreeDef.getId());

                        sql = "SELECT TaxonID FROM taxon WHERE RankID = 0 AND TaxonTreeDefID = "
                                + taxonTreeDef.getId();
                        log.debug(sql);
                        Integer txRootId = BasicSQLUtils.getCount(sql);
                        Taxon txRoot = (Taxon) session.getData("FROM Taxon WHERE id = " + txRootId);

                        NodeNumberer<Taxon, TaxonTreeDef, TaxonTreeDefItem> nodeNumberer = new NodeNumberer<Taxon, TaxonTreeDef, TaxonTreeDefItem>(
                                txRoot.getDefinition());
                        nodeNumberer.doInBackground();

                    } catch (Exception ex) {
                        //session.rollback();
                        ex.printStackTrace();

                    } finally {
                        if (session != null) {
                            session.close();
                        }
                    }
                    ttdHash.add(colInfo.getTaxonTreeDef().getId());
                }
            }
            frame.setDesc("Renumbering done.");
        }
        missingParentList.clear();
        strandedFixedHash.clear();

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

    } finally {
        try {
            stmtTx.close();
            pStmtTx.close();
        } catch (Exception ex) {
        }
    }

    IdHashMapper.setTblWriter(null);
}

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

public MSSBamAnyObjBuff readDerived(MSSBamAuthorization Authorization, MSSBamAnyObjPKey PKey) {
    final String S_ProcName = "readDerived()";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }//  w ww. j  av a  2 s .c om
    MSSBamAnyObjBuff buff;
    long Id = PKey.getRequiredId();
    String classCode;
    try {
        Connection cnx = schema.getCnx();
        String sql = S_sqlSelectAnyObjDistinctClassCode + "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("ANYO")) {
        buff = readBuff(Authorization, PKey);
    } else if (classCode.equals("SCP")) {
        buff = schema.getTableScope().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("DICT")) {
        buff = schema.getTableDictionary().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("RMD")) {
        buff = schema.getTableMSSBam().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("BDM")) {
        buff = schema.getTableBaseDomain().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("DOM")) {
        buff = schema.getTableDomain().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("LENT")) {
        buff = schema.getTableLegalEntity().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("COM")) {
        buff = schema.getTableCompany().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("USR")) {
        buff = schema.getTableUser().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("PRJ")) {
        buff = schema.getTableProject().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("VER")) {
        buff = schema.getTableVersion().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("MJV")) {
        buff = schema.getTableMajorVersion().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("MNV")) {
        buff = schema.getTableMinorVersion().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TLD")) {
        buff = schema.getTableTLD().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("IDX")) {
        buff = schema.getTableIndex().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("REL")) {
        buff = schema.getTableRelation().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SCH")) {
        buff = schema.getTableSchemaDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TBL")) {
        buff = schema.getTableTable().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("VAL")) {
        buff = schema.getTableValue().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("ATM")) {
        buff = schema.getTableAtomDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("BLB")) {
        buff = schema.getTableBlobDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } 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 if (classCode.equals("BLN")) {
        buff = schema.getTableBoolDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TBLN")) {
        buff = schema.getTableTableBool().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SBLN")) {
        buff = schema.getTableSchemaBool().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("DAT")) {
        buff = schema.getTableDateDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TDAT")) {
        buff = schema.getTableTableDate().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SDAT")) {
        buff = schema.getTableSchemaDate().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("DBL")) {
        buff = schema.getTableDoubleDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TDBL")) {
        buff = schema.getTableTableDouble().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SDBL")) {
        buff = schema.getTableSchemaDouble().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("NUM")) {
        buff = schema.getTableNumberDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TNUM")) {
        buff = schema.getTableTableNumber().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SNUM")) {
        buff = schema.getTableSchemaNumber().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("FLT")) {
        buff = schema.getTableFloatDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TFLT")) {
        buff = schema.getTableTableFloat().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SFLT")) {
        buff = schema.getTableSchemaFloat().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("I16")) {
        buff = schema.getTableInt16Def().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TI16")) {
        buff = schema.getTableTableInt16().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SI16")) {
        buff = schema.getTableSchemaInt16().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("ENM")) {
        buff = schema.getTableEnumDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TENM")) {
        buff = schema.getTableTableEnum().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SENM")) {
        buff = schema.getTableSchemaEnum().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("G16")) {
        buff = schema.getTableId16GenDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TG16")) {
        buff = schema.getTableTableId16Gen().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SG16")) {
        buff = schema.getTableSchemaId16Gen().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("U16")) {
        buff = schema.getTableUInt16Def().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TU16")) {
        buff = schema.getTableTableUInt16().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SU16")) {
        buff = schema.getTableSchemaUInt16().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("I32")) {
        buff = schema.getTableInt32Def().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TI32")) {
        buff = schema.getTableTableInt32().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SI32")) {
        buff = schema.getTableSchemaInt32().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("G32")) {
        buff = schema.getTableId32GenDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TG32")) {
        buff = schema.getTableTableId32Gen().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SG32")) {
        buff = schema.getTableSchemaId32Gen().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("U32")) {
        buff = schema.getTableUInt32Def().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TU32")) {
        buff = schema.getTableTableUInt32().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SU32")) {
        buff = schema.getTableSchemaUInt32().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("I64")) {
        buff = schema.getTableInt64Def().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TI64")) {
        buff = schema.getTableTableInt64().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SI64")) {
        buff = schema.getTableSchemaInt64().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("G64")) {
        buff = schema.getTableId64GenDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TG64")) {
        buff = schema.getTableTableId64Gen().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SG64")) {
        buff = schema.getTableSchemaId64Gen().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("U64")) {
        buff = schema.getTableUInt64Def().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TU64")) {
        buff = schema.getTableTableUInt64().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SU64")) {
        buff = schema.getTableSchemaUInt64().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("UUID")) {
        buff = schema.getTableUuidDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TUUI")) {
        buff = schema.getTableTableUuid().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SUUI")) {
        buff = schema.getTableSchemaUuid().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("IDGU")) {
        buff = schema.getTableUuidGenDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TGUU")) {
        buff = schema.getTableTableUuidGen().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SGUU")) {
        buff = schema.getTableSchemaUuidGen().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("NMT")) {
        buff = schema.getTableNmTokenDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TNTK")) {
        buff = schema.getTableTableNmToken().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SNTK")) {
        buff = schema.getTableSchemaNmToken().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("NMS")) {
        buff = schema.getTableNmTokensDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TNTS")) {
        buff = schema.getTableTableNmTokens().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SNTS")) {
        buff = schema.getTableSchemaNmTokens().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("STR")) {
        buff = schema.getTableStringDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TSTR")) {
        buff = schema.getTableTableString().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SSTR")) {
        buff = schema.getTableSchemaString().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("ZDY")) {
        buff = schema.getTableTZDateDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TZDY")) {
        buff = schema.getTableTableTZDate().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SZDY")) {
        buff = schema.getTableSchemaTZDate().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("ZTM")) {
        buff = schema.getTableTZTimeDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TZTM")) {
        buff = schema.getTableTableTZTime().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SZTM")) {
        buff = schema.getTableSchemaTZTime().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("ZSP")) {
        buff = schema.getTableTZTimestampDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TZST")) {
        buff = schema.getTableTableTZTimestamp().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("SZST")) {
        buff = schema.getTableSchemaTZTimestamp().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TXT")) {
        buff = schema.getTableTextDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TTXT")) {
        buff = schema.getTableTableText().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("STXT")) {
        buff = schema.getTableSchemaText().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TIM")) {
        buff = schema.getTableTimeDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TTIM")) {
        buff = schema.getTableTableTime().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("STIM")) {
        buff = schema.getTableSchemaTime().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TSP")) {
        buff = schema.getTableTimestampDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TTSM")) {
        buff = schema.getTableTableTimestamp().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("STSM")) {
        buff = schema.getTableSchemaTimestamp().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TKN")) {
        buff = schema.getTableTokenDef().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TTOK")) {
        buff = schema.getTableTableToken().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("STOK")) {
        buff = schema.getTableSchemaToken().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("TBC")) {
        buff = schema.getTableTableCol().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("LIC")) {
        buff = schema.getTableLicense().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("CHN")) {
        buff = schema.getTableChain().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("RLC")) {
        buff = schema.getTableRelationCol().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("ETG")) {
        buff = schema.getTableEnumTag().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else if (classCode.equals("IXC")) {
        buff = schema.getTableIndexCol().readBuffByIdIdx(Authorization, PKey.getRequiredId());
    } else {
        throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                "Did not expect ClassCode \"" + classCode + "\"");
    }
    return (buff);
}

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

public MSSBamChainBuff[] readBuffByNextRelIdx(MSSBamAuthorization Authorization, Long NextRelationId) {
    final String S_ProcName = "readBuffByNextRelIdx";
    try {/*from w ww.ja v  a 2s . c  o  m*/
        Connection cnx = schema.getCnx();
        String sql = S_sqlSelectChainBuff + "WHERE "
                + ((NextRelationId == null) ? "chn.NextRelationId is null "
                        : "chn.NextRelationId = " + NextRelationId.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:com.cloudera.sqoop.manager.OracleManager.java

@Override
public String getPrimaryKey(String tableName) {
    Connection conn = null;// w  w w .j a  v  a2  s . com
    PreparedStatement pStmt = null;
    ResultSet rset = null;
    List<String> columns = new ArrayList<String>();

    try {
        conn = getConnection();

        pStmt = conn.prepareStatement(QUERY_PRIMARY_KEY_FOR_TABLE, ResultSet.TYPE_FORWARD_ONLY,
                ResultSet.CONCUR_READ_ONLY);
        pStmt.setString(1, tableName);
        rset = pStmt.executeQuery();

        while (rset.next()) {
            columns.add(rset.getString(1));
        }
        conn.commit();
    } catch (SQLException e) {
        try {
            conn.rollback();
        } catch (Exception ex) {
            LOG.error("Failed to rollback transaction", ex);
        }
        LOG.error("Failed to list columns", e);
    } finally {
        if (rset != null) {
            try {
                rset.close();
            } catch (SQLException ex) {
                LOG.error("Failed to close resultset", ex);
            }
        }
        if (pStmt != null) {
            try {
                pStmt.close();
            } catch (Exception ex) {
                LOG.error("Failed to close statement", ex);
            }
        }

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

    if (columns.size() == 0) {
        // Table has no primary key
        return null;
    }

    if (columns.size() > 1) {
        // The primary key is multi-column primary key. Warn the user.
        // TODO select the appropriate column instead of the first column based
        // on the datatype - giving preference to numerics over other types.
        LOG.warn("The table " + tableName + " " + "contains a multi-column primary key. Sqoop will default to "
                + "the column " + columns.get(0) + " only for this job.");
    }

    return columns.get(0);
}

From source file:edu.ncsa.sstde.indexing.postgis.PostgisIndexer.java

private PreparedStatement createSqlQuery(SqlQueryBuilder builder) throws SQLException {
    String sql = builder.getSQL();
    boolean success = false;
    if (builder.limit > 0) {
        sql += " limit ?";
    }/*from  www .  j ava  2s.c o  m*/
    PreparedStatement ps = getConnection().prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE,
            ResultSet.CONCUR_READ_ONLY);
    try {

        int bindingIdx = 1;

        for (Binding binding : builder.inputBindings)
            ps.setObject(bindingIdx++, binding.value, binding.type);
        success = true;

        // if (builder.limit > 0) {

        // ps.setFetchSize((int)builder.limit + 1);
        // }
        return ps;
    } finally {
        if (!success)
            IndexedStatement.closeQuietly(ps);
    }
}

From source file:edu.ku.brc.specify.toycode.mexconabio.CopyFromGBIF.java

public void testSearch() {
    Statement stmt = null;//www . j av  a 2 s .  c  om

    String querystr = "Andrew AND Bentley AND Apogon AND angustatus";
    String term = "contents";
    try {
        stmt = srcDBConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);

        if (analyzer == null) {
            analyzer = new StandardAnalyzer(Version.LUCENE_36);
        }
        reader = IndexReader.open(FSDirectory.open(INDEX_DIR), true);

        long startTime = System.currentTimeMillis();
        Query q = new QueryParser(Version.LUCENE_36, term, analyzer).parse(querystr);
        int hitsPerPage = 10;
        searcher = new IndexSearcher(reader);
        TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage, true);
        searcher.search(q, collector);
        ScoreDoc[] hits = collector.topDocs().scoreDocs;
        System.out.println("Found " + hits.length + " hits.");
        for (int i = 0; i < hits.length; ++i) {
            int docId = hits[i].doc;
            Document d = searcher.doc(docId);
            System.out.println((i + 1) + ". " + d.get("id"));

            String id = d.get("id");

            ResultSet rs = stmt.executeQuery(
                    "SELECT id, catalogue_number, genus, species, collector_num, collector_name, year, month, day FROM raw WHERE id = "
                            + id);
            ResultSetMetaData rsmd = rs.getMetaData();

            while (rs.next()) {
                for (int j = 1; j <= rsmd.getColumnCount(); j++) {
                    System.out.print(rs.getObject(j) + "\t");
                }
                System.out.println();
            }
            rs.close();
        }
        System.out.println(String.format("Time: %8.2f", (System.currentTimeMillis() - startTime) / 1000.0));
        searcher.close();
        reader.close();
        analyzer.close();

    } catch (SQLException e) {
        e.printStackTrace();

    } catch (IOException e) {
        e.printStackTrace();

    } catch (ParseException e) {
        e.printStackTrace();
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}

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

public MSSBamBlobDefBuff[] readDerivedByScopeIdx(MSSBamAuthorization Authorization, Long ScopeId) {
    final String S_ProcName = "readDerivedByScopeIdx";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }/*from   w  w  w  .  j a  v a2s .  com*/
    ArrayList<String> classCodeList = new ArrayList<String>();
    String classCode;
    try {
        Connection cnx = schema.getCnx();
        String sql = S_sqlSelectBlobDefDistinctClassCode + "WHERE "
                + ((ScopeId == null) ? "anyo.ScopeId is null " : "anyo.ScopeId = " + ScopeId.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<MSSBamBlobDefBuff> resultList = new ArrayList<MSSBamBlobDefBuff>();
    ListIterator<String> classCodeIter = classCodeList.listIterator();
    while (classCodeIter.hasNext()) {
        classCode = classCodeIter.next();
        if (classCode.equals("BLB")) {
            MSSBamBlobDefBuff[] subList = readBuffByScopeIdx(Authorization, ScopeId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("TBLB")) {
            MSSBamTableBlobBuff[] subList = schema.getTableTableBlob().readBuffByScopeIdx(Authorization,
                    ScopeId);
            for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                resultList.add(subList[subListIdx]);
            }
        } else if (classCode.equals("SBLB")) {
            MSSBamSchemaBlobBuff[] subList = schema.getTableSchemaBlob().readBuffByScopeIdx(Authorization,
                    ScopeId);
            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 MSSBamBlobDefBuff[0]));

}

From source file:com.alibaba.wasp.jdbc.JdbcConnection.java

private void checkTypeConcurrency(int resultSetType, int resultSetConcurrency) {
    switch (resultSetType) {
    case ResultSet.TYPE_FORWARD_ONLY:
    case ResultSet.TYPE_SCROLL_INSENSITIVE:
    case ResultSet.TYPE_SCROLL_SENSITIVE:
        break;/*  w ww.  j av  a2 s  .co m*/
    default:
        throw JdbcException.getInvalidValueException("resultSetType", resultSetType);
    }
    switch (resultSetConcurrency) {
    case ResultSet.CONCUR_READ_ONLY:
    case ResultSet.CONCUR_UPDATABLE:
        break;
    default:
        throw JdbcException.getInvalidValueException("resultSetConcurrency", resultSetConcurrency);
    }
}

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

@Override
public void executeUpdate(final String user, final String password, final String db, final String statement)
        throws BackendException {
    Statement st = null;/*from   w w  w .j a va  2 s.com*/
    Connection conn = null;
    try {
        conn = this.connectToDB(user, password, db);
        st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.logString(statement.trim(), user);
        st.executeUpdate(statement.trim());
    } catch (SQLException e) {
        throw new BackendException(e);
    } catch (ClassNotFoundException e) {
        throw new BackendException(e);
    } finally {
        DbUtils.closeQuietly(st);
        DbUtils.closeQuietly(conn);
    }
}