PlayerIO

The fastest way to build online games without breaking a sweat.

Android Client Reference

Android  class documentationClass 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
clear ()

Removes all properties on this object

public boolean
contains (String propertyExpression)

Returns true if the given property exists on this object

public
DatabaseObject ()

Create a new DatabaseObject

public boolean
existsInDatabase ()

Returns true if this object has been persisted.

public DatabaseArray
getArray (String propertyExpression)

Get the given DatabaseArray property

public boolean
getBool (String propertyExpression)

Get the given boolean property

public boolean
getBool (String propertyExpression, boolean defaultValue)

Get the given boolean property, or the default if it doesn't exist.

public byte[]
getBytes (String propertyExpression)

Get the given byte array property

public byte[]
getBytes (String propertyExpression, byte[] defaultValue)

Get the given byte array property, or the default if it doesn't exist.

public Date
getDateTime (String propertyExpression, Date defaultValue)

Get the given Date property, or the default if it doesn't exist.

public Date
getDateTime (String propertyExpression)

Get the given Date property

public double
getDouble (String propertyExpression, double defaultValue)

Get the given double property, or the default if it doesn't exist.

public double
getDouble (String propertyExpression)

Get the given double property

public float
getFloat (String propertyExpression)

Get the given float property

public float
getFloat (String propertyExpression, float defaultValue)

Get the given float property, or the default if it doesn't exist.

public int
getInt (String propertyExpression)

Get the given int property

public int
getInt (String propertyExpression, int defaultValue)

Get the given int property, or the default if it doesn't exist.

public String
getKey ()

The key of the object.

public long
getLong (String propertyExpression, long defaultValue)

Get the given long property, or the default if it doesn't exist.

public long
getLong (String propertyExpression)

Get the given long property

public DatabaseObject
getObject (String propertyExpression)

Get the given DatabaseObject property

public String
getString (String propertyExpression)

Get the given String property

public String
getString (String propertyExpression, String defaultValue)

Get the given String property, or the default if it doesn't exist.

public String
getTable ()

The name of the BigDB table this object belongs to

public int
getUInt (String propertyExpression)

Get the given uint property

public int
getUInt (String propertyExpression, int defaultValue)

Get the given uint property, or the default if it doesn't exist.

public Object
getValue (String propertyExpression)

Get the given property as an object

public ArrayList<String>
properties ()

Get the names of all properties on this object

public DatabaseObject
remove (String propertyExpression)

Removes the given property from this object

public void
save ()

Persist the object to the database.

public void
save (boolean useOptimisticLock, Callback<Void> callback)

Persist the object to the database asynchronously, using optimistic locking if specified

public void
save (boolean useOptimisticLock, boolean fullOverwrite, Callback<Void> callback)

Persist the object to the database asynchronously, using optimistic locking and full overwrite if specified.

public void
save (Callback<Void> callback)

Persist the object to the database asynchronously.

public void
save (boolean useOptimisticLock)

Persist the object to the database.

public void
save (boolean useOptimisticLock, boolean fullOverwrite)

Persist the object to the database, using optimistic locking and full overwrite if specified.

public DatabaseObject
set (String propertyExpression, double value)

Set the given property to the given double value

public DatabaseObject
set (String propertyExpression, float value)

Set the given property to the given float value

public DatabaseObject
set (String propertyExpression, byte[] value)

Set the given property to the given bye array value

public DatabaseObject
set (String propertyExpression, DatabaseObject value)

Set the given property to the given DatabaseObject value

public DatabaseObject
set (String propertyExpression, Date value)

Set the given property to the given Date value

public DatabaseObject
set (String propertyExpression, boolean value)

Set the given property to the given boolean value

public DatabaseObject
set (String propertyExpression, String value)

Set the given property to the given string value

public DatabaseObject
set (String propertyExpression, DatabaseArray value)

Set the given property to the given DatabaseArray value

public DatabaseObject
set (String propertyExpression, int value)

Set the given property to the given int value

public DatabaseObject
set (String propertyExpression, long value)

Set the given property to the given long value

public DatabaseObject
setUInt (String propertyExpression, int value)

