List of usage examples for java.sql ResultSet CONCUR_READ_ONLY
int CONCUR_READ_ONLY
To view the source code for java.sql ResultSet CONCUR_READ_ONLY.
Click Source Link
ResultSet
object that may NOT be updated. From source file:net.firejack.platform.core.utils.db.DBUtils.java
private static ResultSet selectDataFromSource(Connection sourceConnection, TablesMapping mapping) throws SQLException { Map<Column, Column> columnMapping = mapping.getColumnMapping(); StringBuilder selectQuery = new StringBuilder("select "); for (Map.Entry<Column, Column> columnEntry : columnMapping.entrySet()) { Column sourceColumn = columnEntry.getKey(); selectQuery.append(sourceColumn.getName()).append(','); }/* w w w.j a va2s . c om*/ if (!columnMapping.isEmpty()) { selectQuery.replace(selectQuery.length() - 1, selectQuery.length(), ""); } selectQuery.append(" from ").append(mapping.getSourceTable().getName()); String sql = selectQuery.toString(); Statement statement = sourceConnection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet rs = statement.executeQuery(sql); rs.setFetchSize(DEFAULT_BATCH_SIZE); return rs; }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8AddressTable.java
public MSSBamAddressBuff[] readBuffByContactIdx(MSSBamAuthorization Authorization, long ContactId) { final String S_ProcName = "readBuffByContactIdx"; try {//from ww w .j a v a 2 s . co m Connection cnx = schema.getCnx(); String sql = S_sqlSelectAddressBuff + "WHERE " + "adr.ContactId = " + Long.toString(ContactId) + " " + "ORDER BY " + "adr.AddressId ASC"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); List<MSSBamAddressBuff> buffList = new ArrayList<MSSBamAddressBuff>(); while (resultSet.next()) { MSSBamAddressBuff buff = unpackAddressResultSetToBuff(resultSet); buffList.add(buff); } return (buffList.toArray(new MSSBamAddressBuff[0])); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8AccessSecurityTable.java
public void deleteAccessSecurity(MSSBamAuthorization Authorization, MSSBamAccessSecurityBuff Buff) { final String S_ProcName = "deleteAccessSecurity"; try {//from w ww. j a v a 2s. c o m Connection cnx = schema.getCnx(); short Id = Buff.getRequiredId(); String Name = Buff.getRequiredName(); int Revision = Buff.getRequiredRevision(); MSSBamAccessSecurityBuff readBuff = readBuffByIdIdx(Authorization, Id); int oldRevision = readBuff.getRequiredRevision(); if (oldRevision != Revision) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), S_ProcName, Buff); } String sql = "DELETE FROM mssbam110.accsec " + "WHERE " + "Id = " + Short.toString(Id) + " " + "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); } }
From source file:com.google.enterprise.connector.salesforce.storetype.DBStore.java
public DocListEntry getDocsImmediatelyAfter(String checkpoint) { DatabaseMetaData dbm = null;//from w ww .j av a 2 s . c o m Connection connection = null; try { connection = ds.getConnection(); connection.setAutoCommit(true); dbm = connection.getMetaData(); //get the most recent database row after 'checkpoint' if (dbm.getDatabaseProductName().equals("MySQL")) { Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); String update_stmt = "select crawl_set,insert_timestamp,UNCOMPRESS(crawl_data) as cdata from " + this.instance_table + " where crawl_set>" + checkpoint + " LIMIT 1"; logger.log(Level.FINER, update_stmt); ResultSet rs = statement.executeQuery(update_stmt); boolean ret_rows = rs.first(); if (!ret_rows) { logger.log(Level.FINER, "No Rows Returned."); connection.close(); return null; } BigDecimal crawl_set = null; String crawl_data = null; while (ret_rows) { crawl_set = rs.getBigDecimal("crawl_set"); //crawl_data = rs.getString("crawl_data"); crawl_data = rs.getString("cdata"); ret_rows = rs.next(); } rs.close(); statement.close(); connection.close(); //BASE64 DECODE byte[] byte_decoded_entry = org.apache.commons.codec.binary.Base64 .decodeBase64(crawl_data.getBytes()); crawl_data = new String(byte_decoded_entry); logger.log(Level.INFO, "Returning from DBStore. Index Value: " + crawl_set.toPlainString()); logger.log(Level.FINEST, "Returning from DBStore. " + crawl_data); DocListEntry dret = new DocListEntry(crawl_set.toPlainString(), crawl_data); return dret; } } catch (Exception ex) { logger.log(Level.SEVERE, "Unable to retrieve docListEntry " + ex); } return new DocListEntry(checkpoint, null); }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8AttachmentTable.java
public MSSBamAttachmentBuff readBuffByUDescrIdx(MSSBamAuthorization Authorization, long ContactId, String Description) {/* w w w . j a va 2s . c o m*/ final String S_ProcName = "readBuffByUDescrIdx"; try { Connection cnx = schema.getCnx(); String sql = S_sqlSelectAttachmentBuff + "WHERE " + "attc.ContactId = " + Long.toString(ContactId) + " " + "AND " + "attc.Description = " + MSSBamPg8Schema.getQuotedString(Description) + " "; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); if (resultSet.next()) { MSSBamAttachmentBuff buff = unpackAttachmentResultSetToBuff(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.MSSBamPg8AccessFrequencyTable.java
public void deleteAccessFrequency(MSSBamAuthorization Authorization, MSSBamAccessFrequencyBuff Buff) { final String S_ProcName = "deleteAccessFrequency"; try {/* w w w .j a v a2 s.c o m*/ Connection cnx = schema.getCnx(); short Id = Buff.getRequiredId(); String Name = Buff.getRequiredName(); int Revision = Buff.getRequiredRevision(); MSSBamAccessFrequencyBuff readBuff = readBuffByIdIdx(Authorization, Id); int oldRevision = readBuff.getRequiredRevision(); if (oldRevision != Revision) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), S_ProcName, Buff); } String sql = "DELETE FROM mssbam110.accfreq " + "WHERE " + "Id = " + Short.toString(Id) + " " + "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); } }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8BoolDefTable.java
public MSSBamBoolDefBuff 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. ja v a 2 s. c o m*/ MSSBamBoolDefBuff buff; long Id = PKey.getRequiredId(); String classCode; try { Connection cnx = schema.getCnx(); String sql = S_sqlSelectBoolDefDistinctClassCode + "WHERE " + "bln.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 = readBuff(Authorization, PKey); } 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 { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect ClassCode \"" + classCode + "\""); } return (buff); }
From source file:edu.ku.brc.specify.conversion.ConvertTaxonHelper.java
/** * Converts the taxonomy tree definition from the old taxonomicunittype table to the new table * pair: TaxonTreeDef & TaxonTreeDefItems. * /*from w w w .ja v a2 s . c o m*/ * @param taxonomyTypeId the tree def id in taxonomicunittype * @return the TaxonTreeDef object * @throws SQLException */ public void convertTaxonTreeDefinition(final CollectionInfo colInfo) { if (!colInfo.isInUse()) { return; } TaxonTreeDef taxonTreeDef = newTaxonInfoHash.get(colInfo.getTaxonNameId()); if (taxonTreeDef != null) { colInfo.setTaxonTreeDef(taxonTreeDef); return; } Integer oldTaxonRootId = colInfo.getTaxonNameId(); Integer taxonomyTypeId = colInfo.getTaxonomyTypeId(); try { Statement st = oldDBConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); taxonTreeDef = new TaxonTreeDef(); taxonTreeDef.initialize(); String sql = "SELECT TaxonomyTypeName, KingdomID FROM taxonomytype WHERE TaxonomyTypeID = " + taxonomyTypeId; log.debug(sql); ResultSet rs = st.executeQuery(sql); rs.next(); String taxonomyTypeName = rs.getString(1); int kingdomID = rs.getInt(2); rs.close(); taxonTreeDef.setName(taxonomyTypeName + " taxonomy tree"); taxonTreeDef.setRemarks("Tree converted from " + oldDBName); taxonTreeDef.setFullNameDirection(TreeDefIface.FORWARD); sql = String.format( "SELECT RankID, RankName, RequiredParentRankID, TaxonomicUnitTypeID FROM taxonomicunittype " + "WHERE TaxonomyTypeID = %d AND (Kingdom = %d OR RankID = 0) ORDER BY RankID", taxonomyTypeId, kingdomID); log.debug(sql); rs = st.executeQuery(sql); Hashtable<Integer, Integer> rankId2TxnUntTypId = new Hashtable<Integer, Integer>(); int rank; String name; int requiredRank; Vector<TaxonTreeDefItem> items = new Vector<TaxonTreeDefItem>(); Vector<Integer> enforcedRanks = new Vector<Integer>(); while (rs.next()) { rank = rs.getInt(1); name = rs.getString(2); requiredRank = rs.getInt(3); int taxUnitTypeId = rs.getInt(4); if (StringUtils.isEmpty(name) || (rank > 0 && requiredRank == 0)) { continue; } if (rankId2TxnUntTypId.get(rank) != null) { String msg = String.format( "Old TreeDef has two of the same Rank %d, throwing it out.\n\nYou must fix this before proceeding.", rank); tblWriter.logError(msg); log.debug(msg); UIRegistry.displayErrorDlg(msg); System.exit(0); } rankId2TxnUntTypId.put(rank, taxUnitTypeId); log.debug(rank + " " + name + " TaxonomicUnitTypeID: " + taxUnitTypeId); TaxonTreeDefItem ttdi = new TaxonTreeDefItem(); ttdi.initialize(); ttdi.setName(name); ttdi.setFullNameSeparator(" "); ttdi.setRankId(rank); ttdi.setTreeDef(taxonTreeDef); taxonTreeDef.getTreeDefItems().add(ttdi); ttdi.setIsInFullName(rank >= TaxonTreeDef.GENUS); // setup the parent/child relationship if (items.isEmpty()) { ttdi.setParent(null); } else { ttdi.setParent(items.lastElement()); } items.add(ttdi); enforcedRanks.add(requiredRank); } rs.close(); for (TaxonTreeDefItem i : items) { i.setIsEnforced(enforcedRanks.contains(i.getRankId())); } try { Session session = HibernateUtil.getNewSession(); Transaction trans = session.beginTransaction(); session.save(taxonTreeDef); trans.commit(); session.close(); } catch (Exception ex) { ex.printStackTrace(); throw new RuntimeException(ex); } IdMapperMgr idMapperMgr = IdMapperMgr.getInstance(); IdMapperIFace tutMapper = idMapperMgr.get("TaxonomicUnitType", "TaxonomicUnitTypeID"); IdMapperIFace taxonomyTypeMapper = idMapperMgr.get("TaxonomyType", "TaxonomyTypeID"); //tutMapper.reset(); //if (taxonomyTypeMapper.get(taxonomyTypeId) == null) //{ taxonomyTypeMapper.put(taxonomyTypeId, taxonTreeDef.getId()); //} for (TaxonTreeDefItem ttdi : taxonTreeDef.getTreeDefItems()) { int ttdiId = rankId2TxnUntTypId.get(ttdi.getRankId()); log.debug("Mapping " + ttdiId + " -> " + ttdi.getId() + " RankId: " + ttdi.getRankId()); tutMapper.put(ttdiId, ttdi.getId()); } newTaxonInfoHash.put(oldTaxonRootId, taxonTreeDef); CollectionInfo ci = getCIByTaxonTypeId(taxonomyTypeId); ci.setTaxonTreeDef(taxonTreeDef); taxonTreeDefHash.put(taxonomyTypeId, taxonTreeDef); log.debug("Hashing taxonomyTypeId: " + taxonomyTypeId + " -> taxonTreeDefId:" + taxonTreeDef.getId()); } catch (SQLException ex) { ex.printStackTrace(); throw new RuntimeException(ex); } }
From source file:com.itemanalysis.jmetrik.graph.nicc.NonparametricCurveAnalysis.java
public void evaluateAll() throws SQLException { categoryRegression = new TreeMap<VariableAttributes, KernelRegressionCategories>(); for (VariableAttributes v : variables) { KernelRegressionCategories kCat = new KernelRegressionCategories(v, kernelFunction, bandwidth, uniformDistributionApproximation); categoryRegression.put(v, kCat); }//from w w w . j a v a 2 s .c o m //connect to db Table sqlTable = new Table(tableName.getNameForDatabase()); SelectQuery select = new SelectQuery(); for (VariableAttributes v : variables) { select.addColumn(sqlTable, v.getName().nameForDatabase()); } select.addColumn(sqlTable, regressorVariable.getName().nameForDatabase()); if (hasGroupVariable) select.addColumn(sqlTable, groupByVariable.getName().nameForDatabase()); ResultSet rs = null; Statement stmt = null; try { stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = stmt.executeQuery(select.toString()); KernelRegressionCategories kernelRegressionCategories; Object itemResponse; Double score; Object tempGroup; String group; while (rs.next()) { //increment kernel regression objects //omit examinees with missing data score = rs.getDouble(regressorVariable.getName().nameForDatabase()); if (!rs.wasNull()) { for (VariableAttributes v : categoryRegression.keySet()) { kernelRegressionCategories = categoryRegression.get(v); itemResponse = rs.getObject(v.getName().nameForDatabase()); if (itemResponse != null) kernelRegressionCategories.increment(score, itemResponse); } } updateProgress(); } } catch (SQLException ex) { throw ex; } finally { if (rs != null) rs.close(); if (stmt != null) stmt.close(); } this.firePropertyChange("progress-ind-on", null, null); }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8BaseDomainTable.java
public MSSBamBaseDomainBuff readDerivedByIdIdx(MSSBamAuthorization Authorization, long Id) { final String S_ProcName = "MSSBamPg8BaseDomainTable.readDerivedByIdIdx() "; MSSBamBaseDomainBuff buff;// w w 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_sqlSelectBaseDomainDistinctClassCode + "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("BDM")) { buff = readBuffByIdIdx(Authorization, Id); } else if (classCode.equals("DOM")) { buff = schema.getTableDomain().readBuffByIdIdx(Authorization, Id); } else if (classCode.equals("LENT")) { buff = schema.getTableLegalEntity().readBuffByIdIdx(Authorization, Id); } else if (classCode.equals("COM")) { buff = schema.getTableCompany().readBuffByIdIdx(Authorization, Id); } else if (classCode.equals("USR")) { buff = schema.getTableUser().readBuffByIdIdx(Authorization, Id); } else if (classCode.equals("PRJ")) { buff = schema.getTableProject().readBuffByIdIdx(Authorization, Id); } else if (classCode.equals("VER")) { buff = schema.getTableVersion().readBuffByIdIdx(Authorization, Id); } else if (classCode.equals("MJV")) { buff = schema.getTableMajorVersion().readBuffByIdIdx(Authorization, Id); } else if (classCode.equals("MNV")) { buff = schema.getTableMinorVersion().readBuffByIdIdx(Authorization, Id); } else if (classCode.equals("TLD")) { buff = schema.getTableTLD().readBuffByIdIdx(Authorization, Id); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect ClassCode \"" + classCode + "\""); } return (buff); }