...
In this example Unique is declared for the attribute VendorName.
Code Block |
---|
language | xmlruby |
---|
theme | Emacs |
---|
title | Unique Constraint on Attribute LightNumber |
---|
linenumbers | true |
---|
|
<DataModel Name=#
DataModel(name: "VendorInfo">):
<Sid Sid(name=: "VendorSysId"/>)
<String name=String(name: "VendorName"/>)
<String name=String(name: "VendorTitle"/>)
<PostalAddress name=PostalAddress(name: "VendorAddress"/>)
<String Name=String(name: "DeviceTypes", Cardinality=: "0..m"/>)
<Unique Name=Unique(name: "UniqueVendorName", Value=: "VendorName"/>
</DataModel>) |
If you try to create more than one VendorInfo with the same VendorName for the model, the Create TQL Query will fail with Unique constraint violation
Code Block |
---|
language | ruby |
---|
theme | xmlEmacs |
---|
title | Unique Constraint Violation Error |
---|
linenumbers | true |
---|
|
<Create#
Create(Status=: "Failure">):
VendorInfo: <VendorInfo>
<VendorSysId>chag3vw7tcet7dvg2athubjwl2gvth73</VendorSysId>VendorSysId: chag3vw7tcet7dvg2athubjwl2gvth73/VendorSysId:
<VendorName VendorName(Status=: "Failure!UpdateConflict:Create:Record exists:integrity constraint violation: unique constraint or index violation; SYS_PK_10098 table: TR;", Value=: "Phidget"/>)
<VendorTitle Status=VendorTitle(Status: "Failure!UpdateConflict:Create:Record exists:integrity constraint violation: unique constraint or index violation; SYS_PK_10098 table: TR;", Value=: "Sensor Provider"/>)
<VendorAddress>VendorAddress:
<Street Street(Status=: "Failure!UpdateConflict:Create:Record exists:integrity constraint violation: unique constraint or index violation; SYS_PK_10098 table: TR;", Value=: "123 TQL Way"/>)
<City Status=City(Status: "Failure!UpdateConflict:Create:Record exists:integrity constraint violation: unique constraint or index violation; SYS_PK_10098 table: TR;", Value=: "Sunnyvale"/>)
<Zipcode Status=Zipcode(Status: "Failure!UpdateConflict:Create:Record exists:integrity constraint violation: unique constraint or index violation; SYS_PK_10098 table: TR;", Value=: "91234"/>
</VendorAddress>
</VendorInfo>
</Create>) |
Inline Constraint
Inline Constraint is a constraint written as an XML attribute, and directly apply to the element to which it belongs. Inline Constraint can be of any subtype of Constraint.
...
For example:
Code Block |
---|
language | ruby |
---|
theme | xmlEmacs |
---|
title | Inline Constraint example |
---|
linenumbers | true |
---|
|
<Def#
Def(name=: "Manager", inherits=: "Employee">):
<String String(name=: "Employment.BusinnesRole", default=: "manager", eq=: "manager", cardinality=: "1", modifiers=: "hidden,readonly"/>
</Def>) |
Standalone Constraint
Constraint can be defines a block under model definition.
Code Block |
---|
language | ruby |
---|
theme | xmlEmacs |
---|
title | Inline Constraint example |
---|
linenumbers | true |
---|
|
<Def#
Def(name=: "Janitor", inherits=: "Employee">):
<Constraint Constraint(target=: "Employment.BusinnesRole", eq=: "janitor"/>
</Def>
)
|
Nested Constraint
Constraints can be nested by using And, Or and XoR constructs.
Code Block |
---|
language | ruby |
---|
theme | xmlEmacs |
---|
title | Inline Constraint example |
---|
linenumbers | true |
---|
|
<DataModel#
name='OlegOrder'>DataModel(name: "OlegOrder"):
<Attribute name='Owner' value='Order.Owner'>Attribute(name: "Owner", value: "Order.Owner"):
<And>And:
<OR>OR:
<EQEQ value='Oleg'/>: "Oleg")
<EQEQ value='Michael'/>: "Michael")
</OR>OR:
<OR> EQ <EQ target='ShippingCost' value='10.2'/>target: "ShippingCost", value: "10.2")
<EQEQ target='TotalCost' value=': "TotalCost", value: "20.2'/>")
Attribute </OR>
</And>
</Attribute>
<Attribute name='ShippingCost' value='Order.ShippingCost'/>name: "ShippingCost", value: "Order.ShippingCost")
<AttributeAttribute name='TotalCost' value='Order.TotalCost'/>
</DataModel>
: "TotalCost", value: "Order.TotalCost")
|