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


Java Realm.copyToRealmOrUpdate方法代碼示例

本文整理匯總了Java中io.realm.Realm.copyToRealmOrUpdate方法的典型用法代碼示例。如果您正苦於以下問題:Java Realm.copyToRealmOrUpdate方法的具體用法?Java Realm.copyToRealmOrUpdate怎麽用?Java Realm.copyToRealmOrUpdate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.realm.Realm的用法示例。


在下文中一共展示了Realm.copyToRealmOrUpdate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: insertOrUpdate

import io.realm.Realm; //導入方法依賴的package包/類
/**
 * Insert or update all
 * @param items
 * @return List of item copied from realm
 */
@Override
public Flowable<Optional<List<T>>> insertOrUpdate(List<T> items) {
    final Realm realm = Realm.getDefaultInstance();
    realm.beginTransaction();
    items = realm.copyToRealmOrUpdate(items);
    realm.commitTransaction();
    List<T> copies = realm.copyFromRealm(items);
    realm.close();

    return Flowable.just(Optional.wrap(copies));
}
 
開發者ID:playmoweb,項目名稱:store2realm,代碼行數:17,代碼來源:RealmDao.java

示例2: save

import io.realm.Realm; //導入方法依賴的package包/類
@Override
public void save(Post post, Callbacks.IResultCallback<Post> callback) {
    Realm realm = Realm.getDefaultInstance();

    try {
        realm.beginTransaction(); // open a transation
        realm.copyToRealmOrUpdate(post); // satve or update the data
        realm.commitTransaction(); // close the transation

        if (callback != null)
            callback.onSuccess(post);
    } catch (Exception ex) {
        ex.printStackTrace();

        if (callback != null)
            callback.onDataUnavailable();
    }
}
 
開發者ID:pedromassango,項目名稱:Programmers,代碼行數:19,代碼來源:PostsLocalDataSource.java

示例3: setPackageReadable

import io.realm.Realm; //導入方法依賴的package包/類
/**
 * Set a package of specific number read or unread new.
 * @param packageId The primary key or the package id.
 *                  See {@link Package#number}
 * @param readable Read or unread new.
 *                 See {@link Package#readable}
 */
@Override
public void setPackageReadable(@NonNull String packageId, boolean readable) {
    Realm rlm = RealmHelper.newRealmInstance();
    Package p = rlm.copyFromRealm(rlm.where(Package.class)
            .equalTo("number", packageId)
            .findFirst());
    if (p != null) {
        rlm.beginTransaction();
        p.setReadable(readable);
        // When a package is not readable, it is not pushable.
        p.setPushable(readable);
        rlm.copyToRealmOrUpdate(p);
        rlm.commitTransaction();
        rlm.close();
    }
}
 
開發者ID:TonnyL,項目名稱:Espresso,代碼行數:24,代碼來源:PackagesLocalDataSource.java

示例4: populateRealm

import io.realm.Realm; //導入方法依賴的package包/類
private void populateRealm() {
    final Realm realm = Realm.getDefaultInstance();

    final Author moses = new Author();
    moses.name = "Moses";
    final Book genesis = new Book();
    genesis.index = 0;
    genesis.name = "Genesis";
    genesis.author = moses;
    final Book exodus = new Book();
    exodus.index = 1;
    exodus.name = "Exodus";
    exodus.author = moses;
    final Book hebrews = new Book();
    hebrews.index = 57;
    hebrews.name = "Letter to the Hebrews";

    realm.beginTransaction();
    realm.copyToRealmOrUpdate(genesis);
    realm.copyToRealmOrUpdate(exodus);
    realm.copyToRealmOrUpdate(hebrews);
    realm.commitTransaction();

    realm.close();
}
 
開發者ID:xizzhu,項目名稱:stetho-realm,代碼行數:26,代碼來源:App.java

示例5: populateRealm2

