com.vodafone360.people.database.tables
Class NativeChangeLogTable

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

public abstract class NativeChangeLogTable
extends java.lang.Object

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

Version:
%I%, %G%

Nested Class Summary
static class NativeChangeLogTable.ContactChangeInfo
          Wraps up the data present in the change log table
static class NativeChangeLogTable.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 in the native.
private static class NativeChangeLogTable.Field
          An enumeration of all the field names in the database.
 
Field Summary
private static int DETAILKEY
           
private static int LOCALCONTACTID
           
private static int LOCALDETAILID
           
private static int NATIVECHANGEID
          Column indices for database queries
private static int NATIVECONTACTID
           
private static int NATIVEDETAILID
           
private static java.lang.String QUERY_DELETED_CONTACT_NATIVE_ID
           
private static java.lang.String QUERY_DELETED_CONTACTS_NATIVE_IDS
          SELECT NativeContactId FROM NativeChangeLog WHERE ChangeType = 0 ORDER BY NativeContactId
private static java.lang.String QUERY_DELETED_DETAILS
          Query string to get a list of deleted details for a provided type and local id.
static java.lang.String QUERY_MODIFIED_CONTACTS_LOCAL_IDS
          SELECT NativeContactId FROM NativeChangeLog WHERE ChangeType = 0 ORDER BY NativeContactId
static java.lang.String QUERY_MODIFIED_CONTACTS_LOCAL_IDS_NO_ORDERBY
           
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
NativeChangeLogTable()
           
 
Method Summary
private static boolean addContactChange(NativeChangeLogTable.ContactChangeInfo info, SQLiteDatabase writableDb)
          Inserts a contact change into the table.
static boolean addDeletedContactChange(java.lang.Long localContactId, java.lang.Integer nativeContactId, SQLiteDatabase writableDb)
          Inserts "Delete Contact" operation into the change log.
static boolean addDeletedContactDetailChange(ContactDetail detail, SQLiteDatabase writableDb)
          Inserts "Delete Contact Detail" operation into the change log.
static void create(SQLiteDatabase writableDb)
          Create Server Change Log Table.
static boolean fetchContactChangeLog(NativeChangeLogTable.ContactChangeType type, java.util.List<NativeChangeLogTable.ContactChangeInfo> nativeInfoList, SQLiteDatabase readableDb)
          Fetches a list of changes from the table for a specific type.
static Cursor fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType type, SQLiteDatabase readableDb)
          Fetches a list of changes from the table for a specific type.
static long fetchNoOfChanges(NativeChangeLogTable.ContactChangeType type, SQLiteDatabase readableDb)
          Fetches the number of changes listed in the table.
static long getDeletedContactNativeId(long localContactId, SQLiteDatabase readableDb)
           
static long[] getDeletedContactsNativeIds(SQLiteDatabase readableDb)
          Gets the list of native ids for the deleted contacts.
static ContactChange[] getDeletedDetails(long localContactId, SQLiteDatabase readableDb)
          Gets the list of deleted details as a ContactChange array.
static long[] getModifiedContactsLocalIds(SQLiteDatabase readableDb)
           
static NativeChangeLogTable.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.
static boolean isContactChangeInList(long nativeContactId, NativeChangeLogTable.ContactChangeType type, SQLiteDatabase readableDb)
           
static boolean isContactChangeInList(java.lang.Long localContactId, NativeChangeLogTable.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, NativeChangeLogTable.ContactChangeType type, SQLiteDatabase readableDb)
          Determines if a specific contact detail and change type exists in the change log.
static boolean removeContactChanges(java.lang.Long localContactId, SQLiteDatabase writableDb)
          Removes all changes from the change log associated with a particular contact.
static boolean removeContactDetailChanges(java.lang.Long localDetailId, SQLiteDatabase writableDb)
          Removes all changes from the change log associated with a particular contact detail.
static boolean syncDeleteNativeChangeLog(java.util.List<java.lang.Long> changeIdList, SQLiteDatabase writableDb)
          Removes a list of changes from the change log table.
 
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

QUERY_DELETED_DETAILS

private static final java.lang.String QUERY_DELETED_DETAILS
Query string to get a list of deleted details for a provided type and local id.

See Also:
getDeletedDetails(long, SQLiteDatabase)

NATIVECHANGEID

private static final int NATIVECHANGEID
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

NATIVECONTACTID

private static final int NATIVECONTACTID
See Also:
Constant Field Values

LOCALDETAILID

private static final int LOCALDETAILID
See Also:
Constant Field Values

NATIVEDETAILID

private static final int NATIVEDETAILID
See Also:
Constant Field Values

DETAILKEY

private static final int DETAILKEY
See Also:
Constant Field Values

QUERY_MODIFIED_CONTACTS_LOCAL_IDS

