@Override public void delete(Comment comment, Callbacks.IRequestCallback callback) { Realm realm = Realm.getDefaultInstance(); try { realm.beginTransaction(); (comment).deleteFromRealm(); realm.commitTransaction(); if (callback != null) callback.onSuccess(); } catch (IOException ex) { ex.printStackTrace(); if (callback != null) callback.onError(); } }
@Override public void getAll(String postId, Callbacks.IResultsCallback<Comment> callback) { Realm realm = Realm.getDefaultInstance(); try { List<Comment> results = realm.where(Comment.class) .equalTo("postId", postId) .findAll(); if (results == null || results.size() == 0) { callback.onDataUnavailable(); return; } callback.onSuccess(results); } catch (IOException ex) { ex.printStackTrace(); callback.onDataUnavailable(); } }
private void insertOrUpdate(Comment comment, Callbacks.IResultCallback<Comment> callback) { Realm realm = Realm.getDefaultInstance(); try { realm.beginTransaction(); realm.copyToRealmOrUpdate(comment); realm.commitTransaction(); if (callback != null) callback.onSuccess(comment); } catch (IOException ex) { ex.printStackTrace(); if (callback != null) callback.onDataUnavailable(); } }
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(); } }