Validators are used to check whether database model matches customs rules, like naming rules. A rule a class implementing the MDValidator interface.
Validator configuration can be expressed in two formats: XML and properties.
Each validation rule is an instance of a validator class. Each instance of validator must have a unique name to identify it. Validator properties can be injected with values. There can be multiple instances of the same validator class (with different properties values)
<?xml version="1.0" encoding="UTF-8"?> <dbtb:validators xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dbtb="http://dbtoolbox.sourceforge.net/xml/validator"> <dbtb:validator name="ValidatorName" class="net.sourceforge.dbtoolbox.validator.ValidatorClass"> <dbtb:property name="validatorProperty">Validator Property Value</dbtb:property> <dbtb:property name="anotherValidatorProperty">Another Validator Property Value</dbtb:property> </dbtb:validator> <dbtb:validator name="AnotherValidatorName" class="net.sourceforge.dbtoolbox.validator.AnotherValidatorClass"/> </dbtb:validators>
validator.ValidatorName.class=net.sourceforge.dbtoolbox.validator.ValidatorClass validator.ValidatorName.validatorProperty=Validator Property Value validator.ValidatorName.anotherValidatorProperty=Another Validator Property Value validator.AnotherValidatorName.class=net.sourceforge.dbtoolbox.validator.AnotherValidatorClass
DB Toolbox comes with some basic validation rules
Checks that element name matchers regular expression.
elementClass | Target model class (subclass of ElementMD) Required. |
elementMatcher | Groovy expression to include/exclude elements from validation |
nameRegEx | Java Regular expression Required. |
Checks that element name length is between min and max. This can be done with a regular expression (see above) as well.
elementClass | Target model class (subclass of ElementMD) Required. |
elementMatcher | Groovy expression to include/exclude elements from validation |
min,max | Minimum and maximum name length |
Checks that element name is not in a list of forbidden names (avoid usage of reserved keywords).
elementClass | Target model class (subclass of ElementMD) Required. |
names | Coma separated, list of forbidden words |
elementMatcher | Groovy expression to include/exclude elements from validation |
Checks that column count is between min and max.
elementClass | Target model class (subclass of ElementMD and ColumnSet: TableMD, PrimaryKeyMD...) Required. |
elementMatcher | Groovy expression to include/exclude elements from validation |
min,max | Minimum and maximum value |
Checks that table has primary key.
elementMatcher | Groovy expression to include/exclude elements from validation |
Checks that table has primary key.
Checks that primary key matches an index.
elementMatcher | Groovy expression to include/exclude elements from validation |
Checks that foreign key references a primary key.
elementMatcher | Groovy expression to include/exclude elements from validation |
Checks that foreign key references an index.
elementMatcher | Groovy expression to include/exclude elements from validation |
Checks that table has at least one relation to another table (avoid abandonned tables).
elementMatcher | Groovy expression to include/exclude elements from validation |
Checks that element validates against a Groovy script.
elementClass | Target model class (subclass of ElementMD and ColumnSet: TableMD, PrimaryKeyMD...) Required. |
elementMatcher | Groovy expression to include/exclude elements from validation |
scriptFile | Groovy script file containing validator code |
bindingName | Name of the script variable corresponding to element being validated. Defaults to 'object'. |
Sample Groovy script:
if (!object.name.toUpperCase().startsWith("ABC")) { validatorMessages.add(validator.createMessage(table,"Name is not prefixed by ABC")); }
Three Groovy variables are pre initialised: