public final class DatabaseProviderVertx extends Object implements java.util.function.Supplier<Database>
| Modifier and Type | Class and Description |
|---|---|
static interface |
DatabaseProviderVertx.Builder
This builder is immutable, so setting various options does not affect
the previous instance.
|
| Constructor and Description |
|---|
DatabaseProviderVertx(io.vertx.core.Vertx vertx,
javax.inject.Provider<Connection> connectionProvider,
Options options) |
| Modifier and Type | Method and Description |
|---|---|
void |
commitAndClose() |
DatabaseProviderVertx.Builder |
fakeBuilder() |
static DatabaseProviderVertx.Builder |
fromPool(io.vertx.core.Vertx vertx,
DatabaseProvider.Pool pool)
Use an externally configured DataSource, Flavor, and optionally a shutdown hook.
|
Database |
get() |
static DatabaseProviderVertx.Builder |
pooledBuilder(io.vertx.core.Vertx vertx,
Config config)
Configure the database from the following properties read from the provided configuration:
|
void |
rollbackAndClose() |
void |
transact(DbCode code)
Execute a transaction on the current thread, with default semantics (commit if
the code completes successfully, or rollback if it throws an error).
|
void |
transact(DbCodeTx code)
Same as
transact(DbCode), but your code block can explicitly
manage the behavior of the transaction. |
<T> void |
transactAsync(DbCodeTyped<T> code,
io.vertx.core.Handler<io.vertx.core.AsyncResult<T>> resultHandler)
Execute a transaction on a Vert.x worker thread, with default semantics (commit if
the code completes successfully, or rollback if it throws an error).
|
<T> void |
transactAsync(DbCodeTypedTx<T> code,
io.vertx.core.Handler<io.vertx.core.AsyncResult<T>> resultHandler)
Execute a transaction on a Vert.x worker thread, with default semantics (commit if
the code completes successfully, or rollback if it throws an error).
|
public DatabaseProviderVertx(io.vertx.core.Vertx vertx,
javax.inject.Provider<Connection> connectionProvider,
Options options)
@CheckReturnValue public static DatabaseProviderVertx.Builder pooledBuilder(io.vertx.core.Vertx vertx, Config config)
database.url=... Database connect string (required)
database.user=... Authenticate as this user (optional if provided in url)
database.password=... User password (optional if user and password provided in
url; prompted on standard input if user is provided and
password is not)
database.pool.size=... How many connections in the connection pool (default 10).
database.driver.class The driver to initialize with Class.forName(). This will
be guessed from the database.url if not provided.
database.flavor One of the enumerated values in Flavor. If this
is not provided the flavor will be guessed based on the
value for database.url, if possible.
The database flavor will be guessed based on the URL.
A database pool will be created using HikariCP.
Be sure to retain a copy of the builder so you can call close() later to destroy the pool. You will most likely want to register a JVM shutdown hook to make sure this happens. See VertxServer.java in the demo directory for an example of how to do this.
@CheckReturnValue public static DatabaseProviderVertx.Builder fromPool(io.vertx.core.Vertx vertx, DatabaseProvider.Pool pool)
public void transact(DbCode code)
public <T> void transactAsync(DbCodeTyped<T> code, io.vertx.core.Handler<io.vertx.core.AsyncResult<T>> resultHandler)
public void transact(DbCodeTx code)
transact(DbCode), but your code block can explicitly
manage the behavior of the transaction.public <T> void transactAsync(DbCodeTypedTx<T> code, io.vertx.core.Handler<io.vertx.core.AsyncResult<T>> resultHandler)
public Database get()
get in interface java.util.function.Supplier<Database>public DatabaseProviderVertx.Builder fakeBuilder()
public void commitAndClose()
public void rollbackAndClose()
Copyright © 2016. All rights reserved.