Once an object is stored in the Backendless data storage, any of its properties (except for the system ones) can be updated using the data update API. The API works the same way as the initial call for saving the object. To update a property value, simply modify it in the instance representing the saved object. The example below retrieves a saved object, modifies the “name” property and saves it back in the data store.
Deleting an object in Backendless using the API is just as easy as creating or updating one. If an object has relations, they are broken up and the related objects are not deleted. The sample below retrieves the first object from a table and deletes it:
Person class – corresponds to the Person table show below:
public class Person
public int age;
public String name;
public Date birthdate;
public String objectId;
In my previous post I wrote how to load the first object from a data table using API. For the symmetry (and out of common sense) there is also API to load the last object from a data table. The last object is determined by the time when it is saved in the data storage. The most recently created (notice it is not the updated one) object is what the API returns.
There is an API for loading the very first object created in the table. The first object is determined by the value in the created column – Backendless picks the one with the smallest timestamp. The code below demonstrating loading an object from the Person table:
As data objects are being saved or updated with the API requests some properties of the objects may not have a value assigned to them. It may be necessary that for those properties a default value is assigned. This is identical to how relational databases may have a default value for a column.
Configuring a default value for a column is very easy. You can set it when you declare a column or after a column is already created.
Alternatively, when a column already exists in a table schema, there is a field which displays and lets you edit the default value:
Once a default value is assigned to a column, it becomes immediately effective. When an object is saved or updated does not have a value for a property corresponding to the column, Backendless inserts the default value.
Backendless provides an easy to use API to introspect data tables. Given a table name, the API provides information about table columns, their names, data types, default values, etc. If a column represents a relationship, it is properly denoted as such in the provided information.
The logout API is a logical counterpart for the User Login API. The logout step is not required for most apps – user session will expire automatically. However, some apps provide the functionality, especially those with a special multiple login policy. The logout API is very simple – a single line of code terminates the current session:
In my previous post I described how to adjust object’s access control list (ACL) using Backendless console. As I mentioned, in addition to console, object’s permissions can be controlled using API. In fact, for any persisted object, Backendless supports the following capabilities:
granting/rejecting permission to execute find/save/update/delete operation on an object to:
The general API usage pattern is:
DataPermission.<OPERATON>.grantForUser( userObjectId, dataObject )
DataPermission.<OPERATON>.denyForAllRoles( dataObject )
Every data objects saved in Backendless has its own access control list (ACL). Object’s ACL includes permissions for users and roles for all Data service operations. Using ACL an application may be configured to allow users (and/or roles they belong to) to be able to execute Data Service API calls. For example, in a shopping app you may have the Customer and SupportRep roles. Users in the Customer role may have the permission to create and update objects in the Incident table, but may not delete them. A user in the SupportRep role may have the permission to delete those objects.
Object ACL configuration can be done via API or Backendless console. This post review the latter. To get to the ACL screen for a specific object:
Previously I wrote about how to store and retrieve objects to and from server-side in-memory cache. Quite often when working with cache, it is required to check if an object already exists in cache. Backendless provides an API for that function. The code below checks if an object exists in cache, if not, it places it in there and then runs the existence check again: