Package cn.leancloud

Class LCObject

java.lang.Object
cn.leancloud.LCObject
Direct Known Subclasses:
LCBlockRelation, LCFile, LCFriendship, LCFriendshipRequest, LCInstallation, LCRole, LCStatus, LCUser

public class LCObject extends Object
  • Field Details

  • Constructor Details

    • LCObject

      public LCObject()
      Default constructor.
    • LCObject

      public LCObject(String className)
      Constructor with class name.
      Parameters:
      className - class name.
    • LCObject

      public LCObject(LCObject other)
      Copy constructor.
      Parameters:
      other - other instance.
  • Method Details

    • getClassName

      public String getClassName()
      Get class name.
      Returns:
      class name.
    • internalClassName

      public String internalClassName()
      Get internal class name.
      Returns:
      internal class name.
    • setClassName

      public void setClassName(String name)
      Set class name.
      Parameters:
      name - class name.
    • getCreatedAt

      public Date getCreatedAt()
      Get createdAt date.
      Returns:
      createdAt date.
    • getCreatedAtString

      public String getCreatedAtString()
      Get createdAt string.
      Returns:
      createdAt string.
    • getUpdatedAt

      public Date getUpdatedAt()
      Get updatedAt date.
      Returns:
      updatedAt date.
    • getUpdatedAtString

      public String getUpdatedAtString()
      Get updatedAt string.
      Returns:
      updatedAt string.
    • getObjectId

      public String getObjectId()
      Get objectId.
      Returns:
      objectId.
    • setObjectId

      public void setObjectId(String objectId)
      Set objectId.
      Parameters:
      objectId - object id.
    • isFetchWhenSave

      public boolean isFetchWhenSave()
      Flag to fetchWhenSave.
      Returns:
      flag for fetchWhenSave.
    • setFetchWhenSave

      public void setFetchWhenSave(boolean fetchWhenSave)
      Set fetchWhenSave flag.
      Parameters:
      fetchWhenSave - flag.
    • getUuid

      public String getUuid()
      Get UUID.
      Returns:
      UUID. Caution: public this method just for compatibility.
    • verifyInternalId

      protected static boolean verifyInternalId(String internalId)
    • internalId

      protected String internalId()
    • containsKey

      public boolean containsKey(String key)
      Contain specified key.
      Parameters:
      key - key
      Returns:
      flag to indicate current object contains the specified key or not.
    • has

      public boolean has(String key)
      Contain specified key.
      Parameters:
      key - key
      Returns:
      flag to indicate current object contains the specified key or not.
    • get

      public Object get(String key)
      Get value of specified key.
      Parameters:
      key - specified key.
      Returns:
      the value associated with specified key.
    • internalGet

      protected Object internalGet(String key)
    • getBoolean

      public boolean getBoolean(String key)
      Get boolean value of specified key.
      Parameters:
      key - specified key.
      Returns:
      the boolean value associated with specified key.
    • getBytes

      public byte[] getBytes(String key)
      Get bytes value of specified key.
      Parameters:
      key - specified key.
      Returns:
      the bytes value associated with specified key.
    • getDate

      public Date getDate(String key)
      Get Date value of specified key.
      Parameters:
      key - specified key.
      Returns:
      the Date value associated with specified key.
    • getString

      public String getString(String key)
      Get string value of specified key.
      Parameters:
      key - specified key.
      Returns:
      the string value associated with specified key.
    • getInt

      public int getInt(String key)
      Get int value of specified key.
      Parameters:
      key - specified key.
      Returns:
      the int value associated with specified key.
    • getLong

      public long getLong(String key)
      Get long value of specified key.
      Parameters:
      key - specified key.
      Returns:
      the long value associated with specified key.
    • getDouble

      public double getDouble(String key)
      Get double value of specified key.
      Parameters:
      key - specified key.
      Returns:
      the double value associated with specified key.
    • getNumber

      public Number getNumber(String key)
      Get numeric value of specified key.
      Parameters:
      key - specified key.
      Returns:
      the numeric value associated with specified key.
    • getList

      public List getList(String key)
      Get list value of specified key.
      Parameters:
      key - specified key.
      Returns:
      the list value associated with specified key.
    • getJSONArray

      public JSONArray getJSONArray(String key)
      Get jsonarray value of specified key.
      Parameters:
      key - specified key.
      Returns:
      the jsonarray value associated with specified key.
    • getJSONObject

      public JSONObject getJSONObject(String key)
      Get jsonobject value of specified key.
      Parameters:
      key - specified key.
      Returns:
      the jsonobject value associated with specified key.
    • getLCGeoPoint

      public LCGeoPoint getLCGeoPoint(String key)
      Get AVGeoPoint value of specified key.
      Parameters:
      key - specified key.
      Returns:
      the AVGeoPoint value associated with specified key.
    • getLCFile

      public LCFile getLCFile(String key)
      Get AVFile value of specified key.
      Parameters:
      key - specified key.
      Returns:
      the AVFile value associated with specified key.
    • getLCObject

      public <T extends LCObject> T getLCObject(String key)
      Get AVObject value of specified key.
      Type Parameters:
      T - template type
      Parameters:
      key - specified key.
      Returns:
      the AVObject value associated with specified key.
    • getRelation

      public <T extends LCObject> LCRelation<T> getRelation(String key)
      Get AVRelation value of specified key.
      Type Parameters:
      T - template type
      Parameters:
      key - specified key.
      Returns:
      the AVRelation value associated with specified key.
    • getServerData

      public ConcurrentMap<String,Object> getServerData()
      Get server data.
      Returns:
      map of server data.
    • validFieldName

      protected void validFieldName(String key)
    • isDataAvailable

      public boolean isDataAvailable()
      Flag to indicate data is available or not.
      Returns:
      available flag.
    • add

      public void add(String key, Object value)
      Add attribute.
      Parameters:
      key - target key.
      value - value object.
    • addAll

      public void addAll(String key, Collection<?> values)
      Add collection attribute.
      Parameters:
      key - target key.
      values - values collection.
    • addUnique

      public void addUnique(String key, Object value)
      Add unique attribute.
      Parameters:
      key - target key.
      value - value object.
    • addAllUnique

      public void addAllUnique(String key, Collection<?> values)
      Add unique collection attribute.
      Parameters:
      key - target key.
      values - value collection.
    • put

      public void put(String key, Object value)
      Set attribute.
      Parameters:
      key - target key.
      value - value object.
    • internalPut

      protected void internalPut(String key, Object value)
    • remove

      public void remove(String key)
      Remove attribute.
      Parameters:
      key - target key.
    • removeAll

      public void removeAll(String key, Collection<?> values)
      Remove all collection.
      Parameters:
      key - target keys.
      values - value collection.
    • increment

      public void increment(String key)
      Increment one attribute.
      Parameters:
      key - target key.
    • increment

      public void increment(String key, Number value)
      Increment one attribute.
      Parameters:
      key - target key.
      value - value object.
    • decrement

      public void decrement(String key)
      Decrement one attribute.
      Parameters:
      key - target key.
    • decrement

      public void decrement(String key, Number value)
      Decrement one attribute.
      Parameters:
      key - target key.
      value - value object.
    • bitAnd

      public void bitAnd(String key, long value)
      Modify integer attribute.
      Parameters:
      key - target key.
      value - value object.
    • bitOr

      public void bitOr(String key, long value)
      Modify integer attribute.
      Parameters:
      key - target key.
      value - value object.
    • bitXor

      public void bitXor(String key, long value)
      Modify integer attribute.
      Parameters:
      key - target key.
      value - value object.
    • abortOperations

      public void abortOperations()
      abort all modify operations. Notice: this method doesn't work for AVInstallation.
    • removeOperationForKey

      protected void removeOperationForKey(String key)
    • addNewOperation

      protected void addNewOperation(cn.leancloud.ops.ObjectFieldOperation op)
    • generateChangedParam

      protected JSONObject generateChangedParam()
      save/update with server.
      Returns:
      json object.
    • extractCascadingObjects

      protected List<LCObject> extractCascadingObjects(Object o)
    • generateCascadingSaveObjects

      protected io.reactivex.Observable<List<LCObject>> generateCascadingSaveObjects()
    • extractUnsavedFiles

      protected List<LCFile> extractUnsavedFiles(Object o)
    • getUnsavedFiles

      protected List<LCFile> getUnsavedFiles()
    • onSaveSuccess

      protected void onSaveSuccess()
    • onSaveFailure

      protected void onSaveFailure()
    • onDataSynchronized

      protected void onDataSynchronized()
    • saveInBackground

      public io.reactivex.Observable<? extends LCObject> saveInBackground()
      Save object in background.
      Returns:
      observable instance.
    • saveInBackground

      public io.reactivex.Observable<? extends LCObject> saveInBackground(LCUser asAuthenticatedUser)
      Save object in background.
      Parameters:
      asAuthenticatedUser - explicit user for request authentication.
      Returns:
      observable instance. in general, this method should be invoked in lean engine.
    • saveInBackground

      public io.reactivex.Observable<? extends LCObject> saveInBackground(LCSaveOption option)
      Save object in background.
      Parameters:
      option - save option.
      Returns:
      observable instance.
    • saveInBackground

      public io.reactivex.Observable<? extends LCObject> saveInBackground(LCUser asAuthenticatedUser, LCSaveOption option)
      Save object in background.
      Parameters:
      asAuthenticatedUser - explicit user for request authentication.
      option - save option.
      Returns:
      observable instance. in general, this method should be invoked in lean engine.
    • hasCircleReference

      public boolean hasCircleReference(Map<LCObject,Boolean> markMap)
      judge operations' value include circle reference or not. notice: internal used, pls not invoke it.
      Parameters:
      markMap - markup map.
      Returns:
      flag to indicate there is circle reference or not.
    • save

      public void save()
      Save in blocking mode.
    • save

      public void save(LCUser asAuthenticatedUser)
      Save in blocking mode.
      Parameters:
      asAuthenticatedUser - explicit user for request authentication. in general, this method should be invoked in lean engine.
    • saveAll

      public static void saveAll(Collection<? extends LCObject> objects) throws LCException
      Save All objects in blocking mode.
      Parameters:
      objects - object collection.
      Throws:
      LCException - error happened.
    • saveAll

      public static void saveAll(LCUser asAuthenticatedUser, Collection<? extends LCObject> objects) throws LCException
      Save All objects in blocking mode.
      Parameters:
      asAuthenticatedUser - explicit user for request authentication.
      objects - object collection.
      Throws:
      LCException - error happened. in general, this method should be invoked in lean engine.
    • saveAllInBackground

      public static io.reactivex.Observable<JSONArray> saveAllInBackground(Collection<? extends LCObject> objects)
      Save all objects in async mode.
      Parameters:
      objects - object collection.
      Returns:
      observable instance.
    • saveAllInBackground

      public static io.reactivex.Observable<JSONArray> saveAllInBackground(LCUser asAuthenticatedUser, Collection<? extends LCObject> objects)
      Save all objects in async mode.
      Parameters:
      asAuthenticatedUser - explicit user for request authentication.
      objects - object collection.
      Returns:
      observable instance. in general, this method should be invoked in lean engine.
    • saveEventually

      public void saveEventually() throws LCException
      Save eventually.
      Throws:
      LCException - error happened.
    • saveEventually

      public void saveEventually(LCUser asAuthenticatedUser) throws LCException
      Save eventually.
      Parameters:
      asAuthenticatedUser - explicit user for request authentication.
      Throws:
      LCException - error happened. in general, this method should be invoked in lean engine.
    • deleteEventually

      public void deleteEventually()
      Delete current object eventually.
    • deleteEventually

      public void deleteEventually(LCUser asAuthenticatedUser)
      Delete current object eventually.
      Parameters:
      asAuthenticatedUser - explicit user for request authentication. in general, this method should be invoked in lean engine.
    • deleteInBackground

      public io.reactivex.Observable<LCNull> deleteInBackground()
      Delete current object in async mode.
      Returns:
      observable instance.
    • deleteInBackground

      public io.reactivex.Observable<LCNull> deleteInBackground(LCUser asAuthenticatedUser)
      Delete current object in async mode.
      Parameters:
      asAuthenticatedUser - explicit user for request authentication.
      Returns:
      observable instance. in general, this method should be invoked in lean engine.
    • delete

      public void delete()
      Delete current object in blocking mode.
    • delete

      public void delete(LCUser asAuthenticatedUser)
      Delete current object in blocking mode.
      Parameters:
      asAuthenticatedUser - explicit user for request authentication. in general, this method should be invoked in lean engine.
    • deleteAll

      public static void deleteAll(Collection<? extends LCObject> objects) throws LCException
      Delete all objects in blocking mode.
      Parameters:
      objects - object collection.
      Throws:
      LCException - error happened.
    • deleteAll

      public static void deleteAll(LCUser asAuthenticatedUser, Collection<? extends LCObject> objects) throws LCException
      Delete all objects in blocking mode.
      Parameters:
      asAuthenticatedUser - explicit user for request authentication.
      objects - object collection.
      Throws:
      LCException - error happened. in general, this method should be invoked in lean engine.
    • deleteAllInBackground

      public static io.reactivex.Observable<LCNull> deleteAllInBackground(Collection<? extends LCObject> objects)
      Delete all objects in async mode.
      Parameters:
      objects - object collection.
      Returns:
      observable instance.
    • deleteAllInBackground

      public static io.reactivex.Observable<LCNull> deleteAllInBackground(LCUser asAuthenticatedUser, Collection<? extends LCObject> objects)
      Delete all objects in async mode.
      Parameters:
      asAuthenticatedUser - explicit user for request authentication.
      objects - object collection.
      Returns:
      observable instance. in general, this method should be invoked in lean engine.
    • refresh

      public void refresh()
      Refresh current object in blocking mode.
    • refresh

      public void refresh(String includeKeys)
      Refresh current object in blocking mode.
      Parameters:
      includeKeys - include keys, which object will be return together.
    • refresh

      public void refresh(LCUser asAuthenticatedUser, String includeKeys)
      Refresh current object in blocking mode.
      Parameters:
      asAuthenticatedUser - explicit user for request authentication.
      includeKeys - include keys, which object will be return together. in general, this method should be invoked in lean engine.
    • refreshInBackground

      public io.reactivex.Observable<LCObject> refreshInBackground()
      Refresh current object in async mode.
      Returns:
      observable instance.
    • refreshInBackground

      public io.reactivex.Observable<LCObject> refreshInBackground(LCUser asAuthenticatedUser)
      Refresh current object in async mode.
      Parameters:
      asAuthenticatedUser - explicit user for request authentication.
      Returns:
      observable instance. in general, this method should be invoked in lean engine.
    • refreshInBackground

      public io.reactivex.Observable<LCObject> refreshInBackground(String includeKeys)
      Refresh current object in async mode.
      Parameters:
      includeKeys - include keys, which object will be return together.
      Returns:
      observable instance.
    • refreshInBackground

      public io.reactivex.Observable<LCObject> refreshInBackground(LCUser asAuthenticatedUser, String includeKeys)
      Refresh current object in async mode.
      Parameters:
      asAuthenticatedUser - explicit user for request authentication.
      includeKeys - include keys, which object will be return together.
      Returns:
      observable instance. in general, this method should be invoked in lean engine.
    • fetch

      public LCObject fetch()
      Fetch current object in blocking mode.
      Returns:
      current object.
    • fetch

      public LCObject fetch(String includeKeys)
      Fetch current object in blocking mode.
      Parameters:
      includeKeys - include keys, which object will be return together.
      Returns:
      current object.
    • fetch

      public LCObject fetch(LCUser asAuthenticatedUser, String includeKeys)
      Fetch current object in blocking mode.
      Parameters:
      asAuthenticatedUser - explicit user for request authentication.
      includeKeys - include keys, which object will be return together.
      Returns:
      current object. in general, this method should be invoked in lean engine.
    • fetchInBackground

      public io.reactivex.Observable<LCObject> fetchInBackground()
      Fetch current object in async mode.
      Returns:
      observable instance.
    • fetchInBackground

      public io.reactivex.Observable<LCObject> fetchInBackground(String includeKeys)
      Fetch current object in async mode.
      Parameters:
      includeKeys - include keys, which object will be return together.
      Returns:
      observable instance.
    • fetchInBackground

      public io.reactivex.Observable<LCObject> fetchInBackground(LCUser asAuthenticatedUser, String includeKeys)
      Fetch current object in async mode.
      Parameters:
      asAuthenticatedUser - explicit user for request authentication.
      includeKeys - include keys, which object will be return together.
      Returns:
      observable instance. in general, this method should be invoked in lean engine.
    • fetchIfNeededInBackground

      public io.reactivex.Observable<LCObject> fetchIfNeededInBackground()
      Fetch current object if needed in async mode.
      Returns:
      observable instance.
    • fetchIfNeededInBackground

      public io.reactivex.Observable<LCObject> fetchIfNeededInBackground(String includeKeys)
      Fetch current object if needed in async mode.
      Parameters:
      includeKeys - include keys, which object will be return together.
      Returns:
      observable instance.
    • fetchIfNeededInBackground

      public io.reactivex.Observable<LCObject> fetchIfNeededInBackground(LCUser asAuthenticatedUser, String includeKeys)
      Fetch current object if needed in async mode.
      Parameters:
      asAuthenticatedUser - explicit user for request authentication.
      includeKeys - include keys, which object will be return together.
      Returns:
      observable instance. in general, this method should be invoked in lean engine.
    • fetchIfNeeded

      public LCObject fetchIfNeeded()
      Fetch current object in blocking mode.
      Returns:
      current object.
    • resetAll

      protected void resetAll()
    • resetByRawData

      protected void resetByRawData(LCObject LCObject)
    • resetServerData

      public void resetServerData(Map<String,Object> data)
      Reset server data with new data.
      Parameters:
      data - new data.
    • getRequestRawEndpoint

      public String getRequestRawEndpoint()
      Get request endpoint.
      Returns:
      endpoint.
    • getRequestMethod

      public String getRequestMethod()
      Get request method.
      Returns:
      http method.
    • registerSubclass

      public static <T extends LCObject> void registerSubclass(Class<T> clazz)
      Register subclass to AVOSCloud SDK.It must be invocated before AVOSCloud.initialize.
      Type Parameters:
      T - template type.
      Parameters:
      clazz - The subclass.
      Since:
      1.3.6
    • getACL

      public LCACL getACL()
      get ACL
      Returns:
      acl object.
    • setACL

      public void setACL(LCACL acl)
      Set ACL
      Parameters:
      acl - acl object.
    • generateACLFromServerData

      protected LCACL generateACLFromServerData()
    • getQuery

      public static <T extends LCObject> LCQuery<T> getQuery(Class<T> clazz)
      Get query for class.
      Type Parameters:
      T - result type.
      Parameters:
      clazz - target class.
      Returns:
      query instance.
    • toJSONObject

      public JSONObject toJSONObject()
      Generate a new json object with server data.
      Returns:
      json object.
    • toJSONString

      public String toJSONString()
      Generate a json string.
      Returns:
      json string.
    • parseLCObject

      public static LCObject parseLCObject(String objectString)
      Create AVObject instance from json string which generated by AVObject.toString or AVObject.toJSONString.
      Parameters:
      objectString - json string.
      Returns:
      AVObject instance, null if objectString is null
    • createWithoutData

      public static LCObject createWithoutData(String className, String objectId)
      Create a new instance with particular classname and objectId.
      Parameters:
      className - class name
      objectId - object id
      Returns:
      AVObject instance
    • createWithoutData

      public static <T extends LCObject> T createWithoutData(Class<T> clazz, String objectId) throws LCException
      Create a new instance with particular class and objectId.
      Type Parameters:
      T - template type.
      Parameters:
      clazz - class info
      objectId - object id
      Returns:
      AVObject instance
      Throws:
      LCException - error happened.
    • disableBeforeHook

      public void disableBeforeHook()
      disable beforeXXX Hooks
    • disableAfterHook

      public void disableAfterHook()
      disable afterXXX Hooks
    • ignoreHook

      public void ignoreHook(LCObject.Hook hook)
      ignore specified Hook
      Parameters:
      hook - target Hook.
    • cast

      protected static <T extends LCObject> T cast(LCObject object, Class<T> clazz) throws Exception
      Throws:
      Exception
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object