Versions Compared

Key

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

...

Simple reference is defined using name and type modifier. The data associations between two models is automatically done via SID. 

Code Block
languagexmlruby
themeEmacs
titleSample Reference Attribute Definition
linenumberstrue
<Reference#
Reference(cardinality=: "1..1", name=: "reference name", type=: "name of model/def"/>)

In this example thingCat is a reference attribute of VendorInfo. thingCat References 1 (cardinality is 1) instance of ThingCategory. The value of thingCat must be the SID of the ThingCategory instance.

Code Block
languagexmlruby
themeEmacs
titleUnique Constraint Violation Error
linenumberstrue
<DataModel#
DataModel(Name=: "VendorInfo">):
      <Sid Name=Sid(Name: "vendorId"/>)
      <String Name=String(Name: "vendorName"/>)
      <String Name=String(Name: "vendorCity"/>)
      <ReferenceReference cardinality=: "1..1", Name: name="thingCat", type=: "ThingCategory"/>
</DataModel>
<DataModel Name=)
DataModel(Name: "ThingCategory">):
      <Sid Name=Sid(Name: "thingCatID"/>)
      <String Name=String(Name: "catList", cardinality=: "1..n"/>)
</DataModel>

# <!-- Let's Create few Thing Categories.
-->Query: <Query>
  <DeleteAll>DeleteAll: 
    <ThingCategory>ThingCategory: 
     <thingCatID thingCatID(ne=: ""/>)
  Create: 
</ThingCategory>   </DeleteAll>  ThingCategory: <Create>
    <ThingCategory>       <catList>
        SensorscatList: "Sensors"
  Create: 
  </catList>  ThingCategory: 
 </ThingCategory>   </Create>   <Create>
    <ThingCategory>
      <catList>
        ActuatorscatList: "Actuators"
  Create: 
  </catList>     </ThingCategory>ThingCategory: 
 </Create>   <Create>     <ThingCategory>
      <catList>
        SensorscatList: "Sensors"
      </catList>
      <catList>
        ActuatorscatList: "Actuators"
      </catList>
      <catList>
        GatewayscatList: "Gateways"


    </catList>
    </ThingCategory>
  </Create>
</Query>


<!-- # Now create VendorInfo with ThingCategory SID Value
-->Query: <Query>
  <Create>Create: 
   <VendorInfo> VendorInfo: 
    <vendorId>         vendorAvendorId: "vendorA"
      </vendorId>
      <vendorName>
        PhidgetvendorName: "Phidget"
      </vendorName>
      <vendorCity>
        CalgaryvendorCity: "Calgary"
      </vendorCity>
      <thingCat>
        LOBF4FOGAAAX6AAAAGEWWHEH
      </thingCat>
    </VendorInfo>
  </Create>
</Query>


<!-- thingCat: "LOBF4FOGAAAX6AAAAGEWWHEH"

# Let's do a Find on VendorInfo with nested *
-->Query: <Query>
  <Find format=Find(format: "all", nested=: "*">):
    <VendorInfo>VendorInfo: 
     <vendorId vendorId(ne=: ""/>)

   </VendorInfo>
  </Find>
</Query>


