Package play.db

Interface Database

All Known Implementing Classes:
DefaultDatabase

public interface Database
Database API for managing data sources and connections.
  • 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

      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 connection
      block - 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 connection
      block - 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 level
      block - 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 level
      block - 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.