Interface DbExecute

  • All Known Subinterfaces:
    DbTransaction
    All Known Implementing Classes:
    AbstractDbExecute, MongoDbExecute, MongoDbTransaction

    public interface DbExecute
    Database executor.

    The database executor provides methods to create DbStatement instances for different types of database statements.

    The recommended approach is to use named statements, as that allows better metrics, tracing, logging etc. In case an unnamed statement is used, a name must be generated

    There are five methods for each DbStatementType, example for query (the implementation detail is for the default implementation, providers may differ):

    1. DbStatement createNamedQuery(String, String) - full control over the name and content of the statement
    2. DbStatement createNamedQuery(String) - use statement text from configuration
    3. DbStatement createQuery(String) - use the provided statement, name is generated
    4. DbRowResult namedQuery(String, Object...) - shortcut method to a named query with a list of parameters (or with no parameters at all)
    5. DbRowResult query(String, Object...) - shortcut method to unnamed query with a list of parameters (or with no parameters at all)
    The first three methods return a statement that can have parameters configured (and other details modified). The last two methods directly execute the statement and provide appropriate response for future processing. All the methods are non-blocking.
    • Method Detail

      • createNamedQuery

        DbStatementQuery createNamedQuery​(String statementName,
                                          String statement)
        Create a database query using a named statement passed as argument.
        Parameters:
        statementName - the name of the statement
        statement - the query statement
        Returns:
        database statement that can process query returning multiple rows
      • createNamedQuery

        DbStatementQuery createNamedQuery​(String statementName)
        Create a database query using a statement defined in the configuration file.
        Parameters:
        statementName - the name of the configuration node with statement
        Returns:
        database statement that can process query returning multiple rows
      • createQuery

        DbStatementQuery createQuery​(String statement)
        Create a database query using a statement passed as an argument.
        Parameters:
        statement - the query statement to be executed
        Returns:
        database statement that can process the query returning multiple rows
      • namedQuery

        default Multi<DbRow> namedQuery​(String statementName,
                                        Object... parameters)
        Create and execute a database query using a statement defined in the configuration file.
        Parameters:
        statementName - the name of the configuration node with statement
        parameters - query parameters to set
        Returns:
        database query execution result which can contain multiple rows
      • query

        default Multi<DbRow> query​(String statement,
                                   Object... parameters)
        Create and execute a database query using a statement passed as an argument.
        Parameters:
        statement - the query statement to be executed
        parameters - query parameters to set
        Returns:
        database query execution result which can contain multiple rows
      • createNamedGet

        DbStatementGet createNamedGet​(String statementName,
                                      String statement)
        Create a database query returning a single row using a named statement passed as an argument.
        Parameters:
        statementName - the name of the statement
        statement - the statement text
        Returns:
        database statement that can process query returning a single row
      • createNamedGet

        DbStatementGet createNamedGet​(String statementName)
        Create a database query returning a single row using a statement defined in the configuration file.
        Parameters:
        statementName - the name of the configuration node with statement
        Returns:
        database statement that can process query returning a single row
      • createGet

        DbStatementGet createGet​(String statement)
        Create a database query returning a single row using a statement passed as an argument.
        Parameters:
        statement - the query statement to be executed
        Returns:
        database statement that can process query returning a single row
      • namedGet

        default Single<Optional<DbRow>> namedGet​(String statementName,
                                                 Object... parameters)
        Create and execute a database query using a statement defined in the configuration file.
        Parameters:
        statementName - the name of the configuration node with statement
        parameters - query parameters to set
        Returns:
        database query execution result which can contain single row
      • get

        default Single<Optional<DbRow>> get​(String statement,
                                            Object... parameters)
        Create and execute a database query using a statement passed as an argument.
        Parameters:
        statement - the query statement to be executed
        parameters - query parameters to set
        Returns:
        database query execution result which can contain single row
      • createNamedInsert

        default DbStatementDml createNamedInsert​(String statementName,
                                                 String statement)
        Create an insert statement using a named statement passed as an argument.
        Parameters:
        statementName - the name of the statement
        statement - the statement text
        Returns:
        database statement that can insert data
      • createNamedInsert

        DbStatementDml createNamedInsert​(String statementName)
        Create an insert statement using a named statement.
        Parameters:
        statementName - the name of the statement
        Returns:
        database statement that can insert data
      • createInsert

        DbStatementDml createInsert​(String statement)
        Create an insert statement using a statement text.
        Parameters:
        statement - the statement text
        Returns:
        database statement that can insert data
      • namedInsert

        default Single<Long> namedInsert​(String statementName,
                                         Object... parameters)
        Create and execute insert statement using a statement defined in the configuration file.
        Parameters:
        statementName - the name of the configuration node with statement
        parameters - query parameters to set
        Returns:
        number of rows inserted into the database
      • insert

        default Single<Long> insert​(String statement,
                                    Object... parameters)
        Create and execute insert statement using a statement passed as an argument.
        Parameters:
        statement - the insert statement to be executed
        parameters - query parameters to set
        Returns:
        number of rows inserted into the database
      • createNamedUpdate

        default DbStatementDml createNamedUpdate​(String statementName,
                                                 String statement)
        Create an update statement using a named statement passed as an argument.
        Parameters:
        statementName - the name of the statement
        statement - the statement text
        Returns:
        database statement that can update data
      • createNamedUpdate

        DbStatementDml createNamedUpdate​(String statementName)
        Create an update statement using a named statement.
        Parameters:
        statementName - the name of the statement
        Returns:
        database statement that can update data
      • createUpdate

        DbStatementDml createUpdate​(String statement)
        Create an update statement using a statement text.
        Parameters:
        statement - the statement text
        Returns:
        database statement that can update data
      • namedUpdate

        default Single<Long> namedUpdate​(String statementName,
                                         Object... parameters)
        Create and execute update statement using a statement defined in the configuration file.
        Parameters:
        statementName - the name of the configuration node with statement
        parameters - query parameters to set
        Returns:
        number of rows updateed into the database
      • update

        default Single<Long> update​(String statement,
                                    Object... parameters)
        Create and execute update statement using a statement passed as an argument.
        Parameters:
        statement - the update statement to be executed
        parameters - query parameters to set
        Returns:
        number of rows updateed into the database
      • createNamedDelete

        default DbStatementDml createNamedDelete​(String statementName,
                                                 String statement)
        Create a delete statement using a named statement passed as an argument.
        Parameters:
        statementName - the name of the statement
        statement - the statement text
        Returns:
        database statement that can delete data
      • createNamedDelete

        DbStatementDml createNamedDelete​(String statementName)
        Create andelete statement using a named statement.
        Parameters:
        statementName - the name of the statement
        Returns:
        database statement that can delete data
      • createDelete

        DbStatementDml createDelete​(String statement)
        Create a delete statement using a statement text.
        Parameters:
        statement - the statement text
        Returns:
        database statement that can delete data
      • namedDelete

        default Single<Long> namedDelete​(String statementName,
                                         Object... parameters)
        Create and execute delete statement using a statement defined in the configuration file.
        Parameters:
        statementName - the name of the configuration node with statement
        parameters - query parameters to set
        Returns:
        number of rows deleted from the database
      • delete

        default Single<Long> delete​(String statement,
                                    Object... parameters)
        Create and execute delete statement using a statement passed as an argument.
        Parameters:
        statement - the delete statement to be executed
        parameters - query parameters to set
        Returns:
        number of rows deleted from the database
      • createNamedDmlStatement

        DbStatementDml createNamedDmlStatement​(String statementName,
                                               String statement)
        Create a data modification statement using a named statement passed as an argument.
        Parameters:
        statementName - the name of the statement
        statement - the statement text
        Returns:
        data modification statement
      • createNamedDmlStatement

        DbStatementDml createNamedDmlStatement​(String statementName)
        Create a data modification statement using a statement defined in the configuration file.
        Parameters:
        statementName - the name of the configuration node with statement
        Returns:
        data modification statement
      • createDmlStatement

        DbStatementDml createDmlStatement​(String statement)
        Create a data modification statement using a statement passed as an argument.
        Parameters:
        statement - the data modification statement to be executed
        Returns:
        data modification statement
      • namedDml

        default Single<Long> namedDml​(String statementName,
                                      Object... parameters)
        Create and execute a data modification statement using a statement defined in the configuration file.
        Parameters:
        statementName - the name of the configuration node with statement
        parameters - query parameters to set
        Returns:
        number of rows modified
      • dml

        default Single<Long> dml​(String statement,
                                 Object... parameters)
        Create and execute data modification statement using a statement passed as an argument.
        Parameters:
        statement - the delete statement to be executed
        parameters - query parameters to set
        Returns:
        number of rows modified
      • unwrap

        <C> Single<C> unwrap​(Class<C> cls)
        Unwrap database executor internals. Only database connection is supported. Any operations based on this connection are blocking. Reactive support must be implemented in user code. This connection instance is being used to execute all statements in current database executor context.
        Type Parameters:
        C - target class to be unwrapped
        Parameters:
        cls - target class to be unwrapped
        Returns:
        database executor internals future matching provided class
        Throws:
        UnsupportedOperationException - when provided class is not supported