Thingworx新建Thing的数据库表变化

为了在Thingworx的基础上建立统一的可视化平台,并且对软件产品具有自主控制权,不依赖于Thingworx软件(防止因Thingworx的升级、Bug导致的自主扩展功能受制),所以最近在研究Thingworx软件操作数据库的过程。这个过程将对自主开发的可视化平台的设计决策树产生一定影响,目前无法预料最终的用途,暂时预计将同步具有OUTPUT的Service,作为可视化图表的数据来源。

方法:

方法很简单,首先pgdump把数据库导出成sql,加入到git或者svn版本控制中。然后在Thingworx中对各类对象进行操作,操作后再次导出sql并覆盖上一次导出文件,通过git或svn观察文件的变化。

1、新建Thing

我新建了一个Database的Thing,并建立了一个Service。

有三张表发生了变化,分别是model_index,thing_model,user_model_properties。

model_index记录的是Thing的名称类别等基本信息,从名字也可以看出,是在Things列表和查询中作为索引记录使用的。

thing_model中是Thing中所有的信息,包括其配置信息(比如Database需要配置jdbc连接信息)和服务信息,所有的数据以JSON格式展现,存在一行数据中。

user_model_properties中存的是Thing的自然信息,即Information页的内容,但是建了两个Thing,数据却在一行,暂时不明白其规则。

 

 

再来分析一下具体内容

Thing名字是ThingName,所以model_index有了一条新数据

entity_name:ThingName

entity_type:2401 (还不知道这个值从哪来)

last_modified_time:2018-03-08 09:09:08.955 类别是时间戳

entity_id:ThingName#Thing

还有几个值我没有填,所以数据库中没有显示,但是很容易理解,由于暂时不涉及接下来做的事,所以暂时不做研究。

注意description这个字段并不是Documentation中填的内容。

 

今天还发现system_ownership也发生了变化,会记录每一次IP发生变化时的登录信息,和要做的事暂时没有关系。

 

thing_model记录了Thing的所有信息

className:指向了实际操作了类,应该是ThingTemplate的实现类(ThingTemplate相当于类或接口,实际上是一个类)。DataBase类别的Thing指向了com.thingworx.things.database.DatabaseSystem

configurationChanges:是记录变化的json数据,不知道这部分数据是不是仅用作于审计,是否有系统业务意义有待考证。

documentationContent:在info页面的备注存在该字段下

designTimePermissions:看字段和时间和授权同时有关联,"{"Read":[],"Delete":[],"Create":[],"Metadata":[],"Update":[]}",不知道具体的数组数据里是怎么影响系统功能的。

ThingShape:包括了Service定义等内容

"{
    "propertyDefinitions": {
        
    },
    "subscriptions": {
        
    },
    "eventDefinitions": {
        
    },
    "serviceImplementations": {
        "ThingService": {
            "name": "ThingService",
            "description": "",
            "handlerName": "Script",
            "configurationTables": {
                "Script": {
                    "isMultiRow": false,
                    "name": "Script",
                    "description": "Script",
                    "rows": [
                        {
                            "code": "var result='Hello World'"
                        }
                    ],
                    "ordinal": 0,
                    "dataShape": {
                        "fieldDefinitions": {
                            "code": {
                                "name": "code",
                                "aspects": {
                                    
                                },
                                "description": "code",
                                "baseType": "STRING",
                                "ordinal": 0
                            }
                        }
                    }
                }
            }
        },
        "SysUserService": {
            "name": "SysUserService",
            "description": "",
            "handlerName": "SQLQuery",
            "configurationTables": {
                "Query": {
                    "isMultiRow": false,
                    "name": "Query",
                    "description": "SQLQuery",
                    "rows": [
                        {
                            "maxItems": 500.0,
                            "timeout": 60.0,
                            "sql": "select * from sys_user"
                        }
                    ],
                    "ordinal": 0,
                    "dataShape": {
                        "fieldDefinitions": {
                            "maxItems": {
                                "name": "maxItems",
                                "aspects": {
                                    
                                },
                                "description": "maxItems",
                                "baseType": "NUMBER",
                                "ordinal": 0
                            },
                            "timeout": {
                                "name": "timeout",
                                "aspects": {
                                    
                                },
                                "description": "timeout",
                                "baseType": "NUMBER",
                                "ordinal": 0
                            },
                            "sql": {
                                "name": "sql",
                                "aspects": {
                                    
                                },
                                "description": "sql",
                                "baseType": "STRING",
                                "ordinal": 0
                            }
                        }
                    }
                }
            }
        }
    },
    "serviceMappings": {
        
    },
    "serviceDefinitions": {
        "ThingService": {
            "isAllowOverride": false,
            "isOpen": false,
            "sourceType": "Unknown",
            "parameterDefinitions": {
                
            },
            "name": "ThingService",
            "aspects": {
                "isAsync": false
            },
            "isLocalOnly": false,
            "description": "",
            "isPrivate": false,
            "sourceName": "",
            "category": "",
            "resultType": {
                "name": "result",
                "aspects": {
                    
                },
                "description": "",
                "baseType": "STRING",
                "ordinal": 0
            }
        },
        "SysUserService": {
            "isAllowOverride": false,
            "isOpen": false,
            "sourceType": "Unknown",
            "parameterDefinitions": {
                
            },
            "name": "SysUserService",
            "aspects": {
                "isAsync": false
            },
            "isLocalOnly": false,
            "description": "",
            "isPrivate": false,
            "sourceName": "",
            "category": "",
            "resultType": {
                "name": "result",
                "aspects": {
                    
                },
                "description": "",
                "baseType": "INFOTABLE",
                "ordinal": 0
            }
        }
    }
}"

 

configurationTables:这里包括了对Database抽象类里关于数据库连接的实现,对应Thing下的Configuration。

{
    "ConnectionInfo": {
        "isMultiRow": false,
        "name": "ConnectionInfo",
        "description": "JDBC Settings",
        "rows": [
            {
                "connectionValidationString": "SELECT NOW()",
                "password": "vjK5R/V7oLTlC4xca7EDCQ==",
                "jDBCConnectionURL": "jdbc:postgresql://localhost:5432/iot",
                "userName": "postgres",
                "jDBCDriverClass": "org.postgresql.Driver",
                "maxConnections": 5.0
            }
        ],
        "ordinal": 0,
        "dataShape": {
            "fieldDefinitions": {
                "connectionValidationString": {
                    "name": "connectionValidationString",
                    "aspects": {
                        "defaultValue": "SELECT NOW()"
                    },
                    "description": "Connection test string/query",
                    "baseType": "STRING",
                    "ordinal": 2
                },
                "password": {
                    "name": "password",
                    "aspects": {
                        "friendlyName": "Database Password"
                    },
                    "description": "Database password",
                    "baseType": "PASSWORD",
                    "ordinal": 5
                },
                "jDBCConnectionURL": {
                    "name": "jDBCConnectionURL",
                    "aspects": {
                        "defaultValue": "jdbc:mydb:/server:port/database?param=value",
                        "friendlyName": "JDBC Connection String"
                    },
                    "description": "JDBC Connection URL",
                    "baseType": "STRING",
                    "ordinal": 1
                },
                "userName": {
                    "name": "userName",
                    "aspects": {
                        "friendlyName": "Database User Name"
                    },
                    "description": "Database user name",
                    "baseType": "STRING",
                    "ordinal": 4
                },
                "jDBCDriverClass": {
                    "name": "jDBCDriverClass",
                    "aspects": {
                        "defaultValue": "com.yourdatabase.yourDriver",
                        "friendlyName": "JDBC Driver Class Name"
                    },
                    "description": "JDBC Driver Class Name",
                    "baseType": "STRING",
                    "ordinal": 0
                },
                "maxConnections": {
                    "name": "maxConnections",
                    "aspects": {
                        "defaultValue": 5.0,
                        "friendlyName": "Maxium Number of Connections"
                    },
                    "description": "Maximum number of connections in the pool",
                    "baseType": "NUMBER",
                    "ordinal": 3
                }
            }
        }
    },
    "ConnectionMonitoring": {
        "isMultiRow": false,
        "name": "ConnectionMonitoring",
        "description": "Connection Monitoring Settings",
        "rows": [
            {
                "retryDelay": 2000.0,
                "connectionMonitorRate": 30000.0,
                "numberOfRetries": 1.0,
                "enableMonitor": false
            }
        ],
        "ordinal": 0,
        "dataShape": {
            "fieldDefinitions": {
                "retryDelay": {
                    "name": "retryDelay",
                    "aspects": {
                        "defaultValue": 2000.0,
                        "friendlyName": "Retry Delay (milliseconds)"
                    },
                    "description": "Retry delay in milliseconds",
                    "baseType": "NUMBER",
                    "ordinal": 3
                },
                "connectionMonitorRate": {
                    "name": "connectionMonitorRate",
                    "aspects": {
                        "defaultValue": 30000.0,
                        "friendlyName": "Monitor Rate (seconds)"
                    },
                    "description": "Monitor rate in milliseconds",
                    "baseType": "NUMBER",
                    "ordinal": 1
                },
                "numberOfRetries": {
                    "name": "numberOfRetries",
                    "aspects": {
                        "defaultValue": 1.0,
                        "friendlyName": "Number of Retries"
                    },
                    "description": "Number of retries",
                    "baseType": "NUMBER",
                    "ordinal": 2
                },
                "enableMonitor": {
                    "name": "enableMonitor",
                    "aspects": {
                        "defaultValue": false,
                        "friendlyName": "Enable Monitoring"
                    },
                    "description": "Enable connection monitoring",
                    "baseType": "BOOLEAN",
                    "ordinal": 0
                }
            }
        }
    },
    "ColumnAliases": {
        "isMultiRow": true,
        "name": "ColumnAliases",
        "description": "Field/Column Name Aliases",
        "rows": [],
        "ordinal": 1,
        "dataShape": {
            "fieldDefinitions": {
                "fieldName": {
                    "name": "fieldName",
                    "aspects": {
                        "friendlyName": "Thingworx Field Name"
                    },
                    "description": "Thingworx field name",
                    "baseType": "STRING",
                    "ordinal": 1
                },
                "columnName": {
                    "name": "columnName",
                    "aspects": {
                        "friendlyName": "Database Column Name"
                    },
                    "description": "Database column name",
                    "baseType": "STRING",
                    "ordinal": 0
                }
            }
        }
    }
}

 

posted @ 2018-03-08 09:54  明月出天山  阅读(842)  评论(0编辑  收藏  举报