private QueryUpdate.Builder createCommitOrRollbackQuery(boolean commit) { String action; if (commit) action = "commit"; else action = "rollback"; QueryUpdate.Builder u = update(action); return u; }
@Override public Observable<Integer> call(Observable<Integer> dep, String command) { return update(command).dependsOn(dep).count(); } }).flatMap(Functions.<Observable<Integer>> identity());
/** * 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 UpdateQueryExecution update(String sql, Object... parameters) { return new UpdateQueryExecutionImpl(getDatabase().update(sql).parameters(Observable.from(parameters))); }
Single<Integer> save(Post post) { return this.db.update("insert into posts(title, content) values(?, ?)") .parameter(post.getTitle()) .parameter(post.getContent()) .returnGeneratedKeys() .getAs(Integer.class) .toSingle(); }