use of io.requery.query.BaseScalar in project requery by requery.
the class EntityUpdateOperation method evaluate.
@Override
public Scalar<Integer> evaluate(final QueryElement<Scalar<Integer>> query) {
return new BaseScalar<Integer>(configuration.getWriteExecutor()) {
@Override
public Integer evaluate() {
// doesn't use the query params, just maps to the parameterBinder callback
QueryBuilder qb = new QueryBuilder(configuration.getQueryBuilderOptions());
DefaultOutput output = new DefaultOutput(configuration, query, qb, null, false);
String sql = output.toSql();
int result;
try (Connection connection = configuration.getConnection()) {
StatementListener listener = configuration.getStatementListener();
try (PreparedStatement statement = prepare(sql, connection)) {
bindParameters(statement);
listener.beforeExecuteUpdate(statement, sql, null);
result = statement.executeUpdate();
listener.afterExecuteUpdate(statement, result);
readGeneratedKeys(0, statement);
}
} catch (SQLException e) {
throw new StatementExecutionException(e, sql);
}
return result;
}
};
}
use of io.requery.query.BaseScalar in project requery by requery.
the class UpdateOperation method evaluate.
@Override
public Scalar<Integer> evaluate(final QueryElement<Scalar<Integer>> query) {
return new BaseScalar<Integer>(configuration.getWriteExecutor()) {
@Override
public Integer evaluate() {
DefaultOutput output = new DefaultOutput(configuration, query);
String sql = output.toSql();
int result;
TransactionProvider transactionProvider = configuration.getTransactionProvider();
Set<Type<?>> types = query.entityTypes();
try (TransactionScope scope = new TransactionScope(transactionProvider, types);
Connection connection = configuration.getConnection()) {
StatementListener listener = configuration.getStatementListener();
try (PreparedStatement statement = prepare(sql, connection)) {
BoundParameters parameters = output.parameters();
mapParameters(statement, parameters);
listener.beforeExecuteUpdate(statement, sql, parameters);
result = statement.executeUpdate();
listener.afterExecuteUpdate(statement, result);
readGeneratedKeys(0, statement);
}
scope.commit();
} catch (SQLException e) {
throw new StatementExecutionException(e, sql);
}
return result;
}
};
}
Aggregations