public final class BaasDocument extends BaasObject implements java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.Object>>, android.os.Parcelable
A document is a schema less JSON like entity that belongs to a given collection on the server.
Documents can be created, stored and retrieved from the server, either synchronously or asynchronously, through the provided methods.
Unlike a raw JSON document, some key names at the top level are reserved: you cannot assign or create properties whose names begin with an underscore or an at sign, the id field is also reserved.
When a document is bound to an entity on the server it's 'id' can be retrieved through BaasDocument.getId().
Documents are versioned by BaasBox and updates with incompatible versions will fail, uless you ignore the
versioning explicitly through SaveMode.IGNORE_VERSION.
| Modifier and Type | Field and Description |
|---|---|
static android.os.Parcelable.Creator<BaasDocument> |
CREATOR |
| Constructor and Description |
|---|
BaasDocument(java.lang.String collection)
Creates a new unbound empty document belonging to the given
collection |
BaasDocument(java.lang.String collection,
android.content.ContentValues values)
Creates a new unbound document that belongs to the given
collection
and with fields initialized from the values ContentValues
values are converted to a JsonObject
using JsonObject.from(android.content.ContentValues) |
BaasDocument(java.lang.String collection,
JsonObject data)
Creates a new unbound document that belongs to the given
collection
and with fields initialized from the data JsonObject. |
| Modifier and Type | Method and Description |
|---|---|
BaasDocument |
clear()
Removes all the mappings from this document
|
boolean |
contains(java.lang.String name)
Checks if this document contains a mapping with
name key |
static RequestToken |
count(java.lang.String collection,
BaasHandler<java.lang.Long> handler)
Asynchronously retrieves the number of documents readable to the user in
collection. |
static RequestToken |
count(java.lang.String collection,
BaasQuery.Criteria filter,
BaasHandler<java.lang.Long> handler)
Asynchronously retrieves the number of documents readable to the user that match the
filter
in collection. |
static RequestToken |
count(java.lang.String collection,
int flags,
BaasHandler<java.lang.Long> handler)
Asynchronously retrieves the number of documents readable to the user in
collection |
static BaasResult<java.lang.Long> |
countSync(java.lang.String collection)
Synchronously retrieves the number of document readable to the user in
collection |
static BaasResult<java.lang.Long> |
countSync(java.lang.String collection,
BaasQuery.Criteria filter)
Synchronously retrieves the number of document readable to the user that match
filter
in collection |
RequestToken |
delete(BaasHandler<java.lang.Void> handler) |
RequestToken |
delete(int flags,
BaasHandler<java.lang.Void> handler) |
static RequestToken |
delete(java.lang.String collection,
java.lang.String id,
BaasHandler<java.lang.Void> handler) |
static RequestToken |
delete(java.lang.String collection,
java.lang.String id,
int flags,
BaasHandler<java.lang.Void> handler) |
BaasResult<java.lang.Void> |
deleteSync() |
static BaasResult<java.lang.Void> |
deleteSync(java.lang.String collection,
java.lang.String id) |
int |
describeContents() |
static RequestToken |
fetch(java.lang.String collection,
java.lang.String id,
BaasHandler<BaasDocument> handler)
Asynchronously fetches the document identified by
id in collection |
static RequestToken |
fetchAll(java.lang.String collection,
BaasHandler<java.util.List<BaasDocument>> handler)
Asynchronously retrieves the list of documents readable to the user in
collection. |
static RequestToken |
fetchAll(java.lang.String collection,
BaasQuery.Criteria filter,
BaasHandler<java.util.List<BaasDocument>> handler)
Asynchronously retrieves the list of documents readable to the user that match
filter
in collection |
static RequestToken |
fetchAll(java.lang.String collection,
BaasQuery.Criteria filter,
int flags,
BaasHandler<java.util.List<BaasDocument>> handler)
Asynchronously retrieves the list of documents readable to the user
in
collection |
static BaasResult<java.util.List<BaasDocument>> |
fetchAllSync(java.lang.String collection) |
static BaasResult<java.util.List<BaasDocument>> |
fetchAllSync(java.lang.String collection,
BaasQuery.Criteria filter)
Synchronously retrieves the list of documents readable to the user
in
collection |
static BaasResult<BaasDocument> |
fetchSync(java.lang.String collection,
java.lang.String id)
Synchronously fetches a document from the server
|
java.util.Set<java.lang.String> |
fields()
Returns a
java.util.Set of all the keys contained in this document |
static BaasDocument |
from(JsonObject data)
Returns a new BaasDocument from it's raw json representation
|
JsonArray |
getArray(java.lang.String name)
|
JsonArray |
getArray(java.lang.String name,
JsonArray otherwise)
|
java.lang.String |
getAuthor()
The username of the owner of this object, or null if this object is new.
|
byte[] |
getBinary(java.lang.String name)
Returns the value mapped to
name as a byte[] array
or null if the mapping is absent. |
byte[] |
getBinary(java.lang.String name,
byte[] otherwise)
Returns the value mapped to
name as a byte[] array
or otherwise if the mapping is absent. |
java.lang.Boolean |
getBoolean(java.lang.String name)
Returns the value mapped to
name as a Boolean
or null if the mapping is absent. |
boolean |
getBoolean(java.lang.String name,
boolean otherwise)
Returns the value mapped to
name as a boolean
or otherwise if the mapping is absent. |
java.lang.String |
getCollection()
Returns the collection to which this document belongs.
|
java.lang.String |
getCreationDate()
The date this object was created on the server, or null if the object is new.
|
java.lang.Double |
getDouble(java.lang.String name)
Returns the value mapped to
name as a Double
or null if the mapping is absent. |
double |
getDouble(java.lang.String name,
double otherwise)
Returns the value mapped to
name as a double
or otherwise if the mapping is absent. |
java.lang.Float |
getFloat(java.lang.String name)
Returns the value mapped to
name as a Float
or null if the mapping is absent. |
float |
getFloat(java.lang.String name,
float otherwise)
Returns the value mapped to
name as a float
or otherwise if the mapping is absent. |
java.lang.String |
getId()
The id of this object on the server.
|
java.lang.Integer |
getInt(java.lang.String name)
Returns the value mapped to
name as a Integer
or null if the mapping is absent. |
int |
getInt(java.lang.String name,
int otherwise)
Returns the value mapped to
name as a int
or otherwise if the mapping is absent. |
java.lang.Long |
getLong(java.lang.String name)
Returns the value mapped to
name as a Long
or null if the mapping is absent. |
long |
getLong(java.lang.String name,
long otherwise)
Returns the value mapped to
name as a long
or otherwise if the mapping is absent. |
JsonObject |
getObject(java.lang.String name)
|
JsonObject |
getObject(java.lang.String name,
JsonObject otherwise)
|
java.lang.String |
getString(java.lang.String name)
Returns the value mapped to
name as a String
or null if the mapping is absent. |
java.lang.String |
getString(java.lang.String name,
java.lang.String otherwise)
Returns the value mapped to
name as a String
or otherwise if the mapping is absent. |
JsonStructure |
getStructure(java.lang.String name)
|
JsonStructure |
getStructure(java.lang.String name,
JsonStructure otherwise)
|
long |
getVersion()
The version number of this object.
|
RequestToken |
grant(Grant grant,
java.lang.String username,
int flags,
BaasHandler<java.lang.Void> handler)
Asynchronously grants the access
grant to this object to username. |
RequestToken |
grantAll(Grant grant,
java.lang.String role,
int flags,
BaasHandler<java.lang.Void> handler)
Asynchronously grants the access
grant to this object to users with role. |
BaasResult<java.lang.Void> |
grantAllSync(Grant grant,
java.lang.String role)
Synchronously grants the acces
grant to this object to all users in role |
BaasResult<java.lang.Void> |
grantSync(Grant grant,
java.lang.String username)
Synchronously grants the access
grant to this object to username. |
boolean |
isDirty() |
boolean |
isDocument() |
boolean |
isFile() |
boolean |
isNull(java.lang.String name)
Checks if
name maps explicitly to null |
java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.Object>> |
iterator()
Returns an
Iterator over the mappings of this document |
BaasDocument |
merge(JsonObject other)
Merges the content of
other into this
document overwriting any mapping for wich other contains a key. |
BaasDocument |
put(java.lang.String name,
boolean value)
Associate
name key to the boolean value
in this document. |
BaasDocument |
put(java.lang.String name,
byte[] value)
Associate
name key to the byte[] value
in this document. |
BaasDocument |
put(java.lang.String name,
double value)
Associate
name key to the double value
in this document. |
BaasDocument |
put(java.lang.String name,
JsonArray value)
|
BaasDocument |
put(java.lang.String name,
JsonObject value)
|
BaasDocument |
put(java.lang.String name,
long value)
Associate
name key to the long value
in this document. |
BaasDocument |
put(java.lang.String name,
java.lang.String value)
Associate
name key to the String value
in this document. |
BaasDocument |
putNull(java.lang.String name)
Puts an explicit mapping to from
name to null
in this document. |
RequestToken |
refresh(BaasHandler<BaasDocument> handler)
Asynchronously refresh the content of this document.
|
BaasResult<BaasDocument> |
refreshSync()
Synchronously refresh the content of this document
|
java.lang.Object |
remove(java.lang.String name)
Removes the mapping with
name key from the document. |
RequestToken |
revoke(Grant grant,
java.lang.String username,
int flags,
BaasHandler<java.lang.Void> handler)
Asynchronously revoke the access
grant to this object to username. |
RequestToken |
revokeAll(Grant grant,
java.lang.String role,
int flags,
BaasHandler<java.lang.Void> handler)
Asynchronously revokes the access
grant to this object from users with role. |
BaasResult<java.lang.Void> |
revokeAllSync(Grant grant,
java.lang.String role)
Synchronously revokes the acces
grant to this object from all users in role |
BaasResult<java.lang.Void> |
revokeSync(Grant grant,
java.lang.String username)
Synchronously revokes the access
grant to this object from username. |
RequestToken |
save(BaasHandler<BaasDocument> handler) |
RequestToken |
save(SaveMode mode,
BaasHandler<BaasDocument> handler) |
RequestToken |
save(SaveMode mode,
int flags,
BaasHandler<BaasDocument> handler) |
BaasResult<BaasDocument> |
saveSync() |
BaasResult<BaasDocument> |
saveSync(SaveMode mode) |
int |
size()
Returns the number of mappings contained in this document.
|
JsonObject |
toJson() |
JsonArray |
values()
Returns a
JsonArray representation
of the values contained in this document. |
void |
writeToParcel(android.os.Parcel dest,
int flags) |
asDocument, asFile, grant, grantAll, isNew, revoke, revokeAllpublic static android.os.Parcelable.Creator<BaasDocument> CREATOR
public BaasDocument(java.lang.String collection)
collectioncollection - a non empty collection name.java.lang.IllegalArgumentException - if collection name is emptypublic BaasDocument(java.lang.String collection,
JsonObject data)
collection
and with fields initialized from the data JsonObject.
Data cannot contain reserved property names at the top level.
Note that the JSON data is copied in the document, so modifications to the original instance will
not be reflected by the document.collection - a non empty collection name.data - a possibly null JsonObjectjava.lang.IllegalArgumentException - if collection name is empty or data contains reserved fieldspublic BaasDocument(java.lang.String collection,
android.content.ContentValues values)
collection
and with fields initialized from the values ContentValues
values are converted to a JsonObject
using JsonObject.from(android.content.ContentValues)collection - a non empty collection name.values - a possibly null ContentValuesjava.lang.IllegalArgumentException - if collection name is empty or values contains reserved fields namespublic static BaasDocument from(JsonObject data)
data - public final boolean isDocument()
isDocument in class BaasObjectpublic final boolean isFile()
isFile in class BaasObjectpublic JsonObject toJson()
public static RequestToken fetchAll(java.lang.String collection, BaasHandler<java.util.List<BaasDocument>> handler)
collection.collection - the collection to retrieve not nullhandler - a callback to be invoked with the result of the requestRequestToken to handle the asynchronous requestpublic static RequestToken fetchAll(java.lang.String collection, BaasQuery.Criteria filter, BaasHandler<java.util.List<BaasDocument>> handler)
filter
in collectioncollection - the collection to retrieve not nullfilter - a filter to apply to the requesthandler - a callback to be invoked with the result of the requestRequestToken to handle the asynchronous requestpublic static RequestToken fetchAll(java.lang.String collection, BaasQuery.Criteria filter, int flags, BaasHandler<java.util.List<BaasDocument>> handler)
collectioncollection - the collection to retrieve not nullflags - RequestOptionshandler - a callback to be invoked with the result of the requestRequestToken to handle the asynchronous requestpublic static BaasResult<java.util.List<BaasDocument>> fetchAllSync(java.lang.String collection)
public static BaasResult<java.util.List<BaasDocument>> fetchAllSync(java.lang.String collection, BaasQuery.Criteria filter)
collectioncollection - the collection to retrieve not nullpublic static RequestToken count(java.lang.String collection, BaasHandler<java.lang.Long> handler)
collection.collection - the collection to count not nullhandler - a callback to be invoked with the result of the requestRequestToken to handle the asynchronous requestpublic static RequestToken count(java.lang.String collection, BaasQuery.Criteria filter, BaasHandler<java.lang.Long> handler)
filter
in collection.collection - the collection to count not nullfilter - a BaasQuery.Criteria to apply to the request. May be nullhandler - a callback to be invoked with the result of the requestRequestToken to handle the asynchronous requestpublic static RequestToken count(java.lang.String collection, int flags, BaasHandler<java.lang.Long> handler)
collectioncollection - the collection to count not nullflags - RequestOptionshandler - a callback to be invoked with the result of the requestRequestToken to handle the asynchronous requestpublic static BaasResult<java.lang.Long> countSync(java.lang.String collection)
collectioncollection - the collection to count not nullpublic static BaasResult<java.lang.Long> countSync(java.lang.String collection, BaasQuery.Criteria filter)
filter
in collectioncollection - the collection to count not nullfilter - a filter to apply to the requestpublic static RequestToken fetch(java.lang.String collection, java.lang.String id, BaasHandler<BaasDocument> handler)
id in collectioncollection - the collection to retrieve the document from. Not nullid - the id of the document to retrieve. Not nullhandler - a callback to be invoked with the result of the requestRequestToken to handle the asynchronous requestpublic static BaasResult<BaasDocument> fetchSync(java.lang.String collection, java.lang.String id)
collection - the collection to retrieve the document from. Not nullid - the id of the document to retrieve. Not nullpublic BaasResult<BaasDocument> refreshSync()
java.lang.IllegalStateException - if this document has no idpublic static RequestToken delete(java.lang.String collection, java.lang.String id, BaasHandler<java.lang.Void> handler)
public static RequestToken delete(java.lang.String collection, java.lang.String id, int flags, BaasHandler<java.lang.Void> handler)
public static BaasResult<java.lang.Void> deleteSync(java.lang.String collection, java.lang.String id)
public RequestToken save(SaveMode mode, int flags, BaasHandler<BaasDocument> handler)
public BaasResult<BaasDocument> saveSync(SaveMode mode)
public final java.lang.String getAuthor()
BaasObjectgetAuthor in class BaasObjectpublic final java.lang.String getCollection()
public final java.lang.String getId()
BaasObjectgetId in class BaasObjectpublic final long getVersion()
BaasObjectgetVersion in class BaasObjectpublic java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.Object>> iterator()
Iterator over the mappings of this documentiterator in interface java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.Object>>public int describeContents()
describeContents in interface android.os.Parcelablepublic void writeToParcel(android.os.Parcel dest,
int flags)
writeToParcel in interface android.os.Parcelablepublic BaasDocument clear()
public boolean contains(java.lang.String name)
name keyname - a non null keytrue if the document contains the mapping false otherwisepublic RequestToken delete(BaasHandler<java.lang.Void> handler)
public RequestToken delete(int flags, BaasHandler<java.lang.Void> handler)
public BaasResult<java.lang.Void> deleteSync()
public JsonArray getArray(java.lang.String name)
name - a non null keyname or nullpublic JsonArray getArray(java.lang.String name, JsonArray otherwise)
name - a non null keyotherwise - a default valuename or otherwisepublic byte[] getBinary(java.lang.String name)
name as a byte[] array
or null if the mapping is absent.name - a non null keyname or nullpublic byte[] getBinary(java.lang.String name,
byte[] otherwise)
name as a byte[] array
or otherwise if the mapping is absent.name - a non null keyotherwise - a default valuename or otherwisepublic java.lang.Boolean getBoolean(java.lang.String name)
name as a Boolean
or null if the mapping is absent.name - a non null keyname or nullpublic boolean getBoolean(java.lang.String name,
boolean otherwise)
name as a boolean
or otherwise if the mapping is absent.otherwise - a boolean defaultname - a non null keyname or otherwisepublic final java.lang.String getCreationDate()
BaasObjectgetCreationDate in class BaasObjectpublic java.lang.Double getDouble(java.lang.String name)
name as a Double
or null if the mapping is absent.name - a non null keyname or nullpublic double getDouble(java.lang.String name,
double otherwise)
name as a double
or otherwise if the mapping is absent.otherwise - a double defaultname - a non null keyname or otherwisepublic java.util.Set<java.lang.String> fields()
java.util.Set of all the keys contained in this documentpublic java.lang.Float getFloat(java.lang.String name)
name as a Float
or null if the mapping is absent.name - a non null keyname or nullpublic float getFloat(java.lang.String name,
float otherwise)
name as a float
or otherwise if the mapping is absent.otherwise - a float defaultname - a non null keyname or otherwisepublic java.lang.Integer getInt(java.lang.String name)
name as a Integer
or null if the mapping is absent.name - a non null keyname or nullpublic int getInt(java.lang.String name,
int otherwise)
name as a int
or otherwise if the mapping is absent.otherwise - a int defaultname - a non null keyname or otherwisepublic java.lang.Long getLong(java.lang.String name)
name as a Long
or null if the mapping is absent.name - a non null keyname or nullpublic long getLong(java.lang.String name,
long otherwise)
name as a long
or otherwise if the mapping is absent.otherwise - a long defaultname - a non null keyname or otherwisepublic JsonObject getObject(java.lang.String name)
name - a non null keyname or nullpublic JsonObject getObject(java.lang.String name, JsonObject otherwise)
name - a non null keyotherwise - a default valuename or otherwisepublic java.lang.String getString(java.lang.String name)
name as a String
or null if the mapping is absent.name - a non null keyname or nullpublic java.lang.String getString(java.lang.String name,
java.lang.String otherwise)
name as a String
or otherwise if the mapping is absent.name - a non null keyotherwise - a default valuename or otherwisepublic JsonStructure getStructure(java.lang.String name)
name - a non null keyname or nullpublic JsonStructure getStructure(java.lang.String name, JsonStructure otherwise)
name - a non null keyotherwise - a default valuename or otherwisepublic RequestToken grant(Grant grant, java.lang.String username, int flags, BaasHandler<java.lang.Void> handler)
BaasObjectgrant to this object to username.
The outcome of the request is handed to the provided handler.grant in class BaasObjectgrant - a non null Grantusername - a non null usernameflags - RequestOptionshandler - an handler that will receive the outcome of the request.RequestToken to manage the asynchronous requestpublic RequestToken grantAll(Grant grant, java.lang.String role, int flags, BaasHandler<java.lang.Void> handler)
BaasObjectgrant to this object to users with role.
The outcome of the request is handed to the provided handler.grantAll in class BaasObjectgrant - a non null Grantrole - a non null usernameflags - RequestOptionshandler - an handler that will receive the outcome of the request.RequestToken to manage the asynchronous requestpublic BaasResult<java.lang.Void> grantAllSync(Grant grant, java.lang.String role)
BaasObjectgrant to this object to all users in rolegrantAllSync in class BaasObjectgrant - a non null Grantrole - a non null roleBaasResultpublic BaasResult<java.lang.Void> grantSync(Grant grant, java.lang.String username)
BaasObjectgrant to this object to username.grantSync in class BaasObjectgrant - a non null Grantusername - a non null usernameBaasResultpublic boolean isNull(java.lang.String name)
name maps explicitly to nullname - a non null keytrue if the document contains a mapping from name to null
false otherwisepublic BaasDocument merge(JsonObject other)
other into this
document overwriting any mapping for wich other contains a key.
Note that other is copied before merging.other - JsonObjectother mappings merged inpublic BaasDocument put(java.lang.String name, JsonArray value)
name - a non null keyvalue - a JsonArraypublic BaasDocument put(java.lang.String name, byte[] value)
name key to the byte[] value
in this document.
Note that binary data is encoded using base64 and added as strings in the object.name - a non null keyvalue - a byte[] arraypublic BaasDocument put(java.lang.String name, boolean value)
name key to the boolean value
in this document.name - a non null keyvalue - a boolean valuepublic BaasDocument put(java.lang.String name, double value)
name key to the double value
in this document.name - a non null keyvalue - a double valuepublic BaasDocument put(java.lang.String name, long value)
name key to the long value
in this document.name - a non null keyvalue - a long valuepublic BaasDocument putNull(java.lang.String name)
name to null
in this document.
This is different from not having the mapping at all, to completely remove
the mapping use instead BaasDocument.remove(String)name - a non null keyBaasDocument.remove(String)public BaasDocument put(java.lang.String name, JsonObject value)
name - a non null keyvalue - a JsonObjectpublic BaasDocument put(java.lang.String name, java.lang.String value)
name key to the String value
in this document.name - a non null keyvalue - a Stringpublic RequestToken refresh(BaasHandler<BaasDocument> handler)
handler - a callback to be invoked with the result of the requestRequestToken to handle the asynchronous requestjava.lang.IllegalStateException - if this document has no idpublic java.lang.Object remove(java.lang.String name)
name key from the document.name - a non null keyname if present or nullpublic RequestToken revoke(Grant grant, java.lang.String username, int flags, BaasHandler<java.lang.Void> handler)
BaasObjectgrant to this object to username.
The outcome of the request is handed to the provided handler.revoke in class BaasObjectgrant - a non null Grantusername - a non null usernameflags - RequestOptionshandler - an handler that will receive the outcome of the request.RequestToken to manage the asynchronous requestpublic RequestToken revokeAll(Grant grant, java.lang.String role, int flags, BaasHandler<java.lang.Void> handler)
BaasObjectgrant to this object from users with role.
The outcome of the request is handed to the provided handler.revokeAll in class BaasObjectgrant - a non null Grantrole - a non null usernameflags - RequestOptionshandler - an handler that will receive the outcome of the request.RequestToken to manage the asynchronous requestpublic BaasResult<java.lang.Void> revokeAllSync(Grant grant, java.lang.String role)
BaasObjectgrant to this object from all users in rolerevokeAllSync in class BaasObjectgrant - a non null Grantrole - a non null roleBaasResultpublic BaasResult<java.lang.Void> revokeSync(Grant grant, java.lang.String username)
BaasObjectgrant to this object from username.revokeSync in class BaasObjectgrant - a non null Grantusername - a non null usernameBaasResultpublic RequestToken save(BaasHandler<BaasDocument> handler)
public RequestToken save(SaveMode mode, BaasHandler<BaasDocument> handler)
public BaasResult<BaasDocument> saveSync()
public int size()
public boolean isDirty()
isDirty in class BaasObject