com.vodafone360.people.database.tables
Class ContactChangeLogTable

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

public abstract class ContactChangeLogTable
extends java.lang.Object

Contains all the functionality related to the contact change log database table. This table is used to persist database changes that have not yet been synced to the server. This class is never instantiated hence all methods must be static.

Version:
%I%, %G%

Nested Class Summary
static class ContactChangeLogTable.ContactChangeInfo
          Wraps up the data present in the change log table
static class ContactChangeLogTable.ContactChangeType
          Enumerates the type of changes supported by this table, including: DELETE_CONTACT: A contact has been deleted from the database and needs to be deleted on the server.
private static class ContactChangeLogTable.Field
          An enumeration of all the field names in the database.
 
Field Summary
private static int CONTACTCHANGEID
          Column indices for database queries
private static int GROUPORRELID
           
private static int LOCALCONTACTID
           
private static int LOCALDETAILID
           
private static int SERVERCONTACTID
           
private static int SERVERDETAILID
           
private static int SERVERDETAILKEY
           
private static java.lang.String TABLE_NAME
          Name of the table as it appears in the database
private static java.lang.String TEMP_CONTACT_CHANGE_LOG_ID
          Secondary key which links to the primary key of the change log table
private static java.lang.String TEMP_CONTACT_CHANGE_TABLE
          Name of a temporary table created and used to batch the deletion of sync data from the change log table.
private static java.lang.String TEMP_CONTACT_CHANGE_TABLE_ID
          Primary key for the temporary table
private static int TYPE
           
 
Constructor Summary
ContactChangeLogTable()
           
 
Method Summary
private static boolean addContactChange(ContactChangeLogTable.ContactChangeInfo info, SQLiteDatabase writableDb)
          Inserts a contact change into the table.
static boolean addDeletedContactChange(java.lang.Long localContactId, java.lang.Long serverContactId, boolean addToLog, SQLiteDatabase writableDb)
          Inserts "Delete Contact" operation into the change log.
static boolean addDeletedContactDetailChange(ContactDetail detail, boolean addToLog, SQLiteDatabase writableDb)
          Inserts "Delete Contact Detail" operation into the change log.
static boolean addGroupRel(long localContactId, java.lang.Long serverContactId, java.lang.Long groupId, SQLiteDatabase writableDb)
          Inserts "Add contact to group" operation into the change log.
static void create(SQLiteDatabase writableDb)
          Create Server Change Log Table.
static boolean deleteContactChanges(java.util.List<ContactChangeLogTable.ContactChangeInfo> changeInfoList, SQLiteDatabase writableDb)
          Removes a list of changes from the change log table.
static boolean deleteGroupRel(long localContactId, java.lang.Long serverContactId, java.lang.Long groupId, SQLiteDatabase writableDb)
          Inserts "Remove contact from group" operation into the change log.
static boolean fetchContactChangeLog(java.util.List<ContactChangeLogTable.ContactChangeInfo> contactChangeList, ContactChangeLogTable.ContactChangeType type, long firstIndex, long count, SQLiteDatabase readableDb)
          Fetches a list of changes from the table for a specific type.
static boolean fetchMeProfileChangeLog(java.util.List<ContactChangeLogTable.ContactChangeInfo> changeList, ContactChangeLogTable.ContactChangeType type, SQLiteDatabase readableDb, java.lang.Long meProfileServerId)
          Fetches a list of changes on the contact details for the me-profile.
static int fetchNoOfContactDetailChanges(ContactChangeLogTable.ContactChangeType type, SQLiteDatabase readableDb)
          Fetches the number of changes listed in the table.
private static java.lang.Long findContactGroup(long localContactId, long groupId, SQLiteDatabase readableDb)
          Searches the change log for an association between contact and group
private static ContactChangeLogTable.ContactChangeInfo getQueryData(Cursor c)
          Fetches change log information from a cursor at the current position.
private static java.lang.String getQueryStringSql(java.lang.String whereClause)
          Fetches a comma separated list of table fields which can be used in an SQL SELECT statement as the query projection.
private static boolean isContactChangeInList(java.lang.Long localContactId, ContactChangeLogTable.ContactChangeType type, SQLiteDatabase readableDb)
          Determines if a specific contact and change type exists in the change log.
private static boolean isContactDetailChangeInList(java.lang.Long localDetailId, ContactChangeLogTable.ContactChangeType type, SQLiteDatabase readableDb)
          Determines if a specific contact detail and change type exists in the change log.
private static boolean removeContactChange(long ContactChangeId, SQLiteDatabase writableDb)
          Deletes a specific contact change record from the table
private static boolean removeContactChanges(java.lang.Long localContactId, SQLiteDatabase writableDb)
          Removes all changes from the change log associated with a particular contact.
