danger.app
Class DataStore

java.lang.Object
  extended by danger.app.DataStore
All Implemented Interfaces:
Comparable


public final class DataStore
extends Object
implements Comparable


Field Summary
static int AUTO_SYNC_WAIT_FOR_CONFIRM
           
static boolean DEBUG_AUTO_SYNC
           
static boolean DEBUG_AUTO_SYNC_UID
           
static String DS_SCHEDULED_FOR_ACTIVATION
           
static int RECORD_FLAG_MASK
           
static int RECORD_MODIFIED
          System Record flags
 
Method Summary
 int addRecord(byte[] data)
          Add a new record with flags=0, return its number
 int addRecord(byte[] data, int flags)
          Add a new record, return its number
 int addRecord(byte[] data, int flags, int uid)
          Add a new record, return its number
static void allowAutoSyncToService(boolean flag)
           
 boolean autoSync()
           
 void autoSyncFromServiceDone()
          resolve the positive and negative UIDs
static boolean autoSyncToService()
           
 int binarySearch(Comparator inComparator, byte[] inKey)
           
 int binarySearch(int inUID)
           
static void broadcastAutoSyncDone()
           
 int compareTo(Object o)
           
static DataStore createDataStore(String name)
           
static DataStore createDataStore(String name, boolean autoSync)
           
static DataStore createSharedDataStore(String name)
          Create a new shared DataStore by name.
static DataStore createSharedDataStore(String name, boolean autoSync)
           
static boolean dataStoresPendingActivation()
           
static void deleteDataStore(DataStore inDS)
           
static void deleteLocalDataStore(DataStore inDS)
           
static void deregisterListenerForAutoSyncDone(Listener inListener)
           
static void discardAllOnReboot()
           
 boolean discardOnReboot()
           
 void discardOnReboot(boolean flag)
           
 void doneResolvingConflict()
           
static void dumpList()
           
static DataStore findDataStore(String name)
          Locate a DataStore by name.
static DataStore findSharedDataStore(String name)
          Locate a shared DataStore by name.
static void flattenStores()
          Used by SimHeap to flatten the stores XXX Security Need to exclude this from the SDK link list
static String[] getAllFullNames()
           
 int getAutoSyncNextUID()
           
 int getByteSize()
           
 int getBytesUsed()
           
 String getDBName()
           
 String getFullName()
          Returns the full name of the database (which will be slightly different than the name an app uses to find the database)
 int getLastModified()
          Get the time the database was last modified.
 long getLastModifiedMillis()
          Get the time the database was last modified.
 int getLastSynced()
          Obtain the time the database was last synced.
 long getLastSyncedMillis()
          Get the time the database was last synced.
 int getRecordCount()
          Obtain the number of records in the datastore
 byte[] getRecordData(int n)
          obtain the byte array containing the data of record #n or null if record n is out of range or empty
 byte[] getRecordDataByUID(int uid)
           
 int getRecordFlags(int n)
          Obtain the flags of record n or 0 if n is an invalid number
 int getRecordIndexByUID(int uid)
           
 byte[][] getRecords()
          obtain an array of byte arrays for all records
 int getRecordUID(int n)
          Obtain the uid for the nth record
 int getVersion()
           
static Object initialize()
           
 int insertRecord(byte[] data, int index)
          Insert a new record
 int insertRecord(byte[] data, int index, int flags)
          Insert a new record
 int insertRecordSorted(Comparator inComparator, byte[] inItem)
           
 int insertRecordSorted(int inUID, byte[] inItem)
           
 boolean isRecordDirty(int n)
          Check if the nth record is dirty
static boolean journalReconcile(Object inKey, String inName)
           
static void processBackingStoreResponse(BackingStoreTransaction bt)
           
static void recoverDataStores()
          only used during system startup
