diff options
author | Dave Santoro <dsantoro@google.com> | 2011-08-01 11:54:26 -0700 |
---|---|---|
committer | Dave Santoro <dsantoro@google.com> | 2011-08-01 11:54:26 -0700 |
commit | a09d7527b132ec82f98cde1564b0262fd85768c2 (patch) | |
tree | fe9dcbd5a29cc5c3382f9ad973787db2c9a99065 /src | |
parent | 75a95333dd37310a369d546649efedb38c1cd9f7 (diff) | |
download | packages_providers_ContactsProvider-a09d7527b132ec82f98cde1564b0262fd85768c2.zip packages_providers_ContactsProvider-a09d7527b132ec82f98cde1564b0262fd85768c2.tar.gz packages_providers_ContactsProvider-a09d7527b132ec82f98cde1564b0262fd85768c2.tar.bz2 |
Create account record if needed on profile insert.
For accounts without a data set, this should be handled automatically
when the account is added. But with data sets, we need to handle it
specially so that the profile raw contact ID reference has a row to
hang off of.
Other raw contacts or groups with a data set will have the account
record created in the background when the provider is initialized.
Change-Id: I24ea0c389c3bc839aee295f1297e2236c473d66f
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/providers/contacts/ContactAggregator.java | 55 |
1 files changed, 45 insertions, 10 deletions
diff --git a/src/com/android/providers/contacts/ContactAggregator.java b/src/com/android/providers/contacts/ContactAggregator.java index 5064ee7..cb13878 100644 --- a/src/com/android/providers/contacts/ContactAggregator.java +++ b/src/com/android/providers/contacts/ContactAggregator.java @@ -137,9 +137,11 @@ public class ContactAggregator { private SQLiteStatement mMarkForAggregation; private SQLiteStatement mPhotoIdUpdate; private SQLiteStatement mDisplayNameUpdate; + private SQLiteStatement mAccountWithDataSetCheck; private SQLiteStatement mProfileUpdate; private SQLiteStatement mNoDataSetProfileUpdate; private SQLiteStatement mNoAccountProfileUpdate; + private SQLiteStatement mAccountWithProfileCreate; private SQLiteStatement mHasPhoneNumberUpdate; private SQLiteStatement mLookupKeyUpdate; private SQLiteStatement mStarredUpdate; @@ -324,6 +326,12 @@ public class ContactAggregator { " SET " + Contacts.NAME_RAW_CONTACT_ID + "=? " + " WHERE " + Contacts._ID + "=?"); + mAccountWithDataSetCheck = db.compileStatement( + "SELECT COUNT(*) FROM " + Tables.ACCOUNTS + + " WHERE " + AccountsColumns.ACCOUNT_TYPE + "=?" + + " AND " + AccountsColumns.ACCOUNT_NAME + "=?" + + " AND " + AccountsColumns.DATA_SET + "=?"); + mProfileUpdate = db.compileStatement( "UPDATE " + Tables.ACCOUNTS + " SET " + AccountsColumns.PROFILE_RAW_CONTACT_ID + "=? " + @@ -345,6 +353,12 @@ public class ContactAggregator { " AND " + AccountsColumns.ACCOUNT_NAME + " IS NULL" + " AND " + AccountsColumns.DATA_SET + " IS NULL"); + mAccountWithProfileCreate = db.compileStatement( + "INSERT INTO " + Tables.ACCOUNTS + + "(" + AccountsColumns.ACCOUNT_TYPE + "," + AccountsColumns.ACCOUNT_NAME + "," + + AccountsColumns.DATA_SET + "," + AccountsColumns.PROFILE_RAW_CONTACT_ID + ")" + + " VALUES (?,?,?,?)"); + mLookupKeyUpdate = db.compileStatement( "UPDATE " + Tables.CONTACTS + " SET " + Contacts.LOOKUP_KEY + "=? " + @@ -618,17 +632,38 @@ public class ContactAggregator { if (accountWithDataSet == null) { mNoAccountProfileUpdate.bindLong(1, rawContactId); mNoAccountProfileUpdate.execute(); - } else if (accountWithDataSet.getDataSet() == null) { - mNoDataSetProfileUpdate.bindLong(1, rawContactId); - mNoDataSetProfileUpdate.bindString(2, accountWithDataSet.getAccountType()); - mNoDataSetProfileUpdate.bindString(3, accountWithDataSet.getAccountName()); - mNoDataSetProfileUpdate.execute(); } else { - mProfileUpdate.bindLong(1, rawContactId); - mProfileUpdate.bindString(2, accountWithDataSet.getAccountType()); - mProfileUpdate.bindString(3, accountWithDataSet.getAccountName()); - mProfileUpdate.bindString(4, accountWithDataSet.getDataSet()); - mProfileUpdate.execute(); + String accountType = accountWithDataSet.getAccountType(); + String accountName = accountWithDataSet.getAccountName(); + String dataSet = accountWithDataSet.getDataSet(); + if (dataSet == null) { + mNoDataSetProfileUpdate.bindLong(1, rawContactId); + mNoDataSetProfileUpdate.bindString(2, accountType); + mNoDataSetProfileUpdate.bindString(3, accountName); + mNoDataSetProfileUpdate.execute(); + } else { + // If there is a data set, it's possible that the account row does not yet exist + // (accounts without data sets are automatically created based on the system + // accounts). So first check to see if the account exists. + mAccountWithDataSetCheck.bindString(1, accountType); + mAccountWithDataSetCheck.bindString(2, accountName); + mAccountWithDataSetCheck.bindString(3, dataSet); + if (mAccountWithDataSetCheck.simpleQueryForLong() == 1) { + // Account record already exists, Update it with the profile raw contact ID. + mProfileUpdate.bindLong(1, rawContactId); + mProfileUpdate.bindString(2, accountType); + mProfileUpdate.bindString(3, accountName); + mProfileUpdate.bindString(4, dataSet); + mProfileUpdate.execute(); + } else { + // Account record needed. + mAccountWithProfileCreate.bindString(1, accountType); + mAccountWithProfileCreate.bindString(2, accountName); + mAccountWithProfileCreate.bindString(3, dataSet); + mAccountWithProfileCreate.bindLong(4, rawContactId); + mAccountWithProfileCreate.execute(); + } + } } } |