當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。