Methods Summary |
---|
public android.content.ContentProviderResult[] | applyBatch(java.util.ArrayList operations)
int ypCount = 0;
int opCount = 0;
mDb = mOpenHelper.getWritableDatabase();
mDb.beginTransactionWithListener(this);
try {
mApplyingBatch.set(true);
final int numOperations = operations.size();
final ContentProviderResult[] results = new ContentProviderResult[numOperations];
for (int i = 0; i < numOperations; i++) {
if (++opCount > getMaxOperationsPerYield()) {
throw new OperationApplicationException(
"Too many content provider operations between yield points. "
+ "The maximum number of operations per yield point is "
+ MAX_OPERATIONS_PER_YIELD_POINT, ypCount);
}
final ContentProviderOperation operation = operations.get(i);
if (i > 0 && operation.isYieldAllowed()) {
opCount = 0;
boolean savedNotifyChange = mNotifyChange;
if (mDb.yieldIfContendedSafely(SLEEP_AFTER_YIELD_DELAY)) {
mDb = mOpenHelper.getWritableDatabase();
mNotifyChange = savedNotifyChange;
ypCount++;
}
}
results[i] = operation.apply(this, results, i);
}
mDb.setTransactionSuccessful();
return results;
} finally {
mApplyingBatch.set(false);
mDb.endTransaction();
onEndTransaction();
}
|
private boolean | applyingBatch()
return mApplyingBatch.get() != null && mApplyingBatch.get();
|
protected void | beforeTransactionCommit()
|
public int | bulkInsert(android.net.Uri uri, android.content.ContentValues[] values)
int numValues = values.length;
mDb = mOpenHelper.getWritableDatabase();
mDb.beginTransactionWithListener(this);
try {
for (int i = 0; i < numValues; i++) {
Uri result = insertInTransaction(uri, values[i]);
if (result != null) {
mNotifyChange = true;
}
boolean savedNotifyChange = mNotifyChange;
SQLiteDatabase savedDb = mDb;
mDb.yieldIfContendedSafely();
mDb = savedDb;
mNotifyChange = savedNotifyChange;
}
mDb.setTransactionSuccessful();
} finally {
mDb.endTransaction();
}
onEndTransaction();
return numValues;
|
public int | delete(android.net.Uri uri, java.lang.String selection, java.lang.String[] selectionArgs)
int count = 0;
boolean applyingBatch = applyingBatch();
if (!applyingBatch) {
mDb = mOpenHelper.getWritableDatabase();
mDb.beginTransactionWithListener(this);
try {
count = deleteInTransaction(uri, selection, selectionArgs);
if (count > 0) {
mNotifyChange = true;
}
mDb.setTransactionSuccessful();
} finally {
mDb.endTransaction();
}
onEndTransaction();
} else {
count = deleteInTransaction(uri, selection, selectionArgs);
if (count > 0) {
mNotifyChange = true;
}
}
return count;
|
protected abstract int | deleteInTransaction(android.net.Uri uri, java.lang.String selection, java.lang.String[] selectionArgs)The equivalent of the {@link #delete} method, but invoked within a transaction.
|
protected abstract android.database.sqlite.SQLiteOpenHelper | getDatabaseHelper(android.content.Context context)
|
public android.database.sqlite.SQLiteOpenHelper | getDatabaseHelper()
return mOpenHelper;
|
public int | getMaxOperationsPerYield()
return MAX_OPERATIONS_PER_YIELD_POINT;
|
public android.net.Uri | insert(android.net.Uri uri, android.content.ContentValues values)
Uri result = null;
boolean applyingBatch = applyingBatch();
if (!applyingBatch) {
mDb = mOpenHelper.getWritableDatabase();
mDb.beginTransactionWithListener(this);
try {
result = insertInTransaction(uri, values);
if (result != null) {
mNotifyChange = true;
}
mDb.setTransactionSuccessful();
} finally {
mDb.endTransaction();
}
onEndTransaction();
} else {
result = insertInTransaction(uri, values);
if (result != null) {
mNotifyChange = true;
}
}
return result;
|
protected abstract android.net.Uri | insertInTransaction(android.net.Uri uri, android.content.ContentValues values)The equivalent of the {@link #insert} method, but invoked within a transaction.
|
protected abstract void | notifyChange()
|
public void | onBegin()
onBeginTransaction();
|
protected void | onBeginTransaction()
|
public void | onCommit()
beforeTransactionCommit();
|
public boolean | onCreate()
Context context = getContext();
mOpenHelper = getDatabaseHelper(context);
return true;
|
protected void | onEndTransaction()
if (mNotifyChange) {
mNotifyChange = false;
notifyChange();
}
|
public void | onRollback()
// not used
|
public int | update(android.net.Uri uri, android.content.ContentValues values, java.lang.String selection, java.lang.String[] selectionArgs)
int count = 0;
boolean applyingBatch = applyingBatch();
if (!applyingBatch) {
mDb = mOpenHelper.getWritableDatabase();
mDb.beginTransactionWithListener(this);
try {
count = updateInTransaction(uri, values, selection, selectionArgs);
if (count > 0) {
mNotifyChange = true;
}
mDb.setTransactionSuccessful();
} finally {
mDb.endTransaction();
}
onEndTransaction();
} else {
count = updateInTransaction(uri, values, selection, selectionArgs);
if (count > 0) {
mNotifyChange = true;
}
}
return count;
|
protected abstract int | updateInTransaction(android.net.Uri uri, android.content.ContentValues values, java.lang.String selection, java.lang.String[] selectionArgs)The equivalent of the {@link #update} method, but invoked within a transaction.
|