Set the given property to the given uint value

public int
size ()

Returns the number of properties on this object

DatabaseObject.clear

public void
clear ()

Removes all properties on this object

DatabaseObject.contains

public boolean
contains (String propertyExpression)

Returns true if the given property exists on this object

Arguments

String propertyExpression

DatabaseObject.DatabaseObject

public
DatabaseObject ()

Create a new DatabaseObject

DatabaseObject.existsInDatabase

public boolean
existsInDatabase ()

Returns true if this object has been persisted.

DatabaseObject.getArray

public DatabaseArray
getArray (String propertyExpression)

Get the given DatabaseArray property

Arguments

String propertyExpression

DatabaseObject.getBool

public boolean
getBool (String propertyExpression)

Get the given boolean property

Arguments

String propertyExpression

DatabaseObject.getBool

public boolean
getBool (String propertyExpression, boolean defaultValue)

Get the given boolean property, or the default if it doesn't exist.

Arguments

String propertyExpression
boolean defaultValue

DatabaseObject.getBytes

public byte[]
getBytes (String propertyExpression)

Get the given byte array property

Arguments

String propertyExpression

DatabaseObject.getBytes

public byte[]
getBytes (String propertyExpression, byte[] defaultValue)

Get the given byte array property, or the default if it doesn't exist.

Arguments

String propertyExpression
byte[] defaultValue

DatabaseObject.getDateTime

public Date
getDateTime (String propertyExpression, Date defaultValue)

Get the given Date property, or the default if it doesn't exist.

Arguments

String propertyExpression
Date defaultValue

DatabaseObject.getDateTime

public Date
getDateTime (String propertyExpression)

Get the given Date property

Arguments

String propertyExpression

DatabaseObject.getDouble

public double
getDouble (String propertyExpression, double defaultValue)

Get the given double property, or the default if it doesn't exist.

Arguments

String propertyExpression
double defaultValue

DatabaseObject.getDouble

public double
getDouble (String propertyExpression)

Get the given double property

Arguments

String propertyExpression

DatabaseObject.getFloat

public float
getFloat (String propertyExpression)

Get the given float property

Arguments

String propertyExpression

DatabaseObject.getFloat

public float
getFloat (String propertyExpression, float defaultValue)

Get the given float property, or the default if it doesn't exist.

Arguments

String propertyExpression
float defaultValue

DatabaseObject.getInt

public int
getInt (String propertyExpression)

Get the given int property

Arguments

String propertyExpression

DatabaseObject.getInt

public int
getInt (String propertyExpression, int defaultValue)

Get the given int property, or the default if it doesn't exist.

Arguments

String propertyExpression
int defaultValue

DatabaseObject.getKey

public String
getKey ()

The key of the object.

DatabaseObject.getLong

public long
getLong (String propertyExpression, long defaultValue)

Get the given long property, or the default if it doesn't exist.

Arguments

String propertyExpression
long defaultValue

DatabaseObject.getLong

public long
getLong (String propertyExpression)

Get the given long property

Arguments

String propertyExpression

DatabaseObject.getObject

public DatabaseObject
getObject (String propertyExpression)

Get the given DatabaseObject property

Arguments

String propertyExpression

DatabaseObject.getString

public String
getString (String propertyExpression)

Get the given String property

Arguments

String propertyExpression

DatabaseObject.getString

public String
getString (String propertyExpression, String defaultValue)

Get the given String property, or the default if it doesn't exist.

Arguments

String propertyExpression
String defaultValue

DatabaseObject.getTable

public String
getTable ()

The name of the BigDB table this object belongs to

DatabaseObject.getUInt

public int
getUInt (String propertyExpression)

Get the given uint property

Arguments

String propertyExpression

DatabaseObject.getUInt

public int
getUInt (String propertyExpression, int defaultValue)

Get the given uint property, or the default if it doesn't exist.

Arguments

String propertyExpression
int defaultValue

DatabaseObject.getValue

public Object
getValue (String propertyExpression)

Get the given property as an object

Arguments

String propertyExpression

DatabaseObject.properties

