Nested Async Queries

I am looking for some guidance / recommendation for nesting async queries; calling second async after the first async has completed. I have looked through most of your examples and I finally found one where you show nesting of query in searchByDateInCategoryAsync() . Can this technique be used to nest all CRUD operation?

public void searchByDateInCategoryAsync() throws ParseException
{
// date
SimpleDateFormat dateFormat = new SimpleDateFormat( "dd.MM.yyyy 'at' HH:mm" );
final Date updated = dateFormat.parse( "17.01.2015 at 12:00" );
// create
GeoPoint geoPoint = new GeoPoint( 21.306944, -157.858333 );
geoPoint.addCategory( "Coffee" );
geoPoint.addMetadata( "Name", "Starbucks" );
geoPoint.addMetadata( "Parking", true );
geoPoint.addMetadata( "updated", new Date().getTime() );
Backendless.Geo.savePoint( geoPoint, new AsyncCallback<GeoPoint>()
{
@Override
public void handleResponse( GeoPoint geoPoint )
{
System.out.println( String.format( "searchByDateInCategory -> point: %s", geoPoint ) );
// search
BackendlessGeoQuery query = new BackendlessGeoQuery( Arrays.asList( "Coffee" ) );
query.setWhereClause( String.format( "updated > %d", updated.getTime() ) );
query.setIncludeMeta( true );
Backendless.Geo.getPoints( query, new AsyncCallback<BackendlessCollection<GeoPoint>>()
{
@Override
public void handleResponse( BackendlessCollection<GeoPoint> points )
{
System.out.println( String.format( "searchByDateInCategory GETPOINTS: %s", points.getCurrentPage() ) );
}
@Override
public void handleFault( BackendlessFault fault )
{
System.err.println( String.format( "searchByDateInCategory FAULT = %s", fault ) );
}
} );
}
@Override
public void handleFault( BackendlessFault fault )
{
System.err.println( String.format( "searchByDateInCategory SAVEPOINT: %s", fault ) );
}
} );
}

Hi Barry,

I would not call it a “technique”, it is simply a logical flow of your app. In the code you showed, you save a geopoint and when that operation is complete, you run a query. There is absolutely nothing that would preclude you from executing any kind of operation in a response handler.

Regards,
Mark