Module io.helidon.dbclient.common
Package io.helidon.dbclient.common
Class AbstractStatement<S extends DbStatement<S,R>,R>
- java.lang.Object
-
- io.helidon.dbclient.common.AbstractStatement<S,R>
-
- Type Parameters:
S- type of a subclassR- the result type of the statement as returned byexecute()
- 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 Summary
Constructors Modifier Constructor Description protectedAbstractStatement(DbStatementContext statementContext)Statement that handles parameters.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description SaddParam(Object parameter)Add next parameter to the list of ordered parameters (e.g.SaddParam(String name, Object parameter)Add next parameter to the map of named parameters (e.g.DbClientContextclientContext()Context of the DB client.protected DbMapperManagerdbMapperManager()Db mapper manager.protected abstract StringdbType()Type of this database to use in interceptor context.protected abstract RdoExecute(Single<DbClientServiceContext> dbContext, CompletableFuture<Void> statementFuture, CompletableFuture<Long> queryFuture)Execute the statement against the database.Rexecute()Execute this statement using the parameters configured withparamsandaddParamsmethods.SindexedParam(Object parameters)Configure parameters usingObjectinstance with registered mapper.protected List<Object>indexedParams()Get the indexed parameters of this statement.protected MapperManagermapperManager()Mapper manager.protected Sme()Returns this builder cast to the correct type.SnamedParam(Object parameters)Configure parameters usingObjectinstance with registered mapper.protected Map<String,Object>namedParams()Get the named parameters of this statement.Sparams(List<?> parameters)Configure parameters from aListby order.Sparams(Map<String,?> parameters)Configure named parameters.protected ParamTypeparamType()Type of parameters of this statement.protected Stringstatement()Statement text.protected StringstatementName()Statement name.protected DbStatementTypestatementType()Type of this statement.protected voidupdate(DbClientServiceContext dbContext)Update the client service context with the statement name, statement and statement parameters.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.helidon.dbclient.DbStatement
params
-
-
-
-
Constructor Detail
-
AbstractStatement
protected AbstractStatement(DbStatementContext statementContext)
Statement that handles parameters.- Parameters:
statementContext- database statement configuration and context
-
-
Method Detail
-
execute
public R execute()
Description copied from interface:DbStatementExecute this statement using the parameters configured withparamsandaddParamsmethods.- Specified by:
executein interfaceDbStatement<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 invokedstatementFuture- future that should complete when the statement finishes executionqueryFuture- 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:DbStatementConfigure parameters from aListby order. The statement must use indexed parameters and configure them by order in the provided array.- Specified by:
paramsin interfaceDbStatement<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:DbStatementConfigure named parameters. The statement must use named parameters and configure them from the provided map.- Specified by:
paramsin interfaceDbStatement<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:DbStatementConfigure parameters usingObjectinstance with registered mapper. The statement must use named parameters and configure them from the map provided by mapper.- Specified by:
namedParamin interfaceDbStatement<S extends DbStatement<S,R>,R>- Parameters:
parameters-Objectinstance containing parameters- Returns:
- updated db statement
-
indexedParam
public S indexedParam(Object parameters)
Description copied from interface:DbStatementConfigure parameters usingObjectinstance with registered mapper. The statement must use indexed parameters and configure them by order in the array provided by mapper.- Specified by:
indexedParamin interfaceDbStatement<S extends DbStatement<S,R>,R>- Parameters:
parameters-Objectinstance containing parameters- Returns:
- updated db statement
-
addParam
public S addParam(Object parameter)
Description copied from interface:DbStatementAdd next parameter to the list of ordered parameters (e.g. the ones that use?in SQL).- Specified by:
addParamin interfaceDbStatement<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:DbStatementAdd next parameter to the map of named parameters (e.g. the ones that use:namein Helidon JDBC SQL integration).- Specified by:
addParamin interfaceDbStatement<S extends DbStatement<S,R>,R>- Parameters:
name- name of parameterparameter- 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
-
-