com.vodafone360.people.database.tables
Class ContactDetailsTable

java.lang.Object
  extended by com.vodafone360.people.database.tables.ContactDetailsTable

public abstract class ContactDetailsTable
extends java.lang.Object

Provides a wrapper for all the operations on the Contact Details Table. Class is never instantiated, all methods and fields are static.


Nested Class Summary
static class ContactDetailsTable.Field
          Associates a constant with a field string in the People database.
static class ContactDetailsTable.NativeIdInfo
          Holds the Native Contact information that is stored in the database for a contact detail.
 
Field Summary
private static int COLUMN_ALT
           
private static int COLUMN_KEY
           
private static int COLUMN_KEYTYPE
           
private static int COLUMN_LOCALCONTACTID
           
private static int COLUMN_LOCALDETAILID
          Identifies the columns of the data returned by getFullQueryList()
private static int COLUMN_NATIVE_SYNC_CONTACT_ID
           
private static int COLUMN_NATIVECONTACTID
           
private static int COLUMN_NATIVEDETAILID
           
private static int COLUMN_NATIVEVAL1
           
private static int COLUMN_NATIVEVAL2
           
private static int COLUMN_NATIVEVAL3
           
private static int COLUMN_ORDER
           
private static int COLUMN_SERVER_SYNC
           
private static int COLUMN_SERVERDETAILID
           
private static int COLUMN_UPDATED
           
private static int COLUMN_VALUE
           
private static int DATA_QUERY_LENGTH
          Equals the number of comma separated items returned by getFullQueryList().
private static java.lang.String QUERY_CONTACT_DETAILS_BY_LOCAL_ID
          SELECT LocalContactId, DetailLocalId, NativeDetailId, NativeContactIdDup, Key, Type, StringVal, OrderNo FROM ContactDetails.
private static java.lang.String QUERY_NATIVE_SYNCABLE_CONTACT_DETAILS_BY_LOCAL_ID
           
static java.lang.String QUERY_NATIVE_SYNCABLE_CONTACTS_LOCAL_IDS
          SELECT DISTINCT LocalId FROM ContactDetails WHERE NativeSyncId IS NULL OR NativeSyncId <> -1
private static java.lang.String SQL_STRING_LOCAL_ID_EQUAL_QUESTION_MARK
          LocalId = ?
static java.lang.String TABLE_NAME
          Name of the table in the people database.
 
Constructor Summary
ContactDetailsTable()
           
 
Method Summary
static ServiceStatus addContactDetail(ContactDetail detail, boolean syncToServer, boolean syncToNative, SQLiteDatabase writeableDb)
          Adds a new contact detail to the table.
static boolean addNativeContactDetails(ContactChange[] contactChange, SQLiteDatabase writeableDb)
          Adds the provided contact details to the ContactDetail table.
static void create(SQLiteDatabase writeableDb)
          Creates the contact detail table.
static ServiceStatus deleteDetailByContactId(long localContactId, SQLiteDatabase writeableDb)
          Deletes all the contact details associated with a contact
static boolean deleteDetailByDetailId(long localDetailId, SQLiteDatabase writeableDb)
          Removes a contact detail from the table
static boolean doContactsMatch(Contact c, long localContactId, java.util.List<ContactDetailsTable.NativeIdInfo> detailIdList, SQLiteDatabase readableDb)
          Compares the details given with a specific contact in the database.
static ServiceStatus fetchContactDetails(java.lang.Long localContactId, java.util.List<ContactDetail> detailList, SQLiteDatabase readableDb)
          Fetch details for a given contact
static boolean fetchContactDetailsForNative(java.util.List<ContactDetail> detailList, ContactDetail.DetailKeys[] keyList, boolean byDetailId, int firstIndex, int count, SQLiteDatabase readableDb)
          Fetches all contact details that need to be synced with the native contacts database
static ServiceStatus fetchContactInfo(java.lang.String phoneNumber, ContactDetail phoneDetail, ContactDetail nameDetail, SQLiteDatabase readableDb)
          Finds a phone contact detail which matches a given telephone number.
