Package play.db
Interface Database
-
- All Known Implementing Classes:
DefaultDatabase
public interface Database
Database API for managing data sources and connections.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default play.api.db.Database
asScala()
Converts the given database to a Scala databaseConnection
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.
-
-
-
Method Detail
-
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
Connection getConnection(boolean autocommit)
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
void withConnection(ConnectionRunnable block)
Execute a block of code, providing a JDBC connection. The connection and all created statements are automatically released.- Parameters:
block
- code to execute
-
withConnection
<A> A withConnection(ConnectionCallable<A> block)
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
void withConnection(boolean autocommit, ConnectionRunnable block)
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
<A> A withConnection(boolean autocommit, ConnectionCallable<A> block)
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
void withTransaction(ConnectionRunnable block)
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
void withTransaction(TransactionIsolationLevel isolationLevel, ConnectionRunnable block)
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
<A> A withTransaction(ConnectionCallable<A> block)
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
<A> A withTransaction(TransactionIsolationLevel isolationLevel, ConnectionCallable<A> block)
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.
-
-