public abstract class Database
extends java.lang.Object
Constructor and Description |
---|
Database() |
Modifier and Type | Method and Description |
---|---|
static Database |
createFrom(java.lang.String driver,
java.lang.String url)
Create a pooled database named "default" with the given driver and url.
|
static Database |
createFrom(java.lang.String driver,
java.lang.String url,
java.util.Map<java.lang.String,? extends java.lang.Object> config)
Create a pooled database named "default" with the given configuration.
|
static Database |
createFrom(java.lang.String name,
java.lang.String driver,
java.lang.String url)
Create a pooled database with the given configuration.
|
static Database |
createFrom(java.lang.String name,
java.lang.String driver,
java.lang.String url,
java.util.Map<java.lang.String,? extends java.lang.Object> config)
Create a pooled database with the given configuration.
|
abstract java.sql.Connection |
getConnection()
Get a JDBC connection from the underlying data source.
|
abstract java.sql.Connection |
getConnection(boolean autocommit)
Get a JDBC connection from the underlying data source.
|
abstract javax.sql.DataSource |
getDataSource()
The underlying JDBC data source for this database.
|
abstract java.lang.String |
getName()
The configuration name for this database.
|
abstract java.lang.String |
getUrl()
The JDBC connection URL this database, i.e.
|
static Database |
inMemory()
Create an in-memory H2 database with name "default".
|
static Database |
inMemory(java.util.Map<java.lang.String,? extends java.lang.Object> config)
Create an in-memory H2 database with name "default".
|
static Database |
inMemory(java.lang.String name)
Create an in-memory H2 database.
|
static Database |
inMemory(java.lang.String name,
java.util.Map<java.lang.String,? extends java.lang.Object> config)
Create an in-memory H2 database.
|
static Database |
inMemory(java.lang.String name,
java.util.Map<java.lang.String,java.lang.String> urlOptions,
java.util.Map<java.lang.String,? extends java.lang.Object> config)
Create an in-memory H2 database.
|
static Database |
inMemory(java.lang.String name,
java.lang.String url,
java.util.Map<java.lang.String,? extends java.lang.Object> config)
Create an in-memory H2 database.
|
static Database |
inMemoryWith(java.lang.String k1,
java.lang.Object v1)
Create an in-memory H2 database with name "default" and with
extra configuration provided by the given entries.
|
static Database |
inMemoryWith(java.lang.String k1,
java.lang.Object v1,
java.lang.String k2,
java.lang.Object v2)
Create an in-memory H2 database with name "default" and with
extra configuration provided by the given entries.
|
static Database |
inMemoryWith(java.lang.String k1,
java.lang.Object v1,
java.lang.String k2,
java.lang.Object v2,
java.lang.String k3,
java.lang.Object v3)
Create an in-memory H2 database with name "default" and with
extra configuration provided by the given entries.
|
abstract void |
shutdown()
Shutdown this database, closing the underlying data source.
|
abstract <A> A |
withConnection(boolean autocommit,
ConnectionCallable<A> block)
Execute a block of code, providing a JDBC connection.
|
abstract void |
withConnection(boolean autocommit,
ConnectionRunnable block)
Execute a block of code, providing a JDBC connection.
|
abstract <A> A |
withConnection(ConnectionCallable<A> block)
Execute a block of code, providing a JDBC connection.
|
abstract void |
withConnection(ConnectionRunnable block)
Execute a block of code, providing a JDBC connection.
|
abstract <A> A |
withTransaction(ConnectionCallable<A> block)
Execute a block of code in the scope of a JDBC transaction.
|
abstract void |
withTransaction(ConnectionRunnable block)
Execute a block of code in the scope of a JDBC transaction.
|
public abstract java.lang.String getName()
public abstract javax.sql.DataSource getDataSource()
public abstract java.lang.String getUrl()
public abstract java.sql.Connection getConnection()
public abstract java.sql.Connection getConnection(boolean autocommit)
autocommit
- determines whether to autocommit the connectionpublic abstract void withConnection(ConnectionRunnable block)
block
- code to executepublic abstract <A> A withConnection(ConnectionCallable<A> block)
block
- code to executepublic abstract void withConnection(boolean autocommit, ConnectionRunnable block)
autocommit
- determines whether to autocommit the connectionblock
- code to executepublic abstract <A> A withConnection(boolean autocommit, ConnectionCallable<A> block)
autocommit
- determines whether to autocommit the connectionblock
- code to executepublic abstract void withTransaction(ConnectionRunnable block)
block
- code to executepublic abstract <A> A withTransaction(ConnectionCallable<A> block)
block
- code to executepublic abstract void shutdown()
public static Database createFrom(java.lang.String name, java.lang.String driver, java.lang.String url, java.util.Map<java.lang.String,? extends java.lang.Object> config)
name
- the database namedriver
- the database driver classurl
- the database urlconfig
- a map of extra database configurationpublic static Database createFrom(java.lang.String name, java.lang.String driver, java.lang.String url)
name
- the database namedriver
- the database driver classurl
- the database urlpublic static Database createFrom(java.lang.String driver, java.lang.String url, java.util.Map<java.lang.String,? extends java.lang.Object> config)
driver
- the database driver classurl
- the database urlconfig
- a map of extra database configurationpublic static Database createFrom(java.lang.String driver, java.lang.String url)
driver
- the database driver classurl
- the database urlpublic static Database inMemory(java.lang.String name, java.lang.String url, java.util.Map<java.lang.String,? extends java.lang.Object> config)
name
- the database nameurl
- the database urlconfig
- a map of extra database configurationpublic static Database inMemory(java.lang.String name, java.util.Map<java.lang.String,java.lang.String> urlOptions, java.util.Map<java.lang.String,? extends java.lang.Object> config)
name
- the database nameurlOptions
- a map of extra url optionsconfig
- a map of extra database configurationpublic static Database inMemory(java.lang.String name, java.util.Map<java.lang.String,? extends java.lang.Object> config)
name
- the database nameconfig
- a map of extra database configurationpublic static Database inMemory(java.lang.String name)
name
- the database namepublic static Database inMemory(java.util.Map<java.lang.String,? extends java.lang.Object> config)
config
- a map of extra database configurationpublic static Database inMemory()
public static Database inMemoryWith(java.lang.String k1, java.lang.Object v1)
public static Database inMemoryWith(java.lang.String k1, java.lang.Object v1, java.lang.String k2, java.lang.Object v2)
public static Database inMemoryWith(java.lang.String k1, java.lang.Object v1, java.lang.String k2, java.lang.Object v2, java.lang.String k3, java.lang.Object v3)