Unconditional Delivery Listeners¶
The where clause
argument in the addCreateListener
method is optional. When it is not provided, the real-time database will deliver any new object created in the database's table:
EventHandler<Map> orderEventHandler = Backendless.Data.of( "Order" ).rt();
orderEventHandler.addCreateListener( new AsyncCallback<Map>()
{
@Override
public void handleResponse( Map createdOrder )
{
Log.i( "MYAPP", "new Order object has been created. Object ID - " + createdOrder.get( "objectId" ) );
}
@Override
public void handleFault( BackendlessFault fault )
{
Log.e( "MYAPP", "Server reported an error " + fault.getDetail() );
}
} );
EventHandler<Order> orderEventHandler = Backendless.Data.of( Order.class ).rt();
orderEventHandler.addCreateListener( new AsyncCallback<Order>()
{
@Override
public void handleResponse( Order createdOrder )
{
Log.i( "MYAPP", "new Order object has been created. Object ID - " + createdOrder.objectId );
}
@Override
public void handleFault( BackendlessFault fault )
{
Log.e( "MYAPP", "Server reported an error " + fault.getDetail() );
}
} );
Codeless Reference
where:
Argument | Description |
---|---|
id |
The unique identifier of the event listener. |
table name |
The name of the data table where the event listener must be registered. |
where clause |
Optional parameter. Condition which determines what events trigger the listener. When this property is not specified, then the operation will retrieve a new object created in the database. For more information about the where clause condition refer to the Search With The Where Clause topic. |
object |
When a listener gets triggered, it assigns an object matching the where clause condition to this variable(object ). |
Returns the object from the data table which has been created, depending on the where clause
condition that tells the listener to catch specific events(changes).
The example below registers a new event listener in the "Order"
data table. When the condition in the where clause
is not specified, it forces the listener to get triggered every time a new object is created in the data table. When the Codeless logic below executes the custom block of code; First the following sentence is printed: "New Order object has been created. ObjectId:"
, then the value of the property objectId
is retrieved from the object
variable and also gets printed.
Note that when the data table is modified and the listener is triggered, it assigns an object from the data table to the object
variable.