Skip to content

Commit

Permalink
Reverting back to previous working method. Figure out the proper way …
Browse files Browse the repository at this point in the history
…to return something from realm after closing the instance.
  • Loading branch information
Iiro Krankka committed Feb 6, 2017
1 parent 9acc11d commit 6697790
Showing 1 changed file with 18 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,37 +44,26 @@ class RealmCoffeeEventRepository : CoffeeEventRepository {
return@with event!!
}

override fun getAccidentCountForUser(user: User) = with(Realm.getDefaultInstance()) {
val count = where(CoffeeBrewingEvent::class.java)
.equalTo("isSuccessful", false)
.equalTo("user.id", user.id)
.count()
override fun getAccidentCountForUser(user: User) =
Realm.getDefaultInstance()
.where(CoffeeBrewingEvent::class.java)
.equalTo("isSuccessful", false)
.equalTo("user.id", user.id)
.count()

close()
return@with count
}

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

close()
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 copy
}
override fun getLastBrewingAccident() =
Realm.getDefaultInstance()
.where(CoffeeBrewingEvent::class.java)
.equalTo("isSuccessful", false)
.findAllSorted("time", Sort.ASCENDING)
.lastOrNull()

private fun newEvent(realm: Realm) =
realm.createObject(
Expand Down

0 comments on commit 6697790

Please sign in to comment.