@VisibleForTesting /*package*/ int getMaxJobId() { SQLiteDatabase database = null; Cursor cursor = null; int jobId = 0; try { database = getDatabase(); cursor = database.rawQuery("SELECT MAX(" + COLUMN_ID + ") FROM " + JOB_TABLE_NAME, null); if (cursor != null && cursor.moveToFirst()) { jobId = cursor.getInt(0); } } catch (Exception e) { CAT.e(e); } finally { closeCursor(cursor); closeDatabase(database); } return Math.max(JobConfig.getJobIdOffset(), Math.max(jobId, mPreferences.getInt(JOB_ID_COUNTER, 0))); }
closeCursor(cursor); closeDatabase(database); mLock.readLock().unlock();
@SuppressWarnings("SameParameterValue") private JobRequest load(int id, boolean includeStarted) { if (didFailToDelete(id)) { return null; } SQLiteDatabase database = null; Cursor cursor = null; try { String where = COLUMN_ID + "=?"; if (!includeStarted) { where += " AND " + COLUMN_STARTED + "<=0"; } database = getDatabase(); cursor = database.query(JOB_TABLE_NAME, null, where, new String[]{String.valueOf(id)}, null, null, null); if (cursor != null && cursor.moveToFirst()) { return JobRequest.fromCursor(cursor); } } catch (Exception e) { CAT.e(e, "could not load id %d", id); } finally { closeCursor(cursor); closeDatabase(database); } return null; }
@VisibleForTesting /*package*/ int getMaxJobId() { SQLiteDatabase database = null; Cursor cursor = null; int jobId = 0; try { database = getDatabase(); cursor = database.rawQuery("SELECT MAX(" + COLUMN_ID + ") FROM " + JOB_TABLE_NAME, null); if (cursor != null && cursor.moveToFirst()) { jobId = cursor.getInt(0); } } catch (Exception e) { CAT.e(e); } finally { closeCursor(cursor); closeDatabase(database); } return Math.max(JobConfig.getJobIdOffset(), Math.max(jobId, mPreferences.getInt(JOB_ID_COUNTER, 0))); }
closeCursor(cursor); closeDatabase(database); mLock.readLock().unlock();
@SuppressWarnings("SameParameterValue") private JobRequest load(int id, boolean includeStarted) { if (didFailToDelete(id)) { return null; } SQLiteDatabase database = null; Cursor cursor = null; try { String where = COLUMN_ID + "=?"; if (!includeStarted) { where += " AND " + COLUMN_STARTED + "<=0"; } database = getDatabase(); cursor = database.query(JOB_TABLE_NAME, null, where, new String[]{String.valueOf(id)}, null, null, null); if (cursor != null && cursor.moveToFirst()) { return JobRequest.fromCursor(cursor); } } catch (Exception e) { CAT.e(e, "could not load id %d", id); } finally { closeCursor(cursor); closeDatabase(database); } return null; }