将Green DAO与内容提供商一起使用

Nit*_*ish 9 database orm android android-sqlite greendao

我打算GreenDAO在我的项目中使用.我已经通过创建测试项目来测试它.但是,我有几个要求,我需要完成.

  1. 我的应用程序的数据库将被加密.为此,我们计划使用SQLCipher.我找到了这个链接.我正在研究它,但有兴趣知道原始的GreenDAO项目有什么可用.

  2. 由于我的应用程序将数据与服务器同步,我将使用SyncAdapter,因为我不想自己完成所有的重量级操作,这已经由Android框架完成.但它需要Content Provider合作.那么,我如何使用GreenDAO Content Provider.

更新2

我的项目有七个实体.我用过addContentProvider()实体.并生成七个不同的内容提供商.有没有办法在单个内容提供商中拥有所有sqlite表?

Eef*_*ret 9

我有一个运行greenDao和内容提供商的项目.首先,我用ProviGen刚刚生成内容提供商和查询与内容解析器但后来项目转向是非常大的,所以我决定实施greenDAO,我所做的是使用provigen创建的ContentProvider从中获得数据库,所以现在我将contentProvider和provigen都​​附加到同一个数据库.我鼓励您创建ContentProvider并将daoMaster附加到使用它生成的数据库.这是我在onCreate应用程序类中使用的一段代码:

private static DaoSession daoSession;
public void onCreate(){
SQLiteOpenHelper myAppOpenHelper = new ProvigenContentProvider().openHelper(this); //ContentProvider created previously
SQLiteDatabase db = myAppOpenHelper.getWritableDatabase();
DaoMaster daoMaster = new DaoMaster(db);
daoSession = daoMaster.newSession();
}
Run Code Online (Sandbox Code Playgroud)

之后使用greendao:

public DaoSession getDaoSession(){
        return daoSession;
}
Run Code Online (Sandbox Code Playgroud)

在那里你可以同时拥有contentProvider和greenDao.如果尚未启动项目,请手动创建内容提供程序,并在此处创建具有相同代码的DaoMaster.祝好运