Skip to content

Bulk Delete Listener

Listeners for bulk deletion work identically to the ones for single deletion. The difference is in the method names to add and remove listener objects:

Conditional bulk delete listener

A conditional bulk delete listener receives an event when an API client uses the bulkDelete API to delete multiple objects in a table with the same whereClause statement as specified by the RT client:

EventHandlerForClass *eventHandler = [Backendless.shared.data of:[Order class]].rt;
RTSubscription *subscription = [eventHandler addBulkDeleteListenerWithWhereClause:@"orderAmount > 1000" responseHandler:^(BulkEvent *bulkEvent) {
    NSLog(@"%@ objects with %@ have been deleted", bulkEvent.count, bulkEvent.whereClause);
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];
let eventHandler = Backendless.shared.data.of(Order.self).rt
let subscription = eventHandler?.addBulkDeleteListener(whereClause: "orderAmount > 1000", responseHandler: { bulkEvent in
    print("\(bulkEvent.count ?? 0) objects with \(bulkEvent.whereClause ?? "no where clause") have been deleted")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

EventHandlerForMap *eventHandler = [Backendless.shared.data ofTable:@"Order"].rt;
RTSubscription *subscription = [eventHandler addBulkDeleteListenerWithWhereClause:@"orderAmount > 1000" responseHandler:^(BulkEvent *bulkEvent) {
    NSLog(@"%@ objects with %@ have been deleted", bulkEvent.count, bulkEvent.whereClause);
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];
let eventHandler = Backendless.shared.data.ofTable("Order")
let subscription = eventHandler?.addBulkDeleteListener(whereClause: "orderAmount > 1000", responseHandler: { bulkEvent in
    print("\(bulkEvent.count ?? 0) objects with \(bulkEvent.whereClause ?? "no where clause") have been deleted")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

Unconditional bulk delete listener

A unconditional bulk delete listener receives events when a client uses the bulkDelete API with any whereClause statement:

EventHandlerForClass *eventHandler = [Backendless.shared.data of:[Order class]].rt;
RTSubscription *subscription = [eventHandler addBulkDeleteListenerWithResponseHandler:^(BulkEvent *bulkEvent) {
    NSLog(@"%@ objects have been deleted", bulkEvent.count);
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];
let eventHandler = Backendless.shared.data.of(Order.self).rt
let subscription = eventHandler?.addBulkDeleteListener(responseHandler: { bulkEvent in
    print("\(bulkEvent.count ?? 0) objects have been deleted")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

EventHandlerForMap *eventHandler = [Backendless.shared.data ofTable:@"Order"].rt;
RTSubscription *subscription = [eventHandler addBulkDeleteListenerWithResponseHandler:^(BulkEvent *bulkEvent) {
    NSLog(@"%@ objects have been deleted", bulkEvent.count);
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];
let eventHandler = Backendless.shared.data.ofTable("Order").rt
let subscription = eventHandler?.addBulkDeleteListener(responseHandler: { bulkEvent in
    print("\(bulkEvent.count ?? 0) objects have been deleted")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

Both conditional and unconditional event listeners receive the following information in the callback object. The properties listed below are included  into the BulkEvent object delivered to the listener's callback.

  • whereClause - the where clause value used in the API call to identify the objects deleted from the database.
  • count - the number of objects deleted from the database.

Removing listeners

The method removes all registered listeners for the bulkDelete event:

// for the class-based approach:
EventHandlerForClass *eventHandler = [Backendless.shared.data of:[Order class]].rt;
[eventHandler removeBulkDeleteListeners];

// for the map-based approach:
EventHandlerForMap *eventHandler = [Backendless.shared.data ofTable:@"Order"].rt;
[eventHandler removeBulkDeleteListeners];
// for the class-based approach:
let eventHandler = Backendless.shared.data.of(Order.self).rt
eventHandler?.removeBulkDeleteListeners()

// for the map-based approach:
let eventHandler = Backendless.shared.data.ofTable("Order").rt
eventHandler?.removeBulkDeleteListeners()

The method below removes all listeners which process events for a specific where clause. The value of the whereClause argument must be the same as one in the addBulkDeleteListener method:

// for the class-based approach:
EventHandlerForClass *eventHandler = [Backendless.shared.data of:[Order class]].rt;
[eventHandler removeBulkDeleteListenersWithWhereClause:@"orderAmount > 1000"];

// for the map-based approach:
EventHandlerForMap *eventHandler = [Backendless.shared.data ofTable:@"Order"].rt;
[eventHandler removeBulkDeleteListenersWithWhereClause:@"orderAmount > 1000"];
// for the class-based approach:
let eventHandler = Backendless.shared.data.of(Order.self).rt
eventHandler?.removeBulkDeleteListeners(whereClause: "orderAmount > 1000")

// for the map-based approach:
let eventHandler = Backendless.shared.data.ofTable("Order").rt
eventHandler?.removeBulkDeleteListeners(whereClause: "orderAmount > 1000")

Removing a specific listener

This method removes a listener identified by subscription that contains this listener:

// for the class-based approach:
EventHandlerForClass *eventHandler = [Backendless.shared.data of:[Order class]].rt;
RTSubscription *subscription = [eventHandler addBulkDeleteListenerWithResponseHandler:^(BulkEvent *bulkEvent) {
    NSLog(@"%@ objects have been deleted", bulkEvent.count);
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];

[subscription stop];

// for the map-based approach:
EventHandlerForMap *eventHandler = [Backendless.shared.data ofTable:@"Order"].rt;
RTSubscription *subscription = [eventHandler addBulkDeleteListenerWithResponseHandler:^(BulkEvent *bulkEvent) {
    NSLog(@"%@ objects have been deleted", bulkEvent.count);
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];

[subscription stop];
// for the class-based approach:
let eventHandler = Backendless.shared.data.of(Order.self).rt
let subscription = eventHandler?.addBulkDeleteListener(responseHandler: { bulkEvent in
    print("\(bulkEvent.count ?? 0) objects have been deleted")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

subscription?.stop()

// for the map-based approach:
let eventHandler = Backendless.shared.data.ofTable("Order").rt
let subscription = eventHandler?.addBulkDeleteListener(responseHandler: { bulkEvent in
    print("\(bulkEvent.count ?? 0) objects have been deleted")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

subscription?.stop()