当前位置: 首页>>代码示例>>Java>>正文


Java Realm.commitTransaction方法代码示例

本文整理汇总了Java中io.realm.Realm.commitTransaction方法的典型用法代码示例。如果您正苦于以下问题:Java Realm.commitTransaction方法的具体用法?Java Realm.commitTransaction怎么用?Java Realm.commitTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.realm.Realm的用法示例。


在下文中一共展示了Realm.commitTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: share

import io.realm.Realm; //导入方法依赖的package包/类
public static void share(Context context, String album) {

        ArrayList<Uri> files = new ArrayList<Uri>();

        Realm realm = Realm.getDefaultInstance();
        for(MediaItem item : realm.where(Album.class).equalTo("path", album).findFirst().getMedia().where().equalTo("isSelected",true).findAll()) {
            File file = new File(item.getPath());
            Uri uri = Uri.fromFile(file);
            files.add(uri);
        }

        final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        intent.setType("image/*");
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);

        realm.beginTransaction();
        realm.where(Album.class).equalTo("path", album).findFirst().clearMediaSelection();
        realm.commitTransaction();
        realm.close();

        context.startActivity(Intent.createChooser(intent, "Share"));
    }
 
开发者ID:garretyoder,项目名称:Cluttr,代码行数:23,代码来源:Media.java

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

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

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

示例5: run

import io.realm.Realm; //导入方法依赖的package包/类
@Override
protected void run() {
    user = UserFactory.getInstance().loginWithDefaultUser(Constants.AUTH_URL);
    String realmUrl = Constants.SYNC_SERVER_URL;

    final SyncConfiguration syncConfig = new SyncConfiguration.Builder(user, realmUrl)
            .directory(getService().getRoot())
            .build();
    getService().setRealm(Realm.getInstance(syncConfig));
    Realm realm = getService().getRealm();

    realm.beginTransaction();
    ProcessInfo processInfo = realm.createObject(ProcessInfo.class);
    processInfo.setName("Background_Process1");
    processInfo.setPid(android.os.Process.myPid());
    processInfo.setThreadId(Thread.currentThread().getId());
    realm.commitTransaction();
    // FIXME: If we close the Realm here, the data won't be able to synced to the main process. Is it a bug
    // in sync client which stops too early?
    // Realm is currently configured with stop_immediately. This means the sync session is closed as soon as
    // the last realm instance is closed. Not doing this would make the Realm lifecycle really
    // unpredictable. We should have an easy way to wait for all changes to be uploaded though.
    // Perhaps SyncSession.uploadAllLocalChanges() or something similar to
    // SyncSesson.downloadAllServerChanges()
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:ProcessCommitTests.java

示例6: removeBookFromDatabase

import io.realm.Realm; //导入方法依赖的package包/类
public void removeBookFromDatabase(String id) {
    Realm realm = Realm.getDefaultInstance();
    realm.beginTransaction();
    RealmResults<BookDB> results = realm.where(BookDB.class).equalTo("idBook", id).findAll();
    results.deleteAllFromRealm();
    realm.commitTransaction();
}
 
开发者ID:OlegKlimenko,项目名称:Plamber-Android,代码行数:8,代码来源:BookUtilsDB.java

示例7: insertOrUpdate

import io.realm.Realm; //导入方法依赖的package包/类
private void insertOrUpdate(Comment comment, Callbacks.IRequestCallback callback) {
    Realm realm = Realm.getDefaultInstance();
    try {
        realm.beginTransaction();
        realm.copyToRealmOrUpdate(comment);
        realm.commitTransaction();

        if (callback != null)
            callback.onSuccess();
    } catch (IOException ex) {
        ex.printStackTrace();
        if (callback != null)
            callback.onError();
    }
}
 
开发者ID:pedromassango,项目名称:Programmers,代码行数:16,代码来源:CommentsLocalDataSource.java

示例8: deleteAll

import io.realm.Realm; //导入方法依赖的package包/类
@Override
public Flowable<Integer> deleteAll() {
    final Realm realm = Realm.getDefaultInstance();
    realm.beginTransaction();
    RealmQuery<T> query = realm.where(clazz);
    long count = query.count();
    realm.delete(clazz);
    realm.commitTransaction();
    realm.close();

    return Flowable.just((int)count);
}
 
开发者ID:playmoweb,项目名称:store2realm,代码行数:13,代码来源:RealmDao.java

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

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

import io.realm.Realm; //导入方法依赖的package包/类
public String getBookPrimaryKey(long id) {
    String primaryKey = null;
    Realm realm = Realm.getDefaultInstance();
    realm.beginTransaction();
    BookDB result = realm.where(BookDB.class).equalTo("idServerBook", id).findFirst();
    if (result != null)
        primaryKey = result.getIdBook();
    realm.commitTransaction();
    return primaryKey;
}
 
开发者ID:OlegKlimenko,项目名称:Plamber-Android,代码行数:11,代码来源:BookUtilsDB.java

示例12: invalidate

import io.realm.Realm; //导入方法依赖的package包/类
public static void invalidate() {
    Log.e(Util.LOG_TAG, "Invalidate called, all caches will be wiped");
    Realm realm = Realm.getDefaultInstance();
    realm.beginTransaction();
    realm.deleteAll();
    realm.commitTransaction();
    realm.close();
}
 
开发者ID:garretyoder,项目名称:Cluttr,代码行数:9,代码来源:Media.java

示例13: getListBookFromDB

import io.realm.Realm; //导入方法依赖的package包/类
public List<Book.BookData> getListBookFromDB() {
    Realm realm = Realm.getDefaultInstance();
    realm.beginTransaction();
    List<BookDB> offlineBooks = new ArrayList<>();
    offlineBooks.addAll(realm.where(BookDB.class).findAll());
    realm.commitTransaction();
    return convertBookListForDB(offlineBooks);
}
 
开发者ID:OlegKlimenko,项目名称:Plamber-Android,代码行数:9,代码来源:BookUtilsDB.java

示例14: savePackage

import io.realm.Realm; //导入方法依赖的package包/类
/**
 * Save a package to database.
 * @param pack The package to save. See {@link Package}
 */
@Override
public void savePackage(@NonNull Package pack) {
    Realm rlm = RealmHelper.newRealmInstance();
    // DO NOT forget begin and commit the transaction.
    rlm.beginTransaction();
    rlm.copyToRealmOrUpdate(pack);
    rlm.commitTransaction();
    rlm.close();
}
 
开发者ID:TonnyL,项目名称:Espresso,代码行数:14,代码来源:PackagesLocalDataSource.java

示例15: deletePackage

import io.realm.Realm; //导入方法依赖的package包/类
/**
 * Delete a package with specific id from database.
 * @param packageId The primary key of a package
 *                  or in another words, the package id.
 *                  See {@link Package#number}
 */
@Override
public void deletePackage(@NonNull String packageId) {
    Realm rlm = RealmHelper.newRealmInstance();
    Package p = rlm.where(Package.class)
            .equalTo("number", packageId)
            .findFirst();
    if (p != null) {
        rlm.beginTransaction();
        p.deleteFromRealm();
        rlm.commitTransaction();
    }
    rlm.close();
}
 
开发者ID:TonnyL,项目名称:Espresso,代码行数:20,代码来源:PackagesLocalDataSource.java


注:本文中的io.realm.Realm.commitTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。