public final class Database extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Database.Builder
Builds a
Database. |
| Modifier and Type | Field and Description |
|---|---|
static Object |
NULL_BLOB
Sentinel object used to indicate in parameters of a query that rather
than calling
PreparedStatement.setObject(int, Object) with a null
we call PreparedStatement.setNull(int, int) with
Types.CLOB. |
static Object |
NULL_CLOB
Sentinel object used to indicate in parameters of a query that rather
than calling
PreparedStatement.setObject(int, Object) with a null
we call PreparedStatement.setNull(int, int) with
Types.CLOB. |
static Object |
NULL_NUMBER |
| Constructor and Description |
|---|
Database(Connection con)
Constructor.
|
Database(ConnectionProvider cp)
Constructor.
|
Database(ConnectionProvider cp,
rx.functions.Func0<rx.Scheduler> nonTransactionalSchedulerFactory)
Constructor.
|
Database(String url,
String username,
String password)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
Database |
asynchronous()
Returns a Database based on the current Database except all
non-transactional queries run
Schedulers.io(). |
Database |
asynchronous(rx.functions.Func0<rx.Scheduler> nonTransactionalSchedulerFactory)
Returns a Database based on the current Database except all
non-transactional queries run on the scheduler provided by the given
factory.
|
Database |
asynchronous(rx.Scheduler nonTransactionalScheduler)
Returns a Database based on the current Database except all
non-transactional queries run on the given scheduler.
|
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)
Returns a
Database based on a jdbc connection string. |
static Database |
from(String url,
String username,
String password)
Returns a
Database based on a jdbc connection string. |
static Database |
fromContext(String jndiResource)
Returns a
Database based on connections obtained from a
DataSource based on looking up the current Context |
static Database |
fromDataSource(DataSource dataSource)
Returns a
Database based on connections obtained from a
DataSource |
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,
Charset charset,
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 with the given Charset using the given
delimiter as the statement delimiter (for example semicolon). |
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()
Returns a
QuerySelect.Builder builder and defers specifying sql
to the `autoMap` Class parameter. |
QuerySelect.Builder |
select(String sql)
Returns a
QuerySelect.Builder builder based on the given select
statement sql. |
static Object |
toSentinelIfNull(byte[] bytes) |
static Object |
toSentinelIfNull(String s) |
QueryUpdate.Builder |
update(String sql)
Returns a
QueryUpdate.Builder builder based on the given
update/insert/delete/DDL statement sql. |
public static final Object NULL_CLOB
PreparedStatement.setObject(int, Object) with a null
we call PreparedStatement.setNull(int, int) with
Types.CLOB. This is required by many databases for setting CLOB
and BLOB fields to null.public static final Object NULL_NUMBER
public static final Object NULL_BLOB
PreparedStatement.setObject(int, Object) with a null
we call PreparedStatement.setNull(int, int) with
Types.CLOB. This is required by many databases for setting CLOB
and BLOB fields to null.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, String username, String password)
ConnectionProviderFromUrl based on the given
url.url - jdbc urlusername - username for connectionpassword - password for connectionpublic Database(Connection con)
con - the connectionpublic ConnectionProvider getConnectionProvider()
ConnectionProvider.public static Database from(String url)
Database based on a jdbc connection string.url - jdbc connection urlpublic static Database from(String url, String username, String password)
Database based on a jdbc connection string.url - jdbc urlusername - username for connectionpassword - password for connectionpublic static Database fromContext(String jndiResource)
Database based on connections obtained from a
DataSource based on looking up the current ContextjndiResource - public static Database fromDataSource(DataSource dataSource)
Database based on connections obtained from a
DataSourcejndiResource - public static Database from(ConnectionProvider cp)
Database that obtains Connections on demand
from the given ConnectionProvider. When close()
is called, ConnectionProvider.close() is called.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 QuerySelect.Builder select()
QuerySelect.Builder builder and defers specifying sql
to the `autoMap` Class parameter.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 rx.Observable<Integer> run(InputStream is, Charset charset, String delimiter)
Observable that is the result of running a sequence of
update commands (insert/update/delete, ddl) commands read from an
InputStream with the given Charset using the given
delimiter as the statement delimiter (for example semicolon).is - delimiter - public Database asynchronous()
Schedulers.io().public Database asynchronous(rx.Scheduler nonTransactionalScheduler)
public Database asynchronous(rx.functions.Func0<rx.Scheduler> nonTransactionalSchedulerFactory)
public static Object toSentinelIfNull(byte[] bytes)
Copyright © 2014–2015. All rights reserved.