当前位置: 首页>>代码示例>>Java>>正文


Java CancellationSignal.throwIfCanceled方法代码示例

本文整理汇总了Java中android.support.v4.os.CancellationSignal.throwIfCanceled方法的典型用法代码示例。如果您正苦于以下问题:Java CancellationSignal.throwIfCanceled方法的具体用法?Java CancellationSignal.throwIfCanceled怎么用?Java CancellationSignal.throwIfCanceled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v4.os.CancellationSignal的用法示例。


在下文中一共展示了CancellationSignal.throwIfCanceled方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: executeSpecial

import android.support.v4.os.CancellationSignal; //导入方法依赖的package包/类
/**
 * Performs special reinterpretation of certain SQL statements such as "BEGIN",
 * "COMMIT" and "ROLLBACK" to ensure that transaction state invariants are
 * maintained.
 *
 * This function is mainly used to support legacy apps that perform their
 * own transactions by executing raw SQL rather than calling {@link #beginTransaction}
 * and the like.
 *
 * @param sql The SQL statement to execute.
 * @param bindArgs The arguments to bind, or null if none.
 * @param connectionFlags The connection flags to use if a connection must be
 * acquired by this operation.  Refer to {@link SQLiteConnectionPool}.
 * @param cancellationSignal A signal to cancel the operation in progress, or null if none.
 * @return True if the statement was of a special form that was handled here,
 * false otherwise.
 *
 * @throws SQLiteException if an error occurs, such as a syntax error
 * or invalid number of bind arguments.
 * @throws OperationCanceledException if the operation was canceled.
 */
private boolean executeSpecial(String sql, Object[] bindArgs, int connectionFlags,
        CancellationSignal cancellationSignal) {
    if (cancellationSignal != null) {
        cancellationSignal.throwIfCanceled();
    }

    final int type = SQLiteStatementType.getSqlStatementType(sql);
    switch (type) {
        case SQLiteStatementType.STATEMENT_BEGIN:
            beginTransaction(TRANSACTION_MODE_EXCLUSIVE, null, connectionFlags,
                    cancellationSignal);
            return true;

        case SQLiteStatementType.STATEMENT_COMMIT:
            setTransactionSuccessful();
            endTransaction(cancellationSignal);
            return true;

        case SQLiteStatementType.STATEMENT_ABORT:
            endTransaction(cancellationSignal);
            return true;
    }
    return false;
}
 
开发者ID:requery,项目名称:sqlite-android,代码行数:46,代码来源:SQLiteSession.java

示例2: loadInBackground

import android.support.v4.os.CancellationSignal; //导入方法依赖的package包/类
@Override
public T loadInBackground() {
  Cursor cursor = null;
  try {
    CancellationSignal cancellationSignal = initCancellationSignal();
    cursor = loadCursorInBackground();
    cancellationSignal.throwIfCanceled();
    final T result = mCursorTransformation.apply(cursor, cancellationSignal);
    Preconditions.checkNotNull(result, "Function passed to this loader should never return null.");

    synchronized (pendingLoadResults) {
      pendingLoadResults.add(new Pair<>(result, cursor));
    }

    return result;
  } catch (OperationCanceledException ex) {
    releaseCursor(cursor);
    throw ex;
  } catch (Throwable t) {
    throw new RuntimeException("Error occurred when running loader: " + this, t);
  } finally {
    destroyCancellationSignal();
  }
}
 
开发者ID:futuresimple,项目名称:android-db-commons,代码行数:25,代码来源:ComposedCursorLoader.java

示例3: attachCancellationSignal

import android.support.v4.os.CancellationSignal; //导入方法依赖的package包/类
private void attachCancellationSignal(CancellationSignal cancellationSignal) {
    if (cancellationSignal != null) {
        cancellationSignal.throwIfCanceled();

        mCancellationSignalAttachCount += 1;
        if (mCancellationSignalAttachCount == 1) {
            // Reset cancellation flag before executing the statement.
            nativeResetCancel(mConnectionPtr, true /*cancelable*/);

            // After this point, onCancel() may be called concurrently.
            cancellationSignal.setOnCancelListener(this);
        }
    }
}
 
