Android Client Reference
Class DatabaseObject
Namespace: com.playerio
Language: Java
This class represents a BigDB Database Object that has a key and a collection of named properties.
There are methods for setting, getting, and removing properties, and changes to the object can be persisted to BigDB with the save() method.
Database objects are very similar to JSON objects and are most easily visualized as such. For example, we can visualize a car object like this:
If we then want to create this object in BigDB, we would have to do this:
To make it easier to work with nested objects, you can reference them directly by separating the property names with a dot. Using this, we can set the stats properties of the car like this instead:
When you want to read properties from a database object, you have to call the corresponding get method indicating the type of the property.
BigDB doesn't enforce anything on your objects. Two objects in the same table do not need to have the same properties set, and do not need to have the same type on the same property. If you try to get a property that is missing, or if you are using a get method of the wrong type, you will get an exception.
One way of avoiding this is to first check the object if a certain property exists before reading this. You can do this with the Contains method.
Another way of avoiding errors is to specify a default value when calling a get method. If the object doesn't contain the property, the method will return your default value instead.
You can also easily remove properties from your object with the Remove method.
Finally, to persist any changes you've made to an object you can call the Save method. Note that you can only call Save on an object that exist in the database. This means that the first time you save an object you have to call the CreateObject method, but all subsequent times you can call the Save method. There is also a method called existsInDatabase that you can use to check if it has been created or not.
The Save method is asynchronous just like the CreateObject method in PlayerIO.BigDB, and you can specify a callback if you wish to do something when the object actually has been saved.
Methods | |||
---|---|---|---|
public void |
Removes all properties on this object |
||
public boolean |
Returns true if the given property exists on this object |
||
public |
Create a new DatabaseObject |
||
public boolean |
Returns true if this object has been persisted. |
||
public DatabaseArray |
Get the given DatabaseArray property |
||
public boolean |
Get the given boolean property |
||
public boolean |
Get the given boolean property, or the default if it doesn't exist. |
||
public byte[] |
Get the given byte array property |
||
public byte[] |
Get the given byte array property, or the default if it doesn't exist. |
||
public Date |
Get the given Date property, or the default if it doesn't exist. |
||
public Date |
Get the given Date property |
||
public double |
Get the given double property, or the default if it doesn't exist. |
||
public double |
Get the given double property |
||
public float |
Get the given float property |
||
public float |
Get the given float property, or the default if it doesn't exist. |
||
public int |
Get the given int property |
||
public int |
Get the given int property, or the default if it doesn't exist. |
||
public String |
The key of the object. |
||
public long |
Get the given long property, or the default if it doesn't exist. |
||
public long |
Get the given long property |
||
public DatabaseObject |
Get the given DatabaseObject property |
||
public String |
Get the given String property |
||
public String |
Get the given String property, or the default if it doesn't exist. |
||
public String |
The name of the BigDB table this object belongs to |
||
public int |
Get the given uint property |
||
public int |
Get the given uint property, or the default if it doesn't exist. |
||
public Object |
Get the given property as an object |
||
public ArrayList<String> |
Get the names of all properties on this object |
||
public DatabaseObject |
Removes the given property from this object |
||
public void |
Persist the object to the database. |
||
public void |
Persist the object to the database asynchronously, using optimistic locking if specified |
||
public void |
Persist the object to the database asynchronously, using optimistic locking and full overwrite if specified. |
||
public void |
Persist the object to the database asynchronously. |
||
public void |
Persist the object to the database. |
||
public void |
Persist the object to the database, using optimistic locking and full overwrite if specified. |
||
public DatabaseObject |
Set the given property to the given double value |
||
public DatabaseObject |
Set the given property to the given float value |
||
public DatabaseObject |
Set the given property to the given bye array value |
||
public DatabaseObject |
Set the given property to the given DatabaseObject value |
||
public DatabaseObject |
Set the given property to the given Date value |
||
public DatabaseObject |
Set the given property to the given boolean value |
||
public DatabaseObject |
Set the given property to the given string value |
||
public DatabaseObject |
Set the given property to the given DatabaseArray value |
||
public DatabaseObject |
Set the given property to the given int value |
||
public DatabaseObject |
Set the given property to the given long value |
||
public DatabaseObject |
Set the given property to the given uint value |
||
public int |
Returns the number of properties on this object |
DatabaseObject.clear
public void |
|
Removes all properties on this object
DatabaseObject.contains
public boolean |
|
Returns true if the given property exists on this object
Arguments
String | propertyExpression |
DatabaseObject.DatabaseObject
public |
|
Create a new DatabaseObject
DatabaseObject.existsInDatabase
public boolean |
|
Returns true if this object has been persisted.
DatabaseObject.getArray
public DatabaseArray |
|
Get the given DatabaseArray property
Arguments
String | propertyExpression |
DatabaseObject.getBool
public boolean |
|
Get the given boolean property
Arguments
String | propertyExpression |
DatabaseObject.getBool
public boolean |
|
Get the given boolean property, or the default if it doesn't exist.
Arguments
String | propertyExpression |
boolean | defaultValue |
DatabaseObject.getBytes
public byte[] |
|
Get the given byte array property
Arguments
String | propertyExpression |
DatabaseObject.getBytes
public byte[] |
|
Get the given byte array property, or the default if it doesn't exist.
Arguments
String | propertyExpression |
byte[] | defaultValue |
DatabaseObject.getDateTime
public Date |
|
Get the given Date property, or the default if it doesn't exist.
Arguments
String | propertyExpression |
Date | defaultValue |
DatabaseObject.getDateTime
public Date |
|
Get the given Date property
Arguments
String | propertyExpression |
DatabaseObject.getDouble
public double |
|
Get the given double property, or the default if it doesn't exist.
Arguments
String | propertyExpression |
double | defaultValue |
DatabaseObject.getDouble
public double |
|
Get the given double property
Arguments
String | propertyExpression |
DatabaseObject.getFloat
public float |
|
Get the given float property
Arguments
String | propertyExpression |
DatabaseObject.getFloat
public float |
|
Get the given float property, or the default if it doesn't exist.
Arguments
String | propertyExpression |
float | defaultValue |
DatabaseObject.getInt
public int |
|
Get the given int property
Arguments
String | propertyExpression |
DatabaseObject.getInt
public int |
|
Get the given int property, or the default if it doesn't exist.
Arguments
String | propertyExpression |
int | defaultValue |
DatabaseObject.getKey
public String |
|
The key of the object.
DatabaseObject.getLong
public long |
|
Get the given long property, or the default if it doesn't exist.
Arguments
String | propertyExpression |
long | defaultValue |
DatabaseObject.getLong
public long |
|
Get the given long property
Arguments
String | propertyExpression |
DatabaseObject.getObject
public DatabaseObject |
|
Get the given DatabaseObject property
Arguments
String | propertyExpression |
DatabaseObject.getString
public String |
|
Get the given String property
Arguments
String | propertyExpression |
DatabaseObject.getString
public String |
|
Get the given String property, or the default if it doesn't exist.
Arguments
String | propertyExpression |
String | defaultValue |
DatabaseObject.getTable
public String |
|
The name of the BigDB table this object belongs to
DatabaseObject.getUInt
public int |
|
Get the given uint property
Arguments
String | propertyExpression |
DatabaseObject.getUInt
public int |
|
Get the given uint property, or the default if it doesn't exist.
Arguments
String | propertyExpression |
int | defaultValue |
DatabaseObject.getValue
public Object |
|
Get the given property as an object
Arguments
String | propertyExpression |
DatabaseObject.properties
public ArrayList<String> |
|
Get the names of all properties on this object
DatabaseObject.remove
public DatabaseObject |
|
Removes the given property from this object
Arguments
String | propertyExpression |
DatabaseObject.save
public void |
|
Persist the object to the database.
Throws
PlayerIOError |
DatabaseObject.save
public void |
|
Persist the object to the database asynchronously, using optimistic locking if specified
Arguments
boolean | useOptimisticLock |
Callback<Void> | callback |
DatabaseObject.save
public void |
|
Persist the object to the database asynchronously, using optimistic locking and full overwrite if specified.
Arguments
boolean | useOptimisticLock |
boolean | fullOverwrite |
Callback<Void> | callback |
DatabaseObject.save
public void |
|
Persist the object to the database asynchronously.
Arguments
Callback<Void> | callback |
DatabaseObject.save
public void |
|
Persist the object to the database.
Arguments
boolean | useOptimisticLock |
Throws
PlayerIOError |
DatabaseObject.save
public void |
|
Persist the object to the database, using optimistic locking and full overwrite if specified.
Arguments
boolean | useOptimisticLock |
boolean | fullOverwrite |
Throws
PlayerIOError |
DatabaseObject.set
public DatabaseObject |
|
Set the given property to the given double value
Arguments
String | propertyExpression |
double | value |
DatabaseObject.set
public DatabaseObject |
|
Set the given property to the given float value
Arguments
String | propertyExpression |
float | value |
DatabaseObject.set
public DatabaseObject |
|
Set the given property to the given bye array value
Arguments
String | propertyExpression |
byte[] | value |
DatabaseObject.set
public DatabaseObject |
|
Set the given property to the given DatabaseObject value
Arguments
String | propertyExpression |
DatabaseObject | value |
DatabaseObject.set
public DatabaseObject |
|
Set the given property to the given Date value
Arguments
String | propertyExpression |
Date | value |
DatabaseObject.set
public DatabaseObject |
|
Set the given property to the given boolean value
Arguments
String | propertyExpression |
boolean | value |
DatabaseObject.set
public DatabaseObject |
|
Set the given property to the given string value
Arguments
String | propertyExpression |
String | value |
DatabaseObject.set
public DatabaseObject |
|
Set the given property to the given DatabaseArray value
Arguments
String | propertyExpression |
DatabaseArray | value |
DatabaseObject.set
public DatabaseObject |
|
Set the given property to the given int value
Arguments
String | propertyExpression |
int | value |
DatabaseObject.set
public DatabaseObject |
|
Set the given property to the given long value
Arguments
String | propertyExpression |
long | value |
DatabaseObject.setUInt
public DatabaseObject |
|
Set the given property to the given uint value
Arguments
String | propertyExpression |
int | value |
DatabaseObject.size
public int |
|
Returns the number of properties on this object