getQueryData方法

getQueryData方法,有6个参数,分别是:

实体id,查询类型,聚集层次,开始时间,结束时间,聚合周期。

该方法还带着一系列异常信息,捕获到这些异常就抛出。

 

getQueryData (int  entityId,
   QueryType  queryType,
   AggregationLevel  aggregationLevel,
  Date  startTime,
  Date  endTime,
  int aggPeriod 
 )  throws DcmIllegalIdException, DcmIllegalQueryException, DcmDataAccessException, DcmIllegalArgumentException, DcmCommunicationException

Performs a query on collection data for the dates specified.
When the requested entity represents a group, the returned value(s) takes into account collected data associated with all managed nodes within that group.

对于指定的日期范围,在收集的数据上,执行查询操作。

当请求的entity是一个group时,返回值就是这个group中包含的所有受管理node的收集数据的合计。

 

This method aggregates data over the aggPeriod specified.

这个方法在指定集聚周期上聚合数据。


Your aggPeriod must be a multiple of the largest measurement data granularity value. To get this value,call getQueryAggregationPeriodList()

你的聚合周期必须是最大存储数据粒度值的倍数。为了获取这个值,请调用方法getQueryAggregationPeriodList()。 

 

Note:
Value of the query result data is aggregated from data?s time-aggPeriod to data?s time.

查询结果数据的值,是从开始时间到间隔时间来统计的。

 

For example, if query with BeginTime = 10:30:00, EndTime = 10:37:10, and aggPeriod = 180 seconds, assume data granularity is the default value (180 seconds), the query results are:

比如,假如查询的开始时间是10:30:00,结束时间是10:37:10,并且,聚集周期是180秒,假设数据粒度是默认值(180秒),则查询结果是:


PTData1--Entity ID: 17,Time: 10:33:00,Value: 3030,
PTData2--Entity ID: 17,Time: 10:36:00,Value: 3100,
PTData3--Entity ID: 17,Time: 10:37:10,Value: -1
PTData1?s value is aggregated from 10:30:00 to 10:33:00, and PTData2?s value is aggregated from 10:33:30 to 10:36:00. PTData3?s value is aggregated from 10:36:00 to 10:37:10, but there is no record so it return -1.

 

PTData1的值是从10:30:00统计到10:33:00,并且PTData2的值是从10:33:30统计到10:36:00;

yinyan说明:这边10:33:30中的30秒,应该是区别前一个PTData值和后一个是不同时间段的意思吧。sampling frequency应该是30秒,在这个例子的假设中。

 

PTData3的值是从10:36:00统计到10:37:10,但是这边没有记录(没有达到180秒),就返回-1.

 

If you send this query at 10:30:00, the data is not returned because there is no aggPeriod from the BeginTime.

假如现在时间是10:30:00,你现在发送这个query,那么是没有数据能返回回来的,因为从开始时间算起没有聚合周期。(即从开始时间算起,相当于是想查询将来时间段的数据,此时肯定还没有数据记录呢)

 

Parameters:
  entityId the unique identifier of the entity
  queryType the type of query.
  aggregationLevel the level to which to aggregate the collected data
  startTime The time at which to start the query. For queries that do not include a measurement granularity greater 360 seconds, use a multiple of 6 minutes (360 seconds). For queries with measurement granularity greater than 360 seconds, must be a multiple of the measurement granularity . A NULL value sets startTime to the earliest time in the database.
  endTime The time at which to end the query. A null value sets endTime to the latest time in the database.
  aggPeriod the period, in seconds, over which the collected data is aggregated. Must be a multiple of the largest measurement granularity value during the time range of this call. A value of 0 sets the aggPeriod to the smallest possible value. A value of -1 sets the aggPeriod to the largest possible value.
To get the largest sampling frequency during the time range of this call, call getQueryAggregationPeriodList().

-->20100122追加:

关于aggPeriod:

关于aggPeriod为0和-1时的解释:


aggPeriod为0,是getQueryAggregationPeriodList()方法 return 值(the value of aggregation period list for the time range 这个时间范围内采样周期的数组)中最大的一个。
表示的意思是:这段时间内采样数据各周期的最小公倍数(但因为各个周期本身就是倍数关系,所以取最大数即可)。
举例:现在查询的周期内,有两种采样周期的数据:3分钟和6分钟。假如aggPeriod值为0,则使用6分钟为查询周期。(假如使用3分钟,会导致6分钟采样周期的数据被生生”断开“,其实也是断不开的)


aggPeriod为-1,表示的意思是:endTime - startTime的值,跟默认值进行比较后修正为结果值。
举例:endTime - startTime的值的结果为45分钟,而默认值是6分钟,则修正后的结果值为42分钟。(6×7+3=45)
endTime - startTime的值的结果为42分钟,而默认值是6分钟,则结果值不需要修正,直接为42分钟。

 

Returns:
an array of data.
返回数据是数组类型的数据。
Exceptions:
  DcmIllegalIdException The entityId parameter is invalid.
  DcmIllegalQueryException the query cannot be executed due to an incorrect time range, a time range beyond database maintenance period, a mismatch between the entity type and the aggregation type.
  DcmDataAccessException The data in the database could not be accessed.
  DcmIllegalArgumentException an argument is invalid.
  DcmCommunicationException  
See also:
DataAccess::getQueryAggregationPeriodList

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据你提供的代码,我发现在第二个while循环中,没有关闭`phone`游标。这可能是导致无法查询出通讯录内容的原因之一。 另外,`cursor.close()`应该在第一个while循环的末尾处调用,而不是在第二个while循环的末尾处调用。因为第二个while循环是在第一个while循环的内部执行的,如果在第二个while循环中关闭了游标,那么第一个while循环将无法正常执行。 此外,我还注意到在查询电话号码时,`columns[3]`应该是`ContactsContract.CommonDataKinds.Phone.CONTACT_ID`,而不是`ContactsContract.CommonDataKinds.Phone.NUMBER`,因为`columns[3]`对应的是通讯录ID,而不是电话号码。 修改后的代码如下: ``` public class RetrieveDataActivity extends Activity { private String[] columns = {ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone.CONTACT_ID}; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView tv = (TextView) findViewById(R.id.result); tv.setText(getQueryData()); } private String getQueryData() { StringBuilder sb = new StringBuilder(); ContentResolver resolver = getContentResolver(); Cursor cursor = resolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); while (cursor.moveToNext()) { int idIndex = cursor.getColumnIndex(columns[0]); int displayNameIndex = cursor.getColumnIndex(columns[1]); int id = cursor.getInt(idIndex); String displayName = cursor.getString(displayNameIndex); Cursor phone = resolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, columns[3] + "=" + id, null, null); while (phone.moveToNext()) { int phoneNumberIndex = phone.getColumnIndex(columns[2]); String phoneNumber = phone.getString(phoneNumberIndex); sb.append(displayName + ":" + phoneNumber + "\n"); } phone.close(); } cursor.close(); return sb.toString(); } } ``` 希望这可以帮到你。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值