private static boolean removeContactDetailChanges(java.lang.Long localDetailId, SQLiteDatabase writableDb)
          Removes all changes from the change log associated with a particular contact detail.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TABLE_NAME

private static final java.lang.String TABLE_NAME
Name of the table as it appears in the database

See Also:
Constant Field Values

TEMP_CONTACT_CHANGE_TABLE

private static final java.lang.String TEMP_CONTACT_CHANGE_TABLE
Name of a temporary table created and used to batch the deletion of sync data from the change log table.

See Also:
Constant Field Values

TEMP_CONTACT_CHANGE_TABLE_ID

private static final java.lang.String TEMP_CONTACT_CHANGE_TABLE_ID
Primary key for the temporary table

See Also:
Constant Field Values

TEMP_CONTACT_CHANGE_LOG_ID

private static final java.lang.String TEMP_CONTACT_CHANGE_LOG_ID
Secondary key which links to the primary key of the change log table

See Also:
Constant Field Values

CONTACTCHANGEID

private static final int CONTACTCHANGEID
Column indices for database queries

See Also:
Constant Field Values

TYPE

private static final int TYPE
See Also:
Constant Field Values

LOCALCONTACTID

private static final int LOCALCONTACTID
See Also:
Constant Field Values

SERVERCONTACTID

private static final int SERVERCONTACTID
See Also:
Constant Field Values

LOCALDETAILID

private static final int LOCALDETAILID
See Also:
Constant Field Values

SERVERDETAILID

private static final int SERVERDETAILID
See Also:
Constant Field Values

SERVERDETAILKEY

private static final int SERVERDETAILKEY
See Also:
Constant Field Values

GROUPORRELID

private static final int GROUPORRELID
See Also:
Constant Field Values
Constructor Detail

ContactChangeLogTable

public ContactChangeLogTable()
Method Detail

create

public static void create(SQLiteDatabase writableDb)
                   throws SQLException
Create Server Change Log Table.

Parameters:
writeableDb - A writable SQLite database
Throws:
SQLException - If an SQL compilation error occurs

getQueryStringSql

private static java.lang.String getQueryStringSql(java.lang.String whereClause)
Fetches a comma separated list of table fields which can be used in an SQL SELECT statement as the query projection. The getQueryData(Cursor) method can used to fetch data from the cursor.

Parameters:
whereClause - A where clause (without the where) to filter the result. Cannot be null.
Returns:
SQL string

getQueryData

private static ContactChangeLogTable.ContactChangeInfo getQueryData(Cursor c)
Fetches change log information from a cursor at the current position. The getQueryStringSql(String) method should be used to make the query.

Parameters:
c - The cursor from the query
Returns:
A filled in ContactChangeInfo object

addGroupRel

public static boolean addGroupRel(long localContactId,
                                  java.lang.Long serverContactId,
                                  java.lang.Long groupId,
                                  SQLiteDatabase writableDb)
Inserts "Add contact to group" operation into the change log.

Parameters:
localContactId - Local contact ID from the Contacts table
serverContactId - Server contact ID or null if the contact has not yet been synced.
groupId - server group ID
writableDb - Writable SQLite database
Returns:
true if successful, false otherwise

deleteGroupRel

public static boolean deleteGroupRel(long localContactId,
                                     java.lang.Long serverContactId,
                                     java.lang.Long groupId,
                                     SQLiteDatabase writableDb)
Inserts "Remove contact from group" operation into the change log.

Parameters:
localContactId - Local contact ID from the Contacts table
serverContactId - Server contact ID or null if the contact has not yet been synced.
groupId - server group ID
writableDb - Writable SQLite database
Returns:
true if successful, false otherwise

addDeletedContactChange

public static boolean addDeletedContactChange(java.lang.Long localContactId,
                                              java.lang.Long serverContactId,
                                              boolean addToLog,
                                              SQLiteDatabase writableDb)
Inserts "Delete Contact" operation into the change log.

Parameters:
localContactId - Local contact ID from the Contacts table
serverContactId - Server contact ID. If this is null it is assumed that the contact hasn't yet been synced with the server, so the new contact change is removed from the log and the function returns.
addToLog - False - removes all changes associated with the contact from the change log True - to also insert deletion in change log.
writableDb - Writable SQLite database
Returns:
true if successful, false otherwise

addDeletedContactDetailChange

public static boolean addDeletedContactDetailChange(ContactDetail detail,
                                                    boolean addToLog,
                                                    SQLiteDatabase writableDb)
Inserts "Delete Contact Detail" operation into the change log.

Parameters:
detail - Must have a valid local contact ID, local detail ID and key. Will not be added to the change log if the contact server ID is null.
addToLog - False - removes all changes associated with the detail from the change log True - to also insert deletion in change log.
writableDb - Writable SQLite database
Returns:
true if successful, false otherwise