public ArrayList<String>
properties ()

Get the names of all properties on this object

DatabaseObject.remove

public DatabaseObject
remove (String propertyExpression)

Removes the given property from this object

Arguments

String propertyExpression

DatabaseObject.save

public void
save ()

Persist the object to the database.

Throws

PlayerIOError

DatabaseObject.save

public void
save (boolean useOptimisticLock, Callback<Void> callback)

Persist the object to the database asynchronously, using optimistic locking if specified

Arguments

boolean useOptimisticLock
If true, the save will only be completed if the database object has not changed in BigDB since this instance was loaded.
Callback<Void> callback
The callback that will be used to return results. On success its onSuccess method will be called, otherwise its onError method.

DatabaseObject.save

public void
save (boolean useOptimisticLock, boolean fullOverwrite, Callback<Void> callback)

Persist the object to the database asynchronously, using optimistic locking and full overwrite if specified.

Arguments

boolean useOptimisticLock
If true, the save will only be completed if the database object has not changed in BigDB since this instance was loaded.
boolean fullOverwrite
Will completely overwrite the database object in BigDB with the properties in this instance, instead of just sending the changed properties to the server.
Callback<Void> callback
The callback that will be used to return results. On success its onSuccess method will be called, otherwise its onError method.

DatabaseObject.save

public void
save (Callback<Void> callback)

Persist the object to the database asynchronously.

Arguments

Callback<Void> callback
The callback that will be used to return results. On success its onSuccess method will be called, otherwise its onError method.

DatabaseObject.save

public void
save (boolean useOptimisticLock)

Persist the object to the database.

Arguments

boolean useOptimisticLock
If true, the save will only be completed if the database object has not changed in BigDB since this instance was loaded.

Throws

PlayerIOError

DatabaseObject.save

public void
save (boolean useOptimisticLock, boolean fullOverwrite)

Persist the object to the database, using optimistic locking and full overwrite if specified.

Arguments

boolean useOptimisticLock
If true, the save will only be completed if the database object has not changed in BigDB since this instance was loaded.
boolean fullOverwrite
Will completely overwrite the database object in BigDB with the properties in this instance, instead of just sending the changed properties to the server.

Throws

PlayerIOError

DatabaseObject.set

public DatabaseObject
set (String propertyExpression, double value)

Set the given property to the given double value

Arguments

String propertyExpression
double value

DatabaseObject.set

public DatabaseObject
set (String propertyExpression, float value)

Set the given property to the given float value

Arguments

String propertyExpression
float value

DatabaseObject.set

public DatabaseObject
set (String propertyExpression, byte[] value)

Set the given property to the given bye array value

Arguments

String propertyExpression
byte[] value

DatabaseObject.set

public DatabaseObject
set (String propertyExpression, DatabaseObject value)

Set the given property to the given DatabaseObject value

Arguments

String propertyExpression
DatabaseObject value

DatabaseObject.set

public DatabaseObject
set (String propertyExpression, Date value)

Set the given property to the given Date value

Arguments

String propertyExpression
Date value

DatabaseObject.set

public DatabaseObject
set (String propertyExpression, boolean value)

Set the given property to the given boolean value

Arguments

String propertyExpression
boolean value

DatabaseObject.set

public DatabaseObject
set (String propertyExpression, String value)

Set the given property to the given string value

Arguments

String propertyExpression
String value

DatabaseObject.set

public DatabaseObject
set (String propertyExpression, DatabaseArray value)

Set the given property to the given DatabaseArray value

Arguments

String propertyExpression
DatabaseArray value

DatabaseObject.set

public DatabaseObject
set (String propertyExpression, int value)

Set the given property to the given int value

Arguments

String propertyExpression
int value

DatabaseObject.set

public DatabaseObject
set (String propertyExpression, long value)

Set the given property to the given long value

Arguments

String propertyExpression
long value

DatabaseObject.setUInt

public DatabaseObject
setUInt (String propertyExpression, int value)

Set the given property to the given uint value

Arguments

String propertyExpression
int value

DatabaseObject.size

public int
size ()

Returns the number of properties on this object