Class AbstractStatement<S extends DbStatement<S,​R>,​R>

    • Constructor Detail

      • AbstractStatement

        protected AbstractStatement​(DbStatementType dbStatementType,
                                    String statementName,
                                    String statement,
                                    DbMapperManager dbMapperManager,
                                    MapperManager mapperManager,
                                    InterceptorSupport interceptors)
        Statement that handles parameters.
        Parameters:
        dbStatementType - type of this statement
        statementName - name of this statement
        statement - text of this statement
        dbMapperManager - db mapper manager to use when mapping types to parameters
        mapperManager - mapper manager to use when mapping results
        interceptors - interceptors to be executed
    • Method Detail

      • execute

        public CompletionStage<R> execute()
        Description copied from interface: DbStatement
        Execute this statement using the parameters configured with params and addParams methods.
        Specified by:
        execute in interface DbStatement<S extends DbStatement<S,​R>,​R>
        Returns:
        The future with result of this statement, as soon as the statement is executed; note that for queries this is before the results are actually obtained from the database
      • statementType

        protected DbStatementType statementType()
        Type of this statement.
        Returns:
        statement type
      • doExecute

        protected abstract CompletionStage<R> doExecute​(CompletionStage<DbInterceptorContext> dbContext,
                                                        CompletableFuture<Void> statementFuture,
                                                        CompletableFuture<Long> queryFuture)
        Execute the statement against the database.
        Parameters:
        dbContext - future that completes after all interceptors are invoked
        statementFuture - future that should complete when the statement finishes execution
        queryFuture - future that should complete when the result set is fully read (if one exists), otherwise complete same as statementFuture
        Returns:
        result of this db statement.
      • dbType

        protected abstract String dbType()
        Type of this database to use in interceptor context.
        Returns:
        type of this db
      • params

        public S params​(List<?> parameters)
        Description copied from interface: DbStatement
        Configure parameters from a List by order. The statement must use indexed parameters and configure them by order in the provided array.
        Specified by:
        params in interface DbStatement<S extends DbStatement<S,​R>,​R>
        Parameters:
        parameters - ordered parameters to set on this statement, never null
        Returns:
        updated db statement
      • params

        public S params​(Map<String,​?> parameters)
        Description copied from interface: DbStatement
        Configure named parameters. The statement must use named parameters and configure them from the provided map.
        Specified by:
        params in interface DbStatement<S extends DbStatement<S,​R>,​R>
        Parameters:
        parameters - named parameters to set on this statement
        Returns:
        updated db statement
      • namedParam

        public S namedParam​(Object parameters)
        Description copied from interface: DbStatement
        Configure parameters using Object instance with registered mapper. The statement must use named parameters and configure them from the map provided by mapper.
        Specified by:
        namedParam in interface DbStatement<S extends DbStatement<S,​R>,​R>
        Parameters:
        parameters - Object instance containing parameters
        Returns:
        updated db statement
      • indexedParam

        public S indexedParam​(Object parameters)
        Description copied from interface: DbStatement
        Configure parameters using Object instance with registered mapper. The statement must use indexed parameters and configure them by order in the array provided by mapper.
        Specified by:
        indexedParam in interface DbStatement<S extends DbStatement<S,​R>,​R>
        Parameters:
        parameters - Object instance containing parameters
        Returns:
        updated db statement
      • addParam

        public S addParam​(Object parameter)
        Description copied from interface: DbStatement
        Add next parameter to the list of ordered parameters (e.g. the ones that use ? in SQL).
        Specified by:
        addParam in interface DbStatement<S extends DbStatement<S,​R>,​R>
        Parameters:
        parameter - next parameter to set on this statement
        Returns:
        updated db statement
      • addParam

        public S addParam​(String name,
                          Object parameter)
        Description copied from interface: DbStatement
        Add next parameter to the map of named parameters (e.g. the ones that use :name in Helidon JDBC SQL integration).
        Specified by:
        addParam in interface DbStatement<S extends DbStatement<S,​R>,​R>
        Parameters:
        name - name of parameter
        parameter - value of parameter
        Returns:
        updated db statement
      • paramType

        protected ParamType paramType()
        Type of parameters of this statement.
        Returns:
        indexed or named, or unknown in case it could not be yet defined
      • dbMapperManager

        protected DbMapperManager dbMapperManager()
        Db mapper manager.
        Returns:
        mapper manager for DB types
      • mapperManager

        protected MapperManager mapperManager()
        Mapper manager.
        Returns:
        generic mapper manager
      • namedParams

        protected Map<String,​Object> namedParams()
        Get the named parameters of this statement.
        Returns:
        name parameter map
        Throws:
        IllegalStateException - in case this statement is using indexed parameters
      • indexedParams

        protected List<Object> indexedParams()
        Get the indexed parameters of this statement.
        Returns:
        parameter list
        Throws:
        IllegalStateException - in case this statement is using named parameters
      • statementName

        protected String statementName()
        Statement name.
        Returns:
        name of this statement (never null, may be generated)
      • statement

        protected String statement()
        Statement text.
        Returns:
        text of this statement
      • update

        protected void update​(DbInterceptorContext dbContext)
        Update the interceptor context with the statement name, statement and statement parameters.
        Parameters:
        dbContext - interceptor context
      • me

        protected S me()
        Returns this builder cast to the correct type.
        Returns:
        this as type extending this class