import io.realm.Realm; //導入方法依賴的package包/類
private void populateRealm2() {
    final Realm realm = Realm.getInstance(
        new RealmConfiguration.Builder().directory(new File(getFilesDir(), "custom"))
            .name("random.realm")
            .build());

    final Author moses = new Author();
    moses.name = "Moses";
    final Book genesis = new Book();
    genesis.index = 0;
    genesis.name = "Genesis";
    genesis.author = moses;
    final Verse verse =
        Verse.create(genesis, 0, 0, "In the beginning God created the heaven and the earth.");

    realm.beginTransaction();
    realm.copyToRealmOrUpdate(verse);
    realm.commitTransaction();

    realm.close();
}
 
開發者ID:xizzhu,項目名稱:stetho-realm,代碼行數:22,代碼來源:App.java

示例6: populateRealmIgnored

import io.realm.Realm; //導入方法依賴的package包/類
private void populateRealmIgnored() {
    final Realm realm =
        Realm.getInstance(new RealmConfiguration.Builder().name("realm.ignored").build());

    final Author moses = new Author();
    moses.name = "Moses";
    final Book genesis = new Book();
    genesis.index = 0;
    genesis.name = "Genesis";
    genesis.author = moses;

    realm.beginTransaction();
    realm.copyToRealmOrUpdate(genesis);
    realm.commitTransaction();

    realm.close();
}
 
開發者ID:xizzhu,項目名稱:stetho-realm,代碼行數:18,代碼來源:App.java

示例7: cachePlaintextObject

import io.realm.Realm; //導入方法依賴的package包/類
static void cachePlaintextObject(Realm userRealm, SyncableObject so) {
	// Per LDLN convention, we need to manually check duplicates based
	// on uuid and timeModifiedSinceCreation with a manual update rule,
	// and only (1) copy to realm if it doesn't exist, or (2) update in
	// realm if an older version of the object does exist.
	//
	// note:
	//   userRealm.insert() produces duplicates
	//   userRealm.copyToRealm() throws RealmPrimaryKeyConstraintException
	if (userRealm.where(PlaintextObject.class)
			.equalTo("uuid", so.getUuid())
			.lessThanOrEqualTo("timeModifiedSinceCreation", so.getTimeModifiedSinceCreation())
			.count() == 0) {
		PlaintextObject obj = new PlaintextObject(so, DEK, encryptionIsEnabled);
		userRealm.copyToRealmOrUpdate(obj);
	}
}
 
開發者ID:LDLN,項目名稱:Responder-Android,代碼行數:18,代碼來源:LDLN.java

示例8: parseRawData

import io.realm.Realm; //導入方法依賴的package包/類
static void parseRawData() {
    Realm realmRawData = Realm.getInstance(realmConfigRawData);
    Realm realmProcessedData = Realm.getInstance(realmConfigProcessedData);

    // if processed data realm is empty
    if (realmProcessedData.isEmpty() && !realmRawData.isEmpty()) {
        // parse data from raw realm into processed data realm
        Log.i(LOG_ID, "Parsing data raw_data realm to processed_data realm.");
        realmProcessedData.beginTransaction();
        for (RawTagData rawTagData : realmRawData.where(RawTagData.class)
                        .findAllSorted(RawTagData.DATE, Sort.ASCENDING)) {
            realmProcessedData.copyToRealmOrUpdate(new ReadingData(rawTagData));
        }
        realmProcessedData.commitTransaction();
    }

    realmProcessedData.close();
    realmRawData.close();
}
 
開發者ID:DorianScholz,項目名稱:OpenLibre,代碼行數:20,代碼來源:OpenLibre.java

示例9: insertOrUpdate

import io.realm.Realm; //導入方法依賴的package包/類
private void insertOrUpdate(Comment comment, Callbacks.IResultCallback<Comment> callback) {
    Realm realm = Realm.getDefaultInstance();
    try {
        realm.beginTransaction();
        realm.copyToRealmOrUpdate(comment);
        realm.commitTransaction();

        if (callback != null)
            callback.onSuccess(comment);
    } catch (IOException ex) {
        ex.printStackTrace();
        if (callback != null)
            callback.onDataUnavailable();
    }
}
 