开发者ID:requery,项目名称:sqlite-android,代码行数:15,代码来源:SQLiteConnection.java

示例4: yieldTransactionUnchecked

import android.support.v4.os.CancellationSignal; //导入方法依赖的package包/类
private boolean yieldTransactionUnchecked(long sleepAfterYieldDelayMillis,
        CancellationSignal cancellationSignal) {
    if (cancellationSignal != null) {
        cancellationSignal.throwIfCanceled();
    }

    if (!mConnectionPool.shouldYieldConnection(mConnection, mConnectionFlags)) {
        return false;
    }

    final int transactionMode = mTransactionStack.mMode;
    final SQLiteTransactionListener listener = mTransactionStack.mListener;
    final int connectionFlags = mConnectionFlags;
    endTransactionUnchecked(cancellationSignal, true); // might throw

    if (sleepAfterYieldDelayMillis > 0) {
        try {
            Thread.sleep(sleepAfterYieldDelayMillis);
        } catch (InterruptedException ex) {
            // we have been interrupted, that's all we need to do
        }
    }

    beginTransactionUnchecked(transactionMode, listener, connectionFlags,
            cancellationSignal); // might throw
    return true;
}
 
开发者ID:requery,项目名称:sqlite-android,代码行数:28,代码来源:SQLiteSession.java

示例5: query

import android.support.v4.os.CancellationSignal; //导入方法依赖的package包/类
public Cursor query(ContentResolver contentresolver, Uri uri, String as[], String s, String as1[], String s1, CancellationSignal cancellationsignal)
{
    if (cancellationsignal != null)
    {
        cancellationsignal.throwIfCanceled();
    }
    return contentresolver.query(uri, as, s, as1, s1);
}
 
开发者ID:Hamz-a,项目名称:MyCTFWriteUps,代码行数:9,代码来源:ContentResolverCompat.java

示例6: query

