am 8587aa61: Make EmailProvider more threadsafe w/r/t transactions

Merge commit '8587aa61211d288d05b5fb2ddf02d69cabe6a9e2' into eclair-plus-aosp

* commit '8587aa61211d288d05b5fb2ddf02d69cabe6a9e2':
  Make EmailProvider more threadsafe w/r/t transactions
This commit is contained in:
Marc Blank 2009-09-20 10:00:53 -07:00 committed by Android Git Automerger
commit f08a92083b

View File

@ -510,7 +510,6 @@ public class EmailProvider extends ContentProvider {
private SQLiteDatabase mDatabase; private SQLiteDatabase mDatabase;
private SQLiteDatabase mBodyDatabase; private SQLiteDatabase mBodyDatabase;
private boolean mInTransaction = false;
public synchronized SQLiteDatabase getDatabase(Context context) { public synchronized SQLiteDatabase getDatabase(Context context) {
if (mDatabase != null) { if (mDatabase != null) {
@ -632,9 +631,7 @@ public class EmailProvider extends ContentProvider {
// Bodies are auto-deleted here; Attachments are auto-deleted via trigger // Bodies are auto-deleted here; Attachments are auto-deleted via trigger
messageDeletion = true; messageDeletion = true;
if (!mInTransaction) {
db.beginTransaction(); db.beginTransaction();
}
break; break;
} }
switch (match) { switch (match) {
@ -687,17 +684,13 @@ public class EmailProvider extends ContentProvider {
// Delete any orphaned Body records // Delete any orphaned Body records
db.execSQL(DELETE_ORPHAN_BODIES); db.execSQL(DELETE_ORPHAN_BODIES);
} }
if (!mInTransaction) {
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} }
}
} finally { } finally {
if (messageDeletion) { if (messageDeletion) {
if (!mInTransaction) {
db.endTransaction(); db.endTransaction();
} }
} }
}
getContext().getContentResolver().notifyChange(uri, null); getContext().getContentResolver().notifyChange(uri, null);
return result; return result;
} }
@ -919,9 +912,7 @@ public class EmailProvider extends ContentProvider {
switch (match) { switch (match) {
case MAILBOX_ID_ADD_TO_FIELD: case MAILBOX_ID_ADD_TO_FIELD:
case ACCOUNT_ID_ADD_TO_FIELD: case ACCOUNT_ID_ADD_TO_FIELD:
if (!mInTransaction) {
db.beginTransaction(); db.beginTransaction();
}
id = uri.getPathSegments().get(1); id = uri.getPathSegments().get(1);
String field = values.getAsString(EmailContent.FIELD_COLUMN_NAME); String field = values.getAsString(EmailContent.FIELD_COLUMN_NAME);
Long add = values.getAsLong(EmailContent.ADD_COLUMN_NAME); Long add = values.getAsLong(EmailContent.ADD_COLUMN_NAME);
@ -944,10 +935,8 @@ public class EmailProvider extends ContentProvider {
} finally { } finally {
c.close(); c.close();
} }
if (!mInTransaction) {
db.setTransactionSuccessful(); db.setTransactionSuccessful();
db.endTransaction(); db.endTransaction();
}
break; break;
case BODY_ID: case BODY_ID:
case MESSAGE_ID: case MESSAGE_ID:
@ -996,14 +985,12 @@ public class EmailProvider extends ContentProvider {
Context context = getContext(); Context context = getContext();
SQLiteDatabase db = getDatabase(context); SQLiteDatabase db = getDatabase(context);
db.beginTransaction(); db.beginTransaction();
mInTransaction = true;
try { try {
ContentProviderResult[] results = super.applyBatch(operations); ContentProviderResult[] results = super.applyBatch(operations);
db.setTransactionSuccessful(); db.setTransactionSuccessful();
return results; return results;
} finally { } finally {
db.endTransaction(); db.endTransaction();
mInTransaction = false;
} }
} }
} }