com.vodafone360.people.database.tables
Class ContactGroupsTable

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

public abstract class ContactGroupsTable
extends java.lang.Object

Contains all the functionality related to the contact groups database table. This table stores all contact/group associations (0-many to 0-many relationship). This class is never instantiated hence all methods must be static.

Version:
%I%, %G%

Nested Class Summary
private static class ContactGroupsTable.ContactGroup
          Represents the data stored in a record
static class ContactGroupsTable.Field
          An enumeration of all the field names in the database.
 
Field Summary
protected static java.lang.String TABLE_NAME
          Name of the table as it appears in the database
 
Constructor Summary
ContactGroupsTable()
           
 
Method Summary
static boolean addContactToGroup(long localContactId, long zybGroupId, SQLiteDatabase writableDb)
          Associates a contact and a group
static void create(SQLiteDatabase writeableDb)
          Create Contact Groups Table.
static boolean deleteContact(long localContactId, SQLiteDatabase writableDb)
          Removes all references to a contact from the table (should be called when a contact is deleted).
static boolean deleteContactFromGroup(long localContactId, long zybGroupId, SQLiteDatabase writableDb)
          Remove the association between contact and group.
static boolean fetchContactGroups(long localContactId, java.util.List<java.lang.Long> groupIds, SQLiteDatabase readableDb)
          Fetches all the groups associated with a given contact.
private static ContentValues fillUpdateData(ContactGroupsTable.ContactGroup contactGroup)
          Returns a ContentValues object that can be used to insert or update a new contact/group association to the table.
static ServiceStatus modifyContact(Contact contact, SQLiteDatabase db)
          Merges the given contact group relation changes into the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TABLE_NAME

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

See Also:
Constant Field Values
Constructor Detail

ContactGroupsTable

public ContactGroupsTable()
Method Detail

create

public static void create(SQLiteDatabase writeableDb)
                   throws SQLException
Create Contact Groups Table.

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

fillUpdateData

private static ContentValues fillUpdateData(ContactGroupsTable.ContactGroup contactGroup)
Returns a ContentValues object that can be used to insert or update a new contact/group association to the table.

Parameters:
contactGroup - A ContactGroup object with the local Contact ID and Group Id set appropriately.
Returns:
The ContactValues object

addContactToGroup

public static boolean addContactToGroup(long localContactId,
                                        long zybGroupId,
                                        SQLiteDatabase writableDb)
Associates a contact and a group

Parameters:
localContactId - The local contact Id from the Contacts table
zybGroupId - The server group ID from groups table
writeableDb - A writable SQLite database
Returns:
true if successful, false otherwise

deleteContactFromGroup

public static boolean deleteContactFromGroup(long localContactId,
                                             long zybGroupId,
                                             SQLiteDatabase writableDb)
Remove the association between contact and group.

Parameters:
localContactId - The local contact Id from the Contacts table
zybGroupId - The server group ID from groups table
writeableDb - A writable SQLite database
Returns:
true if successful, false otherwise

deleteContact

public static boolean deleteContact(long localContactId,
                                    SQLiteDatabase writableDb)
Removes all references to a contact from the table (should be called when a contact is deleted).

Parameters:
localContactId - The local contact Id from the Contacts table
writeableDb - A writable SQLite database
Returns:
true if successful, false otherwise

fetchContactGroups

public static boolean fetchContactGroups(long localContactId,
                                         java.util.List<java.lang.Long> groupIds,
                                         SQLiteDatabase readableDb)
Fetches all the groups associated with a given contact.

Parameters:
localContactId - The local contact Id from the Contacts table
groupIds - A list that will be populated with the result.
readableDb - A readable SQLite database
Returns:
true if successful, false otherwise

modifyContact

public static ServiceStatus modifyContact(Contact contact,
                                          SQLiteDatabase db)
Merges the given contact group relation changes into the database.

Parameters:
contact - the updated contact with the new group relations. If any of the group IDs are -1 the associated will be ignored.
writeableDb - A writable SQLite database
Returns:
SUCCESS or a suitable error code


JavaDoc