use of com.ichi2.utils.DatabaseChangeDecorator in project AnkiChinaAndroid by ankichinateam.
the class Collection method getChunk.
private int getChunk() {
if (sChunk != 0) {
return sChunk;
}
// the window size is saved in
// io.requery.android.database.CursorWindow.sCursorWindowSize.
// Values are copied here. Ideally, a getter would allow to access it.
final int WINDOW_SIZE_KB = 2048;
int sCursorWindowSize = WINDOW_SIZE_KB * 1024;
// We have the ability to look into our sqlite implementation on Android and use it's value
// as a ceiling. Try it, with a reasonable fallback in case of failure
SupportSQLiteDatabase db = mDb.getDatabase();
if (!(db instanceof DatabaseChangeDecorator)) {
return sChunk;
}
String db_name = ((DatabaseChangeDecorator) db).getWrapped().getClass().getName();
if ("io.requery.android.database.sqlite.SQLiteDatabase".equals(db_name)) {
try {
Field cursorWindowSize = io.requery.android.database.CursorWindow.class.getDeclaredField("sDefaultCursorWindowSize");
cursorWindowSize.setAccessible(true);
int possibleCursorWindowSize = cursorWindowSize.getInt(null);
Timber.d("Reflectively discovered database default cursor window size %d", possibleCursorWindowSize);
if (possibleCursorWindowSize > 0) {
sCursorWindowSize = possibleCursorWindowSize;
} else {
Timber.w("Obtained unusable cursor window size: %d. Using default %d", possibleCursorWindowSize, sCursorWindowSize);
}
} catch (Exception e) {
Timber.w(e, "Unable to get window size from requery cursor.");
}
}
// reduce the actual size a little bit.
sChunk = (int) (sCursorWindowSize * 15. / 16.);
return sChunk;
}
Aggregations