2

私は自分のプロジェクトで GreenDao を使用しています。これは、サーバー モデルを Android デバイスにマッピングするのに適しています。私がしばらく苦労しているのは、dao.update および/または dao.updateInTx メソッドがデータベース内の行を更新していないことです。

私がやること:

/**
 *  The first approach -> All in one runnable
 *
 */

// list definitions
ArrayList<Country> countryList;
ArrayList<Country> countryListDetail;  

final DaoSession daoSession = daoMaster.newSession();

// execute everything in runnable 
// in order to optimize insert time
daoSession.runInTx(new Runnable() {

    @Override
    public void run() {
        CountryDao countryDao = new CaountryDao();


                // delete all records first
                countryDao.deleteAll();

                // insert countries with less data
                size = countryList.size(); 
                for (int i=0; i < size; i++) {
                     countryDao.insert(countryList.get(i));
                }

                // update countries with more data
                // ID's of the Objects in countryListDetail match those from
                // the countryList, so the primary key mathces
                size = countryListDetail.size(); 
                for (int i=0; i < size; i++) {
                     countryDao.update(countryListDetail.get(i));
                }

      }
}

/**
 *  The second approach -> updateInTx()
 *
 */

// list definitions
ArrayList<Country> countryList;
ArrayList<Country> countryListDetail;              

// insert & update logic
final DaoSession daoSession = daoMaster.newSession();                                
CountryDao countryDao = new CaountryDao();

countryDao.insertInTx(countryList);
countryDao.updateInTx(countryListDetail);

どちらの場合も、デバイスからデータベースを取得して調べると、Country テーブルには基本挿入データしかありませんが、更新ステートメントから取得する必要がある詳細データはありません。デバッグ時、GreenDao ロジックは updateInsideSynchronized() メソッドを実行しているようで、stmt.execute() も呼び出されます。

私が間違っているかもしれないことを誰かが知っていますか?

4

2 に答える 2

2

これを有効にして確認してください

dao.queryBuilder().LOG_VALUES=true;
dao.queryBuilder().LOG_SQL=true;

更新時にcountryListとcountryListDetailが同じPrimarykeyを持っていることを確認してください

于 2015-01-21T12:23:47.163 に答える