ProcessDB实时/时序数据库——JAVA_API操作数据点对象

一、数据点字段介绍

	int pointId = 0;// 数据点ID

	int tableId; //数据表ID

	String pointName; //数据点名称

	boolean   isReffer;//是否引用其他数据点

	int   refferObjectId;//引用其他数据点ID

	byte pointType; // 数据点类型 REAL / STAT / CAL

    byte priority; // 数据点优先级
    
    byte dataType; // 数据点存储值类型 例如FLOAT32
	
	String pointDesc; // 数据点描述
	
	byte archived; // 是否保存历史数据

	byte ioType; // IO类型 0为输入 1为输出 2为中间变量 3为网关

    byte spaceCompress; //空间维度 1是差值压缩,2是数据块压缩,3是两者全选
    
    byte timeUnit; //分辨率 0是秒 1是毫秒 2是微秒
    
	String unit; // 单位	

	float initValue; // 数据点初始值

	float bottomScale; // 量程低限

	float topScale; // 量程高限

	float alarmLow; // 告警低限

	float alarmHigh; // 告警高限

	float deviation; // 量程数值,默认0.05

	short forceSaveInterval; // 强制存历史数据时间
	
	byte format; // 小数精度 例如数据类型为int,则没有小数精度
	
	byte devType; // 按量程百分比是0 ,按量程物理值是1

	byte compress; // 时间维度 0是deadband死区压缩, 1是linuar线性压缩, 2是None无压缩

	short timeoutInterval; // 超时时间
    
	int creatorId; // 数据点创建人ID

    int createTime; // 数据点创建时间
    
	short period; // 计算周期 计算点专属属性

	String expression; // 计算公式 计算点专属属性

    byte  alarmSwitch;  //是否告警 0:不告警  1: 告警

    byte  alarmAckType;    //告警类型 0:  手动  1:自动

    byte  alarmType;       // 1:死区报警 2:超时报警 3:ON报警 4:OFF报警 5:变化报警

    byte  alarmLevel;    //告警级别 none是0  一级是1 二级是2 三级是3 四级是4

    float  alarmHH;        //告警高高限

    float  alarmLL;        //告警低低限

    int    alarmGroupId;   //告警分组id

    String tableFullName;  //数据点所属的数据库加数据表的名称(例如PUBLIC.SYS)

	private String databaseName;//数据点所属数据库名称

	private String tableName;//数据点所属数据表名称

二、新建数据点

import com.processdb.connection.DBConnect;
import com.processdb.connection.DBConnectManager;
import com.processdb.connection.DBRoot;
import com.processdb.connection.DBTable;
import com.processdb.connection.DBase;
import com.processdb.driver.common.ConnectInfo;
import com.processdb.driver.common.ConstantValue;
import com.processdb.driver.common.PointInfo;
public class Test {
	 public static void main(String[] args) throws Exception
	    {
	    	ConnectInfo host = new ConnectInfo();
	    	host.setConnectName("instance01");
	    	host.setHostName("127.0.0.1");
	    	host.setHostPort(8301);
	    	host.setUserName("root");
	    	host.setPassword("root");
	    	host.setCacheable(false);
	    	DBConnect myConn = null;
			myConn = DBConnectManager.getInstance().getConnect(host);
            DBRoot root = DBRoot.getInstance(myConn);
			String dbname ="D30";
			DBase dBase = root.getCachedDatabaseByName(dbname);
			String tableName ="T31";
			DBTable dbtable = dBase.getCachedTableByName(tableName);
			String pointName = "P30";
			PointInfo pointInfo = new PointInfo();
			pointInfo.setPointType(ConstantValue.POINT_PHY);
			pointInfo.setDataType(ConstantValue.TAG_TYPE_FLOAT32);
			pointInfo.setUnit("N/A");
			pointInfo.setBottomScale(0);
			pointInfo.setTopScale(100);
			pointInfo.setAlarmLow(0);
			pointInfo.setAlarmHigh(100);
			pointInfo.setPointName(pointName);
			pointInfo.setArchived(ConstantValue.POINT_ARCHIVED_YES);
			pointInfo.setIOType(ConstantValue.IO_TYPE_INPUT);
			pointInfo.setCompress(ConstantValue.POINT_COMPRESS_DEAD);
			pointInfo.setDevType(ConstantValue.POINT_DEVTYPE_PERCENT);
			pointInfo.setDeviation(0);
			pointInfo.setExpression("");
		    pointInfo.setTableName(dbtable.getName());
		    int res = dbtable.add(pointInfo);
			if(res != 0)
			{
				System.out.print("Create point failed, error code: " + res);
				return;
			}
			else
			{
				System.out.print("Create point success.");
			}

}}

三、删除数据点

import com.processdb.connection.DBConnect;
import com.processdb.connection.DBConnectManager;
import com.processdb.connection.DBPoint;
import com.processdb.connection.DBRoot;
import com.processdb.connection.DBTable;
import com.processdb.connection.DBase;
import com.processdb.driver.common.ConnectInfo;
public class Test {
	 public static void main(String[] args) throws Exception
	    {
	    	ConnectInfo host = new ConnectInfo();
	    	host.setConnectName("instance01");
	    	host.setHostName("127.0.0.1");
	    	host.setHostPort(8301);
	    	host.setUserName("root");
	    	host.setPassword("root");
	    	host.setCacheable(false);
	    	DBConnect myConn = null;
			myConn = DBConnectManager.getInstance().getConnect(host);
			DBRoot root = DBRoot.getInstance(myConn);
			String dbname ="D30";
			DBase dBase = root.getCachedDatabaseByName(dbname);
			String tableName ="T31";
			DBTable dbtable = dBase.getCachedTableByName(tableName);
			String pointName = "P30";
			try {
				DBPoint dbpoint = dbtable.getCachedPointByName(pointName);
				dbtable.delete(dbpoint);
				System.out.print("Delete point success.");
				}catch (Exception e) {
					System.out.print("Delete point failed, error: " + e);
				}
}}

四、修改数据点

import com.processdb.connection.DBConnect;
import com.processdb.connection.DBConnectManager;
import com.processdb.connection.DBPoint;
import com.processdb.connection.DBRoot;
import com.processdb.connection.DBTable;
import com.processdb.connection.DBase;
import com.processdb.driver.common.ConnectInfo;
import com.processdb.driver.common.PointInfo;
public class Test {
	 public static void main(String[] args) throws Exception
	    {
	    	ConnectInfo host = new ConnectInfo();
	    	host.setConnectName("instance01");
	    	host.setHostName("127.0.0.1");
	    	host.setHostPort(8301);
	    	host.setUserName("root");
	    	host.setPassword("root");
	    	host.setCacheable(false);
	    	DBConnect myConn = null;
			myConn = DBConnectManager.getInstance().getConnect(host);
			DBRoot root = DBRoot.getInstance(myConn);
			String dbname ="D30";
			DBase dBase = root.getCachedDatabaseByName(dbname);
			String tableName ="T31";
			DBTable dbtable = dBase.getCachedTableByName(tableName);
			String pointName = "P30";
			DBPoint dbpoint = dbtable.getCachedPointByName(pointName);
			PointInfo point = dbpoint.getPointInfo();
			//这里是要修改点的属性
			point.setUnit("A");
			point.setTopScale(300);
			point.setDesc("UPDATE TEST");
			int res = dbtable.modify(point);
			if(res != 0)
			{
				System.out.print("Update point failed, error code: " + res);
				return;
			}
			else
			{
				System.out.print("Update point success.");}

}}

五、查询数据点

