Skip to content

Commit

Permalink
Now always returning copies of Realm objects after closing the Realm …
Browse files Browse the repository at this point in the history
…instances, instead of the real ones.
  • Loading branch information
Iiro Krankka committed Feb 6, 2017
1 parent 347c7fd commit 9acc11d
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,21 @@ class RealmCoffeeEventRepository : CoffeeEventRepository {
.equalTo("isSuccessful", true)
.findAllSorted("time", Sort.ASCENDING)
.lastOrNull()
val copy = copyFromRealm(lastEvent)

close()
return@with lastEvent
return@with copy
}

override fun getLastBrewingAccident() = with(Realm.getDefaultInstance()) {
val lastAccident = where(CoffeeBrewingEvent::class.java)
.equalTo("isSuccessful", false)
.findAllSorted("time", Sort.ASCENDING)
.lastOrNull()
val copy = copyFromRealm(lastAccident)

close()
return@with lastAccident
return@with copy
}

private fun newEvent(realm: Realm) =
Expand Down

0 comments on commit 9acc11d

Please sign in to comment.