本文整理汇总了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"));
}
示例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();
}
示例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;
}
示例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);
}
示例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()
}
示例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();
}
示例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();
}
}
示例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);
}
示例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();
}
示例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();
}
}
示例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;
}
示例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();
}
示例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);
}
示例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();
}
示例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();
}