import com.processdb.connection.DBConnect;
import com.processdb.connection.DBConnectManager;
import com.processdb.connection.DBPoint;
import com.processdb.connection.DBRoot;
import com.processdb.connection.DBTable;
import com.processdb.connection.DBase;
import com.processdb.driver.common.ConnectInfo;
import com.processdb.driver.common.PointInfo;
public class Test {
	 public static void main(String[] args) throws Exception
	    {
	    	ConnectInfo host = new ConnectInfo();
	    	host.setConnectName("instance01");
	    	host.setHostName("127.0.0.1");
	    	host.setHostPort(8301);
	    	host.setUserName("root");
	    	host.setPassword("root");
	    	host.setCacheable(false);
	    	DBConnect myConn = null;
			myConn = DBConnectManager.getInstance().getConnect(host);
			DBRoot root = DBRoot.getInstance(myConn);
			String dbname ="PUBLIC";
			DBase dBase = root.getCachedDatabaseByName(dbname);
			String tableName ="SYS";
			DBTable dbtable = dBase.getCachedTableByName(tableName);
			String pointName = "PDB_PROC_CPU_USAGE";
			DBPoint dbpoint = dbtable.getCachedPointByName(pointName);
			PointInfo point = dbpoint.getPointInfo();
			String desc = point.getDesc();
			float topScale = point.getTopScale();
			String unit = point.getUnit();
			int id = point.getId();
			System.out.println(dbname+"库的"+tableName+"表的"+pointName+"点的属性为:");
			System.out.println("ID:"+id+",描述:"+",量程高限:"+topScale+",单 
            位:"+unit);
}}

示例运行结果:

PUBLIC库的SYS表的PDB_PROC_CPU_USAGE点的属性为:
ID:1001000007,描述:,量程高限:100.0,单位:%

六、查询数据点列表

import java.util.Vector;
import com.processdb.connection.DBConnect;
import com.processdb.connection.DBConnectManager;
import com.processdb.connection.DBPoint;
import com.processdb.connection.DBRoot;
import com.processdb.connection.DBTable;
import com.processdb.connection.DBase;
import com.processdb.driver.common.ConnectInfo;
public class Test {
	 public static void main(String[] args) throws Exception
	    {
	    	ConnectInfo host = new ConnectInfo();
	    	host.setConnectName("instance01");
	    	host.setHostName("127.0.0.1");
	    	host.setHostPort(8301);
	    	host.setUserName("root");
	    	host.setPassword("root");
	    	host.setCacheable(false);
	    	DBConnect myConn = null;
			myConn = DBConnectManager.getInstance().getConnect(host);
			DBRoot root = DBRoot.getInstance(myConn);
			String dbname ="PUBLIC";
			DBase dBase = root.getCachedDatabaseByName(dbname);
			String tableName ="SYS";
			DBTable dbtable = dBase.getCachedTableByName(tableName);
			dbtable.loadAllPoint();
			Vector points = dbtable.getCachedPoints();
			System.out.println("SYS表下的数据点:");
			for (DBPoint dbPoint : points) {
				System.out.println("点名:"+dbPoint.getName()+",描述:"+dbPoint.getDesc()
                  +",单位:"+dbPoint.getUnit());
			}
}}

示例运行结果:

SYS表下的数据点:
点名:PDB_PROC_RUNNING_TIME,描述:ProcessDB running time,单位:M
点名:PDB_PROC_CPU_USAGE,描述:ProcessDB cpu load rate,单位:%
点名:PDB_OS_TYPE,描述:System disk available space,单位:N/A
点名:PDB_NET_WRITE_SPEED,描述:System net write speed,单位:m/s
点名:PDB_FREE_DISK,描述:System disk free space,单位:M
点名:PDB_PROC_MEM_USED,描述:ProcessDB physical memory used,单位:M
点名:PDB_AVAILABLE_DISK,描述:System disk available space,单位:M
点名:PDB_DISK_READ_SPEED,描述:System disk read speed,单位:m/s
点名:PDB_OS_RUNNING_TIME,描述:OS running time,单位:H
点名:PDB_PROC_THREAD_COUNT,描述:ProcessDB thread count,单位:M
点名:PDB_DISK_WRITE_SPEED,描述:System disk write speed,单位:m/s
点名:PDB_NET_READ_SPEED,描述:System net read speed,单位:m/s
点名:PDB_HANDLE_COUNT,描述:Used handle count,单位:M
点名:PDB_OS_CPU_USAGE,描述:System total cpu load rate,单位:%
点名:PDB_OS_MEM_USAGE,描述:System physical memory usage rate,单位:%

你可能感兴趣的:(#,java,时序数据库,物联网,ProcessDB,数据库开发)