AggregationExceptions
来源:互联网 发布:算法大数阶乘问题 编辑:程序博客网 时间:2024/05/22 07:45
AggregationExceptions
java.lang.Object
android.provider.ContactsContract.AggregationExceptions
Class Overview
Constants for the contact aggregation exceptions table,
which contains aggregation rules overriding those used by automatic aggregation.
This type only supports query and update. Neither insert nor delete are supported.
该类为用户提供了控制rawContact组不组成一个contact aggregation的方式。
对于该表只能查询和更新。不能插入和删除。插入和删除都是由系统来控制的。
Columns
AggregationExceptions
int TYPE read/write The type of exception: TYPE_KEEP_TOGETHER, TYPE_KEEP_SEPARATE or TYPE_AUTOMATIC.
long RAW_CONTACT_ID1 read/write A reference to the _ID of the raw contact that the rule applies to.
long RAW_CONTACT_ID2 read/write A reference to the other _ID of the raw contact that the rule applies to.
数据查询:
c = managedQuery(AggregationExceptions.CONTENT_URI,
new String[]{AggregationExceptions.TYPE,AggregationExceptions.RAW_CONTACT_ID1,
AggregationExceptions.RAW_CONTACT_ID2},
null, null, null);
注意这里查询到的只是TYPE为TYPE_KEEP_TOGETHER和TYPE_KEEP_SEPARATE的项。
系统的意思就是在这里只是定义Exception的Aggregation规则。默认的为TYPE_AUTOMATIC,自然不在此表。想想如果TYPE_AUTOMATIC得要定义在表中的话,那这个表的数据量就太大了。而且对于TYPE_AUTOMATIC的关系没有必要再定义,不定义就是TYPE_AUTOMATIC。
数据更新:
需要注意的是对于想让一个集合的各元素的TYPE做改变时,最好对各个元素和其他的关系(TYPE)都做改变。
比如想让A,B,C变成一组。不应该简单的让A与B,A与C变成TYPE_KEEP_TOGETHER。
而应该让A与B,A与C,B与C都变成TYPE_KEEP_TOGETHER。
例1:
void doAggregationAllByBatch() {
Cursor c = getContentResolver().query(RawContacts.CONTENT_URI, null,
RawContacts.DELETED + "=0", null, null);//注意这里的条件
int count = c.getCount();
int rawContactIdCol = c.getColumnIndex(RawContacts._ID);
long rawContactIds[] = new long[count];
int i = 0;
while (c.moveToNext()) {
rawContactIds[i++] = c.getLong(rawContactIdCol);
}
long rawContactId = 0;
long rawContactId2 = 0;
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
for (i = 0; i < count; i++) {
rawContactId = rawContactIds;
for (int j = i + 1; j < count; j++) {
rawContactId2 = rawContactIds[j];
ops.add(ContentProviderOperation.newUpdate(
AggregationExceptions.CONTENT_URI).withValue(
AggregationExceptions.TYPE,
AggregationExceptions.TYPE_KEEP_TOGETHER).withValue(
AggregationExceptions.RAW_CONTACT_ID1, rawContactId)
.withValue(AggregationExceptions.RAW_CONTACT_ID2,
rawContactId2).build());
}
}
try {
getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
} catch (Exception e) {
e.printStackTrace();
}
}
例2:
void doAggregationAll() {
Cursor c = getContentResolver().query(RawContacts.CONTENT_URI, null,
RawContacts.DELETED + "=0", null, null);
int count = c.getCount();
int rawContactIdCol = c.getColumnIndex(RawContacts._ID);
long rawContactIds[] = new long[count];
int i = 0;
while (c.moveToNext()) {
rawContactIds[i++] = c.getLong(rawContactIdCol);
}
long rawContactId = 0;
long rawContactId2 = 0;
ContentValues values = new ContentValues();
for (i = 0; i < count; i++) {
rawContactId = rawContactIds;
for (int j = i + 1; j < count; j++) {
rawContactId2 = rawContactIds[j];
values.put(AggregationExceptions.TYPE,
AggregationExceptions.TYPE_KEEP_TOGETHER);
values.put(AggregationExceptions.RAW_CONTACT_ID1, rawContactId);
values
.put(AggregationExceptions.RAW_CONTACT_ID2,
rawContactId2);
getContentResolver().update(AggregationExceptions.CONTENT_URI,
values, null, null);
values.clear();
Log.i("hubin",rawContactId+" unlink "+rawContactId2);
}
}
}
例3:
void doUnAggregationAllByBatch() {
Cursor c = getContentResolver().query(RawContacts.CONTENT_URI, null,
RawContacts.DELETED + "=0", null, null);
int count = c.getCount();
int rawContactIdCol = c.getColumnIndex(RawContacts._ID);
long rawContactIds[] = new long[count];
int i = 0;
while (c.moveToNext()) {
rawContactIds[i++] = c.getLong(rawContactIdCol);
}
long rawContactId = 0;
long rawContactId2 = 0;
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
for (i = 0; i < count; i++) {
rawContactId = rawContactIds;
for (int j = i + 1; j < count; j++) {
rawContactId2 = rawContactIds[j];
ops.add(ContentProviderOperation.newUpdate(
AggregationExceptions.CONTENT_URI).withValue(
AggregationExceptions.TYPE,
AggregationExceptions.TYPE_KEEP_SEPARATE).withValue(
AggregationExceptions.RAW_CONTACT_ID1, rawContactId)
.withValue(AggregationExceptions.RAW_CONTACT_ID2,
rawContactId2).build());
}
}
try {
getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
} catch (Exception e) {
e.printStackTrace();
}
}
例4:
void doUnAggregationAll() {
Cursor c = getContentResolver().query(RawContacts.CONTENT_URI, null,
RawContacts.DELETED + "=0", null, null);
int count = c.getCount();
int rawContactIdCol = c.getColumnIndex(RawContacts._ID);
long rawContactIds[] = new long[count];
int i = 0;
while (c.moveToNext()) {
rawContactIds[i++] = c.getLong(rawContactIdCol);
}
long rawContactId = 0;
long rawContactId2 = 0;
ContentValues values = new ContentValues();
for (i = 0; i < count; i++) {
rawContactId = rawContactIds;
for (int j = i + 1; j < count; j++) {
rawContactId2 = rawContactIds[j];
values.put(AggregationExceptions.TYPE,
AggregationExceptions.TYPE_KEEP_SEPARATE);
values.put(AggregationExceptions.RAW_CONTACT_ID1, rawContactId);
values
.put(AggregationExceptions.RAW_CONTACT_ID2,
rawContactId2);
getContentResolver().update(AggregationExceptions.CONTENT_URI,
values, null, null);
values.clear();
Log.i("hubin",rawContactId+" unlink "+rawContactId2);
}
}
}
java.lang.Object
android.provider.ContactsContract.AggregationExceptions
Class Overview
Constants for the contact aggregation exceptions table,
which contains aggregation rules overriding those used by automatic aggregation.
This type only supports query and update. Neither insert nor delete are supported.
该类为用户提供了控制rawContact组不组成一个contact aggregation的方式。
Columns
AggregationExceptions
int TYPE read/write The type of exception: TYPE_KEEP_TOGETHER, TYPE_KEEP_SEPARATE or TYPE_AUTOMATIC.
long RAW_CONTACT_ID1 read/write A reference to the _ID of the raw contact that the rule applies to.
long RAW_CONTACT_ID2 read/write A reference to the other _ID of the raw contact that the rule applies to.
c = managedQuery(AggregationExceptions.CONTENT_URI,
new String[]{AggregationExceptions.TYPE,AggregationExceptions.RAW_CONTACT_ID1,
AggregationExceptions.RAW_CONTACT_ID2},
null, null, null);
注意这里查询到的只是TYPE为TYPE_KEEP_TOGETHER和TYPE_KEEP_SEPARATE的项。
系统的意思就是在这里只是定义Exception的Aggregation规则。默认的为TYPE_AUTOMATIC,自然不在此表。想想如果TYPE_AUTOMATIC得要定义在表中的话,那这个表的数据量就太大了。而且对于TYPE_AUTOMATIC的关系没有必要再定义,不定义就是TYPE_AUTOMATIC。
需要注意的是对于想让一个集合的各元素的TYPE做改变时,最好对各个元素和其他的关系(TYPE)都做改变。
比如想让A,B,C变成一组。不应该简单的让A与B,A与C变成TYPE_KEEP_TOGETHER。
而应该让A与B,A与C,B与C都变成TYPE_KEEP_TOGETHER。
例1:
void doAggregationAllByBatch() {
Cursor c = getContentResolver().query(RawContacts.CONTENT_URI, null,
RawContacts.DELETED + "=0", null, null);//注意这里的条件
int count = c.getCount();
int rawContactIdCol = c.getColumnIndex(RawContacts._ID);
long rawContactIds[] = new long[count];
int i = 0;
while (c.moveToNext()) {
rawContactIds[i++] = c.getLong(rawContactIdCol);
}
long rawContactId = 0;
long rawContactId2 = 0;
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
for (i = 0; i < count; i++) {
rawContactId = rawContactIds
for (int j = i + 1; j < count; j++) {
rawContactId2 = rawContactIds[j];
ops.add(ContentProviderOperation.newUpdate(
AggregationExceptions.CONTENT_URI).withValue(
AggregationExceptions.TYPE,
AggregationExceptions.TYPE_KEEP_TOGETHER).withValue(
AggregationExceptions.RAW_CONTACT_ID1, rawContactId)
.withValue(AggregationExceptions.RAW_CONTACT_ID2,
rawContactId2).build());
}
}
try {
getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
} catch (Exception e) {
e.printStackTrace();
}
}
例2:
void doAggregationAll() {
Cursor c = getContentResolver().query(RawContacts.CONTENT_URI, null,
RawContacts.DELETED + "=0", null, null);
int count = c.getCount();
int rawContactIdCol = c.getColumnIndex(RawContacts._ID);
long rawContactIds[] = new long[count];
int i = 0;
while (c.moveToNext()) {
rawContactIds[i++] = c.getLong(rawContactIdCol);
}
long rawContactId = 0;
long rawContactId2 = 0;
ContentValues values = new ContentValues();
for (i = 0; i < count; i++) {
rawContactId = rawContactIds
for (int j = i + 1; j < count; j++) {
rawContactId2 = rawContactIds[j];
values.put(AggregationExceptions.TYPE,
AggregationExceptions.TYPE_KEEP_TOGETHER);
values.put(AggregationExceptions.RAW_CONTACT_ID1, rawContactId);
values
.put(AggregationExceptions.RAW_CONTACT_ID2,
rawContactId2);
getContentResolver().update(AggregationExceptions.CONTENT_URI,
values, null, null);
values.clear();
Log.i("hubin",rawContactId+" unlink "+rawContactId2);
}
}
}
例3:
void doUnAggregationAllByBatch() {
Cursor c = getContentResolver().query(RawContacts.CONTENT_URI, null,
RawContacts.DELETED + "=0", null, null);
int count = c.getCount();
int rawContactIdCol = c.getColumnIndex(RawContacts._ID);
long rawContactIds[] = new long[count];
int i = 0;
while (c.moveToNext()) {
rawContactIds[i++] = c.getLong(rawContactIdCol);
}
long rawContactId = 0;
long rawContactId2 = 0;
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
for (i = 0; i < count; i++) {
rawContactId = rawContactIds
for (int j = i + 1; j < count; j++) {
rawContactId2 = rawContactIds[j];
ops.add(ContentProviderOperation.newUpdate(
AggregationExceptions.CONTENT_URI).withValue(
AggregationExceptions.TYPE,
AggregationExceptions.TYPE_KEEP_SEPARATE).withValue(
AggregationExceptions.RAW_CONTACT_ID1, rawContactId)
.withValue(AggregationExceptions.RAW_CONTACT_ID2,
rawContactId2).build());
}
}
try {
getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
} catch (Exception e) {
e.printStackTrace();
}
}
例4:
void doUnAggregationAll() {
Cursor c = getContentResolver().query(RawContacts.CONTENT_URI, null,
RawContacts.DELETED + "=0", null, null);
int count = c.getCount();
int rawContactIdCol = c.getColumnIndex(RawContacts._ID);
long rawContactIds[] = new long[count];
int i = 0;
while (c.moveToNext()) {
rawContactIds[i++] = c.getLong(rawContactIdCol);
}
long rawContactId = 0;
long rawContactId2 = 0;
ContentValues values = new ContentValues();
for (i = 0; i < count; i++) {
rawContactId = rawContactIds
for (int j = i + 1; j < count; j++) {
rawContactId2 = rawContactIds[j];
values.put(AggregationExceptions.TYPE,
AggregationExceptions.TYPE_KEEP_SEPARATE);
values.put(AggregationExceptions.RAW_CONTACT_ID1, rawContactId);
values
.put(AggregationExceptions.RAW_CONTACT_ID2,
rawContactId2);
getContentResolver().update(AggregationExceptions.CONTENT_URI,
values, null, null);
values.clear();
Log.i("hubin",rawContactId+" unlink "+rawContactId2);
}
}
}
- AggregationExceptions
- 8年的计算机,我放弃了!
- 浅谈LZSS与游戏图片破解
- websphere 服务器启停的几个快捷方式
- Getting Started With OData Part 2: Building an OData Services from Any Data Source
- 0-1背包问题,动态规划求解
- AggregationExceptions
- SoundPool&&mediaplayer播放音乐
- 图像的二值化分割,otsu类间方差法
- 有关MFC中使用CButton类后位图按钮闪烁的问题
- Liudmila Loglisci & Davide Caci (专辑)
- DX下的全屏显示模式
- c# 查询结果保存为Excel格式 TAB分割的TXT格式
- C++运算符重载
- 连连看