PlayerIO

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

Android Client Reference

Android  class documentationClass BigDB

Namespace: com.playerio
Language: Java

The BigDB service.

This class is used to create, load, and delete database objects. All database objects are stored in tables and have a unique key. You can set up tables in your admin panel, and you can also set up indexes there for when you want to load objects by properties or ranges of properties. Please note that all methods are asynchronous and any handling of results have to be done in a callback. If you don't care about the results of a method call, typically for create or delete functions, you can just pass in a null callback.

Here's how to store and update an object:

This is how you load an object:

In case you always want to modify an object, you can use the LoadOrCreate method to ensure you get an object back:

BigDB also supports indexes for retrieving objects by a specific property, a range of properties, or to sort objects by properties. Indexes need to be set up in the admin panel for each table, each index needs a name, and a list of properties, and for each property you also need to specify a sort order.

Imagine that we have objects that look like this:

That we have defined an index called "ByUsername" that looks like this:

{Property:"username", Type:String, Order:Ascending}

And an index called "ByCreated" that looks like this:

{Property:"created", Type:Datetime, Order:Descending}

Then we can do lookups like these:

BigDB also supports compound indexes, that is indexes with more than one property. Given our example object above, we can create an index called "ByLocationAgeCreated" that looks like this:

{Property:"location", Type:String, Order:Ascending}

{Property:"age", Type:Integer, Order:Ascending}

{Property:"created", Type:Datetime, Order:Descending}

With this index, we can then lookup on either location, or location and age, or location and age and created. If we use more than one property in the lookup, we can only specify the range for the last one, the preceding ones have to be fixed and are sent in via the path parameter.

Finally, deleting objects is as easy as calling the DeleteKeys method, or DeleteRange if you want to delete by an index.

Methods

 
public void
createObject (String table, String key, DatabaseObject obj, Callback<DatabaseObject> callback)

Creates a new database object in the given table with the specified key. If no key is specified (null), the object will receive an autogenerated id.

public void
deleteKeys (String table, String[] keys, Callback<Void> callback)

Delete a set of database objects from a table.

public void
deleteRange (String table, String index, Object[] indexPath, Object start, Object stop, Callback<Void> callback)

Delete a range of database objects from a table using an index.

public void
load (String table, String key, Callback<DatabaseObject> callback)

Load the database object with the given key from the given table.

public void
loadKeys (String table, String[] keys, Callback<DatabaseObject[]> callback)

Loads the database objects with the given keys from the given table.

public void
loadKeysOrCreate (String table, String[] keys, Callback<DatabaseObject[]> callback)

Loads or creates database objects with the given keys from the given table. New objects are created if there are no existing objects for the given keys.

public void
loadMyPlayerObject (Callback<DatabaseObject> callback)

Loads the database object corresponding to the player from the PlayerObjects table.

public void
loadOrCreate (String table, String key, Callback<DatabaseObject> callback)

Loads or creates the database object with the given key from the given table.

public void
loadRange (String table, String index, Object[] indexPath, Object start, Object stop, int limit, Callback<DatabaseObject[]> callback)

Load a range of database objects from a table using the specified index.

public void
loadSingle (String table, String index, Object[] indexValue, Callback<DatabaseObject> callback)

Load a database object from a table using the specified index.

public void
saveChanges (boolean useOptimisticLock, boolean fullOverwrite, DatabaseObject[] objects, Callback<Void> callback)

Save changes to one or more database objects in one go.

BigDB.createObject

public void
createObject (String table, String key, DatabaseObject obj, Callback<DatabaseObject> callback)

Creates a new database object in the given table with the specified key. If no key is specified (null), the object will receive an autogenerated id.

Arguments

String table
The name of the table to create the database object in.
String key
The key to assign to the database object.
DatabaseObject obj
The database object to create in the table.
Callback<DatabaseObject> callback
The callback that will be used to return results. On success its onSuccess method will be called, otherwise its onError method.

Throws

PlayerIOError

BigDB.deleteKeys

public void
deleteKeys (String table, String[] keys, Callback<Void> callback)

Delete a set of database objects from a table.

Arguments

String table
The table to delete the database objects from.
String[] keys
The keys of the database objects to delete.
Callback<Void> callback
The callback that will be used to return results. On success its onSuccess method will be called, otherwise its onError method.

Throws

PlayerIOError

BigDB.deleteRange

public void
deleteRange (String table, String index, Object[] indexPath, Object start, Object stop, Callback<Void> callback)

Delete a range of database objects from a table using an index.

Arguments

