Interface DbClientServiceContext


  • public interface DbClientServiceContext
    Interceptor context to get (and possibly manipulate) database operations.

    This is a mutable object - acts as a builder during the invocation of DbClientService. The interceptors are executed sequentially, so there is no need for synchronization.

    • Method Detail

      • create

        static DbClientServiceContext create​(String dbType)
        Create a new interceptor context for a database provider.
        Parameters:
        dbType - a short name of the db type (such as jdbc:mysql)
        Returns:
        a new interceptor context ready to be configured
      • context

        Context context()
        Context with parameters passed from the caller, such as SpanContext for tracing.
        Returns:
        context associated with this request
      • statementName

        String statementName()
        Name of a statement to be executed. Ad hoc statements have names generated.
        Returns:
        name of the statement
      • statement

        String statement()
        Text of the statement to be executed.
        Returns:
        statement text
      • statementFuture

        CompletionStage<Void> statementFuture()
        A stage that is completed once the statement finishes execution.
        Returns:
        statement future
      • resultFuture

        CompletionStage<Long> resultFuture()
        A stage that is completed once the results were fully read. The number returns either the number of modified records or the number of records actually read.
        Returns:
        stage that completes once all query results were processed.
      • indexedParameters

        Optional<List<Object>> indexedParameters()
        Indexed parameters (if used).
        Returns:
        indexed parameters (empty if this statement parameters are not indexed)
      • namedParameters

        Optional<Map<String,​Object>> namedParameters()
        Named parameters (if used).
        Returns:
        named parameters (empty if this statement parameters are not named)
      • isIndexed

        boolean isIndexed()
        Whether this is a statement with indexed parameters.
        Returns:
        Whether this statement has indexed parameters (true) or named parameters false.
      • isNamed

        boolean isNamed()
        Whether this is a statement with named parameters.
        Returns:
        Whether this statement has named parameters (true) or indexed parameters false.
      • statementType

        DbStatementType statementType()
        Type of the statement being executed.
        Returns:
        statement type
      • context

        DbClientServiceContext context​(Context context)
        Set a new context to be used by other interceptors and when executing the statement.
        Parameters:
        context - context to use
        Returns:
        updated interceptor context
      • statementName

        DbClientServiceContext statementName​(String newName)
        Set a new statement name to be used.
        Parameters:
        newName - statement name to use
        Returns:
        updated interceptor context
      • statementFuture

        DbClientServiceContext statementFuture​(CompletionStage<Void> statementFuture)
        Set a new future to mark completion of the statement.
        Parameters:
        statementFuture - future
        Returns:
        updated interceptor context
      • resultFuture

        DbClientServiceContext resultFuture​(CompletionStage<Long> queryFuture)
        Set a new future to mark completion of the result (e.g. query or number of modified records).
        Parameters:
        queryFuture - future
        Returns:
        updated interceptor context
      • statement

        DbClientServiceContext statement​(String statement,
                                         List<Object> indexedParams)
        Set a new statement with indexed parameters to be used.
        Parameters:
        statement - statement text
        indexedParams - indexed parameters
        Returns:
        updated interceptor context
      • statement

        DbClientServiceContext statement​(String statement,
                                         Map<String,​Object> namedParams)
        Set a new statement with named parameters to be used.
        Parameters:
        statement - statement text
        namedParams - named parameters
        Returns:
        updated interceptor context
      • parameters

        DbClientServiceContext parameters​(List<Object> indexedParameters)
        Set new indexed parameters to be used.
        Parameters:
        indexedParameters - parameters
        Returns:
        updated interceptor context
        Throws:
        IllegalArgumentException - in case the statement is using named parameters