public interface ConstraintOnTable extends JavaBeanVersion
Constraint
interface, which
performs the validation of each individual record, this interface allows optimizing
the validation algorithm as a set-based operation.
The following examples illustrate how to define constraints for certain complex validation requirements. Each example defines:
setup
method;checkTable
.
This example ensures that, in a table T1
, no group of
records with the same code
value has a sum of their portion
values greater than a fixed threshold.
T1
.
code
and portion
,
thus the insert, delete and modify events must declare dependencies on both these nodes.
ValueContextForValidationOnTable.addMessage
method, for example using an
XPath predicate
that represents the set of records that have violated the constraint.
This example ensures that, in a table T2
, no group of records
with the same code
value contains overlapping time periods,
as defined by the fields beginDate
and endDate
.
T2
.
code
, beginDate
and endDate
, thus the insert, delete and modify events must declare
dependencies on all three nodes.
ValueContextForValidationOnTable.addMessage
method, for example using by specifying a
list of records
that represents the set of records that have violated the constraint.
This example ensures that two tables, T3
and T4
,
contain records with the same primary keys. Specifically,
T3
is considered to be the "master" table,
against which T4
is compared. T4
has an error if it does not
define a record that exists in T3
, or if it defines a record
that does not exist in T3
.
T4
, which contains the validation messages.
T3
and T4
.
Consequently, dependencies on insertion and deletion events in both tables must be declared
in T4
's table node (see addDependencyToInsertAndDelete
).
ValueContextForValidationOnTable.addMessage
method, for example using by specifying an
XPath predicate
.
In this case, the subject of the message will be a ValidationReportItemSubjectForAdaptation
.
The constraint must be declared under the element xs:annotation/xs:appinfo/osd:otherFacets
,
in an element that defines an osd:table
:
where<osd:constraint class="com.foo.MyTableConstraint" />
com.foo.MyTableConstraint
is
the fully qualified name of the class implementing this interface.
It is also possible to set additional JavaBean properties:
where<osd:constraint class="com.foo.MyTableConstraint"> <param1>...</param1> <param2>...</param2> </osd:constraint>
param1
and param2
are JavaBean properties of the specified class.
For more information, see the JavaBean specification.
When the data model is loaded:
setParam1(...)
and
setParam2(...)
);setup(ConstraintContextOnTable)
is called on the new instance.JavaBeanVersion.getBeanVersion()
is called for the new instance for checking if its implementation
has been modified since the last time the data model has been compiled. That is, since validation reports are
persisted into EBX® repository it is important to update the version to indicate that this constraint
has been modified and must be revalidated during the next explicit validation of the container dataset or table.
During the operational phase, the method checkTable(ValueContextForValidationOnTable)
is called whenever the validation report for the table is requested, but
the table's validation state is not up-to-date (the "up-to-date" state depends on
the dependencies specified in the setup
method
and on any changes specified by defining a new version number
.
Unlike with other constraints, no check is performed automatically
when a record creation or update is submitted in the user interface.
If the end-user introduces a validation error, form submission is not be blocked
by the checkTable
method.
If blocking behavior is necessary, the sub-interface
ConstraintOnTableWithRecordLevelCheck
must be used instead.
Modifier and Type | Method and Description |
---|---|
void |
checkTable(ValueContextForValidationOnTable aContext)
Performs a check on the entirety of the table specified by the context,
and adds error messages whenever errors are detected.
|
void |
setup(ConstraintContextOnTable aContext)
Checks and prepares this instance when the data model is loaded.
|
String |
toUserDocumentation(Locale userLocale,
ValueContext aContext)
Returns end-user documentation for this constraint.
|
getBeanVersion
void checkTable(ValueContextForValidationOnTable aContext)
As the whole table is being checked at once, this provides the opportunity to use SQL queries or XPath predicates.
To avoid re-validating this constraint on each request for updating
the validation report, it is necessary to declare dependencies
.
See also performance and tuning.
For a single instance of this interface, this method may be called concurrently by several threads.
InvalidSchemaException
- if a dynamic condition in the data model prevents the execution of this method.ConstraintOnTableWithRecordLevelCheck.checkRecord(ValueContextForValidationOnRecord)
void setup(ConstraintContextOnTable aContext)
This method must also declare any dependencies of the constraint, so that validation is notified when a value is updated. If no dependencies are declared, the dependencies are considered to be unknown.
String toUserDocumentation(Locale userLocale, ValueContext aContext) throws InvalidSchemaException
This method returns null
if the specified locale is not handled by
the current implementation. The container tries several locales
when handling a partial internationalization of this method's implementation and/or
a mismatch between the locales declared by the associated module and the locales supported
by EBX®. In such cases, locales are tried in the following order:
Session.getLocaleForSchemaNode(SchemaNode)
);module.xml
;For a single instance of this interface, this method may be called concurrently by several threads.
InvalidSchemaException
- if a dynamic condition in the data model prevents the execution of this method.