本文整理汇总了Java中android.support.v4.os.CancellationSignal类的典型用法代码示例。如果您正苦于以下问题:Java CancellationSignal类的具体用法?Java CancellationSignal怎么用?Java CancellationSignal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CancellationSignal类属于android.support.v4.os包,在下文中一共展示了CancellationSignal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import android.support.v4.os.CancellationSignal; //导入依赖的package包/类
/**
* Executes a statement that does not return a result.
*
* @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.
*
* @throws SQLiteException if an error occurs, such as a syntax error
* or invalid number of bind arguments.
* @throws OperationCanceledException if the operation was canceled.
*/
public void execute(String sql, Object[] bindArgs, int connectionFlags,
CancellationSignal cancellationSignal) {
if (sql == null) {
throw new IllegalArgumentException("sql must not be null.");
}
if (executeSpecial(sql, bindArgs, connectionFlags, cancellationSignal)) {
return;
}
acquireConnection(sql, connectionFlags, cancellationSignal); // might throw
try {
mConnection.execute(sql, bindArgs, cancellationSignal); // might throw
} finally {
releaseConnection(); // might throw
}
}
示例2: executeForLong
import android.support.v4.os.CancellationSignal; //导入依赖的package包/类
/**
* Executes a statement that returns a single <code>long</code> result.
*
* @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 The value of the first column in the first row of the result set
* as a <code>long</code>, or zero if none.
*
* @throws SQLiteException if an error occurs, such as a syntax error
* or invalid number of bind arguments.
* @throws OperationCanceledException if the operation was canceled.
*/
public long executeForLong(String sql, Object[] bindArgs, int connectionFlags,
CancellationSignal cancellationSignal) {
if (sql == null) {
throw new IllegalArgumentException("sql must not be null.");
}
if (executeSpecial(sql, bindArgs, connectionFlags, cancellationSignal)) {
return 0;
}
acquireConnection(sql, connectionFlags, cancellationSignal); // might throw
try {
return mConnection.executeForLong(sql, bindArgs, cancellationSignal); // might throw
} finally {
releaseConnection(); // might throw
}
}
示例3: executeForString
import android.support.v4.os.CancellationSignal; //导入依赖的package包/类
/**
* Executes a statement that returns a single {@link String} result.
*
* @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 The value of the first column in the first row of the result set
* as a <code>String</code>, or null if none.
*
* @throws SQLiteException if an error occurs, such as a syntax error
* or invalid number of bind arguments.
* @throws OperationCanceledException if the operation was canceled.
*/
public String executeForString(String sql, Object[] bindArgs, int connectionFlags,
CancellationSignal cancellationSignal) {
if (sql == null) {
throw new IllegalArgumentException("sql must not be null.");
}
if (executeSpecial(sql, bindArgs, connectionFlags, cancellationSignal)) {
return null;
}
acquireConnection(sql, connectionFlags, cancellationSignal); // might throw
try {
return mConnection.executeForString(sql, bindArgs, cancellationSignal); // might throw
} finally {
releaseConnection(); // might throw
}
}
示例4: executeForBlobFileDescriptor
import android.support.v4.os.CancellationSignal; //导入依赖的package包/类
/**
* Executes a statement that returns a single BLOB result as a
* file descriptor to a shared memory region.
*
* @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 The file descriptor for a shared memory region that contains
* the value of the first column in the first row of the result set as a BLOB,
* or null if none.
*
* @throws SQLiteException if an error occurs, such as a syntax error
* or invalid number of bind arguments.
* @throws OperationCanceledException if the operation was canceled.
*/
public ParcelFileDescriptor executeForBlobFileDescriptor(String sql, Object[] bindArgs,
int connectionFlags, CancellationSignal cancellationSignal) {
if (sql == null) {
throw new IllegalArgumentException("sql must not be null.");
}
if (executeSpecial(sql, bindArgs, connectionFlags, cancellationSignal)) {
return null;
}
acquireConnection(sql, connectionFlags, cancellationSignal); // might throw
try {
return mConnection.executeForBlobFileDescriptor(sql, bindArgs,
cancellationSignal); // might throw
} finally {
releaseConnection(); // might throw
}
}
示例5: executeForChangedRowCount
import android.support.v4.os.CancellationSignal; //导入依赖的package包/类
/**
* Executes a statement that returns a count of the number of rows
* that were changed. Use for UPDATE or DELETE SQL statements.
*
* @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 The number of rows that were changed.
*
* @throws SQLiteException if an error occurs, such as a syntax error
* or invalid number of bind arguments.
* @throws OperationCanceledException if the operation was canceled.
*/
public int executeForChangedRowCount(String sql, Object[] bindArgs, int connectionFlags,
CancellationSignal cancellationSignal) {
if (sql == null) {
throw new IllegalArgumentException("sql must not be null.");
}
if (executeSpecial(sql, bindArgs, connectionFlags, cancellationSignal)) {
return 0;
}
acquireConnection(sql, connectionFlags, cancellationSignal); // might throw
try {
return mConnection.executeForChangedRowCount(sql, bindArgs,
cancellationSignal); // might throw
} finally {
releaseConnection(); // might throw
}
}
示例6: executeForLastInsertedRowId
import android.support.v4.os.CancellationSignal; //导入依赖的package包/类
/**
* Executes a statement that returns the row id of the last row inserted
* by the statement. Use for INSERT SQL statements.
*
* @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 The row id of the last row that was inserted, or 0 if none.
*
* @throws SQLiteException if an error occurs, such as a syntax error
* or invalid number of bind arguments.
* @throws OperationCanceledException if the operation was canceled.
*/
public long executeForLastInsertedRowId(String sql, Object[] bindArgs, int connectionFlags,
CancellationSignal cancellationSignal) {
if (sql == null) {
throw new IllegalArgumentException("sql must not be null.");
}
if (executeSpecial(sql, bindArgs, connectionFlags, cancellationSignal)) {
return 0;
}
acquireConnection(sql, connectionFlags, cancellationSignal); // might throw
try {
return mConnection.executeForLastInsertedRowId(sql, bindArgs,
cancellationSignal); // might throw
} finally {
releaseConnection(); // might throw
}
}
示例7: 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;
}
示例8: 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)
{
break MISSING_BLOCK_LABEL_29;
}
cancellationsignal = ((CancellationSignal) (cancellationsignal.getCancellationSignalObject()));
_L1:
contentresolver = ContentResolverCompatJellybean.query(contentresolver, uri, as, s, as1, s1, cancellationsignal);
return contentresolver;
cancellationsignal = null;
goto _L1
contentresolver;
if (ContentResolverCompatJellybean.isFrameworkOperationCanceledException(contentresolver))
{
throw new OperationCanceledException();
} else
{
throw contentresolver;
}
}
示例9: 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)
{
break MISSING_BLOCK_LABEL_29;
}
cancellationsignal = ((CancellationSignal) (cancellationsignal.getCancellationSignalObject()));
_L1:
contentresolver = ContentResolverCompatJellybean.query(contentresolver, uri, as, s, as1, s1, cancellationsignal);
return contentresolver;
cancellationsignal = null;
goto _L1
contentresolver;
if (ContentResolverCompatJellybean.isFrameworkOperationCanceledException(contentresolver))
{
throw new OperationCanceledException();
} else
{
throw contentresolver;
}
}
示例10: 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();
}
}
示例11: startListening
import android.support.v4.os.CancellationSignal; //导入依赖的package包/类
public void startListening(FingerprintManagerCompat.CryptoObject cryptoObject) {
if (!isFingerprintAuthAvailable()) {
return;
}
mCancellationSignal = new CancellationSignal();
mSelfCancelled = false;
// The line below prevents the false positive inspection from Android Studio
// noinspection ResourceType
mFingerprintManager .authenticate(cryptoObject, 0 /* flags */, mCancellationSignal, this, null);
mIcon.setImageResource(R.drawable.ic_fp_40px);
}
示例12: startListening
import android.support.v4.os.CancellationSignal; //导入依赖的package包/类
public void startListening(FingerprintManagerCompat.CryptoObject cryptoObject) {
if (!mListening) {
mListening = true;
mCancellationSignal = new CancellationSignal();
mSelfCancelled = false;
mFingerprintManagerCompat
.authenticate(cryptoObject, 0, mCancellationSignal, this, null);
mSwirlView.setState(SwirlView.State.ON);
}
}
示例13: 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) {
Object cancellationSignalObject;
if (cancellationSignal != null) {
try {
cancellationSignalObject = cancellationSignal.getCancellationSignalObject();
} catch (Exception e) {
if (ContentResolverCompatJellybean.isFrameworkOperationCanceledException(e)) {
throw new OperationCanceledException();
}
throw e;
}
}
cancellationSignalObject = null;
return ContentResolverCompatJellybean.query(resolver, uri, projection, selection, selectionArgs, sortOrder, cancellationSignalObject);
}
示例14: loadInBackground
import android.support.v4.os.CancellationSignal; //导入依赖的package包/类
public Cursor loadInBackground() {
Cursor cursor;
synchronized (this) {
if (isLoadInBackgroundCanceled()) {
throw new OperationCanceledException();
}
this.mCancellationSignal = new CancellationSignal();
}
try {
cursor = ContentResolverCompat.query(getContext().getContentResolver(), this.mUri, this.mProjection, this.mSelection, this.mSelectionArgs, this.mSortOrder, this.mCancellationSignal);
if (cursor != null) {
cursor.getCount();
cursor.registerContentObserver(this.mObserver);
}
synchronized (this) {
this.mCancellationSignal = null;
}
return cursor;
} catch (RuntimeException ex) {
cursor.close();
throw ex;
} catch (Throwable th) {
synchronized (this) {
this.mCancellationSignal = null;
}
}
}
示例15: solveHanoi
import android.support.v4.os.CancellationSignal; //导入依赖的package包/类
public static void solveHanoi(int totalDisk, Callback callback, CancellationSignal cancel) {
try {
Brain brain = new Brain(callback, cancel);
brain.moveHanoiTower(totalDisk, totalDisk - 1, 0, 2, 1);
callback.onFinished();
} catch (OperationCanceledException e) {
callback.onCanceled();
}
}