@Target({TYPE,METHOD,FIELD,ANNOTATION_TYPE,CONSTRUCTOR,PARAMETER})
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy=io.xlate.validation.internal.constraintvalidators.JdbcStatementValidator.class)
@Repeatable(List.class)
public @interface JdbcStatement
Constraint to execute a read-only JDBC statement (i.e., a query). By default,
if the query returns at least one result row, the validation is considered to
be successful.
Statements are executed using the default
DataSource,
java:comp/DefaultDataSource.- Author:
- Michael Edgar
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic @interfaceDefines severalJdbcStatementannotations on the same element. -
Required Element Summary
Required Elements -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionThe JNDI lookup name of the resource to be used to obtain aConnection.Class<?>[]Name of the node to be identified in aConstraintViolationshould validation fail.String[]The list of EL expressions used to derive parameters values to be bound to parameter markers (i.e.Class<? extends jakarta.validation.Payload>[]An EL expression used to determine if the expression given byvalue()should be checked.
-
Element Details
-
value
String valueThe JDBC statement to execute to determine the validity of the constraint. The statement must be a valid SQL text that may be used withConnection.prepareStatement(String)and (subsequently)PreparedStatement.executeQuery(). The validation is considered successful when the result of the statement execution returns at least one row from the database.- Returns:
- the JDBC query to evaluate to determine the validity of the constraint
-
-
-
message
String message- Default:
- "statement `{value}` did not return any results"
-
groups
Class<?>[] groups- Default:
- {}
-
payload
Class<? extends jakarta.validation.Payload>[] payload- Default:
- {}
-
parameters
String[] parametersThe list of EL expressions used to derive parameters values to be bound to parameter markers (i.e. ?) in the SQL statement given byvalue(). The annotated target is available as 'self' in expressions. The parameters must be given in the same order that they are to be bound to the parameter marker in the SQL statement.- Returns:
- the list of EL expressions used to derive parameters values
- Default:
- {}
-
when
String whenAn EL expression used to determine if the expression given byvalue()should be checked. This expression is available to short-circuit the constraint validation of thisExpressionin scenarios when it should not apply, e.g. a value is null and the constraint only applies to non-null values.- Returns:
- the expression to evaluate to determine whether the constraint should be checked
- Default:
- ""
-
dataSourceLookup
String dataSourceLookupThe JNDI lookup name of the resource to be used to obtain aConnection. It can link to any compatibleDataSourceusing the global JNDI names.- Returns:
- the JNDI lookup name of the resource to be used to obtain a
Connection
- Default:
- ""
-
node
String nodeName of the node to be identified in aConstraintViolationshould validation fail.- Returns:
- the name of the node to be identified in a
ConstraintViolationshould validation fail.
- Default:
- ""
-