如何向realm对象添加正确的行数?

cotxawn7  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(175)

我有一个包含“时间配置文件数据”的列表。。
18个时间配置文件,每个时间配置文件中有12个时间片,每个时间片中有18个子段。
我试图为每个时间片创建一行(因此我将有216列12x18),但是目前我有2592列。正在为列表的每个元素创建一个新列。。任何关于解决这个问题的正确逻辑的建议都将不胜感激。

public void Update(List<TimeProfiles> timeProfilesList) {
Realm.init(this);
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
realm.deleteAll();
realm.commitTransaction();

RealmConfiguration config = new RealmConfiguration.Builder()
        .deleteRealmIfMigrationNeeded()
        .build();
Realm.setDefaultConfiguration(config);

realm.beginTransaction();

for (TimeProfiles timeProf : timeProfilesList) {

    TimeProfileRealm tpRealm = realm.createObject(TimeProfileRealm.class);

    tpRealm.set_timezone_iid(timeProf.get_timezone_iid());
    tpRealm.set_timezone_id(timeProf.get_timezone_id());
    tpRealm.set_serial(timeProf.get_serial());
    tpRealm.set_from_time(timeProf.get_from_time());
    tpRealm.set_to_time(timeProf.get_to_time());
    tpRealm.set_monday(timeProf.get_monday());
    tpRealm.set_tuesday(timeProf.get_tuesday());
    tpRealm.set_wednesday(timeProf.get_wednesday());
    tpRealm.set_thursday(timeProf.get_thursday());
    tpRealm.set_friday(timeProf.get_friday());
    tpRealm.set_saturday(timeProf.get_saturday());
    tpRealm.set_sunday(timeProf.get_sunday());
    tpRealm.set_holiday(timeProf.get_holiday());
    tpRealm.set_special_day_one(timeProf.get_special_day_one());
    tpRealm.set_special_day_two(timeProf.get_special_day_two());
    tpRealm.set_timezone_item_id(timeProf.get_timezone_item_id());

}
realm.commitTransaction();

File root = new File(Environment.getExternalStorageDirectory(), "/exported.realm");
realm.writeCopyTo(root);

}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题