Java Code Examples for io.realm.Realm#close()
The following examples show how to use
io.realm.Realm#close() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessageRealm.java From talk-android with MIT License | 6 votes |
public Message updateUploadFileSuccessWithCurrentThread(final String msgId) { Message message = new Message(); Realm realm = RealmProvider.getInstance(); try { realm.beginTransaction(); Message msg = realm.where(Message.class) .equalTo(Message.TEAM_ID, BizLogic.getTeamId()) .equalTo(Message.ID, msgId) .findFirst(); msg.setStatus(MessageDataProcess.Status.NONE.ordinal()); copy(message, msg); if (message.getTagToJson() != null) { final List<Tag> tags = mGson.fromJson(message.getTagToJson(), new TypeToken<List<Tag>>() { }.getType()); message.setTags(tags); } realm.commitTransaction(); } catch (Exception e) { e.printStackTrace(); realm.cancelTransaction(); } finally { realm.close(); } return message; }
Example 2
Source File: NotificationRealm.java From talk-android with MIT License | 6 votes |
public void batchAddWithCurrentThread(final List<Notification> notifications) { List<Notification> realmNotifications = new ArrayList<>(notifications.size()); Realm realm = RealmProvider.getInstance(); try { for (Notification realmNotification : notifications) { Notification notification = new Notification(); copy(notification, realmNotification); realmNotifications.add(notification); } realm.beginTransaction(); realm.copyToRealmOrUpdate(realmNotifications); realm.commitTransaction(); } catch (Exception e) { e.printStackTrace(); realm.cancelTransaction(); } finally { realm.close(); } }
Example 3
Source File: RealmRoomMessageWallet.java From iGap-Android with GNU Affero General Public License v3.0 | 6 votes |
public static RealmRoomMessageWallet put(final ProtoGlobal.RoomMessageWallet input) { Realm realm = Realm.getDefaultInstance(); RealmRoomMessageWallet messageWallet = null; messageWallet = realm.createObject(RealmRoomMessageWallet.class, AppUtils.makeRandomId()); messageWallet.setType(input.getType().toString()); messageWallet.setFromUserId(input.getMoneyTransfer().getFromUserId()); messageWallet.setToUserId(input.getMoneyTransfer().getToUserId()); messageWallet.setAmount(input.getMoneyTransfer().getAmount()); messageWallet.setTraceNumber(input.getMoneyTransfer().getTraceNumber()); messageWallet.setInvoiceNumber(input.getMoneyTransfer().getInvoiceNumber()); messageWallet.setPayTime(input.getMoneyTransfer().getPayTime()); messageWallet.setDescription(input.getMoneyTransfer().getDescription()); realm.close(); return messageWallet; }
Example 4
Source File: XMPPSession.java From mangosta-android with Apache License 2.0 | 6 votes |
private void manageMessageCorrection(Message message, Date delayDate) { MessageCorrectExtension messageCorrectExtension = MessageCorrectExtension.from(message); String newMessageBody = message.getBody(); String idInitialMessage = messageCorrectExtension.getIdInitialMessage(); Realm realm = RealmManager.getInstance().getRealm(); realm.beginTransaction(); ChatMessage chatMessage = realm.where(ChatMessage.class) .equalTo("messageId", idInitialMessage) .findFirst(); if (chatMessage != null) { chatMessage.setContent(newMessageBody); manageDelayDate(delayDate, chatMessage); realm.copyToRealmOrUpdate(chatMessage); } realm.commitTransaction(); realm.close(); }
Example 5
Source File: ImageImproveService.java From GankApp with GNU General Public License v2.0 | 6 votes |
@Override protected void onHandleIntent(Intent intent) { Realm realm = Realm.getInstance(this); /**查询所有尺寸为0的图片的数目*/ int count = realm.where(Image.class).equalTo("width",0) .findAllSorted("position", Sort.DESCENDING).size(); Logger.d(count + " image need improve"); if (count == 0) { Logger.d("no new image, fresh fetch"); } else if (ACTION_IMPROVE_IMAGE.equals(intent.getAction())) { improveImageInfo(count,realm); } realm.close(); Logger.d("finished improve num:" + count); Intent broadcast = new Intent(ACTION_UPDATE_RESULT); broadcast.putExtra(EXTRA_CHANGE, count); broadcast.putExtra(EXTRA_ACTION, intent.getAction()); sendBroadcast(broadcast, PERMISSION_ACCESS_UPDATE_RESULT); }
Example 6
Source File: SearchFragment.java From iGap-Android with GNU Affero General Public License v3.0 | 6 votes |
private void goToRoom(final long id, SearchType type, long messageId, String userName) { final Realm realm = Realm.getDefaultInstance(); RealmRoom realmRoom = null; if (type == SearchType.message) { realmRoom = realm.where(RealmRoom.class).equalTo(RealmRoomFields.ID, id).findFirst(); goToRoomWithRealm(realmRoom, type, id); } else if (type == SearchType.contact) { realmRoom = realm.where(RealmRoom.class).equalTo(RealmRoomFields.CHAT_ROOM.PEER_ID, id).findFirst(); goToRoomWithRealm(realmRoom, type, id); } else if (type == SearchType.room) { HelperUrl.checkUsernameAndGoToRoom(userName, HelperUrl.ChatEntry.profile); popBackStackFragment(); } realm.close(); }
Example 7
Source File: MessageRealm.java From talk-android with MIT License | 6 votes |
public List<Message> getUnSendMessageWithCurrentThread(final String foreignId) { final List<Message> messages = new ArrayList<>(); Realm realm = RealmProvider.getInstance(); try { realm.beginTransaction(); RealmResults<Message> realmResults = realm.where(Message.class) .equalTo(Message.TEAM_ID, BizLogic.getTeamId()) .equalTo(Message.FOREIGN_ID, foreignId) .notEqualTo(Message.STATUS, 0) .findAll(); realmResults.sort(Message.CREATE_AT_TIME, Sort.ASCENDING); for (Message realmResult : realmResults) { final Message message = new Message(); copy(message, realmResult); messages.add(message); } realm.commitTransaction(); } catch (Exception e) { e.printStackTrace(); realm.cancelTransaction(); } finally { realm.close(); } return messages; }
Example 8
Source File: RealmManager.java From mangosta-android with Apache License 2.0 | 5 votes |
public void saveBlogPostComment(BlogPostComment comment) { Realm realm = getRealm(); realm.beginTransaction(); realm.copyToRealmOrUpdate(comment); realm.commitTransaction(); realm.close(); }
Example 9
Source File: Database.java From aptoide-client-v8 with GNU General Public License v3.0 | 5 votes |
public <E extends RealmObject> void deleteAll(Class<E> clazz) { Realm realm = get(); try { realm.beginTransaction(); realm.delete(clazz); realm.commitTransaction(); } finally { if (realm != null) { realm.close(); } } }
Example 10
Source File: CharacterLocalDataSource.java From Game-of-Thrones with Apache License 2.0 | 5 votes |
private void remove(GoTCharacter character) { Realm realm = Realm.getDefaultInstance(); realm.executeTransaction(realm1 -> { BddGoTCharacter bddGoTCharacter = find(character); if (bddGoTCharacter != null) { bddGoTCharacter.deleteFromRealm(); } }); realm.close(); }
Example 11
Source File: RealmRegisteredInfo.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
public RealmList<RealmAvatar> getAvatars() { RealmList<RealmAvatar> avatars = new RealmList<>(); Realm realm = Realm.getDefaultInstance(); for (RealmAvatar avatar : realm.where(RealmAvatar.class).equalTo(RealmAvatarFields.OWNER_ID, id).findAll().sort(RealmAvatarFields.ID, Sort.ASCENDING)) { avatars.add(avatar); } realm.close(); return avatars; }
Example 12
Source File: RealmAvatar.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
public static RealmAvatar convert(long userId, final RealmAttachment attachment) { Realm realm = Realm.getDefaultInstance(); // don't put it into transaction RealmAvatar realmAvatar = realm.where(RealmAvatar.class).equalTo(RealmAvatarFields.OWNER_ID, userId).findFirst(); if (realmAvatar == null) { realmAvatar = realm.createObject(RealmAvatar.class, attachment.getId()); realmAvatar.setOwnerId(userId); } realmAvatar.setFile(attachment); realm.close(); return realmAvatar; }
Example 13
Source File: RealmManager.java From mangosta-android with Apache License 2.0 | 5 votes |
public boolean chatMessageExists(String messageId) { Realm realm = getRealm(); boolean hasChat = realm.where(ChatMessage.class) .equalTo("messageId", messageId) .count() > 0; realm.close(); return hasChat; }
Example 14
Source File: Database.java From aptoide-client-v8 with GNU General Public License v3.0 | 5 votes |
public <E extends RealmObject> void delete(Class<E> clazz, String key, Long value) { Realm realm = get(); try { E obj = realm.where(clazz) .equalTo(key, value) .findFirst(); deleteObject(realm, obj); } finally { if (realm != null) { realm.close(); } } }
Example 15
Source File: HouseLocalDataSource.java From Game-of-Thrones with Apache License 2.0 | 5 votes |
private void save(BddHouse house) { Realm realm = Realm.getDefaultInstance(); realm.executeTransaction(realm1 -> { realm1.copyToRealmOrUpdate(house); }); realm.close(); }
Example 16
Source File: FragmentNewGroup.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
private void showInitials() { Realm realm = Realm.getDefaultInstance(); RealmUserInfo realmUserInfo = realm.where(RealmUserInfo.class).findFirst(); imgCircleImageView.setImageBitmap(HelperImageBackColor.drawAlphabetOnPicture((int) imgCircleImageView.getContext().getResources().getDimension(R.dimen.dp100), realmUserInfo.getUserInfo().getInitials(), realmUserInfo.getUserInfo().getColor())); realm.close(); }
Example 17
Source File: RealmDatabase.java From mvvm-template with GNU General Public License v3.0 | 5 votes |
public void clearAll() { Realm mRealm = Realm.getInstance(mRealmConfiguration); mRealm.beginTransaction(); mRealm.delete(Repo.class); mRealm.delete(Issue.class); mRealm.delete(User.class); mRealm.commitTransaction(); mRealm.close(); }
Example 18
Source File: DragonDataManager.java From Theogony with MIT License | 5 votes |
public String getVersion() { Realm realm = RealmProvider.getInstance().getRealm(); try { DragonData result = realm.where(DragonData.class).findFirst(); return result != null ? result.getVersion() : null; } finally { realm.close(); } }
Example 19
Source File: RealmRoom.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
public static boolean isPromote(Long id) { Realm realm = Realm.getDefaultInstance(); RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo(RealmRoomFields.ID, id).findFirst(); if (realmRoom != null) { return realmRoom.isFromPromote(); } realm.close(); return false; }
Example 20
Source File: RealmRegisteredInfo.java From iGap-Android with GNU Affero General Public License v3.0 | 4 votes |
public static void updateBlock(final long userId, final boolean block) { Realm realm = Realm.getDefaultInstance(); updateBlock(userId, block, realm); realm.close(); }