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 protected
AbstractStatement(DbStatementContext statementContext)
Statement that handles parameters.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description S
addParam(Object parameter)
Add next parameter to the list of ordered parameters (e.g.S
addParam(String name, Object parameter)
Add next parameter to the map of named parameters (e.g.DbClientContext
clientContext()
Context of the DB client.protected DbMapperManager
dbMapperManager()
Db mapper manager.protected abstract String
dbType()
Type of this database to use in interceptor context.protected abstract R
doExecute(Single<DbClientServiceContext> dbContext, CompletableFuture<Void> statementFuture, CompletableFuture<Long> queryFuture)
Execute the statement against the database.R
execute()
Execute this statement using the parameters configured withparams
andaddParams
methods.S
indexedParam(Object parameters)
Configure parameters usingObject
instance with registered mapper.protected List<Object>
indexedParams()
Get the indexed parameters of this statement.protected MapperManager
mapperManager()
Mapper manager.protected S
me()
Returns this builder cast to the correct type.S
namedParam(Object parameters)
Configure parameters usingObject
instance with registered mapper.protected Map<String,Object>
namedParams()
Get the named parameters of this statement.S
params(List<?> parameters)
Configure parameters from aList
by order.S
params(Map<String,?> parameters)
Configure named parameters.protected ParamType
paramType()
Type of parameters of this statement.protected String
statement()
Statement text.protected String
statementName()
Statement name.protected DbStatementType
statementType()
Type of this statement.protected void
update(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:DbStatement
Execute this statement using the parameters configured withparams
andaddParams
methods.- Specified by:
execute
in 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:DbStatement
Configure parameters from aList
by order. The statement must use indexed parameters and configure them by order in the provided array.- Specified by:
params
in 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:DbStatement
Configure named parameters. The statement must use named parameters and configure them from the provided map.- Specified by:
params
in 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:DbStatement
Configure parameters usingObject
instance with registered mapper. The statement must use named parameters and configure them from the map provided by mapper.- Specified by:
namedParam
in interfaceDbStatement<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 usingObject
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 interfaceDbStatement<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 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: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 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
-
-