Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Data model is one special kind of models (the other kinds are ThingModels and AppModels). Therefore it has all the properties of Models (Lifecycle of models, Model Attributes, Unique and Constraints).

...

System Attribute NameDescription
ValueThe value of the attribute is stored in "Value". This is specified by user at time of create query
Known

Applicable to ThingFacet/AppFacet - this is the value that is set within the Action. Known can not be

set using Create / Update TQL Query by the user.

VersionVersion number of the attribute. This number is automatically incremented each time the value changes.
TimestampUnix epoch time at the time (in millisecond) of the attribute creation. For example: Timestamp value
1457663102004 is same as Fri, 11 Mar 2016 02:25:02 GMT
DatetimeFormatted data time value of the attribute creation. For example:
2016-03-10 18:25:02.004
QName

Fully qualified name of the attribute. <NamSpace>.<Domain>.<ModelName>.<AttributeName>. For example

SimpleModel.MyModels.VendorInfo.vendorName given that VendorInfo is defined within

Namespace - SimpleModel, with Domain as MyModels and DataModel Name as VendorInfo

FNameGiven name of the attribute name.

...

Code Block
languagexml
titleDataModel attribute with Array
linenumberstrue
<Def Name="PostalAddress">
 <String Name="Street"/>
 <String Name="City"/>
 <String Name="Zipcode"/>
</Def>
<DataModel Name="VendorInfo">
  <Sid name="VendorSysId"/>
  <String name="vendorName"/>
  <String name="vendorTitle"/>
  <PostalAddress name="VendorAddress"/>
  <String Name="DeviceTypes" Cardinality="0..m"/>
</DataModel>

Create Data Model with Array Attribute

Code Block
languagexml
titleCreate DataModel attribute with Array
linenumberstrue
<Query>
  <Create>
    <VendorInfo>
      <vendorName>Phidget</vendorName>
      <vendorTitle>Sensor Provider</vendorTitle>
      <vendorAddress>
        <Street>123 TQL Way</Street>
        <City>Sunnyvale</City>
        <Zipcode>91234</Zipcode>
      </vendorAddress>
      <DeviceTypes>Sensors</DeviceTypes>
      <DeviceTypes>Actuators</DeviceTypes>
    </VendorInfo>
  </Create>
</Query>

Unique Constraints on DataModel

Unique Constraint defined Data Identity definition using list of attributes. Once defined the TQLEngine ensures that a combination of attribute values are unique across all objects. 

...

Code Block
languagexml
titleUnique Constraint Violation Error
linenumberstrue
<Create Status="Failure">
  <VendorInfo>
    <VendorSysId>chag3vw7tcet7dvg2athubjwl2gvth73</VendorSysId>
    <VendorName Status="Failure!UpdateConflict:Create:Record exists:integrity constraint violation: unique constraint or index violation; SYS_PK_10098 table: TR;" Value="Phidget"/>
    <VendorTitle Status="Failure!UpdateConflict:Create:Record exists:integrity constraint violation: unique constraint or index violation; SYS_PK_10098 table: TR;" Value="Sensor Provider"/>
    <VendorAddress>
      <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="Failure!UpdateConflict:Create:Record exists:integrity constraint violation: unique constraint or index violation; SYS_PK_10098 table: TR;" Value="Sunnyvale"/>
      <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>

DataModel by picking Attributes from other defined DataModel

We famously call such DataModel as "Cherry Picked DataModel". Attributes are Cherry picked from some other defined model.

...

Code Block
languagexml
titleFind Result of DataModel with Cherry picked Attributes
linenumberstrue
<Find Status="Success">
  <Result>
    <SensorVendorInfo>
      <SensorVendorSysId>chag3vw7tcet7dvg2athubjwl2gvth73</SensorVendorSysId>
      <SensorVendorName>Phidget</SensorVendorName>
    </SensorVendorInfo>
  </Result>
</Find>

DataModel by picking Attributes from other defined DataModel + newly defined Attributes

DataModel can contain both cherry picked attributes as well as new attributes. Here SensorVendorInfo contains SensorTypes as new attribute of type string.

...

Code Block
languagexml
titleFind VendorInfo Result
linenumberstrue
<Find Status="Success">
  <Result>
    <VendorInfo>
      <VendorSysId>KNTR2FJXAAAAUAABA5OUP375</VendorSysId>
      <VendorName>Phidget</VendorName>
    </VendorInfo>
  </Result>
</Find>

Selective Cherry picking using Constraint

In some cases we may want to selective pick attributes. For example, We only want Vendors with Sensor DeviceType. This can be achieved using Constraint.

...