/** * Eagerly executes a SQL query and subsequently maps each row in the * ResultSet using a provided mapper and return a Stream of the mapped * objects. The ResultSet is eagerly consumed so that all elements in the * ResultSet are read before the Stream produces any objects. If no objects * are present or if an SQLException is thrown internally, an {@code empty} * stream is returned. * * @param <T> the type of the objects in the stream to return * @param dbms the dbms to send it to * @param sql the SQL command to execute * @param rsMapper the mapper to use when iterating over the ResultSet * @return a stream of the mapped objects */ default <T> Stream<T> executeQuery( Dbms dbms, String sql, SqlFunction<ResultSet, T> rsMapper) { return executeQuery(dbms, sql, Collections.emptyList(), rsMapper); }
public long executeAndGetLong(String sql, List<Object> values) { LOGGER_SELECT.debug("%s, values:%s", sql, values); return dbmsType.getOperationHandler().executeQuery(dbms, sql, values, rs -> rs.getLong(1) ).findAny().orElseThrow(() -> new NoSuchElementException("No long value for " + sql + ", values " + values)); }
/** * Counts the number of elements in the current table by querying the * database. * * @param dbmsOperationHandler the operation handler * @param naming the naming convention in use * @param dbms the dbms * @param table the table * * @return the number of elements in the table */ public static long sqlCount(DbmsOperationHandler dbmsOperationHandler, DatabaseNamingConvention naming, Dbms dbms, Table table) { return dbmsOperationHandler.executeQuery(dbms, "SELECT COUNT(*) FROM " + sqlTableReference(naming, table), Collections.emptyList(), rs -> rs.getLong(1) ).findAny().orElseThrow(() -> new NoSuchElementException("Unable to get sql count for table " + table.getId() + " in dbms " + dbms.getId())); }
/** * Eagerly executes a SQL query and subsequently maps each row in the * ResultSet using a provided mapper and return a Stream of the mapped * objects. The ResultSet is eagerly consumed so that all elements in the * ResultSet are read before the Stream produces any objects. If no objects * are present or if an SQLException is thrown internally, an {@code empty} * stream is returned. * * @param <T> the type of the objects in the stream to return * @param dbms the dbms to send it to * @param sql the SQL command to execute * @param rsMapper the mapper to use when iterating over the ResultSet * @return a stream of the mapped objects */ default <T> Stream<T> executeQuery( Dbms dbms, String sql, SqlFunction<ResultSet, T> rsMapper) { return executeQuery(dbms, sql, Collections.emptyList(), rsMapper); }
public long executeAndGetLong(String sql, List<Object> values) { LOGGER_SELECT.debug("%s, values:%s", sql, values); return dbmsType.getOperationHandler().executeQuery(dbms, sql, values, rs -> rs.getLong(1) ).findAny().orElseThrow(() -> new NoSuchElementException("No long value for " + sql + ", values " + values)); }
/** * Counts the number of elements in the current table by querying the * database. * * @param dbmsOperationHandler the operation handler * @param naming the naming convention in use * @param dbms the dbms * @param table the table * * @return the number of elements in the table */ public static long sqlCount(DbmsOperationHandler dbmsOperationHandler, DatabaseNamingConvention naming, Dbms dbms, Table table) { return dbmsOperationHandler.executeQuery(dbms, "SELECT COUNT(*) FROM " + sqlTableReference(naming, table), Collections.emptyList(), rs -> rs.getLong(1) ).findAny().orElseThrow(() -> new NoSuchElementException("Unable to get sql count for table " + table.getId() + " in dbms " + dbms.getId())); }