Various changes
This commit is contained in:
@@ -480,19 +480,19 @@ class LoggingRealmQuery<E : RealmModel>(val query: RealmQuery<E>) {
|
||||
return query.average(fieldName)
|
||||
}
|
||||
|
||||
fun min(fieldName: String): Number {
|
||||
fun min(fieldName: String): Number? {
|
||||
return query.min(fieldName)
|
||||
}
|
||||
|
||||
fun minimumDate(fieldName: String): Date {
|
||||
fun minimumDate(fieldName: String): Date? {
|
||||
return query.minimumDate(fieldName)
|
||||
}
|
||||
|
||||
fun max(fieldName: String): Number {
|
||||
fun max(fieldName: String): Number? {
|
||||
return query.max(fieldName)
|
||||
}
|
||||
|
||||
fun maximumDate(fieldName: String): Date {
|
||||
fun maximumDate(fieldName: String): Date? {
|
||||
return query.maximumDate(fieldName)
|
||||
}
|
||||
|
||||
@@ -540,7 +540,7 @@ class LoggingRealmQuery<E : RealmModel>(val query: RealmQuery<E>) {
|
||||
return query.findAllSortedAsync(fieldName1, sortOrder1, fieldName2, sortOrder2)
|
||||
}
|
||||
|
||||
fun findFirst(): E {
|
||||
fun findFirst(): E? {
|
||||
return query.findFirst()
|
||||
}
|
||||
|
||||
|
||||
@@ -7,24 +7,8 @@ import java.util.*
|
||||
|
||||
inline fun <T> realmTrans(block: (Realm) -> T): T {
|
||||
return defRealm {
|
||||
it.beginTransaction()
|
||||
try {
|
||||
val res = block(it)
|
||||
it.commitTransaction()
|
||||
res
|
||||
} catch(t: Throwable) {
|
||||
if (it.isInTransaction) {
|
||||
it.cancelTransaction()
|
||||
} else {
|
||||
RealmLog.warn("Could not cancel transaction, not currently in a transaction.")
|
||||
}
|
||||
|
||||
throw t
|
||||
} finally {
|
||||
//Just in case
|
||||
if (it.isInTransaction) {
|
||||
it.cancelTransaction()
|
||||
}
|
||||
it.trans {
|
||||
block(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,5 +19,27 @@ inline fun <T> defRealm(block: (Realm) -> T): T {
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <T> Realm.trans(block: () -> T): T {
|
||||
beginTransaction()
|
||||
try {
|
||||
val res = block()
|
||||
commitTransaction()
|
||||
return res
|
||||
} catch(t: Throwable) {
|
||||
if (isInTransaction) {
|
||||
cancelTransaction()
|
||||
} else {
|
||||
RealmLog.warn("Could not cancel transaction, not currently in a transaction.")
|
||||
}
|
||||
|
||||
throw t
|
||||
} finally {
|
||||
//Just in case
|
||||
if (isInTransaction) {
|
||||
cancelTransaction()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun <T : RealmModel> Realm.createUUIDObj(clazz: Class<T>)
|
||||
= createObject(clazz, UUID.randomUUID().toString())
|
||||
= createObject(clazz, UUID.randomUUID().toString())!!
|
||||
|
||||
Reference in New Issue
Block a user