Package play.db
Interface Database
- All Known Implementing Classes:
DefaultDatabase
public interface Database
Database API for managing data sources and connections.
-
Method Summary
Modifier and TypeMethodDescriptiondefault play.api.db.DatabaseasScala()Converts the given database to a Scala databaseGet 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.
-
Method Details
-
getName
String getName()- Returns:
- the configuration name for this database.
-
getDataSource
DataSource getDataSource()- Returns:
- the underlying JDBC data source for this database.
-
getUrl
String getUrl()- Returns:
- the JDBC connection URL this database, i.e. `jdbc:...` Normally retrieved via a connection.
-
getConnection
Connection getConnection()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().
- Returns:
- a JDBC connection
-
getConnection
Get a JDBC connection from the underlying data source.Don't forget to release the connection at some point by calling close().
- Parameters:
autocommit- determines whether to autocommit the connection- Returns:
- a JDBC connection
-
withConnection
Execute a block of code, providing a JDBC connection. The connection and all created statements are automatically released.- Parameters:
block- code to execute
-
withConnection
Execute a block of code, providing a JDBC connection. The connection and all created statements are automatically released.- Type Parameters:
A- the return value's type- Parameters:
block- code to execute- Returns:
- the result of the code block
-
withConnection
Execute a block of code, providing a JDBC connection. The connection and all created statements are automatically released.- Parameters:
autocommit- determines whether to autocommit the connectionblock- code to execute
-
withConnection
Execute a block of code, providing a JDBC connection. The connection and all created statements are automatically released.- 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
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.- Parameters:
block- code to execute
-
withTransaction
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.- Parameters:
isolationLevel- determines transaction isolation levelblock- code to execute
-
withTransaction
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.- Type Parameters:
A- the return value's type- Parameters:
block- code to execute- Returns:
- the result of the code block
-
withTransaction
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.- 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
void shutdown()Shutdown this database, closing the underlying data source. -
asScala
default play.api.db.Database asScala()Converts the given database to a Scala database- Returns:
- the database for scala API.
-