static ContactDetail fetchDetail(long localContactId, ContactDetail.DetailKeys key, SQLiteDatabase readableDb)
          Fetches the first contact detail found for a contact and key.
static ContactDetail fetchDetail(long localDetailId, SQLiteDatabase readableDb)
          Fetches a contact detail from the table
static boolean fetchPreferredDetail(long localContactID, int keyVal, ContactDetail altDetail, SQLiteDatabase readableDb)
          Fetches the preferred detail to use in the contact summary when the name or status field are blank.
private static ContentValues fillUpdateData(ContactDetail detail, boolean syncToServer, boolean syncToNative)
          Extracts the suitable content values from a contact detail which can be used to update or insert a record in the table.
static java.lang.String findChatIdByLocalContactIdAndNetwork(java.lang.String networkName, long localContactId, SQLiteDatabase readableDb)
          This method finds the chat id corresponding to the wanted Alt, LocalContactId and Key fields
private static Cursor findDetailByKey(java.lang.String value, ContactDetail.DetailKeys key, SQLiteDatabase readableDb)
          Returns a cursor of all the contact details that match a specific key and value.
static long findLocalContactIdByKey(java.lang.String networkName, java.lang.String value, ContactDetail.DetailKeys key, SQLiteDatabase readableDb)
          This method finds the localContactId corresponding to the wanted Key and StringVal fields.
static boolean findNativeContact(Contact c, SQLiteDatabase writableDb)
          Searches the contact details table for a contact from the native phonebook.
private static ServiceStatus fixPreferredDetail(long localContactId, ContactDetail.DetailKeys key, SQLiteDatabase writableDb)
          Ensures that for a given key there is at least one preferred detail.
static ServiceStatus fixPreferredValues(long localContactId, SQLiteDatabase writableDb)
          Fixes the phone numbers and emails of a contact to ensure that at least one of each is a preferred detail.
static ContactChange[] getContactChanges(long localId, boolean nativeSyncableOnly, SQLiteDatabase readableDb)
          Gets an array of ContactChange from the contact's local id.
private static java.lang.String getFullQueryList()
          Fetches the list of table fields that can be injected into an SQL query statement.
static ContactDetail getQueryData(Cursor c)
          Returns the contact detail for the current record in the cursor.
private static int getQueryDataLength()
          Returns the number of comma separated items returned by getFullQueryList().
static java.lang.String getQueryStringSql(java.lang.String whereClause)
          Returns the SQL for doing a raw query on the contact details table.
static int mapContactChangeFlagToInternalOrder(int flag)
          Maps a ContactChange flag to a ContactDetail order.
static int mapContactChangeFlagToInternalType(int flag)
          Maps a ContactChange flag to a ContactDetail key type.
static int mapContactChangeKeyToInternalKey(int key)
          Maps a ContactChange key to a ContactDetail key.
static int mapInternalKeyToContactChangeKey(int key)
          Maps ContactDetail key to ContactChange key.
static int mapInternalTypeAndOrderToContactChangeFlag(int type, int order)
          Maps a ContactDetail type and an order to the ContactChange flag equivalent.
static ServiceStatus modifyDetail(ContactDetail detail, boolean syncToServer, boolean syncToNative, SQLiteDatabase writeableDb)
          Updates an existing contact detail in the table.
static boolean modifyDetailNativeId(ContactDetail detail, SQLiteDatabase writeableDb)
          Updates the detail native contact information stored with the record
static boolean modifyDetailServerId(long localId, java.lang.Long serverId, SQLiteDatabase writeableDb)
          Updates the detail server ID stored with the record
static void prepareNativeContactDetailInsert(ContactChange contactChange, ContentValues values)
          Fills a ContentValues object with the provided ContactChange to later be used for database insert.
static boolean removePreferred(java.lang.Long localContactID, ContactDetail.DetailKeys key, SQLiteDatabase writableDb)
          Remove all preferred details from contact for a particular key.
