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


Java Realm.beginTransaction方法代碼示例

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


在下文中一共展示了Realm.beginTransaction方法的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: 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

示例3: 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

示例4: fetchRandomMovieOrTvSeries

import io.realm.Realm; //導入方法依賴的package包/類
private Movie fetchRandomMovieOrTvSeries() {
    Realm realm = Realm.getDefaultInstance();
    //TODO: Add Random TV Series to fetch
    RealmResults<Movie> movieRealmResults = realm.where(Movie.class).equalTo("isNotified", false).findAll();

    Util.debugLog(TAG, "fetchRandomMovieOrTvSeries: Size of movies with isNotified false " + movieRealmResults.size());

    if (movieRealmResults.size() != 0) {

        Random r = new Random();
        int randomNumber = r.nextInt(movieRealmResults.size());

        Movie movie = movieRealmResults.get(randomNumber);

        realm.beginTransaction();
        movieRealmResults.get(randomNumber).setNotified(true);
        realm.commitTransaction();


        return movie;
    } else {
        return null;
    }
}
 
開發者ID:hsm59,項目名稱:WatchIt,代碼行數:25,代碼來源:NotificationPublisher.java

示例5: logoutRealmUser

import io.realm.Realm; //導入方法依賴的package包/類
private void logoutRealmUser() {
    //注冊成功寫數據庫
    RealmConfiguration config = new RealmConfiguration.Builder().name("yyox.realm").build();
    Realm objRealm = Realm.getInstance(config);

    //查找
    RealmUser realmUser = objRealm.where(RealmUser.class).findFirst();
    if (realmUser != null) {
        //先刪除
        objRealm.beginTransaction();
        RealmResults results = objRealm.where(RealmUser.class).findAll();
        results.deleteAllFromRealm();
        objRealm.commitTransaction();
        //再添加
        objRealm.beginTransaction();
        RealmUser realmUserNew = objRealm.createObject(RealmUser.class);
        realmUserNew.setName("");
        objRealm.commitTransaction();

        mRealmUser = null;
    }
}
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:23,代碼來源:WEApplication.java

示例6: insert

import io.realm.Realm; //導入方法依賴的package包/類
@Override
public boolean insert(Note note) {
    Realm realm = Realm.getInstance(configuration);
    final NoteDAO dao = RealmConverter.convert(note);

    realm.beginTransaction();
    try {
        realm.copyToRealm(dao);
        realm.commitTransaction();
    } catch (Throwable throwable) {
        realm.cancelTransaction();
        realm.close();
        return false;
    }
    realm.close();
    return true;
}
 
開發者ID:djuelg,項目名稱:Neuronizer,代碼行數:18,代碼來源:NoteRepositoryImpl.java

示例7: updateDAB

import io.realm.Realm; //導入方法依賴的package包/類
@Override
public void updateDAB(Object object) {
    JSONObject jsonObject = (JSONObject) object;

    String username = "", password = "";
    try {
        username = jsonObject.getString("username");
        password = jsonObject.getString("password");
    } catch (Exception e) {
        e.printStackTrace();
    }

    Realm realm = Realm.getDefaultInstance();
    realm.beginTransaction();
    realm.delete(User.class);

    User user = realm.createObject(User.class);
    user.setUsername(username);
    user.setPassword(password);
    realm.commitTransaction();

    mainController.updateResponse(user);
}
 
開發者ID:attiqrehman1991,項目名稱:AndroidRepositoryWithOfflineMode,代碼行數:24,代碼來源:LoginDAB.java

示例8: readFromRealmSync

import io.realm.Realm; //導入方法依賴的package包/類
protected <T> T readFromRealmSync(SyncCallable<T> callable) {
    Realm realm = null;
    try {
        realm = Realm.getDefaultInstance();
        realm.beginTransaction();
        return callable.execute(realm);
    } finally {
        if (realm != null) {
            realm.commitTransaction();
            realm.close();
        }
    }
}
 
開發者ID:krokers,項目名稱:exchange-rates-mvvm,代碼行數:14,代碼來源:RealmManagerBase.java

