= sqlInfo.dbmsType().getOperationHandler().executeQueryAsync( sqlInfo.dbms(), sql,
private ENTITY remove(ENTITY entity) throws SpeedmentException { final List<Object> values = primaryKeyFields.get() .map(f -> toDatabaseType(f, entity)) .collect(toList()); try { operationHandler.executeDelete(dbms, deleteStatement, values); return entity; } catch (final SQLException ex) { throw new SpeedmentException(ex); } }
private ENTITY persist(ENTITY entity, Predicate<Field<ENTITY>> includedFields, String insertStatement) throws SpeedmentException { final List<Object> values = fields.get() .filter(includedFields) .map(f -> toDatabaseType(f, entity)) .collect(toList()); try { operationHandler.executeInsert(dbms, insertStatement, values, generatedFields, newGeneratedKeyConsumer(entity)); return entity; } catch (final SQLException ex) { throw new SpeedmentException(ex); } }
/** * 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); }
private ENTITY update(ENTITY entity, Predicate<Field<ENTITY>> includedFields, String updateStatement) throws SpeedmentException { final List<Object> values = Stream.concat( fields.get().filter(includedFields), primaryKeyFields.get() ) .map(f -> toDatabaseType(f, entity)) .collect(Collectors.toList()); try { operationHandler.executeUpdate(dbms, updateStatement, values); return entity; } catch (final SQLException ex) { throw new SpeedmentException(ex); } }
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)); }
@Override public ENTITY update(ENTITY entity) throws SpeedmentException { assertHasPrimaryKeyColumns(); final List<Object> values = Stream.concat( fields.get().filter(f -> updateColumnFilter.test(columnsByFields.get(f))), primaryKeyFields.get() ) .map(f -> toDatabaseType(f, entity)) .collect(Collectors.toList()); try { operationHandler.executeUpdate(dbms, updateStatement, values); return entity; } catch (final SQLException ex) { throw new SpeedmentException(ex); } }
@Override public Stream<ENTITY> stream(ParallelStrategy parallelStrategy) { final AsynchronousQueryResult<ENTITY> asynchronousQueryResult = dbmsType.getOperationHandler().executeQueryAsync( dbms, sqlSelect,
/** * 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())); }
@Override public ENTITY remove(ENTITY entity) throws SpeedmentException { assertHasPrimaryKeyColumns(); final List<Object> values = primaryKeyFields.get() .map(f -> toDatabaseType(f, entity)) .collect(toList()); try { operationHandler.executeDelete(dbms, deleteStatement, values); return entity; } catch (final SQLException ex) { throw new SpeedmentException(ex); } }
@Override public ENTITY persist(ENTITY entity) throws SpeedmentException { final List<Object> values = fields.get() .filter(f -> insertColumnFilter.test(columnsByFields.get(f))) .map(f -> toDatabaseType(f, entity)) .collect(toList()); try { operationHandler.executeInsert(dbms, insertStatement, values, generatedFields, newGeneratedKeyConsumer(entity)); return entity; } catch (final SQLException ex) { throw new SpeedmentException(ex); } }
private ENTITY update(ENTITY entity, Predicate<Field<ENTITY>> includedFields, String updateStatement) throws SpeedmentException { final List<Object> values = Stream.concat( fields.get().filter(includedFields), primaryKeyFields.get() ) .map(f -> toDatabaseType(f, entity)) .collect(Collectors.toList()); try { operationHandler.executeUpdate(dbms, updateStatement, values); return entity; } catch (final SQLException ex) { throw new SpeedmentException(ex); } }
= sqlInfo.dbmsType().getOperationHandler().executeQueryAsync( sqlInfo.dbms(), sql,
/** * 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); }
private ENTITY remove(ENTITY entity) throws SpeedmentException { final List<Object> values = primaryKeyFields.get() .map(f -> toDatabaseType(f, entity)) .collect(toList()); try { operationHandler.executeDelete(dbms, deleteStatement, values); return entity; } catch (final SQLException ex) { throw new SpeedmentException(ex); } }
@Override public ENTITY persist(ENTITY entity) throws SpeedmentException { final List<Object> values = fields.get() .filter(f -> insertColumnFilter.test(columnsByFields.get(f))) .map(f -> toDatabaseType(f, entity)) .collect(toList()); try { operationHandler.executeInsert(dbms, insertStatement, values, generatedFields, newGeneratedKeyConsumer(entity)); return entity; } catch (final SQLException ex) { throw new SpeedmentException(ex); } }
@Override public ENTITY update(ENTITY entity) throws SpeedmentException { assertHasPrimaryKeyColumns(); final List<Object> values = Stream.concat( fields.get().filter(f -> updateColumnFilter.test(columnsByFields.get(f))), primaryKeyFields.get() ) .map(f -> toDatabaseType(f, entity)) .collect(Collectors.toList()); try { operationHandler.executeUpdate(dbms, updateStatement, values); return entity; } catch (final SQLException ex) { throw new SpeedmentException(ex); } }
@Override public Stream<ENTITY> stream(ParallelStrategy parallelStrategy) { final AsynchronousQueryResult<ENTITY> asynchronousQueryResult = dbmsType.getOperationHandler().executeQueryAsync( dbms, sqlSelect,
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)); }
@Override public ENTITY remove(ENTITY entity) throws SpeedmentException { assertHasPrimaryKeyColumns(); final List<Object> values = primaryKeyFields.get() .map(f -> toDatabaseType(f, entity)) .collect(toList()); try { operationHandler.executeDelete(dbms, deleteStatement, values); return entity; } catch (final SQLException ex) { throw new SpeedmentException(ex); } }