Package play.db
Class DefaultDatabase
java.lang.Object
play.db.DefaultDatabase
- All Implemented Interfaces:
Database
Default delegating implementation of the database API.
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultDatabase(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
Modifier and TypeMethodDescriptionGet a JDBC connection from the underlying data source.getConnection(boolean autocommit) Get a JDBC connection from the underlying data source.getName()getUrl()voidshutdown()Shutdown this database, closing the underlying data source.<A> AwithConnection(boolean autocommit, ConnectionCallable<A> block) Execute a block of code, providing a JDBC connection.voidwithConnection(boolean autocommit, ConnectionRunnable block) Execute a block of code, providing a JDBC connection.<A> AwithConnection(ConnectionCallable<A> block) Execute a block of code, providing a JDBC connection.voidwithConnection(ConnectionRunnable block) Execute a block of code, providing a JDBC connection.<A> AwithTransaction(ConnectionCallable<A> block) Execute a block of code in the scope of a JDBC transaction.voidExecute a block of code in the scope of a JDBC transaction.<A> AwithTransaction(TransactionIsolationLevel isolationLevel, ConnectionCallable<A> block) Execute a block of code in the scope of a JDBC transaction.voidwithTransaction(TransactionIsolationLevel isolationLevel, ConnectionRunnable block) Execute a block of code in the scope of a JDBC transaction.
-
Constructor Details
-
DefaultDatabase
public DefaultDatabase(play.api.db.Database database) -
DefaultDatabase
Create a default HikariCP-backed database.- Parameters:
name- name for the db's underlying datasourceconfiguration- the database's configuration
-
DefaultDatabase
Create a default HikariCP-backed database.- Parameters:
name- name for the db's underlying datasourceconfig- the db's configuration
-
-
Method Details
-
getName
-
getDataSource
- Specified by:
getDataSourcein interfaceDatabase- Returns:
- the underlying JDBC data source for this database.
-
getUrl
-
getConnection
Description copied from interface:DatabaseGet 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:
getConnectionin interfaceDatabase- Returns:
- a JDBC connection
-
getConnection
Description copied from interface:DatabaseGet a JDBC connection from the underlying data source.Don't forget to release the connection at some point by calling close().
- Specified by:
getConnectionin interfaceDatabase- Parameters:
autocommit- determines whether to autocommit the connection- Returns:
- a JDBC connection
-
withConnection
Description copied from interface:DatabaseExecute a block of code, providing a JDBC connection. The connection and all created statements are automatically released.- Specified by:
withConnectionin interfaceDatabase- Parameters:
block- code to execute
-
withConnection
Description copied from interface:DatabaseExecute a block of code, providing a JDBC connection. The connection and all created statements are automatically released.- Specified by:
withConnectionin interfaceDatabase- Type Parameters:
A- the return value's type- Parameters:
block- code to execute- Returns:
- the result of the code block
-
withConnection
Description copied from interface:DatabaseExecute a block of code, providing a JDBC connection. The connection and all created statements are automatically released.- Specified by:
withConnectionin interfaceDatabase- Parameters:
autocommit- determines whether to autocommit the connectionblock- code to execute
-
withConnection
Description copied from interface:DatabaseExecute a block of code, providing a JDBC connection. The connection and all created statements are automatically released.- Specified by:
withConnectionin 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
Description copied from interface:DatabaseExecute 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:
withTransactionin interfaceDatabase- Parameters:
block- code to execute
-
withTransaction
Description copied from interface:DatabaseExecute 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:
withTransactionin interfaceDatabase- Parameters:
isolationLevel- determines transaction isolation levelblock- code to execute
-
withTransaction
Description copied from interface:DatabaseExecute 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:
withTransactionin interfaceDatabase- Type Parameters:
A- the return value's type- Parameters:
block- code to execute- Returns:
- the result of the code block
-
withTransaction
Description copied from interface:DatabaseExecute 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:
withTransactionin 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
-
shutdown
public void shutdown()Description copied from interface:DatabaseShutdown this database, closing the underlying data source.
-