mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-24 19:56:00 +00:00
Improve handling of unregistered users in storage service.
This commit is contained in:
committed by
Cody Henthorne
parent
ffa249885e
commit
115d1fcf63
@@ -31,6 +31,10 @@ fun Cursor.requireLong(column: String): Long {
|
||||
return CursorUtil.requireLong(this, column)
|
||||
}
|
||||
|
||||
fun Cursor.optionalLong(column: String): Optional<Long> {
|
||||
return CursorUtil.getLong(this, column)
|
||||
}
|
||||
|
||||
fun Cursor.requireBoolean(column: String): Boolean {
|
||||
return CursorUtil.requireInt(this, column) != 0
|
||||
}
|
||||
|
||||
@@ -65,6 +65,14 @@ public final class CursorUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<Long> getLong(@NonNull Cursor cursor, @NonNull String column) {
|
||||
if (cursor.getColumnIndex(column) < 0) {
|
||||
return Optional.empty();
|
||||
} else {
|
||||
return Optional.of(requireLong(cursor, column));
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<Boolean> getBoolean(@NonNull Cursor cursor, @NonNull String column) {
|
||||
if (cursor.getColumnIndex(column) < 0) {
|
||||
return Optional.empty();
|
||||
|
||||
@@ -188,21 +188,16 @@ object SqlUtil {
|
||||
|
||||
/**
|
||||
* A convenient way of making queries in the form: WHERE [column] IN (?, ?, ..., ?)
|
||||
* Handles breaking it
|
||||
* Handles breaking it
|
||||
*/
|
||||
@JvmOverloads
|
||||
@JvmStatic
|
||||
fun buildCollectionQuery(column: String, values: Collection<Any?>): List<Query> {
|
||||
return buildCollectionQuery(column, values, MAX_QUERY_ARGS)
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@JvmStatic
|
||||
fun buildCollectionQuery(column: String, values: Collection<Any?>, maxSize: Int): List<Query> {
|
||||
fun buildCollectionQuery(column: String, values: Collection<Any?>, prefix: String = "", maxSize: Int = MAX_QUERY_ARGS): List<Query> {
|
||||
require(!values.isEmpty()) { "Must have values!" }
|
||||
|
||||
return values
|
||||
.chunked(maxSize)
|
||||
.map { batch -> buildSingleCollectionQuery(column, batch) }
|
||||
.map { batch -> buildSingleCollectionQuery(column, batch, prefix) }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -211,8 +206,9 @@ object SqlUtil {
|
||||
* Important: Should only be used if you know the number of values is < 1000. Otherwise you risk creating a SQL statement this is too large.
|
||||
* Prefer [buildCollectionQuery] when possible.
|
||||
*/
|
||||
@JvmOverloads
|
||||
@JvmStatic
|
||||
fun buildSingleCollectionQuery(column: String, values: Collection<Any?>): Query {
|
||||
fun buildSingleCollectionQuery(column: String, values: Collection<Any?>, prefix: String = ""): Query {
|
||||
require(!values.isEmpty()) { "Must have values!" }
|
||||
|
||||
val query = StringBuilder()
|
||||
@@ -227,7 +223,7 @@ object SqlUtil {
|
||||
}
|
||||
i++
|
||||
}
|
||||
return Query("$column IN ($query)", buildArgs(*args))
|
||||
return Query("$prefix $column IN ($query)".trim(), buildArgs(*args))
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
||||
Reference in New Issue
Block a user