0
我有成千上万的字符串,并根据内容我想将它们添加到不同的RealmObjects
模型,和我有大约10境界 模型,领域,传递领域对象可能的动态模型?
现在我做这样的事情:
if (string.contains("abc")) {
mRealm.beginTransaction();
mRealm.copyToRealmOrUpdate(new ABCModel(string));
mRealm.commitTransaction();
}
if (string.contains("xyz")) {
mRealm.beginTransaction();
mRealm.copyToRealmOrUpdate(new XYZModel(string));
mRealm.commitTransaction();
}
// and so on
我想知道如何可以通过这一个方法来做到哪里我只想通过字符串和模型类名的交易,
如何能够做到这样的事:
private void copyToRealm(RealmModel model, String string){
mRealm.beginTransaction();
mRealm.copyToRealmOrUpdate(new model(string));
mRealm.commitTransaction();
}
,并调用它像
copyToRealm(ABCModel, string);
,我希望做同样的查询像
public RealmResults<?> queryChemistry(RealmModel model, String year) {
return realm.where(model.class)
.contains("Title", "string")
.findAll();
}
时和模型我的意思是它扩展了RealmObject
类。
,如果您需要任何更多的信息还是让我知道,我会更新的问题,谢谢