// We don't want to pass the exceptions up or rethrow a more generic exception, since
// then, we would have to handle this on every object instantiation, but these
// exceptions should never throw in production, since these are static code issues
// (wrongly defined classes) which should be handled once, straight away and then
// never change again.
protected List<T> getList(String[] projection, String selection, String[] selectionArgs,
                              String sortOrder, Integer limit) {
        List<T> rows = new ArrayList<>();
        //noinspection TryWithIdenticalCatches
        try {
            Cursor c = mCr.query(mUri, projection, selection, selectionArgs, sortOrder);
            if (c != null) {
                if (c.moveToFirst()) {
                    int i = 0;
                    Constructor<T> constructor =
                        mTableRowClass.getConstructor(this.getClass(), Cursor.class);
                    do {
                        rows.add(constructor.newInstance(this, c));
                        i++;
                    } while ((limit == null || limit > i) && c.moveToNext());
                }
                c.close();
            }
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
            // We don't want to pass the exceptions up or rethrow a more generic exception, since
            // then, we would have to handle this on every object instantiation, but these
            // exceptions should never throw in production, since these are static code issues
            // (wrongly defined classes) which should be handled once, straight away and then
            // never change again.
            System.exit(-1);
        } catch (InstantiationException e) {
            e.printStackTrace();
            System.exit(-1);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            System.exit(-1);
        } catch (InvocationTargetException e) {
            e.printStackTrace();
            System.exit(-1);
        }
        return rows;
    }
} catch (NoSuchMethodException e) {
e.printStackTrace();
// We don't want to pass the exceptions up or rethrow a more generic exception, since
// then, we would have to handle this on every object instantiation, but these
// exceptions should never throw in production, since these are static code issues
// (wrongly defined classes) which should be handled once, straight away and then
// never change again.
System.exit(-1);
} catch (InstantiationException e) {
mTableRowClass.getConstructor(this.getClass(), Cursor.class);
do {
rows.add(constructor.newInstance(this, c));
i++;
} while ((limit == null || limit > i) && c.moveToNext());
}
c.close();
}
} catch (NoSuchMethodException e) {
e.printStackTrace();
// We don't want to pass the exceptions up or rethrow a more generic exception, since
// then, we would have to handle this on every object instantiation, but these
// exceptions should never throw in production, since these are static code issues
// (wrongly defined classes) which should be handled once, straight away and then
// never change again.
System.exit(-1);
} catch (InstantiationException e) {
e.printStackTrace();
System.exit(-1);
} catch (IllegalAccessException e) {
e.printStackTrace();
System.exit(-1);
} catch (InvocationTargetException e) {
e.printStackTrace();
System.exit(-1);
protected List<T> getList(String[] projection, String selection, String[] selectionArgs,
String sortOrder, Integer limit) {
List<T> rows = new ArrayList<>();
//noinspection TryWithIdenticalCatches
try {
Cursor c = mCr.query(mUri, projection, selection, selectionArgs, sortOrder);
if (c != null) {
if (c.moveToFirst()) {
int i = 0;
Constructor<T> constructor =
mTableRowClass.getConstructor(this.getClass(), Cursor.class);
do {
rows.add(constructor.newInstance(this, c));
i++;
} while ((limit == null || limit > i) && c.moveToNext());
}
c.close();
}
} catch (NoSuchMethodException e) {
e.printStackTrace();
// We don't want to pass the exceptions up or rethrow a more generic exception, since
// then, we would have to handle this on every object instantiation, but these
// exceptions should never throw in production, since these are static code issues
// (wrongly defined classes) which should be handled once, straight away and then
// never change again.
System.exit(-1);
} catch (InstantiationException e) {
e.printStackTrace();
System.exit(-1);
} catch (IllegalAccessException e) {
e.printStackTrace();
System.exit(-1);
} catch (InvocationTargetException e) {
e.printStackTrace();
System.exit(-1);
}
return rows;
}