<!-- # Response to the Find
-->
<Find Status=Find(Status: "Success", Format=: "all">):
    <Result>Result: 
       <VendorInfo VendorInfo(QName=: "Atomiton.Sensors.VendorInfo">):
            <vendorId>vendorA</vendorId>vendorId: "vendorA" 
           <thingCat thingCat(Known=: "LOBF4FOGAAAX6AAAAGEWWHEH", Version=: "1", Timestamp=: "1492540919704", DateTime=: "2017-04-18 11:41:59.704", QName=: "Atomiton.Sensors.VendorInfo.thingCat", FName=: "thingCat">):
                <Value QName=Value(QName: "Atomiton.Sensors.ThingCategory">):
                     <thingCatID>LOBF4FOGAAAX6AAAAGEWWHEH</thingCatID>thingCatID: "LOBF4FOGAAAX6AAAAGEWWHEH" 
                   <catList catList(Value=: "Sensors", Known=: "Sensors", Order=: "0x00", Version=: "1", Timestamp=: "1492540855750", DateTime=: "2017-04-18 11:40:55.75", QName=: "Atomiton.Sensors.ThingCategory.catList", FName=: "catList"/>)
                    <catList Value=catList(Value: "Actuators", Known=: "Actuators", Order=: "0x01", Version=: "1", Timestamp=: "1492540855751", DateTime=: "2017-04-18 11:40:55.751", QName=: "Atomiton.Sensors.ThingCategory.catList", FName=: "catList"/>)
                    <catList Value=catList(Value: "Gateways", Known=: "Gateways", Order=: "0x02", Version=: "1", Timestamp=: "1492540855751", DateTime=: "2017-04-18 11:40:55.751", QName=: "Atomiton.Sensors.ThingCategory.catList", FName=: "catList"/>)
                </Value>
            </thingCat>
            <vendorCity Value=vendorCity(Value: "Calgary", Known=: "Calgary", Version=: "1", Timestamp=: "1492540919704", DateTime=: "2017-04-18 11:41:59.704", QName=: "Atomiton.Sensors.VendorInfo.vendorCity", FName=: "vendorCity"/>)
            <vendorName Value=vendorName(Value: "Phidget", Known=: "Phidget", Version=: "1", Timestamp=: "1492540919704", DateTime=: "2017-04-18 11:41:59.704", QName=: "Atomiton.Sensors.VendorInfo.vendorName", FName=: "vendorName"/>
        </VendorInfo>
    </Result>
</Find>)

Smart Reference

In case of simple references the find result can automatically return the nested references (i.e. SIDs of other instances) can be automatically expanded into their referent instances.

...

  • Find queries can be defined either as reference attribute values (i.e. find query content is stored as a string reference attribute value) or defined in the model like below. usageInfo is a smart reference attribute defined to contain all data in UsageInformation model for the given day's activity.

Code Block
languagexmlruby
themeEmacs
titleSmart Reference Defined during Model definition
linenumberstrue
<DataModel#
DataModel Name=: "SmartMeterUsageVendorInfo">):
      <SidSid Name=: "IdvendorId"/>)
      <StringString Name=: "dayActivityIdvendorName"/>)
      <DoubleString Name=: "totalEnergyConsumptionvendorCity"/>)
      Reference <Referencecardinality: Format="$ObjectFormat(xml)" Name="usageInfo" Type="SMeterUsageInformation">
  "1..1", name: "thingCat", type: "ThingCategory")
DataModel Name: "ThingCategory"):
     <Find> Sid Name: "thingCatID")
      String <UsageInformation>
  Name: "catList", cardinality: "1..n")


# Let's Create few Thing Categories.
Query: <actualUsageId>
  DeleteAll: 
          [:ID:]ThingCategory: 
      thingCatID(ne: "")
  Create: </actualUsageId>
      ThingCategory: 
  </UsageInformation>    catList: "Sensors"
  Create: </Find>
    ThingCategory: 
</Reference>     </DataModel> <DataModelcatList: Name="SMeterUsageInformationActuators">
  Create: 
  <Sid Name="Id"/>
 ThingCategory: 
    <String Name="activityId"/>
      <String Name="actualUsageId"/> catList: "Sensors"
      <DateTime Format="$SimpleDateFormat(yyyy-MM-dd'T'HH:mm:ss.SSS'Z')" Name="Timestamp"/>catList: "Actuators"
      <DoublecatList: Name="energyGateways"/>


# Now create VendorInfo <Double Name="load"/>
    </DataModel>


<!-- Find Query -->
<Query>
  <Find nested="*" format="order">with ThingCategory SID Value
Query: 
  Create: 
    VendorInfo: <SmartMeterUsage>
      <IDvendorId: ne="vendorA"/>
    </SmartMeterUsage>   </Find>
</Query>vendorName: "Phidget"
   <!-- Find Result -->
<Find Status="Success" Format="order"> vendorCity: "Calgary"
     <Result> thingCat: "LOBF4FOGAAAX6AAAAGEWWHEH"


