TIBCO Software Inc. EBX®
Documentation > Developer Guide > Data model
Navigation modeDocumentation > Developer Guide > Data model

Constraints

Facets allow you to define data constraints in your data models. TIBCO EBX® supports XML Schema constraining facets and provides extended and programmatic facets for advanced data controls.

XML Schema supported facets

The tables below show the facets that are supported by different data types.

Key:

length

minLength

max

Length

pattern

enumeration

white

Space

xs:string

X

X

X

X

X

1

xs:boolean

X

1

xs:decimal

X

X

1

xs:dateTime

X

X

1

xs:time

X

X

1

xs:date

X

X

1

xs:anyURI

X

X

X

X

X

1

xs:Name

X

X

X

X

X

1

xs:integer

X

X

1

osd:resource 3

1

osd:dataspaceKey 4

1

osd:datasetName 4

1

osd:color 4

1

fraction

Digits

total

Digits

max

Inclusive

max

Exclusive

min

Inclusive

min

Exclusive

xs:string

2

2

2

2

xs:boolean

xs:decimal

X

X

X

X

X

X

xs:dateTime

X

X

X

X

xs:time

X

X

X

X

xs:date

X

X

X

X

xs:anyURI

xs:Name

2

2

2

2

xs:integer

X

X

X

X

X

X

osd:resource 3
osd:dataspaceKey 4
osd:datasetName 4
osd:color 4

Example:

<xs:element name="loanRate">
	<xs:simpleType>
		<xs:restriction base="xs:decimal">
			<xs:minInclusive value="4.5" />
			<xs:maxExclusive value="17.5" />
		</xs:restriction>
	</xs:simpleType>
</xs:element>

Uniqueness constraint

It is possible to define a uniqueness constraint, using the standard XML Schema element xs:unique. This constraint indicates that a value or a set of values has to be unique inside a table.

Example:

In the example below, a uniqueness constraint is defined on the 'publisher' table, for the target field 'name'. This means that no two records in the 'publisher' table can have the same name.

<xs:element name="publisher">
	...
	<xs:complexType>
		<xs:sequence>
			...
			<xs:element name="name" type="xs:string" />
			...
		</xs:sequence>
	</xs:complexType>
	<xs:unique name="uniqueName">
		<xs:annotation>
			<xs:appinfo>
				<osd:validation>
					<severity>error</severity>
					<message>Name must be unique in table.</message>
					<message xml:lang="en-US">Name must be unique in table.</message>
					<message xml:lang="fr-FR">Le nom doit être unique dans la table.</message>
				</osd:validation>
			</xs:appinfo>
		</xs:annotation>
		<xs:selector xpath="." />
		<xs:field xpath="name" />
	</xs:unique>
</xs:element>

A uniqueness constraint has to be defined within a table and has the following properties:

Property

Description

Mandatory

name attribute

Identifies the constraint in the data model.

Yes

xs:selector element

Indicates the table to which the uniqueness constraint applies using a restricted XPath expression ('..' is forbidden). It can also indicate an element within the table (without changing the meaning of the constraint).

Yes

xs:field element

Indicates the field in the context whose values must be unique, using a restricted XPath expression.

It is possible to indicate that a set of values must be unique by defining multiple xs:field elements.

Yes

Note

Undefined values (null values) are ignored on uniqueness constraints applied to single fields. On multiple fields, undefined values are taken into account. That is, sets of values are considered as being duplicated if they have the same defined and undefined values.

Additional localized validation messages can be defined using the element osd:validation under the elements annotation/appinfo. If no custom validation messages are defined, a built-in validation message will be used.

The uniqueness constraint can also be applied on an simple aggregated list: in this case, each value of the list has to be unique in the scope of the list and not in the scope of the table.

Example:

In the example below, a uniqueness constraint is defined on the 'title' table, for the target field 'printedEditions'. This means that an edition can appear only once in the list.

<xs:element name="title">
	...
	<xs:complexType>
		<xs:sequence>
			...
			<xs:element name="printedEditions" type="xs:string" minOccur="0" maxOccur="5"/>
			...
		</xs:sequence>
	</xs:complexType>
	<xs:unique name="uniquePrintedEditions">
		<xs:annotation>
			<xs:appinfo>
				<osd:validation>
					<severity>error</severity>
					<message xml:lang="en-US">An edition must be referenced only once by this title</message>
					<message xml:lang="fr-FR">Une édition ne peut être référencée qu'une seule fois par ce livre</message>
				</osd:validation>
			</xs:appinfo>
		</xs:annotation>
		<xs:selector xpath="." />
		<xs:field xpath="printedEditions"/>
	</xs:unique>
</xs:element>

Limitations:

  1. The target of the xs:field element must be in a table.

  2. The uniqueness constraint does not apply to computed fields.

  3. The uniqueness constraint cannot be applied on multiple fields that contains an aggregated list.

  4. The uniqueness constraint cannot be applied on embedded lists.

Extended facets

EBX® provides additional constraints that are not specified in XML Schema, but that are useful for managing master data.

In order to guarantee XML Schema conformance, these extended facets are defined under the element annotation/appinfo/otherFacets.

Foreign keys

EBX® allows to create a reference to an existing table by means of a specific facet. See Foreign keys for more information.

Dynamic constraints

Dynamic constraint facets retain the semantics of XML Schema, but the value attribute is replaced with a path attribute that allows fetching the value from another element. The available dynamic constraints are:

Using these facets, the data model can be modified dynamically.

Example:

<xs:element name="amount">
	<xs:annotation>
		<xs:appinfo>
			<osd:otherFacets>
				<osd:minInclusive path="/domain/Loan/Pricing/AmountMini/amount" />
			</osd:otherFacets>
		</xs:appinfo>
	</xs:annotation>
	  ...
</xs:element>

In this example, the boundary of the facet minInclusive is not statically defined. The value of the boundary comes from the node /domain/Loan/Pricing/AmountMini/amount.

Restrictions:

FacetOResource constraint

This facet must be defined for every definition using the type osd:resource, to specify the subset of available packaged resource files as an enumeration. For more information on this type, see osd:resource type. It has the following attributes:

moduleName

Indicates, using an alias, the EBX® module that contains the resource. If the resource is contained in the current module, the alias must be preceded by "wbp". Otherwise, the alias must be one of the values defined in the element <dependencies> in the file module.xml.

resourceType

Represents the resource type that is one of the following values: 'Image', 'JavaScript', 'Style sheet', 'HTML'.

relativePath

Indicates in which directory the resources will be located. This directory must be located under the directory that corresponds to the resource type. For example, for an "Image" type resource, the directory www/common/images/, located at the same level as the directory WEB-INF/ of the target module, will be used and the relative path will have to be defined from this. Furthermore, if a resource is defined in a localized directory (www/fr/ for example), it will only be taken into account if another resource with the same name is defined in the directory www/common/.

This facet has the same behavior as an enumeration facet: the values are collected by recursively listing all the files in the local path in the specified resource type directory in the specified module.

Example:

<xs:element name="promotion" type="osd:resource">
	<xs:annotation>
		<xs:appinfo>
			<osd:otherFacets>
				<osd:FacetOResource osd:moduleName="wbp"
					osd:resourceType="ext-images" osd:relativePath="promotion/" />
			</osd:otherFacets>
		</xs:appinfo>
	</xs:annotation> 
</ xs:element>

For an overview of the standard directory structure of an EBX® module (Java EE web application), see Module structure.

Excluding values

excludeValue constraint

This facet verifies that a value is not the same as the specified excluded value.

In this example, the empty string is excluded from the allowed values.

Example:

<xs:element name="roleName">
	<xs:annotation>
		<xs:appinfo>
			<osd:otherFacets>
				<osd:excludeValue value="">
					<osd:validation> 
						<severity>error</severity>
			 			<message>Please select address role(s).</message> 
					</osd:validation>
				</osd:excludeValue>
			</osd:otherFacets>
		</xs:appinfo>
	</xs:annotation>
	<xs:simpleType type="xs:string" />
</xs:element>

excludeSegment constraint

This facet verifies that a value is not included in a range of values. Boundaries are excluded.

Example:

In this example, values between 20000 and 20999 are not allowed.

<xs:element name="zipCode">
	<xs:annotation>
		<xs:appinfo>
			<osd:otherFacets>
				<osd:excludeSegment minValue="20000" maxValue="20999">
					<osd:validation> 
						<severity>error</severity>
			 			<message>Postal code not valid.</message> 
					</osd:validation>
				</osd:excludeSegment>
			</osd:otherFacets>
		</xs:appinfo>
	</xs:annotation>
	<xs:simpleType type="xs:string" />
</xs:element>

Enumeration constraint defined using another node

Attention

This kind of constraint is obsolete. You should use foreign key constraint. It has limitations, in particular Quick search and sort operations in the user interface will use the raw value of the field instead of the labels defined through the constraint.

By default, an enumeration facet is described statically in XML Schema.

