Package com.thingworx.metadata
Class DataShapeDefinition
- java.lang.Object
-
- com.thingworx.types.NamedObject
-
- com.thingworx.metadata.DataShapeDefinition
-
- All Implemented Interfaces:
IDiffableObject
,INamedObject
,java.io.Serializable
,java.lang.Cloneable
@ThingworxExtensionApiClass(since={6,6}, canInstantiate=true) public final class DataShapeDefinition extends NamedObject implements java.lang.Cloneable
Used to define fields for all data that is managed within ThingWorx. This includes, but is not limited to, all persisted data, transient data, and data in transit.
DataShapeDefinition
is used in the underpinnings ofDataShape
s,InfoTable
s, andStreamThing
s, as well as numerous other classes both directly and indirectly.A
DataShapeDefinition
is ultimately a wrapper around aFieldDefinitionCollection
with some additional methods for matching, cloning, and analysis.- See Also:
FieldDefinitionCollection
,DataShape
,InfoTable
, Serialized Form
-
-
Field Summary
-
Fields inherited from class com.thingworx.types.NamedObject
NAME_COMPARATOR
-
-
Constructor Summary
Constructors Constructor Description DataShapeDefinition()
Constructs a new empty data shape definition.DataShapeDefinition(FieldDefinitionCollection fields)
Constructs a data shape definition containing a predefined collection of fields.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addFieldDefinition(FieldDefinition field)
Adds a new field definition to this data shape definition.DataShapeDefinition
clone()
Creates a deep clone of this data shape definition.static DataShapeDefinition
fromJSON(org.json.JSONObject jsonObject)
Deprecated.FieldDefinition
getFieldDefinition(java.lang.String name)
Returns the field definition with the specified name.FieldDefinitionCollection
getFields()
Returns the collection of field definitions belonging to this data shape definition.boolean
hasField(java.lang.String name)
Tests if the field named exists in this definition.boolean
hasPrimaryKey()
Tests if this definition contains any fields that are designated as primary keys.boolean
matches(DataShapeDefinition ds1)
Determines if this data shape definition has the same fields with the same base types as the provided data shape definition.void
setFields(FieldDefinitionCollection fields)
Replaces the fields belonging to this data shape definition with the fields provided in the specified collection.org.json.JSONObject
toJSON()
Deprecated.no replacement-
Methods inherited from class com.thingworx.types.NamedObject
getDescription, getName, setDescription, setName, toValueCollection
-
-
-
-
Constructor Detail
-
DataShapeDefinition
@ThingworxExtensionApiMethod(since={6,6}) public DataShapeDefinition()
Constructs a new empty data shape definition.
-
DataShapeDefinition
@ThingworxExtensionApiMethod(since={6,6}) public DataShapeDefinition(FieldDefinitionCollection fields)
Constructs a data shape definition containing a predefined collection of fields.- Parameters:
fields
- the fields that will belong to this data shape definition
-
-
Method Detail
-
hasField
@ThingworxExtensionApiMethod(since={6,6}) public boolean hasField(java.lang.String name)
Tests if the field named exists in this definition.- Parameters:
name
- the name of the field- Returns:
true
if the field exists in this definition
-
hasPrimaryKey
@ThingworxExtensionApiMethod(since={6,6}) public boolean hasPrimaryKey()
Tests if this definition contains any fields that are designated as primary keys.- Returns:
true
if any field belonging to this definition is a primary key,false
if none of the fields are primary keys or no fields exist in this definition
-
addFieldDefinition
@ThingworxExtensionApiMethod(since={6,6}) public void addFieldDefinition(FieldDefinition field)
Adds a new field definition to this data shape definition.- Parameters:
field
- the field definition to add
-
getFieldDefinition
@ThingworxExtensionApiMethod(since={6,6}) public FieldDefinition getFieldDefinition(java.lang.String name)
Returns the field definition with the specified name.- Parameters:
name
- the name of the field to return- Returns:
- the specified field definition, or
null
if the field does not exist
-
getFields
@ThingworxExtensionApiMethod(since={6,6}) public FieldDefinitionCollection getFields()
Returns the collection of field definitions belonging to this data shape definition.- Returns:
- the collection of field definitions belonging to this data shape definition
-
setFields
@ThingworxExtensionApiMethod(since={6,6}) public void setFields(FieldDefinitionCollection fields)
Replaces the fields belonging to this data shape definition with the fields provided in the specified collection.- Parameters:
fields
- the field definitions to assign to this data shape definition
-
clone
@ThingworxExtensionApiMethod(since={6,6}) public DataShapeDefinition clone()
Creates a deep clone of this data shape definition. All of the field definitions belonging to this object are also cloned.- Overrides:
clone
in classjava.lang.Object
- Returns:
- a clone of this data shape definition
-
matches
@ThingworxExtensionApiMethod(since={6,6}) public boolean matches(DataShapeDefinition ds1)
Determines if this data shape definition has the same fields with the same base types as the provided data shape definition.- Parameters:
ds1
- the data shape defintion to compare against this one- Returns:
true
if the data shape definitions have the same fields (ignoring aspects)
-
fromJSON
@Deprecated @ThingworxExtensionApiMethod(since={6,6}, deprecatedSince={8,4}) public static DataShapeDefinition fromJSON(org.json.JSONObject jsonObject) throws java.lang.Exception
Deprecated.
Parses a serialized data shape definition as a JSON object. The JSON object must contain a mapping for the field definitions in order to be valid.- Parameters:
jsonObject
- the JSON object containing the serialized data shape definition- Returns:
- the resultant data shape definition
- Throws:
java.lang.Exception
- if the contents of the JSON object do not match the expected format
-
toJSON
@Deprecated @ThingworxExtensionApiMethod(since={6,6}, deprecatedSince={8,4}) public org.json.JSONObject toJSON() throws java.lang.Exception
Deprecated.no replacement
Serializes this data shape definition into JSON format. The resulting JSON object will contain the full list of field definitions belonging to this data shape definition.- Returns:
- a JSON object describing this data shape definition
- Throws:
java.lang.Exception
- a JSON exception occurs during serialization
-
-