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

java.lang.Object
io.helidon.dbclient.common.AbstractStatement<S,R>
Type Parameters:
S - type of a subclass
R - the result type of the statement as returned by execute()
All Implemented Interfaces:
DbStatement<S,R>
Direct Known Subclasses:
MongoDbStatementDml

public abstract class AbstractStatement<S extends DbStatement<S,R>,R> extends Object implements DbStatement<S,R>
Common statement methods and fields.
  • Constructor Details

    • AbstractStatement

      protected AbstractStatement(DbStatementContext statementContext)
      Statement that handles parameters.
      Parameters:
      statementContext - database statement configuration and context
  • Method Details

    • execute

      public 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 result of this statement, never blocking.
    • statementType

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

      protected abstract R doExecute(Single<DbClientServiceContext> dbContext, CompletableFuture<Void> statementFuture, CompletableFuture<Long> queryFuture)
      Execute the statement against the database.
      Parameters:
      dbContext - future that completes after all services 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
    • clientContext

      public DbClientContext clientContext()
      Context of the DB client.
      Returns:
      context with access to client wide configuration and runtime
    • 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(DbClientServiceContext dbContext)
      Update the client service context with the statement name, statement and statement parameters.
      Parameters:
      dbContext - client service context
    • me

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