Interface DbClient

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
DbClientBase, MongoDbClient

public interface DbClient extends AutoCloseable
Helidon database client.
  • Field Details

  • Method Details

    • dbType

      String dbType()
      Type of this database provider (such as jdbc:mysql, mongoDB etc.).
      Returns:
      name of the database provider
    • execute

      DbExecute execute()
      Execute database statements.
      Returns:
      database statements executor
    • transaction

      DbTransaction transaction()
      Execute database statements in transaction. DbTransaction life-cycle must always be finished with DbTransaction.commit() or DbTransaction.rollback(). Those two methods mentioned above will also release database resources allocated by this transaction.
      Returns:
      transaction to execute database statements
    • unwrap

      <C> C unwrap(Class<C> cls)
      Unwrap database client internals. Only database connection is supported.

      When java.sql.Connection is requested for JDBC provider, this connection must be closed by user code using close() method on returned Connection instance.

      Type Parameters:
      C - target class to be unwrapped
      Parameters:
      cls - target class to be unwrapped
      Returns:
      database client internals matching provided class.
      Throws:
      UnsupportedOperationException - when provided class is not supported
    • close

      void close()
      Closes the DbClient and releases any associated resources.
      Specified by:
      close in interface AutoCloseable
    • create

      static DbClient create(Config config)
      Create Helidon database client.
      Parameters:
      config - name of the configuration node with driver configuration
      Returns:
      database client instance
    • builder

      static DbClient.Builder builder()
      Create Helidon database client builder.

      Database driver is loaded as SPI provider which implements the DbClientProvider interface. First provider on the class path is selected.

      Returns:
      database client builder
    • builder

      static DbClient.Builder builder(DbClientProvider provider)
      Create Helidon database client builder using specific SPI provider.
      Parameters:
      provider - SPI provider to use
      Returns:
      database client builder
    • builder

      static DbClient.Builder builder(String providerName)
      Create Helidon database client builder.

      Database driver is loaded as SPI provider which implements the DbClientProvider interface. Provider matching providerName on the class path is selected.

      Parameters:
      providerName - SPI provider name
      Returns:
      database handler builder
      Throws:
      DbClientException - when providerName was not found
    • builder

      static DbClient.Builder builder(Config dbConfig)
      Create Helidon database client builder from configuration.
      Parameters:
      dbConfig - configuration that should contain the key source that defines the type of this database and is used to load appropriate DbClientProvider from Java Service loader
      Returns:
      a builder pre-configured from the provided config