From 7650298e5cb52e223829a28323874bbce9559614 Mon Sep 17 00:00:00 2001 From: Vladimir Yalovy <45172878+JoeSilentJoe@users.noreply.github.com> Date: Wed, 19 Jan 2022 10:39:16 +0200 Subject: [PATCH] [BKNDLSS-25586]: Add support for upserted RT events (#511) [BKNDLSS-25586]: Add support for upserted RT events Co-authored-by: Vladimir Yalovy --- src/com/backendless/rt/data/EventHandler.java | 18 +++++ .../backendless/rt/data/EventHandlerImpl.java | 67 ++++++++++++++++++- src/com/backendless/rt/data/ObjectEvents.java | 4 +- 3 files changed, 87 insertions(+), 2 deletions(-) diff --git a/src/com/backendless/rt/data/EventHandler.java b/src/com/backendless/rt/data/EventHandler.java index c6c6a454..30953688 100644 --- a/src/com/backendless/rt/data/EventHandler.java +++ b/src/com/backendless/rt/data/EventHandler.java @@ -31,6 +31,18 @@ public interface EventHandler extends RTListener void removeUpdateListeners( String whereClause ); + void addUpsertListener( AsyncCallback callback ); + + void addUpsertListener( String whereClause, AsyncCallback callback ); + + void removeUpsertListeners(); + + void removeUpsertListener( AsyncCallback callback ); + + void removeUpsertListeners( String whereClause ); + + void removeUpsertListener( String whereClause, AsyncCallback callback ); + void addDeleteListener( AsyncCallback callback ); void addDeleteListener( String whereClause, AsyncCallback callback ); @@ -61,6 +73,12 @@ public interface EventHandler extends RTListener void removeBulkUpdateListeners( String whereClause ); + void addBulkUpsertListener( AsyncCallback callback ); + + void removeBulkUpsertListeners(); + + void removeBulkUpsertListener( AsyncCallback> callback ); + void addBulkDeleteListener( AsyncCallback callback ); void addBulkDeleteListener( String whereClause, AsyncCallback callback ); diff --git a/src/com/backendless/rt/data/EventHandlerImpl.java b/src/com/backendless/rt/data/EventHandlerImpl.java index 35707bb3..1877f113 100644 --- a/src/com/backendless/rt/data/EventHandlerImpl.java +++ b/src/com/backendless/rt/data/EventHandlerImpl.java @@ -115,6 +115,49 @@ public void removeUpdateListeners( final String whereClause ) removeListeners( ObjectEvents.updated, whereClause ); } + //--------upsert------- + + @Override + public void addUpsertListener( AsyncCallback callback ) + { + DataSubscription subscription = new DataSubscription( ObjectEvents.upserted, tableName, createCallback( callback ) ); + addEventListener( subscription ); + } + + @Override + public void addUpsertListener( String whereClause, AsyncCallback 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 callback ) + { + removeListeners( ObjectEvents.upserted, callback ); + } + + @Override + public void removeUpsertListeners( String whereClause ) + { + removeListeners( ObjectEvents.upserted, whereClause ); + } + + @Override + public void removeUpsertListener( String whereClause, AsyncCallback callback ) + { + removeListeners( ObjectEvents.upserted, whereClause, callback ); + } + //--------remove------- @Override @@ -221,7 +264,29 @@ public void removeBulkUpdateListeners( final String whereClause ) removeListeners( ObjectEvents.bulk_updated, whereClause ); } - //--------bulk-remove------- + //--------bulk-upsert------- + + @Override + public void addBulkUpsertListener( AsyncCallback 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> callback ) + { + removeListeners( ObjectEvents.bulk_upserted, callback ); + } + + //--------bulk-delete------- @Override public void addBulkDeleteListener( AsyncCallback callback ) diff --git a/src/com/backendless/rt/data/ObjectEvents.java b/src/com/backendless/rt/data/ObjectEvents.java index 54b927ee..f361e58b 100644 --- a/src/com/backendless/rt/data/ObjectEvents.java +++ b/src/com/backendless/rt/data/ObjectEvents.java @@ -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" ); @@ -34,4 +36,4 @@ public static ObjectEvents forName( String eventName ) throw new IllegalArgumentException( "There is no object event with name " + eventName ); } -} \ No newline at end of file +}