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