Package play.db
Class DefaultDatabase
- Object
-
- play.db.DefaultDatabase
-
-
Constructor Summary
Constructors Constructor Description DefaultDatabase(String name, com.typesafe.config.Config configuration)
Create a default HikariCP-backed database.DefaultDatabase(String name, Map<String,? extends Object> config)
Create a default HikariCP-backed database.DefaultDatabase(play.api.db.Database database)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Connection
getConnection()
Get a JDBC connection from the underlying data source.Connection
getConnection(boolean autocommit)
Get a JDBC connection from the underlying data source.DataSource
getDataSource()
String
getName()
String
getUrl()
void
shutdown()
Shutdown this database, closing the underlying data source.<A> A
withConnection(boolean autocommit, ConnectionCallable<A> block)
Execute a block of code, providing a JDBC connection.void
withConnection(boolean autocommit, ConnectionRunnable block)
Execute a block of code, providing a JDBC connection.<A> A
withConnection(ConnectionCallable<A> block)
Execute a block of code, providing a JDBC connection.void
withConnection(ConnectionRunnable block)
Execute a block of code, providing a JDBC connection.<A> A
withTransaction(ConnectionCallable<A> block)
Execute a block of code in the scope of a JDBC transaction.void
withTransaction(ConnectionRunnable block)
Execute a block of code in the scope of a JDBC transaction.<A> A
withTransaction(TransactionIsolationLevel isolationLevel, ConnectionCallable<A> block)
Execute a block of code in the scope of a JDBC transaction.void
withTransaction(TransactionIsolationLevel isolationLevel, ConnectionRunnable block)
Execute a block of code in the scope of a JDBC transaction.
-
-
-
Constructor Detail
-
DefaultDatabase
public DefaultDatabase(play.api.db.Database database)
-
DefaultDatabase
public DefaultDatabase(String name, com.typesafe.config.Config configuration)
Create a default HikariCP-backed database.- Parameters:
name
- name for the db's underlying datasourceconfiguration
- the database's configuration
-
-
Method Detail
-
getName
public String getName()
-
getDataSource
public DataSource getDataSource()
- Specified by:
getDataSource
in interfaceDatabase
- Returns:
- the underlying JDBC data source for this database.
-
getUrl
public String getUrl()
-
getConnection
public Connection getConnection()
Description copied from interface:Database
Get a JDBC connection from the underlying data source. Autocommit is enabled by default.Don't forget to release the connection at some point by calling close().
- Specified by:
getConnection
in interfaceDatabase
- Returns:
- a JDBC connection
-
getConnection
public Connection getConnection(boolean autocommit)
Description copied from interface:Database
Get a JDBC connection from the underlying data source.Don't forget to release the connection at some point by calling close().
- Specified by:
getConnection
in interfaceDatabase
- Parameters:
autocommit
- determines whether to autocommit the connection- Returns:
- a JDBC connection
-
withConnection
public void withConnection(ConnectionRunnable block)
Description copied from interface:Database
Execute a block of code, providing a JDBC connection. The connection and all created statements are automatically released.- Specified by:
withConnection
in interfaceDatabase
- Parameters:
block
- code to execute
-
withConnection
public <A> A withConnection(ConnectionCallable<A> block)
Description copied from interface:Database
Execute a block of code, providing a JDBC connection. The connection and all created statements are automatically released.- Specified by:
withConnection
in interfaceDatabase
- Type Parameters:
A
- the return value's type- Parameters:
block
- code to execute- Returns:
- the result of the code block
-
withConnection
public void withConnection(boolean autocommit, ConnectionRunnable block)
Description copied from interface:Database
Execute a block of code, providing a JDBC connection. The connection and all created statements are automatically released.- Specified by:
withConnection
in interfaceDatabase
- Parameters:
autocommit
- determines whether to autocommit the connectionblock
- code to execute
-
withConnection
public <A> A withConnection(boolean autocommit, ConnectionCallable<A> block)
Description copied from interface:Database
Execute a block of code, providing a JDBC connection. The connection and all created statements are automatically released.- Specified by:
withConnection
in interfaceDatabase
- Type Parameters:
A
- the return value's type- Parameters:
autocommit
- determines whether to autocommit the connectionblock
- code to execute- Returns:
- the result of the code block
-
withTransaction
public void withTransaction(ConnectionRunnable block)
Description copied from interface:Database
Execute a block of code in the scope of a JDBC transaction. The connection and all created statements are automatically released. The transaction is automatically committed, unless an exception occurs.- Specified by:
withTransaction
in interfaceDatabase
- Parameters:
block
- code to execute
-
withTransaction
public void withTransaction(TransactionIsolationLevel isolationLevel, ConnectionRunnable block)
Description copied from interface:Database
Execute a block of code in the scope of a JDBC transaction. The connection and all created statements are automatically released. The transaction is automatically committed, unless an exception occurs.- Specified by:
withTransaction
in interfaceDatabase
- Parameters:
isolationLevel
- determines transaction isolation levelblock
- code to execute
-
withTransaction
public <A> A withTransaction(ConnectionCallable<A> block)
Description copied from interface:Database
Execute a block of code in the scope of a JDBC transaction. The connection and all created statements are automatically released. The transaction is automatically committed, unless an exception occurs.- Specified by:
withTransaction
in interfaceDatabase
- Type Parameters:
A
- the return value's type- Parameters:
block
- code to execute- Returns:
- the result of the code block
-
withTransaction
public <A> A withTransaction(TransactionIsolationLevel isolationLevel, ConnectionCallable<A> block)
Description copied from interface:Database
Execute a block of code in the scope of a JDBC transaction. The connection and all created statements are automatically released. The transaction is automatically committed, unless an exception occurs.- Specified by:
withTransaction
in interfaceDatabase
- Type Parameters:
A
- the return value's type- Parameters:
isolationLevel
- determines transaction isolation levelblock
- code to execute- Returns:
- the result of the code block
-
-