if (limit != null) { stmt.setMaxRows(limit.intValue());
if (limit != null) { stmt.setMaxRows(limit.intValue());
/** * Return the first object that matches the {@link PreparedStmt} or null if none. */ public T queryForFirst(DatabaseConnection databaseConnection, PreparedStmt<T> preparedStmt, ObjectCache objectCache) throws SQLException { CompiledStatement compiledStatement = preparedStmt.compile(databaseConnection, StatementType.SELECT); DatabaseResults results = null; try { compiledStatement.setMaxRows(1); results = compiledStatement.runQuery(objectCache); if (results.first()) { logger.debug("query-for-first of '{}' returned at least 1 result", preparedStmt.getStatement()); return preparedStmt.mapRow(results); } else { logger.debug("query-for-first of '{}' returned 0 results", preparedStmt.getStatement()); return null; } } finally { IOUtils.closeThrowSqlException(results, "results"); IOUtils.closeThrowSqlException(compiledStatement, "compiled statement"); } }
/** * Return the first object that matches the {@link PreparedStmt} or null if none. */ public T queryForFirst(DatabaseConnection databaseConnection, PreparedStmt<T> preparedStmt, ObjectCache objectCache) throws SQLException { CompiledStatement compiledStatement = preparedStmt.compile(databaseConnection, StatementType.SELECT); DatabaseResults results = null; try { compiledStatement.setMaxRows(1); results = compiledStatement.runQuery(objectCache); if (results.first()) { logger.debug("query-for-first of '{}' returned at least 1 result", preparedStmt.getStatement()); return preparedStmt.mapRow(results); } else { logger.debug("query-for-first of '{}' returned at 0 results", preparedStmt.getStatement()); return null; } } finally { IOUtils.closeThrowSqlException(results, "results"); IOUtils.closeThrowSqlException(compiledStatement, "compiled statement"); } }