|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectdanger.app.Listener
danger.app.SettingsDB
public class SettingsDB
Application interface to the SettingsDB class. This class can be used to manage setting values, if they are key value pairs. A setting key is a string, and cannot be longer than 128 characters. A setting value may be an integer, string, or a byte array. The keys of a SettingsDB need to be unique and are matched case-sensitively. Each key and value pair is stored in the record field of a DataStore. The SettingsDB has a corresponding DataStore on the device. Since DataStores can be autosync'ed with the service, instances of this class can be autosync'ed as well. SettingsDB is the recommended way to use a DataStore. Accessing it directly is bad idea unless you truly know what it is you are doing (only few can make that claim)
Note that SettingsDB namespaces are local to an application, and one application cannot open another applications SettingsDB.
NOTE: The exception-throwing behavior of this class is a bit
inconsistent (for historical reasons, not by intentional design). The
two methods named getStringValue() return null
when handed a key/index that isn't found or is of the wrong type, but
the other get*() methods throw
SettingsDBException.
Currently, the contents of each record in the DataStore will look like this:
===========================================================================
| type | key length | key | Data |
===========================================================================
1B 1B max 128B variable
The type and key size are both one byte only (which is why
the key is limited in length).
| Field Summary | |
|---|---|
static int |
DATA_TYPE_BYTES
|
static int |
DATA_TYPE_INTEGER
|
static int |
DATA_TYPE_STRING
|
protected static boolean |
DEBUG_CONFLICT_RESOLVE
|
protected static boolean |
DEBUG_CONFLICT_RESOLVE_VERBOSE
|
protected static boolean |
DEBUG_SORT
|
protected static int |
DEFAULT_SETTING
|
protected static boolean |
IS_DEBUG
|
protected Listener |
mAutoSyncNotifyee
Deprecated. |
protected DataStore |
mDataStore
Deprecated. |
| Constructor Summary | |
|---|---|
SettingsDB(String dbName)
Create or get a SettingsDB. |
|
SettingsDB(String dbName,
boolean autoSync)
Create or get a SettingsDB. |
|
| Method Summary | |
|---|---|
void |
clearAll()
Remove all records in a settings database. |
void |
dump()
Dump the contents of the settings database to debug output. |
int |
find(String inKey)
Find and return the index for a record in the database. |
protected int |
find2(String inKey)
Find and return the index for a record in the database. |
static boolean |
findDB(String dbName)
Find a settings database. |
static boolean |
findDB(String dbName,
boolean absolutePath)
Find a settings database. |
byte[] |
getBytes(int i)
Get byte array specifed by index. |
byte[] |
getBytes(String inKey)
Get byte array specifed by key. |
int |
getDataType(int i)
Get the data type of the ith entry in a settings database. |
int |
getIntValue(int i)
Get integer value specifed by index. |
int |
getIntValue(String inKey)
Get integer value specifed by key. |
String |
getKey(int i)
Get a specific key from a settings database. |
int |
getNumEntries()
Get the number of records in a settings database. |
void |
getObject(String inKey,
Storable ioObject)
Get object specifed by key. |
String |
getStringValue(int i)
Get string value specifed by index. |
String |
getStringValue(String inKey)
Get string value specifed by key. |
boolean |
receiveEvent(Event e)
Receive a SettingsDB-related event. |
void |
registerAutoSyncBundleListener(Bundle bundle)
register autosync listener with datastore Registers with datastore the autosync listener and the datastore's owner bundle. |
String |
remove(String inKey)
Remove the record specifed by key. |
boolean |
renameKey(int i,
String newKey)
Rename a specific key in a settings database. |
boolean |
renameKey(String oldKey,
String newKey)
Rename a specific key in a settings database. |
protected void |
resolveAllRecords()
Resolves each record with every other record in the settings database. |
protected void |
resolveAutoSyncConflicts()
Resolves potential conflicts caused by auto-syncing the data from Danger service. |
void |
setAutoSyncNotifyee(Listener inNotifyee)
Set the Listener for AutoSync events. |
void |
setBytes(String inKey,
byte[] inValue)
Set the byte array specifed by key. |
void |
setBytes(String inKey,
byte[] inValue,
boolean isDefault)
Set the byte array specifed by key. |
void |
setIntValue(String inKey,
int inValue)
Set the integer value specifed by key. |
void |
setIntValue(String inKey,
int inValue,
boolean isDefault)
Set the integer value specifed by key. |
void |
setObject(String inKey,
Storable inObject)
Set the object specifed by key. |
void |
setObject(String inKey,
Storable inObject,
boolean isDefaultSetting)
Set the object specifed by key. |
void |
setStringValue(String inKey,
String inValue)
Set the string value specifed by key. |
void |
setStringValue(String inKey,
String inValue,
boolean isDefault)
Set the string value specifed by key. |
protected void |
sort()
Sort the settings database by the keys. |
| Methods inherited from class danger.app.Listener |
|---|
cancelEvents, childEventPump, childEventPumpDone, eventProblem, isDispatchingThread, receiveEventInternal, sendEvent, sendEvent, sendEvent, sendEvent, sendEvent, sendLowPriorityEvent |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected DataStore mDataStore
protected Listener mAutoSyncNotifyee
public static final int DATA_TYPE_INTEGER
public static final int DATA_TYPE_STRING
public static final int DATA_TYPE_BYTES
protected static final int DEFAULT_SETTING
protected static final boolean IS_DEBUG
protected static final boolean DEBUG_CONFLICT_RESOLVE
protected static final boolean DEBUG_CONFLICT_RESOLVE_VERBOSE
protected static final boolean DEBUG_SORT
| Constructor Detail |
|---|
public SettingsDB(String dbName,
boolean autoSync)
dbName - A String specifying the name of the settings database.autoSync - A boolean that is true if the database is to be backed up to the service.public SettingsDB(String dbName)
dbName - A String specifying the name of the settings database.| Method Detail |
|---|
public boolean receiveEvent(Event e)
receiveEvent in class Listenere - An Event object containing the event type and data.
public static boolean findDB(String dbName)
dbName - A String specifying the name of the database to be found.
public static boolean findDB(String dbName,
boolean absolutePath)
dbName - A String specifying the name of the database to be found.
public int getNumEntries()
public int getDataType(int i)
i - An int specifying the index of the record to be retrieved.
public String getKey(int i)
i - An int specifying the index of the record to be retrieved.
public boolean renameKey(String oldKey,
String newKey)
oldKey - A String specifying the name of the key to be renamed.newKey - A String specifying the new name for the key.
public boolean renameKey(int i,
String newKey)
i - An int specifying the index to the key to be renamed.newKey - A String specifying the new name for the key.
public int find(String inKey)
inKey - A String specifying the key for the record.
protected int find2(String inKey)
inKey - A String specifying the key for the record.
protected void sort()
public void dump()
public void clearAll()
public int getIntValue(String inKey)
throws SettingsDBException
inKey - non-null; the key to look up
NullPointerException - thrown if inKey is
null
IllegalArgumentException - thrown if inKey is
non-null but otherwise invalid
SettingsDBException - thrown if the record is not found or
is of the wrong type
public int getIntValue(int i)
throws SettingsDBException
i - An int specifying the index to the record to be found.
SettingsDBException - thrown if the record is not found or
is of the wrong type
public void setIntValue(String inKey,
int inValue)
inKey - non-null; the key to look upinValue - An int containing the value to be associated with the key.
NullPointerException - thrown if inKey is
null
IllegalArgumentException - thrown if inKey is
non-null but otherwise invalid
public void setIntValue(String inKey,
int inValue,
boolean isDefault)
inKey - non-null; the key to look upinValue - An int containing the value to be associated with the key.isDefault - A boolean that is true if the value was not specified by the user.
NullPointerException - thrown if inKey is
null
IllegalArgumentException - thrown if inKey is
non-null but otherwise invalidpublic String getStringValue(String inKey)
null.
inKey - non-null; the key to look up
null if the key was not found or is not of the right type
NullPointerException - thrown if inKey is
null
IllegalArgumentException - thrown if inKey is
non-null but otherwise invalidpublic String getStringValue(int i)
i - An int specifying the index to the record to be found.
null if the key was not found or is not of the right type
public void setStringValue(String inKey,
String inValue)
inKey - non-null; the key to look upinValue - non-null; a String containing the value to be associated with the key.
NullPointerException - thrown if inKey or
inValue is null
IllegalArgumentException - thrown if inKey is
non-null but otherwise invalid
public void setStringValue(String inKey,
String inValue,
boolean isDefault)
inKey - non-null; the key to look upinValue - non-null; a String containing the value to be associated with the key.isDefault - A boolean that is true if the value was not specified by the user.
NullPointerException - thrown if inKey or
inValue is null
IllegalArgumentException - thrown if inKey is
non-null but otherwise invalid
public byte[] getBytes(String inKey)
throws SettingsDBException
inKey - non-null; the key to look up
NullPointerException - thrown if inKey is
null
IllegalArgumentException - thrown if inKey is
non-null but otherwise invalid
SettingsDBException - thrown if the record is not found or is
of the wrong type
public byte[] getBytes(int i)
throws SettingsDBException
i - An int specifying the index to the record to be found.
NullPointerException - thrown if inKey is
null
IllegalArgumentException - thrown if inKey is
non-null but otherwise invalid
SettingsDBException - thrown if the record is not found or is
of the wrong type
public void setBytes(String inKey,
byte[] inValue)
inKey - non-null; the key to look upinValue - non-null; a byte array containing the value to be associated with the key.
NullPointerException - thrown if inKey or
inValue is null
IllegalArgumentException - thrown if inKey is
non-null but otherwise invalid
public void setBytes(String inKey,
byte[] inValue,
boolean isDefault)
inKey - non-null; the key to look upinValue - non-null; A byte array containing the value to be associated with the key.isDefault - A boolean that is true if the value was not specified by the user.
NullPointerException - thrown if inKey or
inValue is null
IllegalArgumentException - thrown if inKey is
non-null but otherwise invalid
public void setObject(String inKey,
Storable inObject)
inKey - non-null; the key to look upinObject - non-null; a Storable object containing the object to be associated with the key.
NullPointerException - thrown if inKey or
inValue is null
IllegalArgumentException - thrown if inKey is
non-null but otherwise invalid
public void setObject(String inKey,
Storable inObject,
boolean isDefaultSetting)
inKey - non-null; the key to look upinObject - non-null; a Storable object containing the object to be associated with the key.isDefaultSetting - A boolean that is true if the value was not specified by the user.
NullPointerException - thrown if inKey or
inValue is null
IllegalArgumentException - thrown if inKey is
non-null but otherwise invalid
public void getObject(String inKey,
Storable ioObject)
throws SettingsDBException
inKey - non-null; the key to look upioObject - A Storable object to hold the data associated with the key.
NullPointerException - thrown if inKey is
null
IllegalArgumentException - thrown if inKey is
non-null but otherwise invalid
SettingsDBException - thrown if the record is not foundpublic String remove(String inKey)
inKey - non-null; the key to look up
NullPointerException - thrown if inKey is
null
IllegalArgumentException - thrown if inKey is
non-null but otherwise invalidprotected void resolveAllRecords()
protected void resolveAutoSyncConflicts()
public void setAutoSyncNotifyee(Listener inNotifyee)
inNotifyee - The listener to be notified of the autosync events.public void registerAutoSyncBundleListener(Bundle bundle)
bundle - The owner bundle of the datastore
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||