Skip to content

Commit

Permalink
[BKNDLSS-25586]: Add support for upserted RT events (#511)
Browse files Browse the repository at this point in the history
[BKNDLSS-25586]: Add support for upserted RT events

Co-authored-by: Vladimir Yalovy <[email protected]>
  • Loading branch information
JoeSilentJoe and Vladimir Yalovy authored Jan 19, 2022
1 parent cfdd4bb commit 7650298
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/com/backendless/rt/data/EventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ public interface EventHandler<T> extends RTListener

void removeUpdateListeners( String whereClause );

void addUpsertListener( AsyncCallback<T> callback );

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

void removeUpsertListeners();

void removeUpsertListener( AsyncCallback<T> callback );

void removeUpsertListeners( String whereClause );

void removeUpsertListener( String whereClause, AsyncCallback<T> callback );

void addDeleteListener( AsyncCallback<T> callback );

void addDeleteListener( String whereClause, AsyncCallback<T> callback );
Expand Down Expand Up @@ -61,6 +73,12 @@ public interface EventHandler<T> extends RTListener

void removeBulkUpdateListeners( String whereClause );

void addBulkUpsertListener( AsyncCallback<List> callback );

void removeBulkUpsertListeners();

void removeBulkUpsertListener( AsyncCallback<List<String>> callback );

void addBulkDeleteListener( AsyncCallback<BulkEvent> callback );

void addBulkDeleteListener( String whereClause, AsyncCallback<BulkEvent> callback );
Expand Down
67 changes: 66 additions & 1 deletion src/com/backendless/rt/data/EventHandlerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,49 @@ public void removeUpdateListeners( final String whereClause )
removeListeners( ObjectEvents.updated, whereClause );
}

//--------upsert-------

@Override
public void addUpsertListener( AsyncCallback<T> callback )
{
DataSubscription subscription = new DataSubscription( ObjectEvents.upserted, tableName, createCallback( callback ) );
addEventListener( subscription );
}

@Override
public void addUpsertListener( String whereClause, AsyncCallback<T> callback )
{
DataSubscription subscription = new DataSubscription( ObjectEvents.upserted, tableName, createCallback( callback ) )
.withWhere( whereClause );

addEventListener( subscription );
}

@Override
public void removeUpsertListeners()
{
removeListeners( ObjectEvents.upserted );
}


@Override
public void removeUpsertListener( AsyncCallback<T> callback )
{
removeListeners( ObjectEvents.upserted, callback );
}

@Override
public void removeUpsertListeners( String whereClause )
{
removeListeners( ObjectEvents.upserted, whereClause );
}

@Override
public void removeUpsertListener( String whereClause, AsyncCallback<T> callback )
{
removeListeners( ObjectEvents.upserted, whereClause, callback );
}

//--------remove-------

@Override
Expand Down Expand Up @@ -221,7 +264,29 @@ public void removeBulkUpdateListeners( final String whereClause )
removeListeners( ObjectEvents.bulk_updated, whereClause );
}

//--------bulk-remove-------
//--------bulk-upsert-------

@Override
public void addBulkUpsertListener( AsyncCallback<List> callback )
{
DataSubscription subscription =
new DataSubscription( ObjectEvents.bulk_upserted, tableName, createCallback( callback, List.class ) );
addEventListener( subscription );
}

@Override
public void removeBulkUpsertListeners()
{
removeListeners( ObjectEvents.bulk_upserted );
}

@Override
public void removeBulkUpsertListener( AsyncCallback<List<String>> callback )
{
removeListeners( ObjectEvents.bulk_upserted, callback );
}

//--------bulk-delete-------

@Override
public void addBulkDeleteListener( AsyncCallback<BulkEvent> callback )
Expand Down
4 changes: 3 additions & 1 deletion src/com/backendless/rt/data/ObjectEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public enum ObjectEvents implements RTEvent
bulk_created( "bulk-created" ),
updated( "updated" ),
bulk_updated( "bulk-updated" ),
upserted( "upserted" ),
bulk_upserted( "bulk-upserted" ),
deleted( "deleted" ),
bulk_deleted( "bulk-deleted" );

Expand All @@ -34,4 +36,4 @@ public static ObjectEvents forName( String eventName )

throw new IllegalArgumentException( "There is no object event with name " + eventName );
}
}
}

0 comments on commit 7650298

Please sign in to comment.