转载请注明出处:http://blog.csdn.net/droyon/article/details/35558697

什么时候delete要么update时间。需要清空缓存并重新加载数据。

1、invalidateCache()//得到当前用户的SettingsCache。remove全部。
public SettingsCache cacheForTable(final int callingUser, String tableName) {
if (TABLE_SYSTEM.equals(tableName)) {
return getOrConstructCache(callingUser, sSystemCaches);
}
if (TABLE_SECURE.equals(tableName)) {
return getOrConstructCache(callingUser, sSecureCaches);
}
if (TABLE_GLOBAL.equals(tableName)) {
return sGlobalCache;
}
return null;
}
二、bulkInsert
public int bulkInsert(Uri uri, ContentValues[] values) {
final int callingUser = UserHandle.getCallingUserId();//得到请求用户id
SettingsCache cache = cacheForTable(callingUser, args.table);//得到SettingsCache
int numValues = values.length;
for (int i = 0; i < numValues; i++) {
if (db.insert(args.table, null, values[i]) < 0) return 0;
SettingsCache.populate(cache, values[i]);
if (LOCAL_LOGV) Log.v(TAG, args.table + " <- " + values[i]);
} 得到SettingsCache(getOrConstructCache ----》 getOrEstablishDatabase ----》 establishDbTracking ---》 startAsyncCachePopulation(userHandle);)
1、if (TABLE_SYSTEM.equals(tableName)) {
return getOrConstructCache(callingUser, sSystemCaches);
}
if (TABLE_SECURE.equals(tableName)) {
return getOrConstructCache(callingUser, sSecureCaches);
}
if (TABLE_GLOBAL.equals(tableName)) {
return sGlobalCache;
}
2、private SettingsCache getOrConstructCache(int callingUser, SparseArray<SettingsCache> which) {
getOrEstablishDatabase(callingUser); // ignore return value; we don't need it
return which.get(callingUser);
}
3、private DatabaseHelper getOrEstablishDatabase(int callingUser) {
if (callingUser >= Process.SYSTEM_UID) {
if (USER_CHECK_THROWS) {
throw new IllegalArgumentException("Uid rather than user handle: " + callingUser);
} else {
Slog.wtf(TAG, "establish db for uid rather than user: " + callingUser);
}
} long oldId = Binder.clearCallingIdentity();
try {
DatabaseHelper dbHelper = mOpenHelpers.get(callingUser);
if (null == dbHelper) {
establishDbTracking(callingUser);
dbHelper = mOpenHelpers.get(callingUser);
}
return dbHelper;
} finally {
Binder.restoreCallingIdentity(oldId);
}
}
4、private void startAsyncCachePopulation(int userHandle) {
new CachePrefetchThread(userHandle).start();
}
class CachePrefetchThread extends Thread {
private int mUserHandle; CachePrefetchThread(int userHandle) {
super("populate-settings-caches");
mUserHandle = userHandle;
} @Override
public void run() {
fullyPopulateCaches(mUserHandle);
}
}
5、fullyPopulateCaches
private void fullyPopulateCaches(final int userHandle) {
DatabaseHelper dbHelper = mOpenHelpers.get(userHandle);
// Only populate the globals cache once, for the owning user
if (userHandle == UserHandle.USER_OWNER) {
fullyPopulateCache(dbHelper, TABLE_GLOBAL, sGlobalCache);
}
fullyPopulateCache(dbHelper, TABLE_SECURE, sSecureCaches.get(userHandle));
fullyPopulateCache(dbHelper, TABLE_SYSTEM, sSystemCaches.get(userHandle));
}
得到DatabaseHelper。
DatabaseHelper dbH = getOrEstablishDatabase(
TABLE_GLOBAL.equals(args.table) ? UserHandle.USER_OWNER : callingUser);
插入到数据库,更新数据到SettingsCache。 for (int i = 0; i < numValues; i++) {
if (db.insert(args.table, null, values[i]) < 0) return 0;
SettingsCache.populate(cache, values[i]);
if (LOCAL_LOGV) Log.v(TAG, args.table + " <- " + values[i]);
} 发送通知。
sendNotify(uri, callingUser);

三、Insert

@Override

    public Uri insert(Uri url, ContentValues initialValues) {

        return insertForUser(url, initialValues, UserHandle.getCallingUserId());

    }

insetForUser

1、转换table数据表。



if (name != null) {

            if (sSecureGlobalKeys.contains(name) || sSystemGlobalKeys.contains(name)) {

                if (!TABLE_GLOBAL.equals(args.table)) {

                    if (LOCAL_LOGV) Slog.i(TAG, "Rewrite of insert() of now-global key " + name);

                }

                args.table = TABLE_GLOBAL;  // next condition will rewrite the user handle

            }

        }

2、得到SettingsCache

SettingsCache cache = cacheForTable(desiredUserHandle, args.table);

3、if (SettingsCache.isRedundantSetValue(cache, name, value)) {

            return Uri.withAppendedPath(url, name);

        }

4、得到DatabaseHelper

DatabaseHelper dbH = getOrEstablishDatabase(desiredUserHandle);

5、inset插入。

final long rowId = db.insert(args.table, null, initialValues);

        mutationCount.decrementAndGet();

        if (rowId <= 0) return null;

6、SettingsCache.populate(cache, initialValues);  // before we notify

7、notify

sendNotify(url, desiredUserHandle);

四、delete

  • 得到DatabaseHelper

    DatabaseHelper dbH = getOrEstablishDatabase(callingUser);
  • delete,

    int count = db.delete(args.table, args.where, args.args);
  • invalidateCache删除SettingsCache元素,并发送通知告知变化(invalidateCache -- -》 )

    invalidateCache(callingUser, args.table);  // before we notify

                sendNotify(url, callingUser);

又一次填充SettingsCache缓冲区。

(startAsyncCachePopulation(callingUser); ---》 new CachePrefetchThread(userHandle).start();)

startAsyncCachePopulation(callingUser);

五、update

  • 得到DatabaseHelper

    DatabaseHelper dbH = getOrEstablishDatabase(callingUser)。
  • 运行update

    int count = db.update(args.table, initialValues, args.where, args.args);
  • invalidateCache删除SettingsCache元素。发通知更新。

    invalidateCache(callingUser, args.table);  // before we notify

                sendNotify(url, callingUser);

又一次填充SettingsCache缓冲区。

startAsyncCachePopulation(callingUser);

六、query ---》 queryForUser

  • 构建查询条件



    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

            qb.setTables(args.table);
  • 开启查询

    Cursor ret = qb.query(db, select, args.where, args.args, null, null, sort);
  • 设置监听并通知。

    AbstractCursor c = (AbstractCursor) ret;

                c.setNotificationUri(getContext().getContentResolver(), url, forUser);

版权声明:本文博客原创文章。博客,未经同意,不得转载。

SettingsProvider该CRUD的更多相关文章

  1. 【翻译】MongoDB指南/CRUD操作(四)

    [原文地址]https://docs.mongodb.com/manual/ CRUD操作(四) 1 查询方案(Query Plans) MongoDB 查询优化程序处理查询并且针对给定可利用的索引选 ...

  2. 【翻译】MongoDB指南/CRUD操作(三)

    [原文地址]https://docs.mongodb.com/manual/ CRUD操作(三) 主要内容: 原子性和事务(Atomicity and Transactions),读隔离.一致性和新近 ...

  3. 【翻译】MongoDB指南/CRUD操作(二)

    [原文地址]https://docs.mongodb.com/manual/ MongoDB CRUD操作(二) 主要内容: 更新文档,删除文档,批量写操作,SQL与MongoDB映射图,读隔离(读关 ...

  4. 【翻译】MongoDB指南/CRUD操作(一)

    [原文地址]https://docs.mongodb.com/manual/ MongoDB CRUD操作(一) 主要内容:CRUD操作简介,插入文档,查询文档. CRUD操作包括创建.读取.更新和删 ...

  5. 【原】无脑操作:express + MySQL 实现CRUD

    基于node.js的web开发框架express简单方便,很多项目中都在使用.这里结合MySQL数据库,实现最简单的CRUD操作. 开发环境: IDE:WebStorm DB:MySQL ------ ...

  6. Hibernate(4)——主键生成策略、CRUD 基础API区别的总结 和 注解的使用

    俗话说,自己写的代码,6个月后也是别人的代码……复习!复习!复习!涉及的知识点总结如下: hibernate的主键生成策略 UUID 配置的补充:hbm2ddl.auto属性用法 注解还是配置文件 h ...

  7. 学习SpringMVC——你们要的REST风格的CRUD来了

    来来来,让一下,客官,您要的REST清蒸CRUD来了,火候刚刚好,不油不腻,请慢用~~~ 如果说前面是准备调料,洗菜,切菜,摆盘,那么今天就来完整的上道菜,主要说的是基于REST风格实现数据的增删改查 ...

  8. Elasticsearch的CRUD:REST与Java API

    CRUD(Create, Retrieve, Update, Delete)是数据库系统的四种基本操作,分别表示创建.查询.更改.删除,俗称"增删改查".Elasticsearch ...

  9. ASP.NET Core Web API Cassandra CRUD 操作

    在本文中,我们将创建一个简单的 Web API 来实现对一个 “todo” 列表的 CRUD 操作,使用 Apache Cassandra 来存储数据,在这里不会创建 UI ,Web API 的测试将 ...

随机推荐

  1. MVC 中使用 SignalR 实现推送功能

    MVC 中使用 SignalR 实现推送功能 一,简介 Signal 是微软支持的一个运行在 Dot NET 平台上的 html websocket 框架.它出现的主要目的是实现服务器主动推送(Pus ...

  2. maven学习系列(一)—maven安装和基本设置

    maven下载和配置 第一步:下载apache-maven-2.3.2-bin.zip并解压到D:\tools,下载地址http://maven.apache.org/download.cgi 第二步 ...

  3. 用PowerDesigner生成自定义建表语句

    原文:用PowerDesigner生成自定义建表语句 我们经常用PowerDesigner来进行数据库表结构的设计,并且设计出来的表比较直观的看出之间的相互关系,方便理解:但其自动生成的脚本并不一定符 ...

  4. mysql 多个字段拼接

    Mysql的查询结果行字段拼接,能够用以下两个函数实现: 1. concat函数 mysql> select concat('1','2','3') from test ; +--------- ...

  5. Android - 和其他APP交互 - 让其他app启动你的activity

    前面的两篇文章主要讲了一个方面:从app中启动其他app.但是如果你的app可以处理对其他app有用的操作,你的app也应该响应其他app的操作请求.例如,如果你创建了一个社交app可以分享信息和图片 ...

  6. windows-install-python-and-sphinx(*.rst file)

    http://sphinx-doc.org/install.html#windows-install-python-and-sphinx

  7. DuiVision开发教程(15)-DUI文本控制基础类

    CControlBaseFont类是DuiVision支持所有基类的控件的文本属性. 此控件例如属性列表,下面: 物业名称 类型 说明 title 字符串 控件的显示标题 font 字体 控件的字体, ...

  8. 复制(1)——SQLServer 复制简介

    原文:复制(1)--SQLServer 复制简介 前言: SQLServer的复制技术最少从SQLServer2000时代已经出现,当初是为了分布式计算,不是为了高可用.但是到了今天,复制也成为了一种 ...

  9. 一天JavaScript示例-判定web页面的区域

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  10. 设置SQLServer数据库中某些表为只读的多种方法

    原文:设置SQLServer数据库中某些表为只读的多种方法 翻译自:http://www.mssqltips.com/sqlservertip/2711/different-ways-to-make- ...