addContactChange

private static boolean addContactChange(ContactChangeLogTable.ContactChangeInfo info,
                                        SQLiteDatabase writableDb)
Inserts a contact change into the table.

Parameters:
info - contact change info. This must have a valid type field and depending on type other fields may also be required (see ContactChangeLogTable.ContactChangeType).
writableDb - Writable SQLite database
Returns:
true if successful, false otherwise

isContactChangeInList

private static boolean isContactChangeInList(java.lang.Long localContactId,
                                             ContactChangeLogTable.ContactChangeType type,
                                             SQLiteDatabase readableDb)
Determines if a specific contact and change type exists in the change log.

Parameters:
localContactId - Local contact ID from the Contacts table
type - The change type to find
readableDb - Readable SQLite database
Returns:
true if the change is found, false otherwise

isContactDetailChangeInList

private static boolean isContactDetailChangeInList(java.lang.Long localDetailId,
                                                   ContactChangeLogTable.ContactChangeType type,
                                                   SQLiteDatabase readableDb)
Determines if a specific contact detail and change type exists in the change log.

Parameters:
localDetailId - Local contact detail ID from ContactDetail table
type - The change type to find
readableDb - Readable SQLite database
Returns:
true if the change is found, false otherwise

findContactGroup

private static java.lang.Long findContactGroup(long localContactId,
                                               long groupId,
                                               SQLiteDatabase readableDb)
Searches the change log for an association between contact and group

Parameters:
localContactId - Local contact ID from the Contacts table
groupId - Server group ID
readableDb - Readable SQLite database
Returns:
Contact Change ID (primary key) of the record found, or NULL if no such logs exist in the table.

removeContactChanges

private static boolean removeContactChanges(java.lang.Long localContactId,
                                            SQLiteDatabase writableDb)
Removes all changes from the change log associated with a particular contact.

Parameters:
localContactId - Local contact ID from the Contacts table
writableDb - Writable SQLite database
Returns:
true if successful, false otherwise

removeContactChange

private static boolean removeContactChange(long ContactChangeId,
                                           SQLiteDatabase writableDb)
Deletes a specific contact change record from the table

Parameters:
ContactChangeId - The primary ID identifying the record
writableDb - Writable SQLite database
Returns:
true if successful, false otherwise

removeContactDetailChanges

private static boolean removeContactDetailChanges(java.lang.Long localDetailId,
                                                  SQLiteDatabase writableDb)
Removes all changes from the change log associated with a particular contact detail.

Parameters:
localDetailId - Local contact detail ID from the Contact details table
writableDb - Writable SQLite database
Returns:
true if successful, false otherwise

fetchNoOfContactDetailChanges

public static int fetchNoOfContactDetailChanges(ContactChangeLogTable.ContactChangeType type,
                                                SQLiteDatabase readableDb)
Fetches the number of changes listed in the table.

Parameters:
type - The ContactChangeType to count, if NULL then all change types are included.
readableDb - Readable SQLite database
Returns:
Total number of records

deleteContactChanges

public static boolean deleteContactChanges(java.util.List<ContactChangeLogTable.ContactChangeInfo> changeInfoList,
                                           SQLiteDatabase writableDb)
Removes a list of changes from the change log table. This method is used once the server has been successfully synced with the client.

Parameters:
changeInfoList - A list of ContactChangeLogTable.ContactChangeInfo objects. Note that only the mContactChangeId field of this object is actually used. The object is passed in as a convenience.
writableDb - Writable SQLite database
Returns:
true if successful, false otherwise

fetchContactChangeLog

public static boolean fetchContactChangeLog(java.util.List<ContactChangeLogTable.ContactChangeInfo> contactChangeList,
                                            ContactChangeLogTable.ContactChangeType type,
                                            long firstIndex,
                                            long count,
                                            SQLiteDatabase readableDb)
Fetches a list of changes from the table for a specific type. The list is ordered by local contact ID.

Parameters:
contactChangeList - The list to be populated
type - The type of change to return
firstIndex - An index of the first record to return (0 based)
count - The number of records to return (or -1 to return all)
readableDb - Readable SQLite database
Returns:
true if successful, false otherwise

fetchMeProfileChangeLog

public static boolean fetchMeProfileChangeLog(java.util.List<ContactChangeLogTable.ContactChangeInfo> changeList,
                                              ContactChangeLogTable.ContactChangeType type,
                                              SQLiteDatabase readableDb,
                                              java.lang.Long meProfileServerId)
Fetches a list of changes on the contact details for the me-profile.

Parameters:
changeList - The list to populate with contact changes.
type - The type of change to fetch from the contact.
readableDb - The database to read from.
meProfileServerId - The server id of the me-profile.
Returns:
True if fetching succeeded, false otherwise.


JavaDoc