当前位置: 首页>>代码示例>>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;未经允许,请勿转载。