Android Client Reference
Class 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 |
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 |
Delete a set of database objects from a table. |
||
public void |
Delete a range of database objects from a table using an index. |
||
public void |
Load the database object with the given key from the given table. |
||
public void |
Loads the database objects with the given keys from the given table. |
||
public void |
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 |
Loads the database object corresponding to the player from the PlayerObjects table. |
||
public void |
Loads or creates the database object with the given key from the given table. |
||
public void |
Load a range of database objects from a table using the specified index. |
||
public void |
Load a database object from a table using the specified index. |
||
public void |
Save changes to one or more database objects in one go. |
BigDB.createObject
public void |
|
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 |
String | key |
DatabaseObject | obj |
Callback<DatabaseObject> | callback |
Throws
PlayerIOError |
BigDB.deleteKeys
public void |
|
Delete a set of database objects from a table.
Arguments
String | table |
String[] | keys |
Callback<Void> | callback |
Throws
PlayerIOError |
BigDB.deleteRange
public void |
|
Delete a range of database objects from a table using an index.
Arguments
String | table |
String | index |
Object[] | indexPath |
Object | start |
Object | stop |
Callback<Void> | callback |
Throws
PlayerIOError |
BigDB.load
public void |
|
Load the database object with the given key from the given table.
Arguments
String | table |
String | key |
Callback<DatabaseObject> | callback |
Throws
PlayerIOError |
BigDB.loadKeys
public void |
|
Loads the database objects with the given keys from the given table.
Arguments
String | table |
String[] | keys |
Callback<DatabaseObject[]> | callback |
Throws
PlayerIOError |
BigDB.loadKeysOrCreate
public void |
|
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 |
String[] | keys |
Callback<DatabaseObject[]> | callback |
Throws
PlayerIOError |
BigDB.loadMyPlayerObject
public void |
|
Loads the database object corresponding to the player from the PlayerObjects table.
Arguments
Callback<DatabaseObject> | callback |
Throws
PlayerIOError |
BigDB.loadOrCreate
public void |
|
Loads or creates the database object with the given key from the given table.
Arguments
String | table |
String | key |
Callback<DatabaseObject> | callback |
Throws
PlayerIOError |
BigDB.loadRange
public void |
|
Load a range of database objects from a table using the specified index.
Arguments
String | table |
String | index |
Object[] | indexPath |
Object | start |
Object | stop |
int | limit |
Callback<DatabaseObject[]> | callback |
Throws
PlayerIOError |
BigDB.loadSingle
public void |
|
Load a database object from a table using the specified index.
Arguments
String | table |
String | index |
Object[] | indexValue |
Callback<DatabaseObject> | callback |
Throws
PlayerIOError |
BigDB.saveChanges
public void |
|
Save changes to one or more database objects in one go.
Arguments
boolean | useOptimisticLock |
boolean | fullOverwrite |
DatabaseObject[] | objects |
Callback<Void> | callback |
Throws
PlayerIOError, InterruptedException |