Commit a0d592c7 authored by Ricki Hirner's avatar Ricki Hirner

Don't throw exception when content provider doesn't return all results

parent 7851ea3a
......@@ -9,7 +9,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
classpath 'com.android.tools.build:gradle:3.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:${dokka_version}"
}
......@@ -25,7 +25,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'org.jetbrains.dokka-android'
ext {
ical4j_version = "2.2.0"
ical4j_version = '2.2.0'
}
android {
......
lombok.addGeneratedAnnotation = false
......@@ -29,9 +29,9 @@ class BatchOperation(
var affected = 0
if (!queue.isEmpty())
try {
Constants.log.fine("Committing ${queue.size} operations")
Constants.log.fine("Committing ${queue.size} operations")
results = Array(queue.size, { null })
results = arrayOfNulls(queue.size)
runBatch(0, queue.size)
for (result in results.filterNotNull())
......@@ -40,6 +40,7 @@ class BatchOperation(
result.uri != null -> affected += 1
}
Constants.log.fine("… $affected record(s) affected")
} catch(e: Exception) {
throw CalendarStorageException("Couldn't apply batch operation", e)
}
......@@ -58,24 +59,25 @@ class BatchOperation(
* @param end index of last operation which will be run (exclusive!)
* @throws RemoteException on calendar provider errors
* @throws OperationApplicationException when the batch can't be processed
* @throws CalendarStorageException if the transaction is too large or if the batch operation failed partially
* @throws CalendarStorageException if the transaction is too large
*/
private fun runBatch(start: Int, end: Int) {
if (end == start)
return // nothing to do
try {
Constants.log.fine("Running operations $start to ${end-1}")
val partResults = providerClient.applyBatch(toCPO(start, end))
val ops = toCPO(start, end)
Constants.log.fine("Running {${ops.size}} operations ($start .. ${end-1})")
val partResults = providerClient.applyBatch(ops)
val n = end - start
if (partResults.size != n)
throw CalendarStorageException("Batch operation failed partially (only ${partResults.size} of $n operations done)")
Constants.log.warning("Batch operation returned only ${partResults.size} instead of $n results")
System.arraycopy(partResults, 0, results, start, n)
System.arraycopy(partResults, 0, results, start, partResults.size)
} catch(e: TransactionTooLargeException) {
if (end <= start + 1)
// only one operation, can't be split
// only one operation, can't be split
throw CalendarStorageException("Can't transfer data to content provider (data row too large)")
Constants.log.warning("Transaction too large, splitting (losing atomicity)")
......@@ -87,13 +89,14 @@ class BatchOperation(
private fun toCPO(start: Int, end: Int): ArrayList<ContentProviderOperation> {
val cpo = ArrayList<ContentProviderOperation>(end - start)
for ((i, op) in queue.subList(start, end).withIndex()) {
val builder = op.builder
op.backrefKey?.let { key ->
if (op.backrefIdx < start)
// back reference is outside of the current batch
results[op.backrefIdx]?.let { result ->
builder.withValueBackReferences(null)
builder .withValueBackReferences(null)
.withValue(key, ContentUris.parseId(result.uri))
}
else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment