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.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8BaseDomainTable.java
public MSSBamBaseDomainBuff readBuffByUNameIdx(MSSBamAuthorization Authorization, Long ScopeId, String Name) { final String S_ProcName = "readBuffByUNameIdx"; try {/*from w w w . j a va2s. com*/ Connection cnx = schema.getCnx(); String sql = S_sqlSelectBaseDomainBuff + "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()) { MSSBamBaseDomainBuff buff = unpackBaseDomainResultSetToBuff(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:it.cnr.icar.eric.server.persistence.rdb.SQLPersistenceManagerImpl.java
/** * Executes an SQL Query.//from w w w . ja v a 2s .c om */ @SuppressWarnings({ "static-access", "unchecked" }) public List<IdentifiableType> executeSQLQuery(ServerRequestContext context, String sqlQuery, List<String> queryParams, ResponseOptionType ebResponseOptionType, String tableName, List<?> objectRefs, IterativeQueryParams paramHolder) throws RegistryException { @SuppressWarnings("rawtypes") List ebIdentifiableTypeResultList = null; Connection connection = null; int startIndex = paramHolder.startIndex; int maxResults = paramHolder.maxResults; int totalResultCount = -1; Statement stmt = null; try { connection = context.getConnection(); java.sql.ResultSet rs = null; tableName = Utility.getInstance().mapTableName(tableName); ReturnType returnType = ebResponseOptionType.getReturnType(); @SuppressWarnings("unused") boolean returnComposedObjects = ebResponseOptionType.isReturnComposedObjects(); if (maxResults < 0) { if (queryParams == null) { stmt = connection.createStatement(); } else { stmt = connection.prepareStatement(sqlQuery); } } else { if (queryParams == null) { stmt = connection.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY); } else { stmt = connection.prepareStatement(sqlQuery, java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY); } } if (log.isDebugEnabled()) { log.debug("Executing query: '" + sqlQuery + "'"); if (dumpStackOnQuery) { Thread.currentThread().dumpStack(); } } if (queryParams == null) { rs = stmt.executeQuery(sqlQuery); } else { Iterator<String> iter = queryParams.iterator(); int paramCount = 0; while (iter.hasNext()) { Object param = iter.next(); ((PreparedStatement) stmt).setObject(++paramCount, param); } rs = ((PreparedStatement) stmt).executeQuery(); } if (maxResults >= 0) { rs.last(); totalResultCount = rs.getRow(); // Reset back to before first row so that DAO can correctly // scroll // through the result set rs.beforeFirst(); } @SuppressWarnings("unused") Iterator<?> iter = null; log.debug("::3:: SQL result ReturnType" + returnType.toString()); if (returnType == ReturnType.OBJECT_REF) { ebIdentifiableTypeResultList = new ArrayList<Object>(); if (startIndex > 0) { rs.last(); totalResultCount = rs.getRow(); rs.beforeFirst(); // calling rs.next() is a workaround for some drivers, such // as Derby's, that do not set the cursor during call to // rs.relative(...) rs.next(); @SuppressWarnings("unused") boolean onRow = rs.relative(startIndex - 1); } int cnt = 0; while (rs.next()) { ObjectRefType ebObjectRefType = bu.rimFac.createObjectRefType(); // TODO: JAXBElement String id = rs.getString(1); ebObjectRefType.setId(id); ebIdentifiableTypeResultList.add(ebObjectRefType); if (++cnt == maxResults) { break; } } } else if (returnType == ReturnType.REGISTRY_OBJECT) { context.setResponseOption(ebResponseOptionType); RegistryObjectDAO roDAO = new RegistryObjectDAO(context); ebIdentifiableTypeResultList = roDAO.getObjects(rs, startIndex, maxResults); } else if ((returnType == ReturnType.LEAF_CLASS) || (returnType == ReturnType.LEAF_CLASS_WITH_REPOSITORY_ITEM)) { ebIdentifiableTypeResultList = getObjects(context, connection, rs, tableName, ebResponseOptionType, objectRefs, startIndex, maxResults); } else { throw new RegistryException(ServerResourceBundle.getInstance() .getString("message.invalidReturnType", new Object[] { returnType })); } } catch (SQLException e) { throw new RegistryException(e); } finally { try { if (stmt != null) { stmt.close(); } } catch (SQLException sqle) { log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), sqle); } } paramHolder.totalResultCount = totalResultCount; return ebIdentifiableTypeResultList; }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8BlobDefTable.java
public MSSBamBlobDefBuff[] readDerivedByEAccSecIdx(MSSBamAuthorization Authorization, Short EditAccessSecurityId) { final String S_ProcName = "readDerivedByEAccSecIdx"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); }// ww w . ja va 2 s.co m ArrayList<String> classCodeList = new ArrayList<String>(); String classCode; try { Connection cnx = schema.getCnx(); String sql = S_sqlSelectBlobDefDistinctClassCode + "WHERE " + ((EditAccessSecurityId == null) ? "val.EditAccessSecurityId is null " : "val.EditAccessSecurityId = " + EditAccessSecurityId.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 = readBuffByEAccSecIdx(Authorization, EditAccessSecurityId); for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) { resultList.add(subList[subListIdx]); } } else if (classCode.equals("TBLB")) { MSSBamTableBlobBuff[] subList = schema.getTableTableBlob().readBuffByEAccSecIdx(Authorization, EditAccessSecurityId); for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) { resultList.add(subList[subListIdx]); } } else if (classCode.equals("SBLB")) { MSSBamSchemaBlobBuff[] subList = schema.getTableSchemaBlob().readBuffByEAccSecIdx(Authorization, EditAccessSecurityId); 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:net.antidot.semantic.rdf.rdb2rdf.r2rml.core.R2RMLEngine.java
private ResultSet constructJointTable(ReferencingObjectMap refObjectMap) throws SQLException { log.debug("[R2RMLEngine:constructJointTable] Run joint SQL Query : " + refObjectMap.getJointSQLQuery()); ResultSet rs = null;//from ww w . ja va 2s. co m java.sql.Statement s = conn.createStatement(ResultSet.HOLD_CURSORS_OVER_COMMIT, ResultSet.CONCUR_READ_ONLY); if (refObjectMap.getJointSQLQuery() != null) { s.executeQuery(refObjectMap.getJointSQLQuery()); rs = s.getResultSet(); if (rs == null) throw new IllegalStateException("[R2RMLEngine:constructJointTable] SQL request " + "failed : result of effective SQL query is null."); } else { throw new IllegalStateException( "[R2RMLEngine:constructJointTable] No effective SQL query has been found."); } return rs; }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8BaseDomainTable.java
public void updateBaseDomain(MSSBamAuthorization Authorization, MSSBamBaseDomainBuff Buff) { final String S_ProcName = "updateBaseDomain"; try {/*from w ww . j a v a 2 s . co m*/ Connection cnx = schema.getCnx(); long Id = Buff.getRequiredId(); String sql = "UPDATE mssbam110.basedom " + "SET " + "Id = " + MSSBamPg8Schema.getInt64String(Id) + " " + "WHERE " + "Id = " + Long.toString(Id) + " "; 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); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
From source file:net.antidot.semantic.rdf.rdb2rdf.r2rml.core.R2RMLEngine.java
private ResultSet constructInversionTable(String instantiation, String effectiveSQLQuery) throws SQLException { String sqlQuery = "SELECT * FROM (" + effectiveSQLQuery + ") AS tmp WHERE " + instantiation + ";"; log.debug("[R2RMLEngine:constructInversionTable] Run inversion SQL Query : " + sqlQuery); ResultSet rs = null;//from w w w.j a v a 2 s. c o m java.sql.Statement s = conn.createStatement(ResultSet.HOLD_CURSORS_OVER_COMMIT, ResultSet.CONCUR_READ_ONLY); s.executeQuery(sqlQuery); rs = s.getResultSet(); if (rs == null) throw new IllegalStateException("[R2RMLEngine:constructInversionTable] SQL request " + "failed : result of effective SQL query is null."); return rs; }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8BoolDefTable.java
public MSSBamBoolDefBuff[] readDerivedByEAccFreqIdx(MSSBamAuthorization Authorization, Short EditAccessFrequencyId) { final String S_ProcName = "readDerivedByEAccFreqIdx"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); }/*from w w w. j a va 2s . co m*/ ArrayList<String> classCodeList = new ArrayList<String>(); String classCode; try { Connection cnx = schema.getCnx(); String sql = S_sqlSelectBoolDefDistinctClassCode + "WHERE " + ((EditAccessFrequencyId == null) ? "val.EditAccessFrequencyId is null " : "val.EditAccessFrequencyId = " + EditAccessFrequencyId.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<MSSBamBoolDefBuff> resultList = new ArrayList<MSSBamBoolDefBuff>(); ListIterator<String> classCodeIter = classCodeList.listIterator(); while (classCodeIter.hasNext()) { classCode = classCodeIter.next(); if (classCode.equals("BLN")) { MSSBamBoolDefBuff[] subList = readBuffByEAccFreqIdx(Authorization, EditAccessFrequencyId); for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) { resultList.add(subList[subListIdx]); } } else if (classCode.equals("TBLN")) { MSSBamTableBoolBuff[] subList = schema.getTableTableBool().readBuffByEAccFreqIdx(Authorization, EditAccessFrequencyId); for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) { resultList.add(subList[subListIdx]); } } else if (classCode.equals("SBLN")) { MSSBamSchemaBoolBuff[] subList = schema.getTableSchemaBool().readBuffByEAccFreqIdx(Authorization, EditAccessFrequencyId); 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:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8BaseDomainTable.java
public void deleteBaseDomain(MSSBamAuthorization Authorization, MSSBamBaseDomainBuff Buff) { final String S_ProcName = "deleteBaseDomain"; try {//from w ww. j a v a 2 s.c om Connection cnx = schema.getCnx(); long Id = Buff.getRequiredId(); String sql = "DELETE FROM mssbam110.basedom " + "WHERE " + "Id = " + Long.toString(Id) + " "; 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.pitt.apollo.db.ApolloDbUtils.java
public PreparedStatement getDataContentForBatchSimulations(BigInteger batchRunId, List<String> fileNamesToMatch, Connection conn) throws ApolloDatabaseException { String query = "SELECT" + " rddav.value AS name," + " rdc.text_content," + " r2.id" + " FROM" + " run_data_description_axis_value rddav," + " run_data_description_axis rdda," + " run_data_content rdc," + " run_data rd," + " simulation_group_definition sgd," + " run r1," + " run r2" + " WHERE" + " rd.content_id = rdc.id AND" + " r2.id = sgd.run_id AND" + " rd.run_id = r2.id AND"; if (!fileNamesToMatch.isEmpty()) { query += " (rddav.value = '" + fileNamesToMatch.get(0) + "'"; for (int i = 1; i < fileNamesToMatch.size(); i++) { query += " OR rddav.value = '" + fileNamesToMatch.get(i) + "'"; }/*from w w w . ja v a 2 s . c om*/ query += ") AND"; } query += " rddav.run_data_description_axis_id = rdda.id AND" + " rddav.run_data_description_id = rd.description_id AND" + " sgd.simulation_group_id = r1.simulation_group_id AND" + " r1.id = ? AND" + " rdda.label = 'label'"; System.out.println(query); PreparedStatement pstmt = null; try { pstmt = conn.prepareStatement(query, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); pstmt.setFetchSize(Integer.MIN_VALUE); pstmt.setInt(1, batchRunId.intValue()); return pstmt; } catch (SQLException ex) { throw new ApolloDatabaseException("SQLException attempting to get data content for batch run ID " + batchRunId + ": " + ex.getMessage()); } }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8BlobDefTable.java
public MSSBamBlobDefBuff[] readDerivedByEAccFreqIdx(MSSBamAuthorization Authorization, Short EditAccessFrequencyId) { final String S_ProcName = "readDerivedByEAccFreqIdx"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); }/*from www. ja v a2 s . co m*/ ArrayList<String> classCodeList = new ArrayList<String>(); String classCode; try { Connection cnx = schema.getCnx(); String sql = S_sqlSelectBlobDefDistinctClassCode + "WHERE " + ((EditAccessFrequencyId == null) ? "val.EditAccessFrequencyId is null " : "val.EditAccessFrequencyId = " + EditAccessFrequencyId.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 = readBuffByEAccFreqIdx(Authorization, EditAccessFrequencyId); for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) { resultList.add(subList[subListIdx]); } } else if (classCode.equals("TBLB")) { MSSBamTableBlobBuff[] subList = schema.getTableTableBlob().readBuffByEAccFreqIdx(Authorization, EditAccessFrequencyId); for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) { resultList.add(subList[subListIdx]); } } else if (classCode.equals("SBLB")) { MSSBamSchemaBlobBuff[] subList = schema.getTableSchemaBlob().readBuffByEAccFreqIdx(Authorization, EditAccessFrequencyId); 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])); }