示例9: updateLastReadDate

import io.realm.Realm; //導入方法依賴的package包/類
public void updateLastReadDate(String id, String date) {
    Realm realm = Realm.getDefaultInstance();
    realm.beginTransaction();
    BookDB result = realm.where(BookDB.class).equalTo("idBook", id).findFirst();
    if (result != null)
        result.setLastReadDate(date);
    realm.commitTransaction();
}
 
開發者ID:OlegKlimenko,項目名稱:Plamber-Android,代碼行數:9,代碼來源:BookUtilsDB.java

示例10: delete

import io.realm.Realm; //導入方法依賴的package包/類
@Override
public void delete(Notification notification, Callbacks.IResultCallback<Notification> callback) {
    Realm realm = Realm.getDefaultInstance();
    try {
        realm.beginTransaction();
        notification.deleteFromRealm();
        realm.commitTransaction();


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

示例11: delete

import io.realm.Realm; //導入方法依賴的package包/類
@Override
public RealmObject delete(String cacheId, Class<? extends RealmObject> aClass) {
    Realm realm = Realm.getDefaultInstance();
    realm.beginTransaction();
    RealmObject realmObject = realm.where(aClass).endsWith("cacheId", cacheId).findFirst();
    realmObject.deleteFromRealm();
    realm.commitTransaction();


    return null;
}
 
開發者ID:killnono,項目名稱:Dalaran,代碼行數:12,代碼來源:RealmClient.java

示例12: writeSampleData

import io.realm.Realm; //導入方法依賴的package包/類
private void writeSampleData(Realm realm) {
    realm.beginTransaction();
    for (int i = 0; i < TEST_SIZE; i++) {
        AllTypes obj = realm.createObject(AllTypes.class);
        obj.setColumnString("Object " + i);
    }
    realm.commitTransaction();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:9,代碼來源:ProgressListenerTests.java

示例13: resetInstance

import io.realm.Realm; //導入方法依賴的package包/類
public static void resetInstance() {
    instance = null;
    Realm realm = Realm.getInstance(configuration);
    UserFactoryStore store = realm.where(UserFactoryStore.class).findFirst();
    realm.beginTransaction();
    if (store == null) {
        store = realm.createObject(UserFactoryStore.class);
    }
    store.setUserName(UUID.randomUUID().toString());
    realm.commitTransaction();
    realm.close();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:13,代碼來源:UserFactory.java

示例14: deleteAllFromDB

import io.realm.Realm; //導入方法依賴的package包/類
public void deleteAllFromDB() {
    Realm realm = Realm.getDefaultInstance();
    realm.beginTransaction();
    RealmResults<BookDB> results = realm.where(BookDB.class).findAll();
    results.deleteAllFromRealm();
    realm.commitTransaction();
}
 
開發者ID:OlegKlimenko,項目名稱:Plamber-Android,代碼行數:8,代碼來源:BookUtilsDB.java

示例15: onReceive

import io.realm.Realm; //導入方法依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
    NotificationManager manager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

    String title = intent.getStringExtra("title");
    String content = intent.getStringExtra("content");
    String id = intent.getStringExtra("id");

    builder.setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(title)
            .setContentText(content)
            .setContentInfo("Alarm")
            .setPriority(Notification.PRIORITY_HIGH)
            .setDefaults(Notification.DEFAULT_ALL)
            .setVisibility(Notification.VISIBILITY_PRIVATE)
            .setWhen(System.currentTimeMillis());

    manager.notify(0, builder.build());

    Realm realm = Realm.getDefaultInstance();
    AlarmRealmData deleteData = realm.where(AlarmRealmData.class).equalTo("geofenceId", id).findFirst();
    if (deleteData != null) {
        realm.beginTransaction();
        // FIXME: 2017/08/18 Error now
        deleteData.deleteFromRealm();
        realm.commitTransaction();
    }

    Log.d("onReceive", "はいったお!!!!!!!!");
}
 
開發者ID:OldBigBuddha,項目名稱:AlarmWithL-T,代碼行數:32,代碼來源:AlarmReceiver.java


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