/** * Returns an {@link Action1} that increments a counter when the call method * is called. * * @param <T> * generic type of item being counted * @return {@link Action1} to count calls. */ public static <T> CountingAction<T> counter() { return new CountingAction<T>(); }
/** * Returns query.getParameters() {@link Observable} but only after query * dependencies have been fully emitted (and ignored). * * @return query parameters */ static Observable<Parameter> parametersAfterDependencies(Query query) { return concatButIgnoreFirstSequence(query.depends(), query.parameters()); }
@Override public Observable<T> call(Observable<Observable<T>> source) { return source.flatMap(Functions.<Observable<T>> 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)); }
/** * Returns an {@link Observable} that is the result of running a sequence of * update commands (insert/update/delete, ddl) commands read from an * {@link InputStream} with the given {@link Charset} using the given * delimiter as the statement delimiter (for example semicolon). * * @param is * @param delimiter * @return */ public Observable<Integer> run(InputStream is, Charset charset, String delimiter) { return Strings.split(Strings.from(new InputStreamReader(is, charset)), ";") // .compose(run()); }
private void requestSome(long n) { // back pressure path // this algorithm copied generally from OnSubscribeFromIterable.java long previousCount = RxUtil.getAndAddRequest(requested, n); if (previousCount == 0) { try { while (true) { long r = requested.get(); long numToEmit = r; while (keepGoing && --numToEmit >= 0) { processRow(subscriber); } if (keepGoing) { if (requested.addAndGet(-r) == 0) { return; } } else { closeQuietly(); complete(subscriber); return; } } } catch (Exception e) { closeAndHandleException(e); } } }
static <T> Observable<T> get(QueryUpdate<T> queryUpdate) { if (queryUpdate.context().batchSize() > 1) { return bufferedParameters(queryUpdate) // // mark the last parameter list as such .compose(Transformers.mapLast(toFinalArrayList))// // execute query for each set of parameters .concatMap(queryUpdate.executeOnce()); } else { return bufferedParameters(queryUpdate) // // execute query for each set of parameters .concatMap(queryUpdate.executeOnce()); } }
public static <T> ResourceManager<T> create(Callable<T> resourceFactory, Checked.A1<? super T> disposeAction) { return new ResourceManager<T>(Functions.toFunc0(resourceFactory), Checked.a1(disposeAction), false); }
@Override public Observable<T> call(T t) { return db.beginTransaction().map(Functions.constant(t)); } });
private static <T> Observable<Boolean> commitOrRollbackOnCompleteTransformerIfAtLeastOneValue( final boolean isCommit, final Database db, Observable<T> source) { CountingAction<T> counter = RxUtil.counter(); Observable<Boolean> commit = counter // get count .count() // greater than zero or empty .filter(greaterThanZero()) // commit if at least one value .compose(db.commitOrRollback_(isCommit)); return Observable // concatenate .concat(source // count emissions .doOnNext(counter) // ignore emissions .ignoreElements() // cast the empty sequence to type Boolean .cast(Boolean.class), // concat with commit commit); }
public static <T> ResourceManager<T> create(Callable<T> resourceFactory, Action1<? super T> disposeAction) { return new ResourceManager<T>(Functions.toFunc0(resourceFactory), disposeAction, false); }
/** * Returns {@link Observable} with one item 1 but only after query * dependencies have been fully emitted (and ignored). * * @param query * * @return {@link Observable} with one element 1 */ static Observable<Integer> singleIntegerAfterDependencies(Query query) { return concatButIgnoreFirstSequence(query.depends(), Observable.just(1)); }
/** * Returns a {@link Func1} that returns an empty {@link Observable}. * * @return */ public static <T> Func1<T, Observable<Object>> toEmpty() { return Functions.constant(Observable.<Object> empty()); }
@Override public Observable<ZippedEntry> call(ZipInputStream zis) { return unzip(zis); } };
/** * Returns an {@link Observable} that is the result of running a sequence of * update commands (insert/update/delete, ddl) read from the given * {@link Observable} sequence. * * @param commands * @return */ public Observable<Integer> run(Observable<String> commands) { return commands.reduce(Observable.<Integer> empty(), new Func2<Observable<Integer>, String, Observable<Integer>>() { @Override public Observable<Integer> call(Observable<Integer> dep, String command) { return update(command).dependsOn(dep).count(); } }).flatMap(Functions.<Observable<Integer>> identity()); }
public static <T> ResourceManager<T> create(Callable<T> resourceFactory, Checked.A1<? super T> disposeAction) { return new ResourceManager<T>(Functions.toFunc0(resourceFactory), Checked.a1(disposeAction), false); }
public static <T> ResourceManager<T> create(Callable<T> resourceFactory, Action1<? super T> disposeAction) { return new ResourceManager<T>(Functions.toFunc0(resourceFactory), disposeAction, false); }