String table
The table to delete the database object from.
String index
The name of the index to query for the database objects to delete.
Object[] indexPath
Where in the index to start the range delete: An array of objects of the same types as the index properties, specifying where in the index to start loading database objects from. For instance, in the index [Mode,Map,Score] you might use new object[]{"expert","skyland"} as the indexPath and use the start and stop arguments to determine the range of scores you wish to delete. IndexPath can be set to null instead of an empty array.
Object start
Where to start the range delete. For instance, if the index is [Mode,Map,Score] and indexPath is ["expert","skyland"], then start defines the minimum score to delete.
Object stop
Where to stop the range delete. For instance, if the index is [Mode,Map,Score] and indexPath is ["expert","skyland"], then stop defines the maximum score to delete.
Callback<Void> callback
The callback that will be used to return results. On success its onSuccess method will be called, otherwise its onError method.

Throws

PlayerIOError

BigDB.load

public void
load (String table, String key, Callback<DatabaseObject> callback)

Load the database object with the given key from the given table.

Arguments

String table
The table to load the database object from.
String key
The key of the database object to load.
Callback<DatabaseObject> callback
The callback that will be used to return results. On success its onSuccess method will be called, otherwise its onError method.

Throws

PlayerIOError

BigDB.loadKeys

public void
loadKeys (String table, String[] keys, Callback<DatabaseObject[]> callback)

Loads the database objects with the given keys from the given table.

Arguments

String table
The table to load the database objects from.
String[] keys
The keys of the database objects to load.
Callback<DatabaseObject[]> callback
The callback that will be used to return results. On success its onSuccess method will be called, otherwise its onError method.

Throws

PlayerIOError

BigDB.loadKeysOrCreate

public void
loadKeysOrCreate (String table, String[] keys, Callback<DatabaseObject[]> callback)

Loads or creates database objects with the given keys from the given table. New objects are created if there are no existing objects for the given keys.

Arguments

String table
The table from which to load or create the database objects.
String[] keys
The keys of the database objects to load or create.
Callback<DatabaseObject[]> callback
The callback that will be used to return results. On success its onSuccess method will be called, otherwise its onError method.

Throws

PlayerIOError

BigDB.loadMyPlayerObject

public void
loadMyPlayerObject (Callback<DatabaseObject> callback)

Loads the database object corresponding to the player from the PlayerObjects table.

Arguments

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

Throws

PlayerIOError

BigDB.loadOrCreate

public void
loadOrCreate (String table, String key, Callback<DatabaseObject> callback)

Loads or creates the database object with the given key from the given table.

Arguments

String table
The table from which to load or create the database object.
String key
The key of the database object to load or create.
Callback<DatabaseObject> callback
The callback that will be used to return results. On success its onSuccess method will be called, otherwise its onError method.

Throws

PlayerIOError

BigDB.loadRange

public void
loadRange (String table, String index, Object[] indexPath, Object start, Object stop, int limit, Callback<DatabaseObject[]> callback)

Load a range of database objects from a table using the specified index.

Arguments

String table
The table to load the database objects from.
String index
The name of the index to query for the database objects.
Object[] indexPath
Where in the index to start the range search: An array of objects of the same types as the index properties, specifying where in the index to start loading database objects from. For instance, in the index [Mode,Map,Score] you might use new object[]{"expert","skyland"} as the indexPath and use the start and stop arguments to determine the range of scores you wish to return. IndexPath can be set to null if there is only one property in the index.
Object start
Where to start the range search. For instance, if the index is [Mode,Map,Score] and indexPath is ["expert","skyland"], then start defines the minimum score to include in the results.
Object stop
Where to stop the range search. For instance, if the index is [Mode,Map,Score] and indexPath is ["expert","skyland"], then stop defines the maximum score to include in the results.
int limit
The max amount of objects to return.
Callback<DatabaseObject[]> callback
The callback that will be used to return results. On success its onSuccess method will be called, otherwise its onError method.

Throws

PlayerIOError

BigDB.loadSingle

public void
loadSingle (String table, String index, Object[] indexValue, Callback<DatabaseObject> callback)

Load a database object from a table using the specified index.

Arguments

String table
The table to load the database object from.
String index
The name of the index to query for the database object.
Object[] indexValue
An array of objects of the same types as the index properties, specifying which object to load.
Callback<DatabaseObject> callback
The callback that will be used to return results. On success its onSuccess method will be called, otherwise its onError method.

Throws

PlayerIOError

BigDB.saveChanges

public void
saveChanges (boolean useOptimisticLock, boolean fullOverwrite, DatabaseObject[] objects, Callback<Void> callback)

Save changes to one or more database objects in one go.

Arguments

boolean useOptimisticLock
Should the save only go through, if no other process has modified the object since it 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.
DatabaseObject[] objects
The objects with changes to save.
Callback<Void> callback
The callback that will be used to return results. On success its onSuccess method will be called, otherwise its onError method.

Throws

PlayerIOError, InterruptedException