static void registerListenerForAutoSyncDone(Listener inListener)
           
 void removeAllRecords()
          Remove all records.
 void removeRecord(int n)
          Remove record #n, causes records after that to renumber
 void removeRecordByUID(int uid)
           
 void removeRecordWithoutAutoSync(int n)
           
 void setAutoSyncNotifyee(Listener inNotifyee)
           
 void setAutoSyncNotifyee(Listener inNotifyee, Bundle bundle)
           
 void setRecordData(int n, byte[] data)
          Replace the data of record #n with the provided byte array.
 void setRecordData(int n, byte[] data, boolean makeDirty)
          Replace the data of record #n with the provided byte array.
 void setRecordDataByUID(int uid, byte[] data)
           
 void setRecordDataByUID(int uid, byte[] data, boolean makeDirty)
           
 void setRecordDirty(int n, boolean flag)
          set nth record's dirty bit
 void setRecordFlags(int n, int flags)
          Replace the flags of record #n with the provided int.
 void setRecordFlagsByUID(int uid, int flags)
          Replace the flags of record #n with the provided int.
 void setRecordUID(int n, int uid)
          set the nth record's uid
 void setVersion(int inVersion)
           
 void sort(Comparator comparator)
           
 void sortByUID()
           
 void swapRecords(int this_rec, int that_rec)
          Exchange the data and flags of this_rec with that_rec.
 void updateLastModified()
          Set Last Modified time to current system time
 void updateLastSynced()
          Set Last Synced time to current system time
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DS_SCHEDULED_FOR_ACTIVATION

public static final String DS_SCHEDULED_FOR_ACTIVATION
See Also:
Constant Field Values

RECORD_MODIFIED

public static final int RECORD_MODIFIED
System Record flags

See Also:
Constant Field Values

AUTO_SYNC_WAIT_FOR_CONFIRM

public static final int AUTO_SYNC_WAIT_FOR_CONFIRM
See Also:
Constant Field Values

RECORD_FLAG_MASK

public static final int RECORD_FLAG_MASK
See Also:
Constant Field Values

DEBUG_AUTO_SYNC

public static final boolean DEBUG_AUTO_SYNC
See Also:
Constant Field Values

DEBUG_AUTO_SYNC_UID

public static final boolean DEBUG_AUTO_SYNC_UID
See Also:
Constant Field Values
Method Detail

initialize

public static Object initialize()

dataStoresPendingActivation

public static boolean dataStoresPendingActivation()

flattenStores

public static void flattenStores()
                          throws IOException
Used by SimHeap to flatten the stores XXX Security Need to exclude this from the SDK link list

Throws:
IOException

dumpList

public static void dumpList()

compareTo

public int compareTo(Object o)
Specified by:
compareTo in interface Comparable

discardAllOnReboot

public static void discardAllOnReboot()

createDataStore

public static DataStore createDataStore(String name)

createDataStore

public static DataStore createDataStore(String name,
                                        boolean autoSync)

createSharedDataStore

public static DataStore createSharedDataStore(String name)
Create a new shared DataStore by name. If DataStore already exists, return the existing one. (Shared datastores are not application-local -- any app can access a shared datastore. The PhotoGallery is an example of a shared datastore.)


createSharedDataStore

public static DataStore createSharedDataStore(String name,
                                              boolean autoSync)

deleteDataStore

public static void deleteDataStore(DataStore inDS)

deleteLocalDataStore

public static void deleteLocalDataStore(DataStore inDS)

recoverDataStores

public static void recoverDataStores()
only used during system startup


getAllFullNames

public static String[] getAllFullNames()

findDataStore

public static DataStore findDataStore(String name)
Locate a DataStore by name. If not found, return null. (DataStores namespaces are application-local -- you cannot open another apps DataStores)


findSharedDataStore

public static DataStore findSharedDataStore(String name)
Locate a shared DataStore by name. If not found, return null (Shared datastores are not application-local -- any app can access them. The PhotoGallery is a shared datastore.)


setVersion

public void setVersion(int inVersion)

getVersion

public int getVersion()

autoSyncToService

public static boolean autoSyncToService()

processBackingStoreResponse

public static void processBackingStoreResponse(BackingStoreTransaction bt)

getRecordCount

public int getRecordCount()
Obtain the number of records in the datastore


getLastModifiedMillis

public long getLastModifiedMillis()
Get the time the database was last modified. Value returned is the number of milliseconds since January 1, 1970 GMT


getLastModified

public int getLastModified()
Get the time the database was last modified. Adding, Removing, or modifying records with the provided methods of DataStore will cause this timestamp on the database to update. Modifying the contents* of a record will not. Value returned is the number of seconds since January 1, 2000 GMT.


getLastSyncedMillis

public long getLastSyncedMillis()
Get the time the database was last synced. Value returned is the number of milliseconds since January 1, 1970 GMT


getLastSynced

public int getLastSynced()
Obtain the time the database was last synced. Currently, this time is only updated when UpdateLastSynced() is called. Value returned is the number of seconds since January 1, 2000 GMT.


getFullName

public String getFullName()
Returns the full name of the database (which will be slightly different than the name an app uses to find the database)


getDBName

public String getDBName()

