Updating Multiple Objects¶
This API updates multiple objects in a data table with a single request. Consider the following example, it demonstrates an API call which updates all objects in the Person
data table where the value of the property age
is greater than 20
. As a result of the request, all updated objects will have the contactType
property set to "personal"
:
Map<String, Object> changes = new HashMap<>();
changes.put( "contactType", "personal" );
Backendless.Data.of( "Person" ).update( "age > 20", changes, new AsyncCallback<Integer>()
{
@Override
public void handleResponse( Integer objectsUpdated )
{
Log.i( "MYAPP", "Server has updated " + objectsUpdated + " objects" );
}
@Override
public void handleFault( BackendlessFault fault )
{
Log.e( "MYAPP", "Server reported an error - " + fault );
}
} );
Blocking API¶
public int Backendless.Data.of( "TABLE-NAME" ).update(
String whereClause,
Map<String, Object> changes ) throws BackendlessException
public <E> int Backendless.Data.of( E ).update(
String whereClause,
Map<String, Object> changes ) throws BackendlessException
Non-Blocking API¶
public void Backendless.Data.of( "TABLE-NAME" ).update(
String whereClause,
Map<String, Object> changes,
AsyncCallback<Integer> responder )
public <E> void Backendless.Data.of( E ).update(
String whereClause,
Map<String, Object> changes,
AsyncCallback<Integer> responder )
where:
Argument | Description |
---|---|
TABLE-NAME |
Name of the table where the objects expressed via java.util.Map instances will be updated. |
E |
Java class of the data objects to update in the database. |
whereClause |
A condition for selecting objects in the data table which will be updated. |
changes |
An instance of java.util.Map containing the changes which will be applied to all objects in the data table which match the condition expressed via whereClause . |
responder |
a responder object which will receive a callback when the method successfully updates the objects or if an error occurs. Applies to the non-blocking method only. |
Return Value¶
The method returns the number of objects updated in the database.
Codeless Reference¶
where:
Argument | Description |
---|---|
table name |
Name of the data table where records must be updated. |
where clause |
A condition which references a column name and a specific value in the data table where an update has to be carried out. Refer to the Search With The Where Clause topic for more information. |
changes |
This parameter expects an object that must contain the name of the column and a new value to update the existing contents with. |
Return count of updated objects |
Optional parameter. When this box is checked, the operation returns the number of updated objects. |
Returns the number of updated records.
Consider the following records in the employees
data table:
In order to select data that must be updated, the example below sets a condition(where clause) for update operation to "ContactType = 'Personal'"
. As you can see in the screenshot above, the contactType
is the column where two string values Personal
are stored. By setting a condition, the method gets instructed to apply an update in a specific place(contactType
column) and for a specific value(Personal
).
The result of this operation will look as shown below after the Codeless logic runs. The values in the contactType
column were changed from Personal
to Work
.
Moreover, the operation has returned the number 2
, indicating the number of updated objects in the employees
data table.