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 ConnectiongetConnection()Get a JDBC connection from the underlying data source.ConnectiongetConnection(boolean autocommit)Get a JDBC connection from the underlying data source.DataSourcegetDataSource()StringgetName()StringgetUrl()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.voidwithTransaction(ConnectionRunnable block)Execute 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 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:
getDataSourcein interfaceDatabase- Returns:
- the underlying JDBC data source for this database.
-
getUrl
public String getUrl()
-
getConnection
public Connection 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
public Connection getConnection(boolean autocommit)
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
public void withConnection(ConnectionRunnable block)
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
public <A> A withConnection(ConnectionCallable<A> block)
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
public void withConnection(boolean autocommit, ConnectionRunnable block)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
public <A> A withConnection(boolean autocommit, ConnectionCallable<A> block)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
public void withTransaction(ConnectionRunnable block)
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
public void withTransaction(TransactionIsolationLevel isolationLevel, ConnectionRunnable block)
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
public <A> A withTransaction(ConnectionCallable<A> block)
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
public <A> A withTransaction(TransactionIsolationLevel isolationLevel, ConnectionCallable<A> block)
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
-
-