/** * Marks the current transaction as successful. Do not do any more database work between * calling this and calling {@link #end()}. Do as little non-database work as possible in that * situation too. If any errors are encountered between this and {@link #end()} the transaction * will still be committed. * * @see SupportSQLiteDatabase#setTransactionSuccessful() */ @WorkerThread void markSuccessful();
/** * This method is called if you returned {@link Result#RESCHEDULE} in {@link #onRunJob(Params)} * and the {@link Job} was successfully rescheduled. The new rescheduled {@link JobRequest} has * a new ID. Override this method if you want to be notified about the change. * * @param newJobId The new ID of the rescheduled {@link JobRequest}. */ @SuppressWarnings("UnusedParameters") @WorkerThread protected void onReschedule(int newJobId) { // override me }
/** * End a transaction. See {@link #newTransaction()} for notes about how to use this and when * transactions are committed and rolled back. * * @see SupportSQLiteDatabase#endTransaction() */ @WorkerThread void end();
@WorkerThread public boolean sync() { // do something fancy if (Looper.myLooper() == Looper.getMainLooper()) { throw new NetworkOnMainThreadException(); } SystemClock.sleep(1_000); boolean success = Math.random() > 0.1; // successful 90% of the time saveSuccess(success); return success; }
/** * Equivalent to calling {@link #end()} */ @WorkerThread @Override void close(); }
/** * Temporarily end the transaction to let other threads run. The transaction is assumed to be * successful so far. Do not call {@link #markSuccessful()} before calling this. When this * returns a new transaction will have been created but not marked as successful. This assumes * that there are no nested transactions (newTransaction has only been called once) and will * throw an exception if that is not the case. * * @return true if the transaction was yielded * * @see SupportSQLiteDatabase#yieldIfContendedSafely() */ @WorkerThread boolean yieldIfContendedSafely();
/** * Gets individual item by ID * @param itemId item ID * @param cacheMode cache mode * @return item or null */ @WorkerThread Item getItem(String itemId, @CacheMode int cacheMode); }
/** * Gets array of stories * @param filter filter of stories to fetch * @param cacheMode cache mode * @return array of stories */ @WorkerThread Item[] getStories(String filter, @CacheMode int cacheMode);
/** * Temporarily end the transaction to let other threads run. The transaction is assumed to be * successful so far. Do not call {@link #markSuccessful()} before calling this. When this * returns a new transaction will have been created but not marked as successful. This assumes * that there are no nested transactions (newTransaction has only been called once) and will * throw an exception if that is not the case. * * @param sleepAmount if > 0, sleep this long before starting a new transaction if * the lock was actually yielded. This will allow other background threads to make some * more progress than they would if we started the transaction immediately. * @return true if the transaction was yielded * * @see SupportSQLiteDatabase#yieldIfContendedSafely(long) */ @WorkerThread boolean yieldIfContendedSafely(long sleepAmount, TimeUnit sleepUnit);
@WorkerThread void parse(String itemId, String url);
/** * Execute the query on the underlying database and return the resulting cursor. * * @return A {@link Cursor} with query results, or {@code null} when the query could not be * executed due to a problem with the underlying store. Unfortunately it is not well documented * when {@code null} is returned. It usually involves a problem in communicating with the * underlying store and should either be treated as failure or ignored for retry at a later * time. */ @CheckResult @WorkerThread @Nullable public abstract Cursor run();
@WorkerThread public List<AttachmentViewInfo> extractAttachmentInfoForView(List<Part> attachmentParts) throws MessagingException { List<AttachmentViewInfo> attachments = new ArrayList<>(); for (Part part : attachmentParts) { AttachmentViewInfo attachmentViewInfo = extractAttachmentInfo(part); attachments.add(attachmentViewInfo); } return attachments; }
/** * Execute {@code statement}, if the the number of rows affected by execution of this SQL * statement is of any importance to the caller - for example, UPDATE / DELETE SQL statements. * * @return the number of rows affected by this SQL statement execution. * @throws android.database.SQLException If the SQL string is invalid * * @see SupportSQLiteStatement#executeUpdateDelete() */ @WorkerThread public int executeUpdateDelete(String table, SupportSQLiteStatement statement) { return executeUpdateDelete(Collections.singleton(table), statement); }
/** * Execute {@code sql} provided it is NOT a {@code SELECT} or any other SQL statement that * returns data. No data can be returned (such as the number of affected rows). Instead, use * {@link #insert}, {@link #update}, et al, when possible. * <p> * A notification to queries for {@code table} will be sent after the statement is executed. * * @see SupportSQLiteDatabase#execSQL(String, Object[]) */ @WorkerThread public void executeAndTrigger(String table, String sql, Object... args) { executeAndTrigger(Collections.singleton(table), sql, args); }
/** * Execute {@code sql} provided it is NOT a {@code SELECT} or any other SQL statement that * returns data. No data can be returned (such as the number of affected rows). Instead, use * {@link #insert}, {@link #update}, et al, when possible. * <p> * A notification to queries for {@code table} will be sent after the statement is executed. * * @see SupportSQLiteDatabase#execSQL(String) */ @WorkerThread public void executeAndTrigger(String table, String sql) { executeAndTrigger(Collections.singleton(table), sql); }
/** * Execute {@code statement} and return the ID of the row inserted due to this call. * The SQL statement should be an INSERT for this to be a useful call. * * @return the row ID of the last row inserted, if this insert is successful. -1 otherwise. * * @throws android.database.SQLException If the SQL string is invalid * * @see SupportSQLiteStatement#executeInsert() */ @WorkerThread public long executeInsert(String table, SupportSQLiteStatement statement) { return executeInsert(Collections.singleton(table), statement); }
@WorkerThread private long extractAttachmentSize(String contentDisposition, long size) { if (size != AttachmentViewInfo.UNKNOWN_SIZE) { return size; } long result = AttachmentViewInfo.UNKNOWN_SIZE; String sizeParam = MimeUtility.getHeaderParameter(contentDisposition, "size"); if (sizeParam != null) { try { result = Integer.parseInt(sizeParam); } catch (NumberFormatException e) { /* ignore */ } } return result; } }
/** * Try parse path. * * @param dAttributeOfPath the d attribute of <path> from the XML * @return the path */ @WorkerThread @Nullable public static Path tryParsePath(String dAttributeOfPath) { try { return parsePath(dAttributeOfPath); } catch (Exception e) { //Log.e(null, "parse svg path error", e); } return null; }
@WorkerThread private static Void loadFromAssets(Context context) throws IOException { InputStream stream = context.getAssets().open(AD_HOSTS_FILE); BufferedSource buffer = Okio.buffer(Okio.source(stream)); String line; while ((line = buffer.readUtf8Line()) != null) { AD_HOSTS.add(line); } buffer.close(); stream.close(); return null; }
/** * See {@link #executeAndTrigger(String, String)} for usage. This overload allows for triggering multiple tables. * * @see BriteDatabase#executeAndTrigger(String, String) */ @WorkerThread public void executeAndTrigger(Set<String> tables, String sql) { execute(sql); sendTableTrigger(tables); }