# Let's do a <SmartMeterUsage>Find on VendorInfo with nested *
Query: 
  Find(format: "all",  <Id>LPFSJ4C3AAAH6AAAAGU6SHHK</Id>nested: "*"):
    VendorInfo: 
      <totalEnergyConsumption Value="100.0"/>vendorId(ne: "")


# Response to the Find
Find(Status:     <usageInfo Order="0x00">"Success", Format: "all"):
    Result: 
        VendorInfo(QName:  <Value>"Atomiton.Sensors.VendorInfo"):
            vendorId: vendorA 
      <Id>LPFSJ4C3AAAX6AAAAHCPOI6Q</Id>      thingCat(Known: "LOBF4FOGAAAX6AAAAGEWWHEH", Version: "1",            <load Value="30.0"/>
                    <Timestamp Value=Timestamp: "1492540919704", DateTime: "2017-04-14T0718 11:2441:5859.263Z704"/>
                    <actualUsageId Value="LPFSJ4C3AAAH6AAAAGU6SHHK"/>
                    <activityId Value="TestActivity"/>, QName: "Atomiton.Sensors.VendorInfo.thingCat", FName: "thingCat"):
                    <energy Value="20.0"/>Value(QName: "Atomiton.Sensors.ThingCategory"):
                </Value>    thingCatID: "LOBF4FOGAAAX6AAAAGEWWHEH"
           <Value>         catList(Value: "Sensors", Known: "Sensors", Order: "0x00", Version:      <Id>LPFSJ4C4AAAH6AAAAEYSWQKW</Id>
                    <load Value="30.0"/>
                    <Timestamp Value="1", Timestamp: "1492540855750", DateTime: "2017-04-14T0718 11:2440:5855.265Z75"/>, QName:                    <actualUsageId Value="LPFSJ4C3AAAH6AAAAGU6SHHK"/>"Atomiton.Sensors.ThingCategory.catList", FName: "catList")
                    <activityId Value="TestActivity"/>
                    <energy Value="20.0"/>
 catList(Value: "Actuators", Known: "Actuators", Order: "0x01", Version: "1", Timestamp: "1492540855751", DateTime: "2017-04-18 11:40:55.751", QName: "Atomiton.Sensors.ThingCategory.catList", FName: "catList")
              </Value>      catList(Value: "Gateways", Known: "Gateways", Order: "0x02", Version:     <Value>
                    <Id>LPFSJ4C4AAAX6AAAAF4TIFYW</Id>
                    <load Value="30.0"/>
                    <Timestamp Value="1", Timestamp: "1492540855751", DateTime: "2017-04-14T0718 11:2440:5855.266Z751"/>, QName: "Atomiton.Sensors.ThingCategory.catList", FName: "catList")
                <actualUsageId Value="LPFSJ4C3AAAH6AAAAGU6SHHK"/>
                    <activityId Value="TestActivity"/>
                    <energy Value="20.0"/>
                </Value>
                <Value>
                    <Id>LPFSJ4C4AABH6AAAAGAQH5K5</Id>
                    <load Value="30.0"/>
                    <Timestamp Value="2017-04-14T07:24:58.266Z"/>
   vendorCity(Value: "Calgary", Known: "Calgary", Version: "1", Timestamp: "1492540919704", DateTime: "2017-04-18 11:41:59.704", QName: "Atomiton.Sensors.VendorInfo.vendorCity", FName: "vendorCity")
            vendorName(Value: "Phidget", Known:  <actualUsageId Value="LPFSJ4C3AAAH6AAAAGU6SHHK"/>
                    <activityId Value="TestActivity"/>
                    <energy Value="20.0"/>
                </Value>
            </usageInfo>
            <activityId Value="TestActivity"/>
        </SmartMeterUsage>
    </Result>
</Find>"Phidget", Version: "1", Timestamp: "1492540919704", DateTime: "2017-04-18 11:41:59.704", QName: "Atomiton.Sensors.VendorInfo.vendorName", FName: "vendorName")


Find result set with smart references

...