開發者ID:pedromassango,項目名稱:Programmers,代碼行數:16,代碼來源:CommentsLocalDataSource.java

示例10: delete

import io.realm.Realm; //導入方法依賴的package包/類
@Override
public Flowable<Integer> delete(T object) {
    if(object.isManaged()) {
        object.deleteFromRealm();
    } else {
        Realm realm = Realm.getDefaultInstance();
        realm.beginTransaction();
        T managedObject = realm.copyToRealmOrUpdate(object);
        managedObject.deleteFromRealm();
        realm.commitTransaction();
        realm.close();
    }
    return Flowable.just(1);
}
 
開發者ID:playmoweb,項目名稱:store2realm,代碼行數:15,代碼來源:RealmDao.java

示例11: convertInTransaction

import io.realm.Realm; //導入方法依賴的package包/類
public static void convertInTransaction(final Realm realm, final Feed feed, final List<SyndEntry> items, final ConversionCallback c) {
    ArrayList<Article> toAdd = new ArrayList<>();
    for (SyndEntry i : items) {
        if (realm.where(Article.class).equalTo("title", i.getTitle()).findFirst() == null) {
            Article a = new Article();
            a.setAll(i, feed);
            realm.copyToRealmOrUpdate(a);
            toAdd.add(a);
        }
    }
    Collections.reverse(toAdd);
    c.onCompletion(toAdd.size());
}
 
開發者ID:ccrama,項目名稱:Slide-RSS,代碼行數:14,代碼來源:XMLToRealm.java

示例12: setAllPackagesRead

import io.realm.Realm; //導入方法依賴的package包/類
/**
 * Set all the packages which are the unread new read.
 */
@Override
public void setAllPackagesRead() {
    Realm rlm = RealmHelper.newRealmInstance();
    List<Package> results = rlm.copyFromRealm(rlm.where(Package.class).findAll());

    for (Package p : results) {
        p.setReadable(false);
        p.setPushable(false);
        rlm.beginTransaction();
        rlm.copyToRealmOrUpdate(p);
        rlm.commitTransaction();
    }
    rlm.close();
}
 
開發者ID:TonnyL,項目名稱:Espresso,代碼行數:18,代碼來源:PackagesLocalDataSource.java

示例13: updatePackageName

import io.realm.Realm; //導入方法依賴的package包/類
@Override
public void updatePackageName(@NonNull String packageId, @NonNull String name) {
    Realm rlm = RealmHelper.newRealmInstance();
    Package p = rlm.where(Package.class)
            .equalTo("number", packageId)
            .findFirst();
    if (p != null) {
        rlm.beginTransaction();
        p.setName(name);
        rlm.copyToRealmOrUpdate(p);
        rlm.commitTransaction();
    }
    rlm.close();
}
 
開發者ID:TonnyL,項目名稱:Espresso,代碼行數:15,代碼來源:PackagesLocalDataSource.java

示例14: saveOrUpdateUser

import io.realm.Realm; //導入方法依賴的package包/類
/**
 * This method is just to save with no callback required.
 *
 * @param usuario the uer to be saved.
 */
public void saveOrUpdateUser(Usuario usuario) {
    Realm realm = Realm.getDefaultInstance();
    try {
        //save ususario on realm
        realm.beginTransaction();
        realm.copyToRealmOrUpdate(usuario);
        realm.commitTransaction();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:pedromassango,項目名稱:Programmers,代碼行數:17,代碼來源:UserLocalDataSource.java

示例15: saveOrUpdate

import io.realm.Realm; //導入方法依賴的package包/類
public static <O extends RealmObject> void saveOrUpdate(Realm realmInstance, O object) {
    Realm realm = realmInstance;
    realm.beginTransaction();
    realm.copyToRealmOrUpdate(object);
    realm.commitTransaction();
    realm.close();
}
 
開發者ID:rezkyatinnov,項目名稱:kyandroid,代碼行數:8,代碼來源:LocalData.java


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