static boolean setDetailSyncedWithNative(long localDetailId, long nativeContactId, long nativeDetailId, boolean isNewlySynced, SQLiteDatabase writableDb)
          Sets the detail as synchronized with native side.
static Cursor syncNativeFetchContactChanges(SQLiteDatabase readableDb, boolean newContacts)
          Fetches all the details that have changed and need to be synced with the native.
static int syncNativeFetchNoOfChanges(SQLiteDatabase readableDb)
          Retrieves the total number of details that have changed and need to be synced with the native database.
static boolean syncNativeGetNextNewContactDetails(Cursor c, java.util.List<Contact> contactList, int maxContactsToFetch)
          Returns the next batch of contacts which need to be added on the native database.
static Cursor syncServerFetchContactChanges(SQLiteDatabase readableDb, boolean newContacts)
          Fetches all the details that have changed and need to be synced with the server.
static int syncServerFetchNoOfChanges(SQLiteDatabase db)
          Retrieves the total number of details that have changed and need to be synced with the server.
static void syncServerGetNextNewContactDetails(Cursor c, java.util.List<Contact> contactList, int maxContactsToFetch)
          Returns the next batch of contacts which need to be added on the server.
static ServiceStatus syncSetNativeIds(java.util.List<ContactDetailsTable.NativeIdInfo> nativeIdList, SQLiteDatabase writableDb)
          Set native detail ID for all those details which require an ID.
static ServiceStatus syncSetServerIds(java.util.List<DatabaseHelper.ServerIdInfo> serverIdList, SQLiteDatabase writableDb)
          Set contact detail server ID for all those details which require a server ID.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TABLE_NAME

public static final java.lang.String TABLE_NAME
Name of the table in the people database.

See Also:
Constant Field Values

QUERY_CONTACT_DETAILS_BY_LOCAL_ID

private static final java.lang.String QUERY_CONTACT_DETAILS_BY_LOCAL_ID
SELECT LocalContactId, DetailLocalId, NativeDetailId, NativeContactIdDup, Key, Type, StringVal, OrderNo FROM ContactDetails.

See Also:
#getContactChanges(long, SQLiteDatabase)

QUERY_NATIVE_SYNCABLE_CONTACT_DETAILS_BY_LOCAL_ID

private static final java.lang.String QUERY_NATIVE_SYNCABLE_CONTACT_DETAILS_BY_LOCAL_ID

QUERY_NATIVE_SYNCABLE_CONTACTS_LOCAL_IDS

public static final java.lang.String QUERY_NATIVE_SYNCABLE_CONTACTS_LOCAL_IDS
SELECT DISTINCT LocalId FROM ContactDetails WHERE NativeSyncId IS NULL OR NativeSyncId <> -1


DATA_QUERY_LENGTH

private static final int DATA_QUERY_LENGTH
Equals the number of comma separated items returned by getFullQueryList().

See Also:
Constant Field Values

COLUMN_LOCALDETAILID

private static final int COLUMN_LOCALDETAILID
Identifies the columns of the data returned by getFullQueryList()

See Also:
Constant Field Values

COLUMN_SERVERDETAILID

private static final int COLUMN_SERVERDETAILID
See Also:
Constant Field Values

COLUMN_LOCALCONTACTID

private static final int COLUMN_LOCALCONTACTID
See Also:
Constant Field Values

COLUMN_KEY

private static final int COLUMN_KEY
See Also:
Constant Field Values

COLUMN_KEYTYPE

private static final int COLUMN_KEYTYPE
See Also:
Constant Field Values

COLUMN_VALUE

private static final int COLUMN_VALUE
See Also:
Constant Field Values

COLUMN_ALT

private static final int COLUMN_ALT
See Also:
Constant Field Values

COLUMN_ORDER

private static final int COLUMN_ORDER
See Also:
Constant Field Values

COLUMN_UPDATED

private static final int COLUMN_UPDATED
See Also:
Constant Field Values

COLUMN_NATIVECONTACTID

private static final int COLUMN_NATIVECONTACTID
See Also:
Constant Field Values

