本文整理匯總了Java中io.realm.Realm.executeTransactionAsync方法的典型用法代碼示例。如果您正苦於以下問題:Java Realm.executeTransactionAsync方法的具體用法?Java Realm.executeTransactionAsync怎麽用?Java Realm.executeTransactionAsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.realm.Realm
的用法示例。
在下文中一共展示了Realm.executeTransactionAsync方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: processAndAddData
import io.realm.Realm; //導入方法依賴的package包/類
private void processAndAddData(final Realm realm, final String sectionKey, final List<NYTimesStory> stories) {
if (stories.isEmpty()) return;
realm.executeTransactionAsync(r -> {
for (NYTimesStory story : stories) {
Date parsedPublishedDate = inputDateFormat.parse(story.getPublishedDate(), new ParsePosition(0));
story.setSortTimeStamp(parsedPublishedDate.getTime());
story.setPublishedDate(outputDateFormat.format(parsedPublishedDate));
// Find existing story in Realm (if any)
// If it exists, we need to merge the local state with the remote, because the local state
// contains more info than is available on the server.
NYTimesStory persistedStory = r.where(NYTimesStory.class).equalTo(NYTimesStory.URL, story.getUrl()).findFirst();
if (persistedStory != null) {
// Only local state is the `read` boolean.
story.setRead(persistedStory.isRead());
}
// Only create or update the local story if needed
if (persistedStory == null || !persistedStory.getUpdatedDate().equals(story.getUpdatedDate())) {
story.setApiSection(sectionKey);
r.copyToRealmOrUpdate(story);
}
}
}, throwable -> Timber.e(throwable, "Could not save data"));
}
示例2: insertOrUpdateElephant
import io.realm.Realm; //導入方法依賴的package包/類
static public void insertOrUpdateElephant(final Elephant elephant, final List<Document> documents) {
Realm realm = Realm.getDefaultInstance();
realm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm bgRealm) {
if (elephant.id == -1) {
elephant.id = getNextId(bgRealm, Elephant.class, Elephant.ID);
}
bgRealm.insertOrUpdate(elephant);
for (Document document : documents) {
if (document.id == -1) {
document.id = getNextId(bgRealm, Document.class, Document.ID);
}
document.elephant_id = elephant.id;
bgRealm.insertOrUpdate(document);
}
}
});
}
示例3: save
import io.realm.Realm; //導入方法依賴的package包/類
public void save(Date date,long num)
{
Realm realm = Realm.getDefaultInstance();
realmAsyncTask = realm.executeTransactionAsync(
new StepTransaction(date, num),
new SuccessTransaction(realmAsyncTask),
new Realm.Transaction.OnError() {
@Override
public void onError(Throwable error) {
error.printStackTrace();
Log.d("realm", "insert error");
}
}
);
realm.close();
}
示例4: saveOrUpdate
import io.realm.Realm; //導入方法依賴的package包/類
public static <O extends RealmObject> void saveOrUpdate(Realm realmInstance,O object, OnTransactionCallback callback) {
Realm realm = realmInstance;
realm.executeTransactionAsync(
realm1 -> realm1.copyToRealmOrUpdate(object),
callback::onSuccess,
callback::onError
);
}