updateLastModified

public void updateLastModified()
Set Last Modified time to current system time


updateLastSynced

public void updateLastSynced()
Set Last Synced time to current system time


discardOnReboot

public void discardOnReboot(boolean flag)

discardOnReboot

public boolean discardOnReboot()

autoSync

public boolean autoSync()

getAutoSyncNextUID

public int getAutoSyncNextUID()

addRecord

public int addRecord(byte[] data)
Add a new record with flags=0, return its number


addRecord

public int addRecord(byte[] data,
                     int flags)
Add a new record, return its number


addRecord

public int addRecord(byte[] data,
                     int flags,
                     int uid)
Add a new record, return its number


insertRecord

public int insertRecord(byte[] data,
                        int index)
Insert a new record


insertRecord

public int insertRecord(byte[] data,
                        int index,
                        int flags)
Insert a new record


removeRecord

public void removeRecord(int n)
Remove record #n, causes records after that to renumber


removeRecordWithoutAutoSync

public void removeRecordWithoutAutoSync(int n)

removeRecordByUID

public void removeRecordByUID(int uid)

removeAllRecords

public void removeAllRecords()
Remove all records. Be careful using this API. If the data store is an auto-sync DB, RemoveAllRecords() will remove all the records of this database on the service.


getRecords

public byte[][] getRecords()
obtain an array of byte arrays for all records


getRecordData

public byte[] getRecordData(int n)
obtain the byte array containing the data of record #n or null if record n is out of range or empty


getRecordIndexByUID

public int getRecordIndexByUID(int uid)

getRecordDataByUID

public byte[] getRecordDataByUID(int uid)

getRecordFlags

public int getRecordFlags(int n)
Obtain the flags of record n or 0 if n is an invalid number


isRecordDirty

public boolean isRecordDirty(int n)
Check if the nth record is dirty


getRecordUID

public int getRecordUID(int n)
Obtain the uid for the nth record


setRecordData

public void setRecordData(int n,
                          byte[] data)
Replace the data of record #n with the provided byte array. Does nothing if n is out of bounds.


setRecordData

public void setRecordData(int n,
                          byte[] data,
                          boolean makeDirty)
Replace the data of record #n with the provided byte array. Does nothing if n is out of bounds.


setRecordDataByUID

public void setRecordDataByUID(int uid,
                               byte[] data)

setRecordDataByUID

public void setRecordDataByUID(int uid,
                               byte[] data,
                               boolean makeDirty)

setRecordFlags

public void setRecordFlags(int n,
                           int flags)
Replace the flags of record #n with the provided int. Does nothing if n is out of bounds.


setRecordFlagsByUID

public void setRecordFlagsByUID(int uid,
                                int flags)
Replace the flags of record #n with the provided int. Does nothing if n is out of bounds.


setRecordDirty

public void setRecordDirty(int n,
                           boolean flag)
set nth record's dirty bit


setRecordUID

public void setRecordUID(int n,
                         int uid)
set the nth record's uid


sort

public void sort(Comparator comparator)

sortByUID

public void sortByUID()

insertRecordSorted

public int insertRecordSorted(Comparator inComparator,
                              byte[] inItem)

insertRecordSorted

public int insertRecordSorted(int inUID,
                              byte[] inItem)

binarySearch

public int binarySearch(int inUID)

binarySearch

public int binarySearch(Comparator inComparator,
                        byte[] inKey)

swapRecords

public void swapRecords(int this_rec,
                        int that_rec)
Exchange the data and flags of this_rec with that_rec. This allows records to be reordered.


autoSyncFromServiceDone

public void autoSyncFromServiceDone()
resolve the positive and negative UIDs


doneResolvingConflict

public void doneResolvingConflict()

setAutoSyncNotifyee

public void setAutoSyncNotifyee(Listener inNotifyee)

setAutoSyncNotifyee

public void setAutoSyncNotifyee(Listener inNotifyee,
                                Bundle bundle)

allowAutoSyncToService

public static void allowAutoSyncToService(boolean flag)

getByteSize

public int getByteSize()

getBytesUsed

public int getBytesUsed()

registerListenerForAutoSyncDone

public static void registerListenerForAutoSyncDone(Listener inListener)

deregisterListenerForAutoSyncDone

public static void deregisterListenerForAutoSyncDone(Listener inListener)

broadcastAutoSyncDone

public static void broadcastAutoSyncDone()

journalReconcile

public static boolean journalReconcile(Object inKey,
                                       String inName)