public class AVObject extends Object implements android.os.Parcelable
The AVObject is a local representation of data that can be saved and retrieved from the AVOSCloud cloud.
The basic workflow for creating new data is to construct a new AVObject, use put() to fill it with data, and then use save() to persist to the database.
The basic workflow for accessing existing data is to use a AVQuery to specify which existing data to retrieve.
| Modifier and Type | Class and Description |
|---|---|
static class |
AVObject.AVObjectCreator |
static class |
AVObject.Hook |
| Modifier and Type | Field and Description |
|---|---|
protected AVACL |
acl |
static String |
CREATED_AT |
protected String |
createdAt |
static android.os.Parcelable.Creator |
CREATOR |
static Set<String> |
INVALID_KEYS |
static String |
OBJECT_ID |
protected String |
objectId |
protected boolean |
requestStatistic |
static String |
UPDATED_AT |
protected String |
updatedAt |
| Constructor and Description |
|---|
AVObject() |
AVObject(android.os.Parcel in) |
AVObject(String theClassName)
Constructs a new AVObject with no data in it.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(String key,
Object value)
Atomically adds an object to the end of the array associated with a given key.
|
void |
addAll(String key,
Collection<?> values)
Atomically adds the objects contained in a Collection to the end of the array associated with a
given key.
|
void |
addAllUnique(String key,
Collection<?> values)
Atomically adds the objects contained in a Collection to the array associated with a given key,
only adding elements which are not already present in the array.
|
void |
addUnique(String key,
Object value)
Atomically adds an object to the array associated with a given key, only if it is not already
present in the array.
|
protected boolean |
alwaysSaveAllKeyValues() |
protected boolean |
alwaysUsePost() |
protected void |
buildBatchParameterForNonSavedObject(List<AVObject> unSavedChildren,
List requestQueue) |
protected static <T extends AVObject> |
cast(AVObject object,
Class<T> clazz) |
boolean |
containsKey(String key)
Whether this object has a particular key.
|
protected void |
copyFromJson(String jsonStr) |
protected void |
copyFromMap(Map map) |
static AVObject |
create(String className)
Creates a new AVObject based upon a class name.
|
static <T extends AVObject> |
createWithoutData(Class<T> clazz,
String objectId)
Creates a reference to an existing AVObject subclass instance for use in creating associations
between AVObjects.
|
static AVObject |
createWithoutData(String className,
String objectId)
Creates a reference to an existing AVObject for use in creating associations between AVObjects.
|
void |
delete()
Deletes this object on the server.
|
void |
delete(AVDeleteOption option)
Deletes this object on the server.
|
static void |
deleteAll(Collection<? extends AVObject> objects)
Delete AVObject in batch.The objects class name must be the same.
|
static void |
deleteAllInBackground(Collection<? extends AVObject> objects,
DeleteCallback deleteCallback)
Delete AVObject in batch with callback in background.The objects class name must be the same.
|
void |
deleteEventually()
Deletes this object from the server at some unspecified time in the future, even if AVOSCloud
is currently inaccessible.
|
void |
deleteEventually(DeleteCallback callback)
Deletes this object from the server at some unspecified time in the future, even if AVOSCloud
is currently inaccessible.
|
void |
deleteInBackground()
Deletes this object on the server in a background thread.
|
void |
deleteInBackground(AVDeleteOption option)
Deletes this object on the server in a background thread.
|
void |
deleteInBackground(AVDeleteOption option,
DeleteCallback callback)
Deletes this object on the server in a background thread.
|
void |
deleteInBackground(DeleteCallback callback)
Deletes this object on the server in a background thread.
|
int |
describeContents() |
void |
disableAfterHook() |
void |
disableBeforeHook() |
boolean |
equals(Object obj) |
AVObject |
fetch() |
AVObject |
fetch(String includeKeys) |
static List<AVObject> |
fetchAll(List<AVObject> objects)
Fetches all the objects in the provided list.
|
static List<AVObject> |
fetchAllIfNeeded(List<AVObject> objects)
Fetches all the objects that don't have data in the provided list.
|
static void |
fetchAllIfNeededInBackground(List<AVObject> objects,
FindCallback<AVObject> callback)
Fetches all the objects that don't have data in the provided list in the background
|
static void |
fetchAllInBackground(List<AVObject> objects,
FindCallback<AVObject> callback)
Fetches all the objects in the provided list in the background
|
AVObject |
fetchIfNeeded() |
AVObject |
fetchIfNeeded(String includeKeys) |
void |
fetchIfNeededInBackground(GetCallback<AVObject> callback)
If this AVObject has not been fetched (i.e.
|
void |
fetchIfNeededInBackground(String includeKeys,
GetCallback<AVObject> callback)
If this AVObject has not been fetched (i.e.
|
void |
fetchInBackground(GetCallback<AVObject> callback)
Fetches this object with the data from the server in a background thread.
|
void |
fetchInBackground(String includeKeys,
GetCallback<AVObject> callback)
Fetches this object with the data from the server in a background thread.
|
Object |
get(String key)
Access a value.
|
AVACL |
getACL()
Access the AVACL governing this object.
|
<T extends AVFile> |
getAVFile(String key)
Access a AVFile value.
|
AVGeoPoint |
getAVGeoPoint(String key)
Access a AVGeoPoint value.
|
<T extends AVObject> |
getAVObject(String key)
Access a AVObject value.
|
<T extends AVObject> |
getAVObject(String key,
Class<T> clazz) |
<T extends AVUser> |
getAVUser(String key)
Access a AVUser value.
|
<T extends AVUser> |
getAVUser(String key,
Class<T> clazz)
Access a AVUser subclass value.
|
boolean |
getBoolean(String key)
Access a boolean value.
|
byte[] |
getBytes(String key)
Access a byte array value.
|
String |
getClassName()
Accessor to the class name.
|
Date |
getCreatedAt()
This reports time as the server sees it, so that if you create a AVObject, then wait a while,
and then call save(), the creation time will be the time of the first save() call rather than
the time the object was created locally.
|
Date |
getDate(String key)
Access a Date value.
|
double |
getDouble(String key)
Access a double value.
|
int |
getInt(String key)
Access an int value.
|
org.json.JSONArray |
getJSONArray(String key)
Access a JSONArray value.
|
org.json.JSONObject |
getJSONObject(String key)
Access a JSONObject value.
|
List |
getList(String key)
Access a List value
|
<T extends AVObject> |
getList(String key,
Class<T> clazz)
获得一个指定类型的List值
|
long |
getLong(String key)
Access a long value.
|
<V> Map<String,V> |
getMap(String key)
Access a Map value
|
Number |
getNumber(String key)
Access a numerical value.
|
String |
getObjectId()
Accessor to the object id.
|
static <T extends AVObject> |
getQuery(Class<T> clazz)
Create a AVQuery with special sub-class.
|
<T extends AVObject> |
getRelation(String key)
Access or create a Relation value for a key
|
String |
getString(String key)
Access a string value.
|
Date |
getUpdatedAt()
This reports time as the server sees it, so that if you make changes to a AVObject, then wait a
while, and then call save(), the updated time will be the time of the save() call rather than
the time the object was changed locally.
|
String |
getUuid() |
boolean |
has(String key)
Whether this object has a particular key.
|
int |
hashCode() |
boolean |
hasSameId(AVObject other) |
protected Map<String,String> |
headerMap() |
void |
ignoreHook(AVObject.Hook hook) |
void |
increment(String key)
Atomically increments the given key by 1.
|
void |
increment(String key,
Number amount)
Atomically increments the given key by the given number.
|
protected String |
internalClassName() |
protected String |
internalId() |
boolean |
isDataAvailable()
Gets whether the AVObject has been fetched.
|
boolean |
isFetchWhenSave() |
Set<String> |
keySet()
Returns a set view of the keys contained in this object.
|
protected void |
onDataSynchronized() |
protected void |
onSaveFailure() |
protected void |
onSaveSuccess() |
static AVObject |
parseAVObject(String avObjectString)
通过解析AVObject.toString得到的String对象来获取AVObject对象
|
void |
put(String key,
Object value)
Add a key-value pair to this object.
|
protected void |
put(String key,
Object value,
boolean pending) |
protected void |
rebuildInstanceData() |
void |
refresh()
Refreshes this object with the data from the server.
|
void |
refresh(String includeKeys)
Refreshes this object with the data from the server.
|
void |
refreshInBackground(RefreshCallback<AVObject> callback)
Refreshes this object with the data from the server in a background thread.
|
void |
refreshInBackground(String includeKeys,
RefreshCallback<AVObject> callback)
Refreshes this object with the data from the server in a background thread.
|
static <T extends AVObject> |
registerSubclass(Class<T> clazz)
Register subclass to AVOSCloud SDK.It must be invocated before AVOSCloud.initialize.
|
void |
remove(String key)
Removes a key from this object's data if it exists.
|
void |
removeAll(String key,
Collection<?> values)
Atomically removes all instances of the objects contained in a Collection from the array
associated with a given key.
|
void |
save()
Saves this object to the server.
|
void |
save(AVSaveOption option)
Saves this object to the server.
|
static void |
saveAll(List<? extends AVObject> objects)
Saves each object in the provided list.
|
static void |
saveAllInBackground(List<? extends AVObject> objects)
Saves each object in the provided list to the server in a background thread.
|
static void |
saveAllInBackground(List<? extends AVObject> objects,
SaveCallback callback)
Saves each object in the provided list to the server in a background thread.
|
void |
saveEventually()
适用于用户并不关心具体保存到服务器的具体时间,或者数据并不需要时常与服务器发生交互时,可以使用本方法 在网络请求遇到异常时,AVOS
Cloud会将此类请求保存到本地,等到网络回复正常或者排除故障以后再发送请求 被保存下来的请求会按照初始的发送顺序进行发送
|
void |
saveEventually(SaveCallback callback)
适用于用户并不关心具体保存到服务器的具体时间,或者数据并不需要时常与服务器发生交互时,可以使用本方法 在网络请求遇到异常时,AVOS
Cloud会将此类请求保存到本地,等到网络回复正常或者排除故障以后再发送请求 被保存下来的请求会按照初始的发送顺序进行发送
|
static void |
saveFileBeforeSave(List<AVFile> files,
boolean sync,
SaveCallback callback) |
void |
saveInBackground()
Saves this object to the server in a background thread.
|
void |
saveInBackground(AVSaveOption option)
Saves this object to the server in a background thread.Use this when you do not have code to
run on completion of the push.
|
void |
saveInBackground(AVSaveOption option,
SaveCallback callback)
Saves this object to the server in a background thread.
|
void |
saveInBackground(SaveCallback callback)
Saves this object to the server in a background thread.
|
void |
setACL(AVACL acl)
Set the AVACL governing this object
|
void |
setFetchWhenSave(boolean fetchWhenSave) |
void |
setObjectId(String newObjectId)
Setter for the object id.
|
protected boolean |
shouldThrowException(Throwable error,
String content) |
org.json.JSONObject |
toJSONObject()
将本对象转化为一个jsonObject
|
String |
toString() |
void |
writeToParcel(android.os.Parcel out,
int i) |
public static final String CREATED_AT
public static final String UPDATED_AT
public static final String OBJECT_ID
protected boolean requestStatistic
protected String objectId
protected String updatedAt
protected String createdAt
protected transient AVACL acl
public static final transient android.os.Parcelable.Creator CREATOR
public AVObject()
public AVObject(String theClassName)
Constructs a new AVObject with no data in it. A AVObject constructed in this way will not have an objectId and will not persist to the database until save() is called.
Class names must be alphanumerical plus underscore, and start with a letter. It is recommended to name classes in CamelCaseLikeThis.
theClassName - The className for this AVObject.public AVObject(android.os.Parcel in)
public org.json.JSONObject toJSONObject()
public boolean isFetchWhenSave()
public void setFetchWhenSave(boolean fetchWhenSave)
public String getUuid()
public static <T extends AVObject> void registerSubclass(Class<T> clazz)
T - AVObject subclassclazz - The subclass.public void add(String key, Object value)
key - The key.value - The object to add.public void addAll(String key, Collection<?> values)
key - The key.values - The objects to add.public static <T extends AVObject> AVQuery<T> getQuery(Class<T> clazz)
T - AVObject subclassclazz - The AVObject subclasspublic void addAllUnique(String key, Collection<?> values)
key - The key.values - The objects to add.public void addUnique(String key, Object value)
key - The key.value - The object to add.public boolean containsKey(String key)
key - The key to check forpublic static AVObject create(String className)
className - The class of object to create.public static AVObject parseAVObject(String avObjectString) throws Exception
avObjectString - string got from AVObject.toStringException - exception during AVObject parse497public static AVObject createWithoutData(String className, String objectId)
className - The object's class.objectId - The object id for the referenced object.public static <T extends AVObject> T createWithoutData(Class<T> clazz, String objectId) throws AVException
T - AVObject subclassclazz - The object's class.objectId - The object id for the referenced object.AVException - exception if clazz instance creation failurepublic void delete()
throws AVException
AVException - Throws an error if the object does not exist or if the internet fails.public void delete(AVDeleteOption option) throws AVException
option - options for server toAVException - Throws an error if the object does not exist or if the internet fails.public static void deleteAll(Collection<? extends AVObject> objects) throws AVException
objects - the AVObject list to be deleted.AVException - Throws an error if any object does not exist or if the internet fails.public static void deleteAllInBackground(Collection<? extends AVObject> objects, DeleteCallback deleteCallback)
objects - objects the AVObject list to be deleted.deleteCallback - deleteCallback.done will be called when api donepublic void deleteEventually()
public void deleteEventually(DeleteCallback callback)
callback - callback which will be called if the delete completes before the app exits.public void deleteInBackground()
public void deleteInBackground(AVDeleteOption option)
option - option or conditions for delete operationpublic void deleteInBackground(AVDeleteOption option, DeleteCallback callback)
option - option or conditions for delete operationcallback - callback.done will be called when the delete completespublic void deleteInBackground(DeleteCallback callback)
callback - callback.done(e) is called when the delete completes.public AVObject fetch() throws AVException
AVExceptionpublic AVObject fetch(String includeKeys) throws AVException
AVExceptionpublic static List<AVObject> fetchAll(List<AVObject> objects) throws AVException
objects - The list of objects to fetch.AVException - Throws an exception if the server returns an error or is inaccessible.public static List<AVObject> fetchAllIfNeeded(List<AVObject> objects) throws AVException
objects - The list of objects to fetch.AVException - Throws an exception if the server returns an error or is inaccessible.public static void fetchAllIfNeededInBackground(List<AVObject> objects, FindCallback<AVObject> callback)
objects - The list of objects to fetch.callback - callback.done(result, e) is called when the fetch completes.public static void fetchAllInBackground(List<AVObject> objects, FindCallback<AVObject> callback)
objects - The list of objects to fetch.callback - callback.done(result, e) is called when the fetch completes.public AVObject fetchIfNeeded() throws AVException
AVExceptionpublic AVObject fetchIfNeeded(String includeKeys) throws AVException
AVExceptionpublic void fetchIfNeededInBackground(GetCallback<AVObject> callback)
callback - callback.done(object, e) is called when the fetch completes.public void fetchIfNeededInBackground(String includeKeys, GetCallback<AVObject> callback)
includeKeys - 以逗号隔开的include字段列表组成的字符串,形如'author,comment'callback - callback.done(object, e) is called when the fetch completes.public void fetchInBackground(GetCallback<AVObject> callback)
callback - callback.done(object, e) is called when the fetch completes.public void fetchInBackground(String includeKeys, GetCallback<AVObject> callback)
includeKeys - 以逗号隔开的include字段列表组成的字符串,例如'author,comment'callback - callback.done(object, e) is called when the fetch completes.public Object get(String key)
key - The key to access the value for.public AVACL getACL()
public boolean getBoolean(String key)
key - The key to access the value for.public byte[] getBytes(String key)
key - The key to access the value for.public String getClassName()
public Date getCreatedAt()
public Date getDate(String key)
key - The key to access the value for.public double getDouble(String key)
key - The key to access the value for.public int getInt(String key)
key - The key to access the value for.public org.json.JSONArray getJSONArray(String key)
key - The key to access the value for.public org.json.JSONObject getJSONObject(String key)
key - The key to access the value for.public List getList(String key)
key - The key to access the value forpublic <T extends AVObject> List<T> getList(String key, Class<T> clazz)
T - AVObject subclasskey - The key to access the value forclazz - specified class type for return listpublic long getLong(String key)
key - The key to access the value for.public <V> Map<String,V> getMap(String key)
V - generic type for map valuekey - The key to access the value forpublic Number getNumber(String key)
key - The key to access the value for.public String getObjectId()
public <T extends AVFile> T getAVFile(String key)
T - AVFile subclasskey - The key to access the value for.public AVGeoPoint getAVGeoPoint(String key)
key - The key to access the value forpublic <T extends AVObject> T getAVObject(String key)
T - AVObject subclasskey - The key to access the value for.public <T extends AVObject> T getAVObject(String key, Class<T> clazz) throws Exception
Exceptionpublic <T extends AVUser> T getAVUser(String key)
T - AVObject subclasskey - The key to access the value for.public <T extends AVUser> T getAVUser(String key, Class<T> clazz)
T - subclass of AVObjectkey - The key to access the value for.clazz - subclass of AVUser as the class of return valuepublic <T extends AVObject> AVRelation<T> getRelation(String key)
key - The key to access the relation for.subclass - of AVObjectpublic String getString(String key)
key - The key to access the value for.public Date getUpdatedAt()
public boolean has(String key)
key - The key to check forpublic boolean hasSameId(AVObject other)
public void increment(String key)
key - The key to increment.public void increment(String key, Number amount)
key - The key to increment.amount - The amount to increment by.public boolean isDataAvailable()
public Set<String> keySet()
public void put(String key, Object value)
key - Keys must be alphanumerical plus underscore, and start with a letter.value - Values may be numerical, String, JSONObject, JSONArray, JSONObject.NULL, or other
AVObjects. value may not be null.public void refresh()
throws AVException
AVException - Throws an exception if the server is inaccessible.public void refresh(String includeKeys) throws AVException
includeKeys - 以逗号隔开的include字段列表字符串,例如'author,comment'AVException - Throws an exception if the server is inaccessible.public void refreshInBackground(RefreshCallback<AVObject> callback)
callback - callback.done(object, e) is called when the refresh completes.public void refreshInBackground(String includeKeys, RefreshCallback<AVObject> callback)
includeKeys - 以逗号隔开的include字段列表字符串,例如'author,comment'callback - callback.done(object, e) is called when the refresh completes.public void remove(String key)
key - The key to remove.public void removeAll(String key, Collection<?> values)
key - The key.values - The objects to remove.public void save()
throws AVException
AVException - exception during save operationpublic void save(AVSaveOption option) throws AVException
option - save optionsAVException - exception during save operationpublic static void saveAll(List<? extends AVObject> objects) throws AVException
objects - The objects to save.AVException - Throws an exception if the server returns an error or is inaccessible.public static void saveAllInBackground(List<? extends AVObject> objects)
objects - The objects to save.public static void saveAllInBackground(List<? extends AVObject> objects, SaveCallback callback)
objects - The objects to save.callback - callback.done(e) is called when the save completes.public void saveEventually()
public void saveEventually(SaveCallback callback)
适用于用户并不关心具体保存到服务器的具体时间,或者数据并不需要时常与服务器发生交互时,可以使用本方法 在网络请求遇到异常时,AVOS Cloud会将此类请求保存到本地,等到网络回复正常或者排除故障以后再发送请求 被保存下来的请求会按照初始的发送顺序进行发送
由于保存的时间无法确定,回调发生时可能已经超出了原来的运行环境,即便发生也没有意义,所以不鼓励用户saveEventually中传入callbackcallback - A callback which will be called if the save completes before the app exits.protected void onSaveSuccess()
protected void onDataSynchronized()
protected void onSaveFailure()
protected void copyFromJson(String jsonStr)
protected void copyFromMap(Map map)
protected boolean alwaysUsePost()
protected String internalId()
protected boolean alwaysSaveAllKeyValues()
protected void buildBatchParameterForNonSavedObject(List<AVObject> unSavedChildren, List requestQueue)
public void saveInBackground()
public void saveInBackground(AVSaveOption option)
option - save optionspublic void saveInBackground(SaveCallback callback)
callback - callback.done(e) is called when the save completes.public void saveInBackground(AVSaveOption option, SaveCallback callback)
option - save optionscallback - callback.done(e) is called when the save completes.public void setACL(AVACL acl)
acl - access control levelpublic void setObjectId(String newObjectId)
newObjectId - id for AVObjectprotected String internalClassName()
public static void saveFileBeforeSave(List<AVFile> files, boolean sync, SaveCallback callback) throws AVException
AVExceptionprotected void rebuildInstanceData()
protected static <T extends AVObject> T cast(AVObject object, Class<T> clazz) throws Exception
Exceptionpublic int describeContents()
describeContents in interface android.os.Parcelablepublic void writeToParcel(android.os.Parcel out,
int i)
writeToParcel in interface android.os.Parcelablepublic void disableBeforeHook()
public void disableAfterHook()
public void ignoreHook(AVObject.Hook hook)
Copyright © 2017. All rights reserved.