COLUMN_NATIVEDETAILID

private static final int COLUMN_NATIVEDETAILID
See Also:
Constant Field Values

COLUMN_NATIVEVAL1

private static final int COLUMN_NATIVEVAL1
See Also:
Constant Field Values

COLUMN_NATIVEVAL2

private static final int COLUMN_NATIVEVAL2
See Also:
Constant Field Values

COLUMN_NATIVEVAL3

private static final int COLUMN_NATIVEVAL3
See Also:
Constant Field Values

COLUMN_SERVER_SYNC

private static final int COLUMN_SERVER_SYNC
See Also:
Constant Field Values

COLUMN_NATIVE_SYNC_CONTACT_ID

private static final int COLUMN_NATIVE_SYNC_CONTACT_ID
See Also:
Constant Field Values

SQL_STRING_LOCAL_ID_EQUAL_QUESTION_MARK

private static final java.lang.String SQL_STRING_LOCAL_ID_EQUAL_QUESTION_MARK
LocalId = ?

Constructor Detail

ContactDetailsTable

public ContactDetailsTable()
Method Detail

create

public static void create(SQLiteDatabase writeableDb)
                   throws SQLException
Creates the contact detail table.

Parameters:
writeableDb - The SQLite database
Throws:
SQLException - If the table already exists or the database is corrupt

getFullQueryList

private static java.lang.String getFullQueryList()
Fetches the list of table fields that can be injected into an SQL query statement. The getQueryData(Cursor) method can be used to obtain the data from the query.

Returns:
The query string

getQueryStringSql

public static java.lang.String getQueryStringSql(java.lang.String whereClause)
Returns the SQL for doing a raw query on the contact details table. The getQueryData(Cursor) method can be used for fetching the data from the resulting cursor.

Parameters:
whereClause - The SQL constraint (cannot be empty or null)
Returns:
The SQL query string

getQueryDataLength

private static int getQueryDataLength()
Returns the number of comma separated items returned by getFullQueryList().

Returns:
The number of items

getQueryData

public static ContactDetail getQueryData(Cursor c)
Returns the contact detail for the current record in the cursor. Query to produce the cursor must be obtained using the getFullQueryList() .

Parameters:
The - cursor obtained from doing the query
Returns:
The contact detail object.

fillUpdateData

private static ContentValues fillUpdateData(ContactDetail detail,
                                            boolean syncToServer,
                                            boolean syncToNative)
Extracts the suitable content values from a contact detail which can be used to update or insert a record in the table.

Parameters:
detail - The contact detail
syncToServer - If true the detail needs to be synced to the server, otherwise no sync required
syncToNative - If true the detail needs to be synced with the native, otherwise no sync required
Returns:
The ContentValues to use for the update or insert.

fetchDetail

public static ContactDetail fetchDetail(long localDetailId,
                                        SQLiteDatabase readableDb)
Fetches a contact detail from the table

Parameters:
localDetailId - The local ID of the required detail
readableDb - The readable SQLite database object
Returns:
ContactDetail object or NULL if the detail was not found

deleteDetailByDetailId

public static boolean deleteDetailByDetailId(long localDetailId,
                                             SQLiteDatabase writeableDb)
Removes a contact detail from the table

Parameters:
localDetailId - The local ID identifying the detail
writeableDb - A writable SQLite database object.
Returns:
true if the delete was successful, false otherwise

deleteDetailByContactId

public static ServiceStatus deleteDetailByContactId(long localContactId,
                                                    SQLiteDatabase writeableDb)
Deletes all the contact details associated with a contact

Parameters:
localContactId - The local contact ID identifying the contact
writeableDb - A writable SQLite database object.
Returns:
true if the delete was successful, false otherwise

addContactDetail

public static ServiceStatus addContactDetail(ContactDetail detail,
                                             boolean syncToServer,
                                             boolean syncToNative,
                                             SQLiteDatabase writeableDb)
Adds a new contact detail to the table.

