danger.app
Class DataStore

java.lang.Object
  |
  +--danger.app.DataStore

public final class DataStore
extends java.lang.Object


Field Summary
static boolean DEBUG_AUTO_SYNC
           
static boolean DEBUG_AUTO_SYNC_UID
           
static int kAutoSyncWaitForConfirm
           
static int kRecordFlagMask
           
static int kRecordModified
          System Record flags
 
Constructor Summary
protected DataStore()
          DataStores may not be directly created or destroyed
 
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()
           
protected  void autoSync(boolean flag)
           
 void autoSyncFromServiceDone()
          resolve the positive and negative UIDs
static boolean autoSyncToService()
           
protected  void autoSyncWaitForConfirm(int n, boolean flag)
          Check if the nth record needs to be confirmed for autosync
 int binarySearch(java.util.Comparator inComparator, byte[] inKey)
           
 int binarySearch(int inUID)
           
protected  int binarySearchFaster(java.util.Comparator inComparator, byte[] inKey)
           
protected  int binarySearchFaster(int inUID)
           
static DataStore createDataStore(java.lang.String name)
           
static DataStore createDataStore(java.lang.String name, boolean autoSync)
           
static DataStore createDataStore(java.lang.String name, boolean autoSync, boolean isFullName)
          Create a new DataStore by name.
static DataStore createSharedDataStore(java.lang.String name)
          Create a new shared DataStore by name.
static DataStore createSharedDataStore(java.lang.String name, boolean autoSync)
           
static void discardAllOnReboot()
           
 void discardOnReboot(boolean flag)
           
 void doneResolvingConflict()
           
static void dumpList()
           
static DataStore findDataStore(java.lang.String name)
          Locate a DataStore by name.
static DataStore findDataStore(java.lang.String name, boolean isFullPath)
          Locate a DataStore by name.
static DataStore findSharedDataStore(java.lang.String name)
          Locate a shared DataStore by name.
 int getByteSize()
           
 int getBytesUsed()
           
 java.lang.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.
 int getLastSynced()
          Obtain 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()
           
 int insertRecord(byte[] data, int index)
          Insert a new record
 int insertRecord(byte[] data, int index, int flags)
          Insert a new record
 int insertRecordSorted(java.util.Comparator inComparator, byte[] inItem)
           
 int insertRecordSorted(int inUID, byte[] inItem)
           
 boolean isRecordDirty(int n)
          Check if the nth record is dirty
static void processBackingStoreResponse(danger.io.BackingStoreTransaction bt)
           
static void recoverDataStores()
          only used during system startup
 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)
           
protected  void requestAutoSync()
           
 void setAutoSyncNotifyee(Listener inNotifyee)
           
 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(java.util.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

kRecordModified

public static final int kRecordModified
System Record flags

kAutoSyncWaitForConfirm

public static final int kAutoSyncWaitForConfirm

kRecordFlagMask

public static final int kRecordFlagMask

DEBUG_AUTO_SYNC

public static final boolean DEBUG_AUTO_SYNC

DEBUG_AUTO_SYNC_UID

public static final boolean DEBUG_AUTO_SYNC_UID
Constructor Detail

DataStore

protected DataStore()
DataStores may not be directly created or destroyed
Method Detail

createDataStore

public static DataStore createDataStore(java.lang.String name,
                                        boolean autoSync,
                                        boolean isFullName)
Create a new DataStore by name. If DataStore already exists, return the existing one. (DataStores namespaces are application-local -- you cannot open another apps DataStores) XXX Security Issue: Only SysApp Should be allowed to set XXX isFullName to true

dumpList

public static void dumpList()

discardAllOnReboot

public static void discardAllOnReboot()

createDataStore

public static DataStore createDataStore(java.lang.String name)

createDataStore

public static DataStore createDataStore(java.lang.String name,
                                        boolean autoSync)

createSharedDataStore

public static DataStore createSharedDataStore(java.lang.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(java.lang.String name,
                                              boolean autoSync)

recoverDataStores

public static void recoverDataStores()
only used during system startup

findDataStore

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

findDataStore

public static DataStore findDataStore(java.lang.String name,
                                      boolean isFullPath)
Locate a DataStore by name. If not found, return null.
Parameters:
name - A string that specifies the datastore name.
isFullPath - A boolean that specifies whether the datastore name is the full path.

findSharedDataStore

public static DataStore findSharedDataStore(java.lang.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(danger.io.BackingStoreTransaction bt)

getRecordCount

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

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.

getLastSynced

public int getLastSynced()
Obtain the time the database was last synced. Currently, this time is only updated when UpdateLastSynced() is called

getFullName

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

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)

autoSync

public boolean autoSync()

autoSync

protected void autoSync(boolean flag)

requestAutoSync

protected void requestAutoSync()

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

autoSyncWaitForConfirm

protected void autoSyncWaitForConfirm(int n,
                                      boolean flag)
Check if the nth record needs to be confirmed for autosync

setRecordUID

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

sort

public void sort(java.util.Comparator comparator)

sortByUID

public void sortByUID()

insertRecordSorted

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

insertRecordSorted

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

binarySearch

public int binarySearch(int inUID)

binarySearch

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

binarySearchFaster

protected int binarySearchFaster(java.util.Comparator inComparator,
                                 byte[] inKey)

binarySearchFaster

protected int binarySearchFaster(int inUID)

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)

allowAutoSyncToService

public static void allowAutoSyncToService(boolean flag)

getByteSize

public int getByteSize()

getBytesUsed

public int getBytesUsed()


Danger Confidential. Copyright © 2000-2003, Danger Inc.