mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-22 14:11:00 +00:00
Simplify error handling
This commit is contained in:
parent
6a9cfbf24d
commit
9a66d0716c
2 changed files with 31 additions and 91 deletions
|
@ -114,38 +114,29 @@ public abstract class LimitOffsetDataSource<T> extends PositionalDataSource<T> {
|
||||||
int firstLoadPosition = 0;
|
int firstLoadPosition = 0;
|
||||||
RoomSQLiteQuery sqLiteQuery = null;
|
RoomSQLiteQuery sqLiteQuery = null;
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
int retry = 0;
|
mDb.beginTransaction();
|
||||||
while (cursor == null) {
|
try {
|
||||||
mDb.beginTransaction();
|
totalCount = countItems();
|
||||||
try {
|
if (totalCount != 0) {
|
||||||
totalCount = countItems();
|
// bound the size requested, based on known count
|
||||||
if (totalCount != 0) {
|
firstLoadPosition = computeInitialLoadPosition(params, totalCount);
|
||||||
// bound the size requested, based on known count
|
int firstLoadSize = computeInitialLoadSize(params, firstLoadPosition, totalCount);
|
||||||
firstLoadPosition = computeInitialLoadPosition(params, totalCount);
|
|
||||||
int firstLoadSize = computeInitialLoadSize(params, firstLoadPosition, totalCount);
|
|
||||||
|
|
||||||
sqLiteQuery = getSQLiteQuery(firstLoadPosition, firstLoadSize);
|
sqLiteQuery = getSQLiteQuery(firstLoadPosition, firstLoadSize);
|
||||||
cursor = mDb.query(sqLiteQuery);
|
cursor = mDb.query(sqLiteQuery);
|
||||||
List<T> rows = convertRows(cursor);
|
List<T> rows = convertRows(cursor);
|
||||||
mDb.setTransactionSuccessful();
|
mDb.setTransactionSuccessful();
|
||||||
list = rows;
|
list = rows;
|
||||||
}
|
}
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
if (++retry > 10)
|
eu.faircode.email.Log.w(ex);
|
||||||
throw ex;
|
} finally {
|
||||||
eu.faircode.email.Log.w(ex);
|
if (cursor != null) {
|
||||||
try {
|
cursor.close();
|
||||||
Thread.sleep(3000L);
|
}
|
||||||
} catch (InterruptedException ignored) {
|
mDb.endTransaction();
|
||||||
}
|
if (sqLiteQuery != null) {
|
||||||
} finally {
|
sqLiteQuery.release();
|
||||||
if (cursor != null) {
|
|
||||||
cursor.close();
|
|
||||||
}
|
|
||||||
mDb.endTransaction();
|
|
||||||
if (sqLiteQuery != null) {
|
|
||||||
sqLiteQuery.release();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
--- /home/marcel/support/room/runtime/src/main/java/androidx/room/paging/LimitOffsetDataSource.java 2020-05-18 15:59:35.380887546 +0200
|
--- /home/marcel/support/room/runtime/src/main/java/androidx/room/paging/LimitOffsetDataSource.java 2020-05-18 15:59:35.380887546 +0200
|
||||||
+++ /home/marcel/email/app/src/main/java/androidx/room/paging/LimitOffsetDataSource.java 2020-06-15 15:44:12.388117961 +0200
|
+++ /home/marcel/email/app/src/main/java/androidx/room/paging/LimitOffsetDataSource.java 2020-06-15 16:11:37.701097921 +0200
|
||||||
@@ -20,6 +20,7 @@ import android.database.Cursor;
|
@@ -20,6 +20,7 @@ import android.database.Cursor;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
@ -19,63 +19,12 @@
|
||||||
private final RoomSQLiteQuery mSourceQuery;
|
private final RoomSQLiteQuery mSourceQuery;
|
||||||
private final String mCountQuery;
|
private final String mCountQuery;
|
||||||
private final String mLimitOffsetQuery;
|
private final String mLimitOffsetQuery;
|
||||||
@@ -114,27 +114,38 @@ public abstract class LimitOffsetDataSou
|
@@ -128,6 +128,8 @@ public abstract class LimitOffsetDataSou
|
||||||
int firstLoadPosition = 0;
|
mDb.setTransactionSuccessful();
|
||||||
RoomSQLiteQuery sqLiteQuery = null;
|
list = rows;
|
||||||
Cursor cursor = null;
|
|
||||||
- mDb.beginTransaction();
|
|
||||||
- try {
|
|
||||||
- totalCount = countItems();
|
|
||||||
- if (totalCount != 0) {
|
|
||||||
- // bound the size requested, based on known count
|
|
||||||
- firstLoadPosition = computeInitialLoadPosition(params, totalCount);
|
|
||||||
- int firstLoadSize = computeInitialLoadSize(params, firstLoadPosition, totalCount);
|
|
||||||
-
|
|
||||||
- sqLiteQuery = getSQLiteQuery(firstLoadPosition, firstLoadSize);
|
|
||||||
- cursor = mDb.query(sqLiteQuery);
|
|
||||||
- List<T> rows = convertRows(cursor);
|
|
||||||
- mDb.setTransactionSuccessful();
|
|
||||||
- list = rows;
|
|
||||||
- }
|
|
||||||
- } finally {
|
|
||||||
- if (cursor != null) {
|
|
||||||
- cursor.close();
|
|
||||||
- }
|
|
||||||
- mDb.endTransaction();
|
|
||||||
- if (sqLiteQuery != null) {
|
|
||||||
- sqLiteQuery.release();
|
|
||||||
+ int retry = 0;
|
|
||||||
+ while (cursor == null) {
|
|
||||||
+ mDb.beginTransaction();
|
|
||||||
+ try {
|
|
||||||
+ totalCount = countItems();
|
|
||||||
+ if (totalCount != 0) {
|
|
||||||
+ // bound the size requested, based on known count
|
|
||||||
+ firstLoadPosition = computeInitialLoadPosition(params, totalCount);
|
|
||||||
+ int firstLoadSize = computeInitialLoadSize(params, firstLoadPosition, totalCount);
|
|
||||||
+
|
|
||||||
+ sqLiteQuery = getSQLiteQuery(firstLoadPosition, firstLoadSize);
|
|
||||||
+ cursor = mDb.query(sqLiteQuery);
|
|
||||||
+ List<T> rows = convertRows(cursor);
|
|
||||||
+ mDb.setTransactionSuccessful();
|
|
||||||
+ list = rows;
|
|
||||||
+ }
|
|
||||||
+ } catch (Throwable ex) {
|
|
||||||
+ if (++retry > 10)
|
|
||||||
+ throw ex;
|
|
||||||
+ eu.faircode.email.Log.w(ex);
|
|
||||||
+ try {
|
|
||||||
+ Thread.sleep(3000L);
|
|
||||||
+ } catch (InterruptedException ignored) {
|
|
||||||
+ }
|
|
||||||
+ } finally {
|
|
||||||
+ if (cursor != null) {
|
|
||||||
+ cursor.close();
|
|
||||||
+ }
|
|
||||||
+ mDb.endTransaction();
|
|
||||||
+ if (sqLiteQuery != null) {
|
|
||||||
+ sqLiteQuery.release();
|
|
||||||
+ }
|
|
||||||
}
|
}
|
||||||
}
|
+ } catch (Throwable ex) {
|
||||||
|
+ eu.faircode.email.Log.w(ex);
|
||||||
|
} finally {
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
|
Loading…
Reference in a new issue