Parameters:
detail - The new detail
syncToServer - Mark the new detail so it will be synced to the server
syncToNative - Mark the new detail so it will be synced to the native database
writeableDb - A writable SQLite database object.
Returns:
SUCCESS or a suitable error code.

modifyDetail

public static ServiceStatus modifyDetail(ContactDetail detail,
                                         boolean syncToServer,
                                         boolean syncToNative,
                                         SQLiteDatabase writeableDb)
Updates an existing contact detail in the table.

Parameters:
detail - The modified detail.
syncToServer - Mark the new detail so it will be synced to the server
syncToNative - Mark the new detail so it will be synced to the native database
writeableDb - A writable SQLite database object.
Returns:
SUCCESS or a suitable error code.

modifyDetailServerId

public static boolean modifyDetailServerId(long localId,
                                           java.lang.Long serverId,
                                           SQLiteDatabase writeableDb)
Updates the detail server ID stored with the record

Parameters:
localId - The local detail ID identifying the record
serverId - The new server ID
writeableDb - A writable SQLite database object.
Returns:
true if the update was successful, false otherwise

modifyDetailNativeId

public static boolean modifyDetailNativeId(ContactDetail detail,
                                           SQLiteDatabase writeableDb)
Updates the detail native contact information stored with the record

Parameters:
detail - The contact detail which contacts the new native information and the local ID of the detail to be modified.
writeableDb - A writable SQLite database object.
Returns:
true if the update was successful, false otherwise

fetchContactDetailsForNative

public static boolean fetchContactDetailsForNative(java.util.List<ContactDetail> detailList,
                                                   ContactDetail.DetailKeys[] keyList,
                                                   boolean byDetailId,
                                                   int firstIndex,
                                                   int count,
                                                   SQLiteDatabase readableDb)
Fetches all contact details that need to be synced with the native contacts database

Parameters:
detailList - A list that will be populated with the contact details.
keyList - A list of keys to filter the result
byDetailId - true to order the details by native detail ID, false to order by native contact ID
firstIndex - The index of the first record to fetch
count - The number of records to fetch (or -1 to fetch all)
readableDb - A readable SQLite database object.
Returns:
true if the operation was successful, false otherwise

fetchDetail

public static ContactDetail fetchDetail(long localContactId,
                                        ContactDetail.DetailKeys key,
                                        SQLiteDatabase readableDb)
Fetches the first contact detail found for a contact and key.

Parameters:
localContactId - The local contact ID
key - The contact detail key value
readableDb - A readable SQLite database object.
Returns:
The contact detail, or NULL if it could not be found.

fetchContactInfo

public static ServiceStatus fetchContactInfo(java.lang.String phoneNumber,
                                             ContactDetail phoneDetail,
                                             ContactDetail nameDetail,
                                             SQLiteDatabase readableDb)
Finds a phone contact detail which matches a given telephone number. Uses the native Android functionality for matching the numbers.

Parameters:
phoneNumber - The number to find
phoneDetail - An empty contact detail where the resulting phone contact detail will be stored.
nameDetail - An empty contact detail where the resulting name contact detail will be stored.
readableDb - A readable SQLite database object.
Returns:
SUCCESS or a suitable error code.

fetchContactDetails

public static ServiceStatus fetchContactDetails(java.lang.Long localContactId,
                                                java.util.List<ContactDetail> detailList,
                                                SQLiteDatabase readableDb)
Fetch details for a given contact

Parameters:
localContactId - The local ID of the contact
detailList - A list which will be populated with the details
readableDb - A readable SQLite database object.
Returns:
SUCCESS or a suitable error code.

syncSetServerIds

public static ServiceStatus syncSetServerIds(java.util.List<DatabaseHelper.ServerIdInfo> serverIdList,
                                             SQLiteDatabase writableDb)
Set contact detail server ID for all those details which require a server ID. In any case, the server sync contact ID flag is set to -1 to indicate that the detail has been fully synced with the server.

Parameters:
serverIdList - The list of contact details. This list should include all details even the ones which don't have server IDs.
writableDb - A writable SQLite database object
Returns:
SUCCESS or a suitable error code.

syncSetNativeIds

public static ServiceStatus syncSetNativeIds(java.util.List<ContactDetailsTable.NativeIdInfo> nativeIdList,
                                             SQLiteDatabase writableDb)
Set native detail ID for all those details which require an ID. In any case, the native sync contact ID flag is set to -1 to indicate that the detail has been fully synced with the native contacts database.

Parameters:
serverIdList - The list of contact details. This list should include all details even the ones which don't have native IDs.
writableDb - A writable SQLite database object
Returns:
SUCCESS or a suitable error code.

fetchPreferredDetail

public static boolean fetchPreferredDetail(long localContactID,
                                           int keyVal,
                                           ContactDetail altDetail,
                                           SQLiteDatabase readableDb)
Fetches the preferred detail to use in the contact summary when the name or status field are blank.

Parameters:
localContactID - The local contact ID
keyVal - The key to fetch (normally either VCARD_PHONE or VCARD_EMAIL).
altDetail - A contact detail object where the result will be stored.
readableDb - A readable SQLite database object
Returns:
true if successful, false otherwise.

fixPreferredValues

public static ServiceStatus fixPreferredValues(long localContactId,
                                               SQLiteDatabase writableDb)
Fixes the phone numbers and emails of a contact to ensure that at least one of each is a preferred detail.

Parameters:
localContactId - The local Id of the contact
writableDb - A writable SQLite database object
Returns:
SUCCESS or a suitable error code.

fixPreferredDetail

private static ServiceStatus fixPreferredDetail(long localContactId,
                                                ContactDetail.DetailKeys key,
                                                SQLiteDatabase writableDb)
Ensures that for a given key there is at least one preferred detail. Modifying the database if necessary.

Parameters:
localContactId - The local ID of the contact.
key - The key to fix.
writableDb - A writable SQLite database object
Returns:
SUCCESS or a suitable error code.

findDetailByKey

private static Cursor findDetailByKey(java.lang.String value,
                                      ContactDetail.DetailKeys key,
                                      SQLiteDatabase readableDb)
Returns a cursor of all the contact details that match a specific key and value. Used by the findNativeContact(Contact, SQLiteDatabase) method to find all the contacts by name, phone number or email.

Parameters:
value - The string value to match.
key - The key to match.
readableDb - A readable SQLite database object
Returns:
A cursor containing the local detail ID and local contact ID for each result.

findLocalContactIdByKey

public static long findLocalContactIdByKey(java.lang.String networkName,
                                           java.lang.String value,
                                           ContactDetail.DetailKeys key,
                                           SQLiteDatabase readableDb)
                                    throws SQLException
This method finds the localContactId corresponding to the wanted Key and StringVal fields.

Parameters:
value - - StringVal
key - - Key
readableDb - A readable SQLite database object
Returns:
- localContactId (it is unique)
Throws:
SQLException

findChatIdByLocalContactIdAndNetwork

public static java.lang.String findChatIdByLocalContactIdAndNetwork(java.lang.String networkName,
                                                                    long localContactId,
                                                                    SQLiteDatabase readableDb)
                                                             throws java.lang.NullPointerException,
                                                                    SQLException
This method finds the chat id corresponding to the wanted Alt, LocalContactId and Key fields

Parameters:
networkName - - network name (google,MSN)
localContactId - - localContactId of the contcat
readableDb - A readable SQLite database object
Returns:
- chatId for this network(it is unique)
Throws:
java.lang.NullPointerException
SQLException

doContactsMatch

public static boolean doContactsMatch(Contact c,
                                      long localContactId,
                                      java.util.List<ContactDetailsTable.NativeIdInfo> detailIdList,
                                      SQLiteDatabase readableDb)
Compares the details given with a specific contact in the database. If the contacts match a list of native sync information is returned.

Parameters:
c - Contact to compare
localContactId - Contact in the database to compare with
detailIdList - A list which will be populated if a match is found.
readableDb - A readable SQLite database object
Returns:
true if a match is found, false otherwise

findNativeContact

public static boolean findNativeContact(Contact c,
                                        SQLiteDatabase writableDb)
Searches the contact details table for a contact from the native phonebook. If a match is found, the native sync information is transfered from the given contact into the matching database contact. Tries to match in the following sequence: 1) If there is a name, match by name 2) Otherwise, if there is a phone number, match by number 3) Otherwise, if there is an email, match by email 4) Otherwise return false For a match to occur, all given contact details must be identical to those in the database. There may be more details in the database but this won't change the result.

Parameters:
c - The contact to match
writableDb - A writable SQLite database object
Returns:
true if the contact was found, false otherwise

syncServerFetchContactChanges

public static Cursor syncServerFetchContactChanges(SQLiteDatabase readableDb,
                                                   boolean newContacts)
Fetches all the details that have changed and need to be synced with the server. Details associated with new contacts are returned separately, this is determined by a parameter. The syncSetServerIds(List, SQLiteDatabase) method is used to mark the details as up to date, once the sync has completed.

Parameters:
readableDb - A readable SQLite database object
newContacts - true if details associated with new contacts should be returned, otherwise modified details are returned.
Returns:
A cursor which can be passed into the syncServerGetNextNewContactDetails(Cursor, List, int) method.

syncServerGetNextNewContactDetails

public static void syncServerGetNextNewContactDetails(Cursor c,
                                                      java.util.List<Contact> contactList,
                                                      int maxContactsToFetch)
Returns the next batch of contacts which need to be added on the server. The syncServerFetchContactChanges(SQLiteDatabase, boolean) method is used to retrieve the cursor initially, then this function can be called many times until all the contacts have been fetched. When the list returned from this method is empty the cursor has reached the end and the sync is complete.

Parameters:
c - The cursor (see description above)
contactList - Will be filled with contacts that need to be added to the server
maxContactsToFetch - Maximum number of contacts to return in the list. The function can be called in a loop until all the contacts have been retrieved.

syncServerFetchNoOfChanges

public static int syncServerFetchNoOfChanges(SQLiteDatabase db)
Retrieves the total number of details that have changed and need to be synced with the server. Includes both new and modified contacts.

Parameters:
db - Readable SQLiteDatabase object.
Returns:
The number of details.

syncNativeFetchContactChanges

public static Cursor syncNativeFetchContactChanges(SQLiteDatabase readableDb,
                                                   boolean newContacts)
Fetches all the details that have changed and need to be synced with the native. Details associated with new contacts are returned separately, this is determined by a parameter. The syncSetNativeIds(List, SQLiteDatabase) method is used to mark the details as up to date, once the sync has completed.

Parameters:
readableDb - A readable SQLite database object
newContacts - true if details associated with new contacts should be returned, otherwise modified details are returned.
Returns:
A cursor which can be passed into the syncNativeGetNextNewContactDetails(Cursor, List, int) method.

syncNativeGetNextNewContactDetails

public static boolean syncNativeGetNextNewContactDetails(Cursor c,
                                                         java.util.List<Contact> contactList,
                                                         int maxContactsToFetch)
Returns the next batch of contacts which need to be added on the native database. The syncNativeFetchContactChanges(SQLiteDatabase, boolean) method is used to retrieve the cursor initially, then this function can be called many times until all the contacts have been fetched. When the list returned from this method is empty the cursor has reached the end and the sync is complete.

Parameters:
c - The cursor (see description above)
contactList - Will be filled with contacts that need to be added to the native
maxContactsToFetch - Maximum number of contacts to return in the list. The function can be called in a loop until all the contacts have been retrieved.
Returns:
true if successful, false if an error occurred (there seems to be a defect in Android which occasionally causes this to fail due to bad cursor state. The workaround is to retry the operation).

syncNativeFetchNoOfChanges

public static int syncNativeFetchNoOfChanges(SQLiteDatabase readableDb)
                                      throws SQLException
Retrieves the total number of details that have changed and need to be synced with the native database. Does not include new contacts.

Parameters:
readableDb - A readable SQLite database object
Returns:
The number of details.
Throws:
SQLException

removePreferred

public static boolean removePreferred(java.lang.Long localContactID,
                                      ContactDetail.DetailKeys key,
                                      SQLiteDatabase writableDb)
Remove all preferred details from contact for a particular key.

Parameters:
localContactID - Identifies the contact in the database
key - The contact detail key (phone, email, address, etc.)
writableDb - A writable SQLite database object

mapContactChangeFlagToInternalType

public static int mapContactChangeFlagToInternalType(int flag)
Maps a ContactChange flag to a ContactDetail key type.

Parameters:
flag - the ContactChange flag to convert
Returns:
the ContactDetail key type equivalent
See Also:
ContactChange#FLAG_XXX, ContactDetail#DetailKeyTypes

mapContactChangeFlagToInternalOrder

public static int mapContactChangeFlagToInternalOrder(int flag)
Maps a ContactChange flag to a ContactDetail order.

Parameters:
flag - the ContactChange flag to convert
Returns:
the ContactDetail order equivalent
See Also:
ContactChange#FLAG_XXX, ContactDetail#ORDER_XXX

mapContactChangeKeyToInternalKey

public static int mapContactChangeKeyToInternalKey(int key)
Maps a ContactChange key to a ContactDetail key.

Parameters:
key - the ContactChange key to convert
Returns:
the ContactDetail key equivalent
See Also:
ContactChange#KEY_XXX, ContactDetail#DetailKeys

mapInternalKeyToContactChangeKey

public static int mapInternalKeyToContactChangeKey(int key)
Maps ContactDetail key to ContactChange key.

Parameters:
key - the ContactDetail key to convert
Returns:
the ContactChange key equivalent
See Also:
ContactChange#KEY_XXX, ContactDetail#DetailKeys

mapInternalTypeAndOrderToContactChangeFlag

public static int mapInternalTypeAndOrderToContactChangeFlag(int type,
                                                             int order)
Maps a ContactDetail type and an order to the ContactChange flag equivalent.

Parameters:
type - the ContactDetail type
order - the ContactDetail order
Returns:
the ContactChange flag equivalent
See Also:
ContactChange#FLAG_XXX, ContactDetail#ORDER_XXX, ContactDetail#DetailKeyTypes

prepareNativeContactDetailInsert

public static void prepareNativeContactDetailInsert(ContactChange contactChange,
                                                    ContentValues values)
Fills a ContentValues object with the provided ContactChange to later be used for database insert.

Parameters:
contactChange - the ContactChange to get the values from
values - the ContentValues object to fill

addNativeContactDetails

public static boolean addNativeContactDetails(ContactChange[] contactChange,
                                              SQLiteDatabase writeableDb)
Adds the provided contact details to the ContactDetail table. Note: the provided ContactChange are modified with the corresponding internalDetailId from the database insertion.

Parameters:
contactChange - the contact details
writeableDb - the db where to write
Returns:
true if successful, false otherwise
See Also:
ContactChange

getContactChanges

public static ContactChange[] getContactChanges(long localId,
                                                boolean nativeSyncableOnly,
                                                SQLiteDatabase readableDb)
Gets an array of ContactChange from the contact's local id.

Parameters:
localId - the local id of the contact to get
Returns:
an array of ContactChange
See Also:
ContactChange

setDetailSyncedWithNative

public static boolean setDetailSyncedWithNative(long localDetailId,
                                                long nativeContactId,
                                                long nativeDetailId,
                                                boolean isNewlySynced,
                                                SQLiteDatabase writableDb)
Sets the detail as synchronized with native side.

Parameters:
localContactId - the local id of the detail
nativeContactId - the native contact (only needed for added details i.e. isNewlySynced = true)
nativeDetailId - the native detail id (only needed for added details i.e. isNewlySynced = true)
writableDb - the db where to write
isNewlySynced - true if the detail as not been synchronized before, false if this is an update
Returns:
true if sucessful, false otherwise


JavaDoc