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:com.netspective.axiom.sql.StoredProcedure.java
/** * Executes the stored procedure and records different statistics such as database connection times, * parameetr binding times, and procedure execution times. * * @param overrideIndexes parameter indexes to override * @param overrideValues parameter override values *///w w w . j av a 2 s . c o m protected QueryResultSet executeAndRecordStatistics(ConnectionContext cc, int[] overrideIndexes, Object[] overrideValues, boolean scrollable) throws NamingException, SQLException { if (log.isTraceEnabled()) trace(cc, overrideIndexes, overrideValues); QueryExecutionLogEntry logEntry = execLog.createNewEntry(cc, this.getQualifiedName()); Connection conn = null; CallableStatement stmt = null; boolean closeConnection = true; try { logEntry.registerGetConnectionBegin(); conn = cc.getConnection(); logEntry.registerGetConnectionEnd(conn); String sql = StringUtils.strip(getSqlText(cc)); if (scrollable) stmt = conn.prepareCall(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); else stmt = conn.prepareCall(sql); logEntry.registerBindParamsBegin(); if (parameters != null) { parameters.apply(cc, stmt, overrideIndexes, overrideValues); logEntry.registerBindParamsEnd(); logEntry.registerExecSqlBegin(); stmt.execute(); logEntry.registerExecSqlEndSuccess(); parameters.extract(cc, stmt); StoredProcedureParameter rsParameter = parameters.getResultSetParameter(); if (rsParameter != null) { closeConnection = false; Value val = rsParameter.getValue().getValue(cc.getDatabaseValueContext()); return (QueryResultSet) val.getValue(); } else return null; } else { logEntry.registerExecSqlBegin(); stmt.execute(); logEntry.registerExecSqlEndSuccess(); return null; } } catch (SQLException e) { logEntry.registerExecSqlEndFailed(); log.error(createExceptionMessage(cc, overrideIndexes, overrideValues), e); throw e; } }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8ChainTable.java
public MSSBamChainBuff readBuffByUNameIdx(MSSBamAuthorization Authorization, Long ScopeId, String Name) { final String S_ProcName = "readBuffByUNameIdx"; try {//from w w w . j a v a 2s . c om Connection cnx = schema.getCnx(); String sql = S_sqlSelectChainBuff + "WHERE " + ((ScopeId == null) ? "anyo.ScopeId is null " : "anyo.ScopeId = " + ScopeId.toString() + " ") + "AND " + "anyo.Name = " + MSSBamPg8Schema.getQuotedString(Name) + " "; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); if (resultSet.next()) { MSSBamChainBuff buff = unpackChainResultSetToBuff(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.MSSBamPg8BoolDefTable.java
public MSSBamBoolDefBuff[] readDerivedByTenantIdx(MSSBamAuthorization Authorization, long TenantId) { final String S_ProcName = "readDerivedByTenantIdx"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); }/*from www.j a va 2 s . c o m*/ ArrayList<String> classCodeList = new ArrayList<String>(); String classCode; try { Connection cnx = schema.getCnx(); String sql = S_sqlSelectBoolDefDistinctClassCode + "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<MSSBamBoolDefBuff> resultList = new ArrayList<MSSBamBoolDefBuff>(); ListIterator<String> classCodeIter = classCodeList.listIterator(); while (classCodeIter.hasNext()) { classCode = classCodeIter.next(); if (classCode.equals("BLN")) { MSSBamBoolDefBuff[] subList = readBuffByTenantIdx(Authorization, TenantId); for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) { resultList.add(subList[subListIdx]); } } else if (classCode.equals("TBLN")) { MSSBamTableBoolBuff[] subList = schema.getTableTableBool().readBuffByTenantIdx(Authorization, TenantId); for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) { resultList.add(subList[subListIdx]); } } else if (classCode.equals("SBLN")) { MSSBamSchemaBoolBuff[] subList = schema.getTableSchemaBool().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 MSSBamBoolDefBuff[0])); }
From source file:jp.mathes.databaseWiki.db.postgres.PostgresBackend.java
@Override public Document saveDocument(final String user, final String password, final String db, final String table, final String name, final Document document) throws BackendException { Statement st = null;// w w w . j a va2 s .c o m Connection conn = null; ResultSet rs = null; try { conn = this.connectToDB(user, password, db); String nameField = this.getNameField(conn, table, db); st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = st.executeQuery(String.format("select count(*) from \"%s\".\"%s\" where \"%s\"='%s'", this.getSchemaName(table, db), this.getPlainTableName(table), nameField, name)); rs.next(); int numEntries = rs.getInt(1); if (numEntries > 1) { throw new BackendException(String.format( "There are more than two entries with the name '%s' in the table '%s.%s', something is wrong with the database design.", name, this.getSchemaName(table, db), this.getPlainTableName(table))); } boolean isNewDocument = numEntries == 0 ? true : false; String insertOrUpdate = isNewDocument ? this.getInsertStatement(document, name, table, nameField, db) : this.getUpdateStatement(document, name, table, nameField, db); rs.close(); if (!isNewDocument && document.getAllFields().containsKey("version")) { conn.setAutoCommit(false); st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); String queryString = String.format("select version from \"%s\".\"%s\" where \"%s\"='%s'", this.getSchemaName(table, db), this.getPlainTableName(table), nameField, name); this.logString(queryString, user); rs = st.executeQuery(queryString); rs.next(); if (rs.getInt(1) != (Integer) document.getAllFields().get("version").getValue()) { conn.rollback(); throw new BackendException(String.format( "There is a new version of the record with name '%s' in table '%s.%s', please repeat editing.", name, this.getSchemaName(table, db), this.getPlainTableName(table))); } this.logString(insertOrUpdate, user); st.executeUpdate(insertOrUpdate); conn.commit(); conn.setAutoCommit(true); } else { this.logString(insertOrUpdate, user); st.executeUpdate(insertOrUpdate); } } catch (SQLException e) { throw new BackendException(e); } catch (ClassNotFoundException e) { throw new BackendException(e); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(st); DbUtils.closeQuietly(conn); } return document; }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8AddressTable.java
public void deleteAddress(MSSBamAuthorization Authorization, MSSBamAddressBuff Buff) { final String S_ProcName = "deleteAddress"; try {// ww w.j a v a 2 s . c o m 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); } String sql = "DELETE FROM mssbam110.Address " + "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 delete, not " + rowsAffected); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
From source file:edu.ku.brc.specify.toycode.mexconabio.CopyFromGBIF.java
/** * //from w w w .j a v a 2 s . c om */ public void index() { IndexWriter writer = null; try { analyzer = new StandardAnalyzer(Version.LUCENE_36); FileUtils.deleteDirectory(INDEX_DIR); System.out.println("Indexing to directory '" + INDEX_DIR + "'..."); long totalRecs = BasicSQLUtils.getCount(srcDBConn, "SELECT COUNT(*) FROM raw"); long procRecs = 0; long startTime = System.currentTimeMillis(); int secsThreshold = 0; PrintWriter pw = null; final double HRS = 1000.0 * 60.0 * 60.0; Statement stmt = null; try { writer = new IndexWriter(FSDirectory.open(INDEX_DIR), analyzer, true, IndexWriter.MaxFieldLength.LIMITED); pw = new PrintWriter("gbif.log"); System.out.println("Total Records: " + totalRecs); pw.println("Total Records: " + totalRecs); stmt = srcDBConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setFetchSize(Integer.MIN_VALUE); //String[] fldNames = {"id", "cn", "gn", "sp", "cln", "ctr", "yr", "mn", "dy"}; ResultSet rs = stmt.executeQuery( "SELECT id, catalogue_number, genus, species, collector_num, collector_name, year, month, day, state_province, county FROM raw");// LIMIT 100000,1000"); ResultSetMetaData rsmd = rs.getMetaData(); StringBuilder sb = new StringBuilder(); while (rs.next()) { String id = rs.getString(1); Document doc = new Document(); doc.add(new Field("id", id.toString(), Field.Store.YES, Field.Index.NO)); sb.setLength(0); for (int i = 2; i <= rsmd.getColumnCount(); i++) { String val = rs.getString(i); if (StringUtils.isNotEmpty(val)) { sb.append(val); sb.append(' '); } } doc.add(new Field("contents", sb.toString(), Field.Store.NO, Field.Index.ANALYZED)); writer.addDocument(doc); procRecs++; if (procRecs % 10000 == 0) { long endTime = System.currentTimeMillis(); long elapsedTime = endTime - startTime; double timePerRecord = (elapsedTime / procRecs); double hrsLeft = ((totalRecs - procRecs) * timePerRecord) / HRS; int seconds = (int) (elapsedTime / 60000.0); if (secsThreshold != seconds) { secsThreshold = seconds; String msg = String.format("Elapsed %8.2f hr.mn Percent: %6.3f Hours Left: %8.2f ", ((double) (elapsedTime)) / HRS, 100.0 * ((double) procRecs / (double) totalRecs), hrsLeft); System.out.println(msg); pw.println(msg); pw.flush(); } } } } catch (SQLException sqlex) { sqlex.printStackTrace(); } catch (IOException e) { e.printStackTrace(); System.out.println("IOException adding Lucene Document: " + e.getMessage()); } finally { if (stmt != null) { try { stmt.close(); } catch (SQLException e) { e.printStackTrace(); } } } } catch (IOException e) { e.printStackTrace(); System.out.println(" caught a " + e.getClass() + "\n with message: " + e.getMessage()); } finally { analyzer.close(); analyzer = null; if (writer != null) { try { System.out.println("Optimizing..."); writer.optimize(); writer.close(); System.out.println("Done Optimizing."); } catch (CorruptIndexException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } writer = null; } } }
From source file:fr.bird.bloom.model.GeographicTreatment.java
/** * Create temporary table "temp" with only correct iso2 code in DarwinCoreInput table. * Iso2 code (countryCode_) is correct if it's contained in IsoCode table (iso2_). * /* w ww .j av a 2s . c om*/ * @return void */ public void deleteWrongIso2() { 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 newConnectionTemp = new DatabaseTreatment(statement); List<String> messages = new ArrayList<>(); String choiceStatement = "executeUpdate"; messages.add("\n--- Create temporary table with correct ISO2 ---"); String sqlCreateTemp = "CREATE TABLE Workflow.temp_" + this.getUuid() + " AS SELECT DarwinCoreInput.* FROM Workflow.DarwinCoreInput,Workflow.IsoCode WHERE countryCode_=IsoCode.iso2_ AND UUID_=\"" + this.getUuid() + "\";"; System.out.println(sqlCreateTemp); messages.addAll(newConnectionTemp.executeSQLcommand(choiceStatement, sqlCreateTemp)); for (int i = 0; i < messages.size(); i++) { System.out.println(messages.get(i)); } }
From source file:com.cloudera.sqoop.manager.OracleManager.java
@Override public String[] listTables() { Connection conn = null;/*from w ww . ja va2 s . c o m*/ Statement stmt = null; ResultSet rset = null; List<String> tables = new ArrayList<String>(); try { conn = getConnection(); stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); rset = stmt.executeQuery(QUERY_LIST_TABLES); while (rset.next()) { tables.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 tables", 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 tables.toArray(new String[tables.size()]); }
From source file:annis.dao.SpringAnnisDao.java
@Transactional(readOnly = true) @Override//from w ww . jav a 2 s. c o m public boolean find(final QueryData queryData, final OutputStream out) { prepareTransaction(queryData); Boolean finished = getJdbcTemplate().execute(new ConnectionCallback<Boolean>() { @Override public Boolean doInConnection(Connection con) throws SQLException, DataAccessException { try (Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);) { String sql = findSqlGenerator.toSql(queryData); PrintWriter w; try (ResultSet rs = stmt.executeQuery(sql)) { w = new PrintWriter(new OutputStreamWriter(out, "UTF-8")); ResultSetTypedIterator<Match> itMatches = new ResultSetTypedIterator<>(rs, findSqlGenerator); int i = 1; while (itMatches.hasNext()) { // write single match to output stream Match m = itMatches.next(); w.print(m.toString()); w.print("\n"); // flush after every 10th item if (i % 10 == 0) { w.flush(); } i++; } // end for each match } w.flush(); return true; } catch (UnsupportedEncodingException ex) { log.error("Your system is not able to handle UTF-8 but ANNIS really needs this charset", ex); } return false; } }); return finished; }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8ChainTable.java
public MSSBamChainBuff[] readBuffByTableIdx(MSSBamAuthorization Authorization, long TableId) { final String S_ProcName = "readBuffByTableIdx"; try {//from w ww .j a va2s . c om Connection cnx = schema.getCnx(); String sql = S_sqlSelectChainBuff + "WHERE " + "chn.TableId = " + Long.toString(TableId) + " " + "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); } }