當前位置: 首頁>>代碼示例>>Java>>正文


Java Realm.executeTransactionAsync方法代碼示例

本文整理匯總了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"));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:27,代碼來源:NYTimesDataLoader.java

示例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);
			}
		}
	});
}
 
開發者ID:goutfeb,項目名稱:ElephantAsia,代碼行數:21,代碼來源:RealmDB.java

示例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();
}
 
開發者ID:gojuukaze,項目名稱:healthgo,代碼行數:17,代碼來源:StepThread.java

示例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
    );
}
 
開發者ID:rezkyatinnov,項目名稱:kyandroid,代碼行數:9,代碼來源:LocalData.java


注:本文中的io.realm.Realm.executeTransactionAsync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。