The content of an enumeration facet can also be provided dynamically by a list of simple elements in the data model.

Example:

In this example, the content of an enumeration facet is sourced from the node CountryList.

<xs:annotation>
	<xs:appinfo>
		<osd:otherFacets>
			<osd:enumeration osd:path="../CountryList" />
		</osd:otherFacets>
	</xs:appinfo>
</xs:annotation>

The referred node CountryList:

Example:

<xs:element name="FacetEnumBasedOnList">
	<xs:complexType>
		<xs:sequence>
			<xs:element name="CountryList" maxOccurs="unbounded">
				<xs:simpleType>
					<xs:restriction base="xs:string">
						<xs:enumeration value="DE" osd:label="Germany" />
						<xs:enumeration value="AT" osd:label="Austria" />
						<xs:enumeration value="BE" osd:label="Belgium" />
						<xs:enumeration value="JP" osd:label="Japan" />
						<xs:enumeration value="KR" osd:label="Korea" />
						<xs:enumeration value="CN" osd:label="China" />
					</xs:restriction>
				</xs:simpleType>
			</xs:element>
			<xs:element name="CountryChoice" type="xs:string">
				<xs:annotation>
					<xs:appinfo>
						<osd:otherFacets>
							<osd:enumeration osd:path="../CountryList" />
						</osd:otherFacets>
					</xs:appinfo>
				</xs:annotation>
			</xs:element>
		</xs:sequence>
	</xs:complexType>
</xs:element>

Programmatic facets

A programmatic constraint can be added to any XML element declaration for a simple type.

In order to guarantee XML Schema conformance, programmatic constraints are specified under the element annotation/appinfo/otherFacets.

Programmatic constraints

A programmatic constraint is defined by a Java class that implements the interface Constraint.

As additional parameters can be defined, the implemented Java class must conform to the JavaBean protocol.

Example:

In the example below, the Java class must define the methods: getParam1(), setParam1(String), getParamX(), setParamX(String), etc.

<xs:element name="amount">
	<xs:annotation>
		<xs:appinfo>
			<osd:otherFacets>
				<osd:constraint class="com.foo.CheckAmount">
					<param1>...</param1>
					<param...n>...</param...n>
				</osd:constraint>
			</osd:otherFacets>
		</xs:appinfo>
	</xs:annotation>
	...
</xs:element>

Programmatic enumeration constraints

An enumeration constraint adds an ordered list of values to a basic programmatic constraint. This facet allows selecting a value from a list. It is defined by a Java class that implements the interface ConstraintEnumeration.

Example:

<xs:element name="amount">
	<xs:annotation>
		<xs:appinfo>
			<osd:otherFacets>
				<osd:constraintEnumeration class="com.foo.CheckAmountInEnumeration">
					<param1>...</param1>
					<param...n>...</param...n>
				</osd:constraintEnumeration>
			</osd:otherFacets>
		</xs:appinfo>
	</xs:annotation>
	...
</xs:element>
Attention

Quick search and sort operations in the user interface will use the raw value of the field instead of its label. Consider whether this enumeration can be replaced by a foreign key constraint to a table that defines the same set of values.

Constraint on 'null' values

In some cases, a value is only mandatory if some conditions are satisfied, for example, if another field has a given value. In this case, the standard XML Schema attribute minOccurs is insufficient because it is static.

In order to check if a value is mandatory according to its context, the following requirements must be satisfied:

  1. A programmatic constraint must be defined by a Java class (see above).

  2. This class must implement the interface ConstraintOnNull.

  3. The XML Schema cardinality attributes must specify that the element is optional (minOccurs="0" and maxOccurs="1" ).

Note

By default, constraints on 'null' values are not checked upon user input. In order to enable a check at the input, the 'checkNullInput' property must be set. Also, if the element is terminal, the dataset must also be activated.

Example:

<xs:element name="amount" minOccurs="0" maxOccurs="1">
	<xs:annotation>
		<xs:appinfo>
			<osd:otherFacets>
				<osd:constraint class="com.foo.CheckIfNull">
					<param1>...</param1>
					<param...n>...</param...n>
				</osd:constraint>
			</osd:otherFacets>
		</xs:appinfo>
	</xs:annotation>
	...
</xs:element>

Constraints on table

A constraint on table is defined by a Java class that implements the interface ConstraintOnTable. It can only be defined on table nodes.

As additional parameters can be defined. the implemented Java class must conform to the JavaBean protocol.

Example:

In the example below, the Java class must define the methods: getParam1(), setParam1(String), getParamX(), setParamX(String), etc.

