public final class Database extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Database.Builder
Builds a
Database. |
| Constructor and Description |
|---|
Database(Connection con)
Constructor.
|
Database(ConnectionProvider cp)
Constructor.
|
Database(ConnectionProvider cp,
rx.functions.Func0<rx.Scheduler> nonTransactionalSchedulerFactory)
Constructor.
|
Database(String url)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
rx.Observable<Boolean> |
beginTransaction()
Starts a transaction.
|
rx.Observable<Boolean> |
beginTransaction(rx.Observable<?> dependency)
Starts a transaction.
|
<T> rx.Observable.Operator<T,T> |
beginTransactionOnNextOperator()
Starts a database transaction for each onNext call.
|
static Database.Builder |
builder()
Returns a new
Database.Builder. |
Database |
close()
Close the database in particular closes the
ConnectionProvider
for the database. |
rx.Observable<Boolean> |
commit(rx.Observable<?>... depends)
Commits a transaction and resets the current query context so that
further queries will use the asynchronous version by default.
|
<T> rx.Observable.Operator<Boolean,T> |
commitOnCompleteOperator()
Commits current transaction on the completion of source if and only if
the source sequence is non-empty.
|
<T> rx.Observable.Operator<Boolean,rx.Observable<T>> |
commitOnNextListOperator() |
<T> rx.Observable.Operator<Boolean,T> |
commitOnNextOperator()
Commits the currently open transaction.
|
<T> rx.Observable.Operator<Boolean,T> |
commitOperator()
Waits for the source to complete before returning the result of
db.commit();
|
static Database |
from(Connection con)
Factory method.
|
static Database |
from(ConnectionProvider cp) |
static Database |
from(String url) |
ConnectionProvider |
getConnectionProvider()
Returns the
ConnectionProvider. |
rx.Observable<Boolean> |
lastTransactionResult()
Returns observable that emits true when last transaction committed or
false when last transaction is rolled back.
|
com.github.davidmoten.rx.jdbc.QueryContext |
queryContext()
Returns the thread local current query context (will not return null).
|
rx.Observable<Boolean> |
rollback(rx.Observable<?>... depends)
Rolls back a transaction and resets the current query context so that
further queries will use the asynchronous version by default.
|
<T> rx.Observable.Operator<Boolean,T> |
rollbackOnCompleteOperator()
Rolls back current transaction on the completion of source if and only if
the source sequence is non-empty.
|
<T> rx.Observable.Operator<Boolean,rx.Observable<T>> |
rollbackOnNextListOperator() |
rx.Observable.Operator<Boolean,?> |
rollbackOnNextOperator()
Rolls back the current transaction.
|
<T> rx.Observable.Operator<Boolean,T> |
rollbackOperator()
Waits for the source to complete before returning the result of
db.rollback();
|
rx.Observable.Operator<Integer,String> |
run()
Returns an
Observable.Operator version of run(Observable). |
rx.Observable<Integer> |
run(InputStream is,
String delimiter)
Returns an
Observable that is the result of running a sequence of
update commands (insert/update/delete, ddl) commands read from an
InputStream using the given delimiter as the statement delimiter (for
example semicolon). |
rx.Observable<Integer> |
run(rx.Observable<String> commands)
Returns an
Observable that is the result of running a sequence of
update commands (insert/update/delete, ddl) read from the given
Observable sequence. |
QuerySelect.Builder |
select(String sql)
Returns a
QuerySelect.Builder builder based on the given select
statement sql. |
Database |
synchronous()
Returns a Database based on the current Database except all queries run
on the same thread.
|
QueryUpdate.Builder |
update(String sql)
Returns a
QueryUpdate.Builder builder based on the given
update/insert/delete/DDL statement sql. |
public Database(ConnectionProvider cp, rx.functions.Func0<rx.Scheduler> nonTransactionalSchedulerFactory)
cp - provides connectionsnonTransactionalSchedulerFactory - schedules non transactional queriespublic Database(ConnectionProvider cp)
Runtime.getRuntime().availableProcessors()+1. This
may be too conservative if the database is on another server. If that is
the case then you may want to use a thread pool size equal to the
available processors + 1 on the database server.cp - provides connectionspublic Database(String url)
ConnectionProviderFromUrl based on the given
url.url - jdbc connection urlpublic Database(Connection con)
con - the connectionpublic ConnectionProvider getConnectionProvider()
ConnectionProvider.public static Database from(ConnectionProvider cp)
public static Database from(Connection con)
con - the connectionpublic static Database.Builder builder()
Database.Builder.public com.github.davidmoten.rx.jdbc.QueryContext queryContext()
beginTransaction() if set.public QuerySelect.Builder select(String sql)
QuerySelect.Builder builder based on the given select
statement sql.sql - a select statement.public QueryUpdate.Builder update(String sql)
QueryUpdate.Builder builder based on the given
update/insert/delete/DDL statement sql.sql - an update/insert/delete/DDL statement.public rx.Observable<Boolean> beginTransaction(rx.Observable<?> dependency)
dependency - public rx.Observable<Boolean> beginTransaction()
public rx.Observable<Boolean> commit(rx.Observable<?>... depends)
depends - depdencies that must complete before commit occurs.public <T> rx.Observable.Operator<Boolean,T> commitOperator()
public <T> rx.Observable.Operator<Boolean,T> rollbackOperator()
public rx.Observable<Boolean> rollback(rx.Observable<?>... depends)
depends - depdencies that must complete before commit occurs.public rx.Observable<Boolean> lastTransactionResult()
public Database close()
ConnectionProvider
for the database. For a ConnectionProviderPooled this will be a
required call for cleanup.public <T> rx.Observable.Operator<Boolean,T> commitOnCompleteOperator()
public <T> rx.Observable.Operator<Boolean,T> rollbackOnCompleteOperator()
public <T> rx.Observable.Operator<T,T> beginTransactionOnNextOperator()
Connection until transaction is rolled back or
committed.public <T> rx.Observable.Operator<Boolean,T> commitOnNextOperator()
public <T> rx.Observable.Operator<Boolean,rx.Observable<T>> commitOnNextListOperator()
public <T> rx.Observable.Operator<Boolean,rx.Observable<T>> rollbackOnNextListOperator()
public rx.Observable.Operator<Boolean,?> rollbackOnNextOperator()
public rx.Observable<Integer> run(rx.Observable<String> commands)
Observable that is the result of running a sequence of
update commands (insert/update/delete, ddl) read from the given
Observable sequence.commands - public rx.Observable.Operator<Integer,String> run()
Observable.Operator version of run(Observable).public rx.Observable<Integer> run(InputStream is, String delimiter)
Observable that is the result of running a sequence of
update commands (insert/update/delete, ddl) commands read from an
InputStream using the given delimiter as the statement delimiter (for
example semicolon).is - delimiter - public Database synchronous()
Copyright © 2014. All Rights Reserved.