Missing delete resolver

Before we finish this chapter, it will be useful to create the last missing resolver for StorIO--DeleteResolver. We will add it so that we can use StorIO to the full if there is a need. At the moment, if we try to create a DELETE query with StorIO, it will fail, since there is no mapper for DELETE queries.

To implement DeleteResolver, we will create the StockUpdateDeleteResolver class (similar to before) that extends DefaultDeleteResolver<StockUpdate>:

public class StockUpdateDeleteResolver 
extends DefaultDeleteResolver<StockUpdate> {
}

Also, we will implement mapToDeleteQuery() with this:

@NonNull
@Override
protected DeleteQuery mapToDeleteQuery(@NonNull StockUpdate object) {
return DeleteQuery.builder()
.table(StockUpdateTable.TABLE)
.where(StockUpdateTable.Columns.ID + " = ?")
.whereArgs(object.getId())
.build();
}

This creates a DeleteQuery object that queries the StockUpdate table based on the ID of the object. Later, if it is found, it is deleted.

Finally, this Resolver needs to be added to the configuration next to the other Resolvers:

.deleteResolver(new StockUpdateDeleteResolver())

If we ever want to use the delete functionality of StorIO, it would look something like this:

StorIOFactory.get(this)
.delete()
.object(stockUpdate)
.prepare()
.asRxCompletable()
.subscribe()

It is a very similar approach to the one we used to retrieve entries (.get()), but here we will use .delete(), and we will specify the instance of the object to be deleted.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.138.202