fossasia / open-event-droidgen

Open Event Android App Generator https://github.com/fossasia/open-event-android/raw/apk/sample-apk-fossasia17-development.apk
GNU General Public License v3.0
2.06k stars 828 forks source link

using realm.executeTransaction() instead of realm.beginTransaction() and realm.commitTransaction() #2474

Open simarsingh24 opened 6 years ago

simarsingh24 commented 6 years ago

Expected Behaviour

Realm.executeTransaction() should be used as it automatically handles calling realm.cancelTransaction() in case an exception is thrown.

Would you like to work on the issue?

Yes

What I propose This should be changed to

Realm realm = Realm.getDefaultInstance();
realm.beginTransaction(); 
realm.copyToRealm(_something_)
realm.commitTransaction();

this->

try(Realm realmInstance = Realm.getDefaultInstance()) {
    realmInstance.executeTransaction((realm) -> realm.insertOrUpdate(_something_));
}
simarsingh24 commented 6 years ago

@iamareebjamal should I proceed?