Merge "Delete provider data before insert"
This commit is contained in:
committed by
Android (Google) Code Review
commit
031de928a5
@@ -77,8 +77,11 @@ public class CardContentProvider extends ContentProvider {
|
|||||||
|
|
||||||
final String table = getTableFromMatch(uri);
|
final String table = getTableFromMatch(uri);
|
||||||
database.beginTransaction();
|
database.beginTransaction();
|
||||||
|
|
||||||
|
// Here deletion first is avoiding redundant insertion. According to cl/215350754
|
||||||
|
database.delete(table, null /* whereClause */, null /* whereArgs */);
|
||||||
for (ContentValues value : values) {
|
for (ContentValues value : values) {
|
||||||
long ret = database.insert(table, null, value);
|
long ret = database.insert(table, null /* nullColumnHack */, value);
|
||||||
if (ret != -1L) {
|
if (ret != -1L) {
|
||||||
numInserted++;
|
numInserted++;
|
||||||
} else {
|
} else {
|
||||||
@@ -87,7 +90,7 @@ public class CardContentProvider extends ContentProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
database.setTransactionSuccessful();
|
database.setTransactionSuccessful();
|
||||||
getContext().getContentResolver().notifyChange(uri, null);
|
getContext().getContentResolver().notifyChange(uri, null /* observer */);
|
||||||
} finally {
|
} finally {
|
||||||
database.endTransaction();
|
database.endTransaction();
|
||||||
StrictMode.setThreadPolicy(oldPolicy);
|
StrictMode.setThreadPolicy(oldPolicy);
|
||||||
@@ -103,7 +106,7 @@ public class CardContentProvider extends ContentProvider {
|
|||||||
final SQLiteDatabase database = mDBHelper.getWritableDatabase();
|
final SQLiteDatabase database = mDBHelper.getWritableDatabase();
|
||||||
final String table = getTableFromMatch(uri);
|
final String table = getTableFromMatch(uri);
|
||||||
final int rowsDeleted = database.delete(table, selection, selectionArgs);
|
final int rowsDeleted = database.delete(table, selection, selectionArgs);
|
||||||
getContext().getContentResolver().notifyChange(uri, null);
|
getContext().getContentResolver().notifyChange(uri, null /* observer */);
|
||||||
return rowsDeleted;
|
return rowsDeleted;
|
||||||
} finally {
|
} finally {
|
||||||
StrictMode.setThreadPolicy(oldPolicy);
|
StrictMode.setThreadPolicy(oldPolicy);
|
||||||
@@ -127,7 +130,8 @@ public class CardContentProvider extends ContentProvider {
|
|||||||
queryBuilder.setTables(table);
|
queryBuilder.setTables(table);
|
||||||
final SQLiteDatabase database = mDBHelper.getReadableDatabase();
|
final SQLiteDatabase database = mDBHelper.getReadableDatabase();
|
||||||
final Cursor cursor = queryBuilder.query(database,
|
final Cursor cursor = queryBuilder.query(database,
|
||||||
projection, selection, selectionArgs, null, null, sortOrder);
|
projection, selection, selectionArgs, null /* groupBy */, null /* having */,
|
||||||
|
sortOrder);
|
||||||
|
|
||||||
cursor.setNotificationUri(getContext().getContentResolver(), uri);
|
cursor.setNotificationUri(getContext().getContentResolver(), uri);
|
||||||
return cursor;
|
return cursor;
|
||||||
@@ -145,7 +149,7 @@ public class CardContentProvider extends ContentProvider {
|
|||||||
final SQLiteDatabase database = mDBHelper.getWritableDatabase();
|
final SQLiteDatabase database = mDBHelper.getWritableDatabase();
|
||||||
final String table = getTableFromMatch(uri);
|
final String table = getTableFromMatch(uri);
|
||||||
final int rowsUpdated = database.update(table, values, selection, selectionArgs);
|
final int rowsUpdated = database.update(table, values, selection, selectionArgs);
|
||||||
getContext().getContentResolver().notifyChange(uri, null);
|
getContext().getContentResolver().notifyChange(uri, null /* observer */);
|
||||||
return rowsUpdated;
|
return rowsUpdated;
|
||||||
} finally {
|
} finally {
|
||||||
StrictMode.setThreadPolicy(oldPolicy);
|
StrictMode.setThreadPolicy(oldPolicy);
|
||||||
|
Reference in New Issue
Block a user