/** * Executes the update query immediately, blocking till completion and * returns total of counts of records affected. * * @return total of counts of records affected by update queries */ public int execute() { return count().reduce(0, TotalHolder.TOTAL).toBlocking().single(); }
@Override public Observable<Integer> call(Observable<R> source) { if (operatorType == OperatorType.PARAMETER) return builder.parameters(source).count(); else if (operatorType == OperatorType.DEPENDENCY) // dependency return builder.dependsOn(source).count(); else throw new RuntimeException("does not handle " + operatorType); } }
/** * Starts a transaction. Until commit() or rollback() is called on the * source this will set the query context for all created queries to be a * single threaded executor with one (new) connection. * * @param dependency * @return */ public Observable<Boolean> beginTransaction(Observable<?> dependency) { return update("begin").dependsOn(dependency).count().map(Functions.constant(true)); }
@Override public Observable<Integer> count() { return updateBuilder.count() .doOnError(t -> logger.error("Error executing update statement!", t)); }
/** * Commits or rolls back a transaction depending on the <code>commit</code> * parameter and resets the current query context so that further queries * will use the asynchronous version by default. All Observable dependencies * must be complete before commit/rollback is called. * * @param commit * @param depends * @return */ private Observable<Boolean> commitOrRollback(boolean commit, Observable<?>... depends) { QueryUpdate.Builder u = createCommitOrRollbackQuery(commit); for (Observable<?> dep : depends) u = u.dependsOn(dep); Observable<Boolean> result = u.count().exists(IS_NON_ZERO); lastTransactionResult.set(result); return result; }
@Override public Observable<Boolean> call(Observable<T> source) { return updateBuilder.dependsOn(source).count().exists(IS_NON_ZERO); } };
@Override public Observable<Integer> call(Observable<Integer> dep, String command) { return update(command).dependsOn(dep).count(); } }).flatMap(Functions.<Observable<Integer>> identity());
@Override public Observable<Integer> call(Observable<R> parameters) { return builder.clearParameters().parameters(parameters).count(); } });