Skip to content

Conditional Delivery of Upserted Objects

Description

This operation allows registering a conditional event listener for a specific data table. The condition is expressed using the where clause syntax. The listener is triggered only when the upsert operation is invoked and the  specified condition is met.  The event listener will receive only those objects which are being upserted in the database.

Method

public void addUpsertListener( String whereClause, AsyncCallback<T> callback )

where:

Argument                Description
whereClause Optional parameter. String value. Sets the condition for an event listener which gets triggered every time the condition is met when the upsert operation is invoked for a specific data table. For more information about the whereClause syntax, see the Condition Syntax section of the guide.
callback Represents an object returned by the event listener after the upsert operation takes place in the data table. The object contains properties and updated values as presented in the data table.

Return Value

None.

Example

The example below registers a new event listener in the "Person" data table. The listener is triggered when the where clause condition is met, specifically when a new object is updated/inserted in the data table and the value in the "age" property is greater than 30.

EventHandler<Person> eventHandler = Backendless.Data.of( Person.class ).rt();
eventHandler.addUpsertListener( "age > 30", new AsyncCallback<Person>()
{
  @Override
  public void handleResponse( Person response )
  {
    // result handling logic
  }

  @Override
  public void handleFault( BackendlessFault fault )
  {
    // error handling logic
  }
} );

Codeless Reference

rt_database_upsert_conditional_delivery_1

where:

Argument                Description
id Unique identifier of the new event listener.
table name The name of the data table where a conditional event listener must be registered.
where clause Optional parameter. Sets the condition for an event listener which gets triggered every time the condition is met when the upsert operation is invoked for a specific data table. For more information about the where clause syntax, see the Condition Syntax section of the guide.
object When a listener gets triggered, the Backendless delivers a callback object containing the upserted object to the listener.

The example below registers a new event listener for the "Person" data table. The listener is triggered when the where clause condition is met, specifically when a new object is upserted in the data table and the value in the "age" property is greater than 30.

Assume the where clause condition is met, and the Codeless logic below executes a custom block of code; First the following sentence is printed: "Upsert operation has triggered the listener.", then the value of the property objectId is retrieved from the object variable and also gets printed.

rt_database_upsert_conditional_delivery_2