<xs:element name="myTable" type="MyTableType" minOccurs="0" maxOccurs="unbounded">
	<xs:annotation>
		<xs:appinfo>
			<osd:table>
				<primaryKeys>/key</primaryKeys>
			</osd:table>
			<osd:otherFacets>
				<osd:constraint class="com.foo.checkTable">
					<param1>...</param1>
					<param...n>...</param...n>
				</osd:constraint>
			</osd:otherFacets>
		</xs:appinfo>
	</xs:annotation>
</xs:element>
Attention

For performance reasons, constraints on tables are only checked when getting the validation report of a dataset or table. This means that these constraints are not checked when updates, such as record insertions, deletions or modifications, occur on tables. However, the internal incremental validation framework will optimize the validation cost of these constraints if dependencies are defined. For more information, see Data validation.

Control policy

Blocking and non-blocking constraints

When an update in the repository is performed, and this update adds a validation error according to a given constraint, it is possible to specify whether the new error blocks the update (and cancels the transaction) or if it is considered as non-blocking (so that the update can be committed and the error can be corrected later). The element blocksCommit within the element osd:validation allows this specification, with the following supported values:

onInsertUpdateOrDelete

Specifies that the constraint must always remain valid after an operation (dataset update, dataset deletion, record creation, update or deletion). In this case, any operation that would violate the constraint is rejected and the values remain unchanged.

This is the default and mandatory policy for primary key constraints, data type conversion constraints (an integer or a date must be well-written) and also structural constraints in mapped tables.

onUserSubmit-checkModifiedValues

Specifies that the constraint must remain valid whenever a user modifies the associated value and submits a form. In this case, any form input that would violate the constraint is rejected and the values remain unchanged.

This is the default policy for all blocking constraints mentioned in the previous case. For example, a foreign key constraint is by default not blocking (a record referred to by other records can be deleted, etc.), except in the context of a form submit.

never

Specifies that the constraint must never block operations. In this case, any operation that would violate the constraint is allowed. In the context of the user interface, this constraint does not block the form submission if the user sets a value that violates this constraint.

On foreign key constraints, the control policy that blocks all operations does not apply to filtered records. That is, a foreign key constraint is not blocking if a referenced record exists but does not satisfy a foreign key filter. In this case, updates are not rejected and a validation error occurs.

It is not possible to specify a control policy on structural constraints that are defined in mapped tables. That is, this property is not available for fixed length, maximum length, maximum number of digits, and decimal place constraints due to the validation policy of the underlying RDBMS blocking constraints.

This property does not apply to archive imports and when merging dataspaces. That is, all blocking constraints, except structural constraints, are always disabled when importing archives and merging dataspaces.

XML Schema facet

The control policy is described by the element osd:validation in annotation/appinfo under the definition of the facet.

Example:

<xs:element name="zipCode">
	<xs:simpleType>
		<xs:restriction base="xs:string">
			<xs:minInclusive value="1000">
				<xs:annotation>
					<xs:appinfo>
						<osd:validation>
							<blocksCommit>onInsertUpdateOrDelete</blocksCommit>
						</osd:validation>
					</xs:appinfo>
				</xs:annotation>
			</xs:minInclusive>
		</xs:restriction>
	</xs:simpleType>
</xs:element>

XML Schema enumeration facet

The control policy is described by the element osd:enumerationValidation in annotation/appinfo under the definition of the field.

Example:

<xs:element name="Gender">
	<xs:annotation>
		<xs:appinfo>
			<osd:enumerationValidation>
				<blocksCommit>onInsertUpdateOrDelete</blocksCommit>
			</osd:enumerationValidation>
		</xs:appinfo>
	</xs:annotation>
	<xs:simpleType>
		<xs:restriction base="xs:string">
			<xs:enumeration value="0" osd:label="male" />
			<xs:enumeration value="1" osd:label="female" />
		</xs:restriction>
	</xs:simpleType>
</xs:element>

EBX® facet

The control policy is described by the element osd:validation under the definition of the facet (which is defined in annotation/appinfo/otherFacets).

The control policy with values onInsertUpdateOrDelete and onUserSubmit-checkModifiedValues is only available on osd:excludeSegment, osd:excludeValue and osd:tableRef EBX® facets.

The control policy with the value never can be defined on all EBX® facets.

On programmatic constraints, the control policy with the value never can only be set directly during the setup of the corresponding constraint. See ConstraintContext.setBlocksCommitToNever and ConstraintContextOnTable.setBlocksCommitToNever in the Java API for more information.

Example:

<xs:element name="price" type="xs:decimal">
	<xs:annotation>
		<xs:appinfo>
			<osd:otherFacets>
				<osd:minInclusive path="../priceMin">
					<osd:validation>
						<blocksCommit>onInsertUpdateOrDelete</blocksCommit>
					</osd:validation>
				</osd:minInclusive>
			</osd:otherFacets>
		</xs:appinfo>
	</xs:annotation>
</xs:element>

Check 'null' input

According to the EBX® default validation policy, in order to allow temporarily incomplete input, a mandatory element is not checked for completion upon user input. Rather, it is verified at the dataset validation only. If completion must be checked immediately upon user input, the element must additionally specify the attribute osd:checkNullInput="true". This property is ignored if defined on an aggregated list (maxOccurs > 1).

Note

A value is mandatory if the data model specifies a mandatory element, either statically, using minOccurs="1", or dynamically, using a constraint on 'null'. For terminal elements, mandatory values are only checked for an activated dataset. For non-terminal elements, the dataset does not need to be activated.

Example:

<xs:element name="amount" osd:checkNullInput="true" minOccurs="1">
	...
</xs:element>

EBX® whitespace management for data types

According to XML Schema (see https://www.w3.org/TR/xmlschema-2/#rf-whiteSpace), whitespace handling must follow one of the procedures preserve, replace or collapse:

preserve

No normalization is performed, the value is unchanged.

replace

All occurrences of #x9 (tab), #xA (line feed) and #xD (carriage return) are replaced with #x20 (space).

collapse

After the processing according to the replace procedure, contiguous sequences of #x20 are then collapsed to a single #x20, and any leading or trailing #x20s are removed.

General whitespace handling

EBX® complies with the XML Schema recommendation:

Attention

Exceptions:

  • For fields of type osd:html or osd:password, whitespaces are always preserved and empty strings are converted to null.

  • For fields of type xs:string that define the property osd:checkNullInput="true", an empty string is interpreted as null at user input by EBX®.

Whitespace handling upon user input

The rules described in the previous section are applied in the user interface, but leading and trailing whitespaces are removed upon user input. That is, in the user interface, whitespaces are by default always trimmed upon user input. Other input methods (Import XML/CSV, Data services, API updates) are not trimmed from the user interface.

Attention

Exceptions:

  • For fields of type osd:password, whitespaces are not trimmed upon user input.

  • For foreign key fields, whitespaces are not trimmed upon user input.

It is possible to indicate in a data model that whitespaces should not be trimmed upon user input. The attribute osd:trim="disable" can be set on the fields that allow leading and trailing whitespaces upon user input.

Example:

<xs:element name="field" osd:trim="disable" type="xs:string">
	...
</xs:element>

Whitespace handling for primary keys of type string

For primary key columns of type xs:string, a default EBX® constraint is defined. This constraint forbids empty strings and non-collapsed whitespace values when creating a record. That is, any record creation that would violate this constraint is rejected.

However, if the primary key node specifies its own xs:pattern facet, this facet overrides the default EBX® constraint. For example, the specific pattern ".*" would accept any string, although this is not recommended.

The default constraint allows handling certain ambiguities. For example, it would be difficult for a user to distinguish between the following strings: "12 34" and "12  34". For generic values, this would not create conflicts, however, errors would occur for primary keys.

Empty string management

Default conversion

For nodes of type xs:string, no distinction is made at user input between an empty string and a null value. That is, an empty string value is automatically converted to null at user input.

Distinction between empty strings and 'null' value

There are certain cases where the distinction is made between an empty string and the null value, such as when:

If the distinction is made between an empty string and a null value, this implies the following behaviors:

Validation message threshold

It is possible to specify at the data model level the maximum number of validation messages allowed per constraint when performing a validation.

Example:

<xs:schema ...>
	...
	<xs:annotation>
		<xs:appinfo>
			<osd:validation>
				<validationMessageThreshold>250</validationMessageThreshold>
			</osd:validation>
		</xs:appinfo>
	</xs:annotation>
	...
</xs:schema>

The threshold is considered for each constraint defined in a data model and in each dataset validation report. When the threshold is reached by a constraint, the validation of the constraint is stopped and an error message indicating that the threshold has been reached is added to the validation report.

The validation message threshold is set by default to 1000 if it is not defined in the data model. It is not allowed to set an unlimited number of validation messages. Also, the specified validation message threshold must be greater or equal than 100.

Documentation > Developer Guide > Data model