import android.support.v4.os.CancellationSignal; //导入方法依赖的package包/类
public Cursor query(ContentResolver resolver, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder, CancellationSignal cancellationSignal) {
    if (cancellationSignal != null) {
        cancellationSignal.throwIfCanceled();
    }
    return resolver.query(uri, projection, selection, selectionArgs, sortOrder);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:7,代码来源:ContentResolverCompat.java

示例7: beginTransactionUnchecked

import android.support.v4.os.CancellationSignal; //导入方法依赖的package包/类
private void beginTransactionUnchecked(int transactionMode,
        SQLiteTransactionListener transactionListener, int connectionFlags,
        CancellationSignal cancellationSignal) {
    if (cancellationSignal != null) {
        cancellationSignal.throwIfCanceled();
    }

    if (mTransactionStack == null) {
        acquireConnection(null, connectionFlags, cancellationSignal); // might throw
    }
    try {
        // Set up the transaction such that we can back out safely
        // in case we fail part way.
        if (mTransactionStack == null) {
            // Execute SQL might throw a runtime exception.
            switch (transactionMode) {
                case TRANSACTION_MODE_IMMEDIATE:
                    mConnection.execute("BEGIN IMMEDIATE;", null,
                            cancellationSignal); // might throw
                    break;
                case TRANSACTION_MODE_EXCLUSIVE:
                    mConnection.execute("BEGIN EXCLUSIVE;", null,
                            cancellationSignal); // might throw
                    break;
                default:
                    mConnection.execute("BEGIN;", null, cancellationSignal); // might throw
                    break;
            }
        }

        // Listener might throw a runtime exception.
        if (transactionListener != null) {
            try {
                transactionListener.onBegin(); // might throw
            } catch (RuntimeException ex) {
                if (mTransactionStack == null) {
                    mConnection.execute("ROLLBACK;", null, cancellationSignal); // might throw
                }
                throw ex;
            }
        }

        // Bookkeeping can't throw, except an OOM, which is just too bad...
        Transaction transaction = obtainTransaction(transactionMode, transactionListener);
        transaction.mParent = mTransactionStack;
        mTransactionStack = transaction;
    } finally {
        if (mTransactionStack == null) {
            releaseConnection(); // might throw
        }
    }
}
 
开发者ID:requery,项目名称:sqlite-android,代码行数:53,代码来源:SQLiteSession.java

示例8: endTransactionUnchecked

import android.support.v4.os.CancellationSignal; //导入方法依赖的package包/类
private void endTransactionUnchecked(CancellationSignal cancellationSignal, boolean yielding) {
    if (cancellationSignal != null) {
        cancellationSignal.throwIfCanceled();
    }

    final Transaction top = mTransactionStack;
    boolean successful = (top.mMarkedSuccessful || yielding) && !top.mChildFailed;

    RuntimeException listenerException = null;
    final SQLiteTransactionListener listener = top.mListener;
    if (listener != null) {
        try {
            if (successful) {
                listener.onCommit(); // might throw
            } else {
                listener.onRollback(); // might throw
            }
        } catch (RuntimeException ex) {
            listenerException = ex;
            successful = false;
        }
    }

    mTransactionStack = top.mParent;
    recycleTransaction(top);

    if (mTransactionStack != null) {
        if (!successful) {
            mTransactionStack.mChildFailed = true;
        }
    } else {
        try {
            if (successful) {
                mConnection.execute("COMMIT;", null, cancellationSignal); // might throw
            } else {
                mConnection.execute("ROLLBACK;", null, cancellationSignal); // might throw
            }
        } finally {
            releaseConnection(); // might throw
        }
    }

    if (listenerException != null) {
        throw listenerException;
    }
}
 
开发者ID:requery,项目名称:sqlite-android,代码行数:47,代码来源:SQLiteSession.java

示例9: prepare

import android.support.v4.os.CancellationSignal; //导入方法依赖的package包/类
/**
 * Prepares a statement for execution but does not bind its parameters or execute it.
 * <p>
 * This method can be used to check for syntax errors during compilation
 * prior to execution of the statement.  If the {@code outStatementInfo} argument
 * is not null, the provided {@link SQLiteStatementInfo} object is populated
 * with information about the statement.
 * </p><p>
 * A prepared statement makes no reference to the arguments that may eventually
 * be bound to it, consequently it it possible to cache certain prepared statements
 * such as SELECT or INSERT/UPDATE statements.  If the statement is cacheable,
 * then it will be stored in the cache for later and reused if possible.
 * </p>
 *
 * @param sql The SQL statement to prepare.
 * @param connectionFlags The connection flags to use if a connection must be
 * acquired by this operation.  Refer to {@link SQLiteConnectionPool}.
 * @param cancellationSignal A signal to cancel the operation in progress, or null if none.
 * @param outStatementInfo The {@link SQLiteStatementInfo} object to populate
 * with information about the statement, or null if none.
 *
 * @throws SQLiteException if an error occurs, such as a syntax error.
 * @throws OperationCanceledException if the operation was canceled.
 */
public void prepare(String sql, int connectionFlags, CancellationSignal cancellationSignal,
        SQLiteStatementInfo outStatementInfo) {
    if (sql == null) {
        throw new IllegalArgumentException("sql must not be null.");
    }

    if (cancellationSignal != null) {
        cancellationSignal.throwIfCanceled();
    }

    acquireConnection(sql, connectionFlags, cancellationSignal); // might throw
    try {
        mConnection.prepare(sql, outStatementInfo); // might throw
    } finally {
        releaseConnection(); // might throw
    }
}
 
开发者ID:requery,项目名称:sqlite-android,代码行数:42,代码来源:SQLiteSession.java

示例10: apply

import android.support.v4.os.CancellationSignal; //导入方法依赖的package包/类
@Override
public final TOut apply(TIn input, CancellationSignal signal) {
  TOut result = transform.apply(input);
  signal.throwIfCanceled();
  return result;
}
 
开发者ID:futuresimple,项目名称:android-db-commons,代码行数:7,代码来源:SimpleCancellableFunction.java


注:本文中的android.support.v4.os.CancellationSignal.throwIfCanceled方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。