public ResultSet readForUpdate(String fullId,String type,String localId,Connection connection) throws NotFoundException, SQLException {
  PreparedStatement readForUpdateStatement=null;
  ResultSet rs=null;
  try {
    readForUpdateStatement=getPreparedStatement(connection,QueryDefinition.READFORUPDATEQUERYSTR);
    logger.trace("Populating prepared statement {} for {}",readForUpdateStatement,fullId);
    readForUpdateStatement.setString(1,type);
    readForUpdateStatement.setString(2,localId);
    logger.debug("Executing: {}",readForUpdateStatement);
    rs=readForUpdateStatement.executeQuery();
    if (rs.next()) {
      logger.debug("Read for update full id: {}",fullId);
      return rs;
    }
 else {
      CleanupHelper.loggedClose(rs);
      CleanupHelper.loggedClose(readForUpdateStatement);
      throw new NotFoundException("Object " + fullId + " not found in "+ type);
    }
  }
 catch (  SQLException ex) {
    CleanupHelper.loggedClose(rs);
    CleanupHelper.loggedClose(readForUpdateStatement);
    throw ex;
  }
}

public ResultSet readForUpdate ( String fullId , String type , String localId , Connection connection ) throws NotFoundException , SQLException { PreparedStatement readForUpdateStatement = null ; ResultSet rs = null ; try { readForUpdateStatement = getPreparedStatement ( connection , QueryDefinition . READFORUPDATEQUERYSTR ) ; logger . trace ( "Populating prepared statement {} for {}" , readForUpdateStatement , fullId ) ; readForUpdateStatement . setString ( 1 , type ) ; readForUpdateStatement . setString ( 2 , localId ) ; logger . debug ( "Executing: {}" , readForUpdateStatement ) ; rs = readForUpdateStatement . executeQuery ( ) ; if ( rs . next ( ) ) { logger . debug ( "Read for update full id: {}" , fullId ) ; return rs ; } else { CleanupHelper . loggedClose ( rs ) ; CleanupHelper . loggedClose ( readForUpdateStatement ) ; throw new NotFoundException ( "Object " + fullId + " not found in " + type ) ; } } catch ( SQLException ex ) { CleanupHelper . loggedClose ( rs ) ; CleanupHelper . loggedClose ( readForUpdateStatement ) ; throw ex ; } }
reads an object with for update locking applied note : statement associated with the returned resultset is not closed upon return . aside from taking care to close the resultset it also is the responsibility of the caller to close the associated statement . although the specification specifies that drivers / pools should close the statement automatically , not all do this reliably .