public static final java.lang.String QUERY_MODIFIED_CONTACTS_LOCAL_IDS
SELECT NativeContactId FROM NativeChangeLog WHERE ChangeType = 0 ORDER BY NativeContactId


QUERY_MODIFIED_CONTACTS_LOCAL_IDS_NO_ORDERBY

public static final java.lang.String QUERY_MODIFIED_CONTACTS_LOCAL_IDS_NO_ORDERBY

QUERY_DELETED_CONTACTS_NATIVE_IDS

private static final java.lang.String QUERY_DELETED_CONTACTS_NATIVE_IDS
SELECT NativeContactId FROM NativeChangeLog WHERE ChangeType = 0 ORDER BY NativeContactId


QUERY_DELETED_CONTACT_NATIVE_ID

private static final java.lang.String QUERY_DELETED_CONTACT_NATIVE_ID
Constructor Detail

NativeChangeLogTable

public NativeChangeLogTable()
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

public static NativeChangeLogTable.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

addDeletedContactChange

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

Parameters:
localContactId - Local contact ID from the Contacts table
nativeContactId - Native contact ID. If this is null it is assumed that the contact hasn't yet been synced with the native phonebook, so the new contact change is removed from the log and the function returns.
writableDb - Writable SQLite database
Returns:
true if successful, false otherwise

addDeletedContactDetailChange

public static boolean addDeletedContactDetailChange(ContactDetail detail,
                                                    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 native ID is null.
writableDb - Writable SQLite database
Returns:
true if successful, false otherwise

addContactChange

private static boolean addContactChange(NativeChangeLogTable.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 NativeChangeLogTable.ContactChangeType).
writableDb - Writable SQLite database
Returns:
true if successful, false otherwise

isContactChangeInList

public static boolean isContactChangeInList(java.lang.Long localContactId,
                                            NativeChangeLogTable.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

isContactChangeInList

public static boolean isContactChangeInList(long nativeContactId,
                                            NativeChangeLogTable.ContactChangeType type,
                                            SQLiteDatabase readableDb)
Parameters:
nativeContactId -
type -
readableDb -
Returns:

isContactDetailChangeInList

private static boolean isContactDetailChangeInList(java.lang.Long localDetailId,
                                                   NativeChangeLogTable.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

removeContactChanges

public 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

removeContactDetailChanges

public 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

fetchNoOfChanges

public static long fetchNoOfChanges(NativeChangeLogTable.ContactChangeType type,
                                    SQLiteDatabase readableDb)
Fetches the number of changes listed in the table.

Parameters:
type - The type of change to count, if null all change types are included
readableDb - Readable SQLite database
Returns:
The number of records

syncDeleteNativeChangeLog

public static boolean syncDeleteNativeChangeLog(java.util.List<java.lang.Long> changeIdList,
                                                SQLiteDatabase writableDb)
Removes a list of changes from the change log table. This method is used once the native has been successfully updated by the client.

Parameters:
changeIdList - A list of contact change IDs (can be obtained from NativeChangeLogTable.ContactChangeInfo.mNativeChangeId.
writableDb - Writable SQLite database
Returns:
true if successful, false otherwise

fetchContactChangeLogCursor

public static Cursor fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType type,
                                                 SQLiteDatabase readableDb)
Fetches a list of changes from the table for a specific type. The list is ordered by local contact ID.

Parameters:
type - The type of change to return (cannot be null)
readableDb - Readable SQLite database
Returns:
A cursor for use with getQueryData(Cursor) if successful, null otherwise

fetchContactChangeLog

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

Parameters:
type - The type of change to return
contactChangeList - The list to be populated
readableDb - Readable SQLite database
Returns:
true if successful, false otherwise

getModifiedContactsLocalIds

public static long[] getModifiedContactsLocalIds(SQLiteDatabase readableDb)
Parameters:
readableDb -
Returns:

getDeletedContactsNativeIds

public static long[] getDeletedContactsNativeIds(SQLiteDatabase readableDb)
Gets the list of native ids for the deleted contacts.

Parameters:
readableDb - the db to query from
Returns:
an array of long ids of deleted native contacts, null if none

getDeletedDetails

public static ContactChange[] getDeletedDetails(long localContactId,
                                                SQLiteDatabase readableDb)
Gets the list of deleted details as a ContactChange array. Note: the ContactChange object will have the type ContactChange.TYPE_DELETE_DETAIL

Parameters:
localContactId - the local contact id to query
readableDb - the db to query from
Returns:
an array of ContactChange, null if no details where found
See Also:
ContactChange

getDeletedContactNativeId

public static long getDeletedContactNativeId(long localContactId,
                                             SQLiteDatabase readableDb)
Parameters:
localContactId -
readableDb -
Returns:


JavaDoc