public interface SQLCompositionContext extends SQLContext, com.holonplatform.core.ExpressionResolver.ResolutionContext, com.holonplatform.core.ExpressionResolver.ExpressionResolverSupport
Supports ExpressionResolvers to resolve SQL expressions and extends ExpressionResolver.ResolutionContext.
Supports named parameters definitions, which can be added using addNamedParameter(SQLParameter). The named
parameters can be normalized as SQL statement parameters through the prepareStatement(String) method.
SQL compostion contexts are hierarchical and provides methods to get the parent context and to create children using
childContext().
| Modifier and Type | Interface and Description |
|---|---|
static class |
SQLCompositionContext.SQLStatementPreparationException
Runtime exception related to SQL statements preparation errors.
|
| Modifier and Type | Method and Description |
|---|---|
default <T> String |
addNamedParameter(SQLParameter<T> parameter)
Convenience method to add a named parameter using current
SQLContextParametersHandler. |
SQLCompositionContext |
childContext()
Create a new
SQLCompositionContext as child of this context. |
static SQLCompositionContext |
create(SQLContext context)
Create a new default
SQLCompositionContext. |
static int |
getContextSequence(SQLCompositionContext context,
Class<? extends SQLCompositionContext> contextType)
Get the given
context hierarchy sequence, where 0 is the sequence number of the root
context. |
SQLContextParametersHandler |
getNamedParametersHandler()
Get the SQL named parameters handler.
|
Optional<SQLCompositionContext> |
getParent()
Get the parent context, if available.
|
static Optional<SQLCompositionContext> |
isSQLCompositionContext(com.holonplatform.core.ExpressionResolver.ResolutionContext context)
Checks if given
ExpressionResolver.ResolutionContext is a SQLCompositionContext. |
default Optional<SQLStatementCompositionContext> |
isStatementCompositionContext()
Checks whether this context is a
SQLStatementCompositionContext. |
SQLStatement |
prepareStatement(String sql)
Prepare given SQL statement, replacing named parameters with the default
? parameter placeholder. |
default <E extends com.holonplatform.core.Expression,R extends com.holonplatform.core.Expression> |
resolve(E expression,
Class<R> resolutionType)
Try to resolve given
expression using current context resolvers to obtain a
resolutionType type expression. |
default <E extends com.holonplatform.core.Expression,R extends com.holonplatform.core.Expression> |
resolveOrFail(E expression,
Class<R> resolutionType)
Resolve given
expression using current context resolvers to obtain a resolutionType
type expression. |
getDialect, getTypeConverter, getValueDeserializer, getValueSerializer, traceresolveOptional<SQLCompositionContext> getParent()
SQLContextParametersHandler getNamedParametersHandler()
default <T> String addNamedParameter(SQLParameter<T> parameter)
SQLContextParametersHandler.T - Parameter expression typeparameter - Parameter definition (not null)SQLStatement prepareStatement(String sql)
? parameter placeholder.sql - The SQL statement to prepare (not null)SQLStatement which provides the prepared SQL and the statement parameter definition in the
right order according to the parameters placeholder indexSQLCompositionContext.SQLStatementPreparationException - If an error occurreddefault <E extends com.holonplatform.core.Expression,R extends com.holonplatform.core.Expression> Optional<R> resolve(E expression, Class<R> resolutionType) throws com.holonplatform.core.Expression.InvalidExpressionException
expression using current context resolvers to obtain a
resolutionType type expression.
The resolved expression is validate using Expression.validate() before returning it to caller.
E - Expression typeR - Resolution typeexpression - Expression to resolveresolutionType - Expression type to obtaincom.holonplatform.core.Expression.InvalidExpressionExceptiondefault <E extends com.holonplatform.core.Expression,R extends com.holonplatform.core.Expression> R resolveOrFail(E expression,
Class<R> resolutionType)
expression using current context resolvers to obtain a resolutionType
type expression. If no ExpressionResolver is available to resolve given expression, an
Expression.InvalidExpressionException is thrown.
The resolved expression is validate using Expression.validate() before returning it to caller.
E - Expression typeR - Resolution typeexpression - Expression to resolveresolutionType - Expression type to obtaincom.holonplatform.core.Expression.InvalidExpressionException - If an error occurred during resolution, or if no ExpressionResolver is
available to resolve given expression or if expression validation failedSQLCompositionContext childContext()
SQLCompositionContext as child of this context. This context will be setted as parent of the
new context.SQLCompositionContext with this context as parentdefault Optional<SQLStatementCompositionContext> isStatementCompositionContext()
SQLStatementCompositionContext.SQLStatementCompositionContext returns the context itself as
SQLStatementCompositionContext, otherwise returns an empty Optionalstatic SQLCompositionContext create(SQLContext context)
SQLCompositionContext.context - SQL context to use (not null)SQLCompositionContextstatic Optional<SQLCompositionContext> isSQLCompositionContext(com.holonplatform.core.ExpressionResolver.ResolutionContext context)
ExpressionResolver.ResolutionContext is a SQLCompositionContext.context - The context to checkSQLCompositionContext, it is returned as a SQLCompositionContext
type. Otherwise, an empty Optional is returned.static int getContextSequence(SQLCompositionContext context, Class<? extends SQLCompositionContext> contextType)
context hierarchy sequence, where 0 is the sequence number of the root
context.context - The context for which to obtain the sequence (not null)contextType - The context type to take into account to calculate the sequenceCopyright © 2019 The Holon Platform. All rights reserved.