Class InboxDatasource


  • public final class InboxDatasource
    extends java.lang.Object
    Inbox datasource. Wraps SQLite queries (DAO).
    • Constructor Summary

      Constructors 
      Constructor Description
      InboxDatasource​(android.content.Context context)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean cleanDatabase()
      Remove notifications older than 90 days Also remove related row in other tables
      void close()
      Close the datasource.
      boolean deleteNotifications​(java.util.List<java.lang.String> notificationIds)
      Delete notification by ID
      java.util.List<InboxCandidateNotificationInternal> getCandidateNotifications​(java.lang.String cursor, int limit, long fetcherId)
      Look in database for cached notifications
      protected android.database.sqlite.SQLiteDatabase getDatabase()
      Get database (for test purpose)
      long getFetcherID​(com.batch.android.inbox.FetcherType type, java.lang.String identifier)
      Try to get the fetcher ID from the SQLite Create and insert it if it doesn't exist
      java.util.List<InboxNotificationContentInternal> getNotifications​(java.util.List<java.lang.String> notificationIds, long fetcherId)  
      protected long getNotificationTime​(java.lang.String notificationId)  
      protected boolean insert​(InboxNotificationContentInternal notification, long fetcherId)
      Insert a notification to SQLite.
      boolean insertResponse​(InboxWebserviceResponse response, long fetcherId)
      Add a response's notification to the database
      int markAllAsRead​(long time, long fetcherId)
      Mark all notification received before a specified time as read
      void markNotificationAsDeleted​(java.lang.String notificationID)
      Mark a notification as deleted locally
      void markNotificationAsRead​(java.lang.String notificationID)
      Mark a notification as read
      java.lang.String updateNotification​(JSONObject notification, long fetcherId)
      Read the notification object and update the row in database We update different values depending on what the server actually sent
      void wipeData()
      Clear all content
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • InboxDatasource

        public InboxDatasource​(android.content.Context context)
                        throws android.database.sqlite.SQLiteException
        Throws:
        android.database.sqlite.SQLiteException
    • Method Detail

      • wipeData

        public void wipeData()
        Clear all content
      • close

        public void close()
        Close the datasource. You should not make any other call to this datasource once this has been called.
      • getDatabase

        protected android.database.sqlite.SQLiteDatabase getDatabase()
        Get database (for test purpose)
        Returns:
      • getNotifications

        public java.util.List<InboxNotificationContentInternal> getNotifications​(java.util.List<java.lang.String> notificationIds,
                                                                                 long fetcherId)
      • getNotificationTime

        protected long getNotificationTime​(java.lang.String notificationId)
      • getFetcherID

        public long getFetcherID​(com.batch.android.inbox.FetcherType type,
                                 java.lang.String identifier)
        Try to get the fetcher ID from the SQLite Create and insert it if it doesn't exist
        Parameters:
        type -
        identifier -
      • getCandidateNotifications

        public java.util.List<InboxCandidateNotificationInternal> getCandidateNotifications​(@Nullable
                                                                                            java.lang.String cursor,
                                                                                            int limit,
                                                                                            long fetcherId)
        Look in database for cached notifications
        Parameters:
        cursor -
        fetcherId -
        Returns:
      • insertResponse

        public boolean insertResponse​(InboxWebserviceResponse response,
                                      long fetcherId)
        Add a response's notification to the database
        Parameters:
        response - response to add
        fetcherId -
      • insert

        protected boolean insert​(InboxNotificationContentInternal notification,
                                 long fetcherId)
        Insert a notification to SQLite.
        Parameters:
        notification - Notification to insert
        fetcherId - Fetcher id
        Returns:
        If the insert succeeded or not
      • updateNotification

        public java.lang.String updateNotification​(JSONObject notification,
                                                   long fetcherId)
        Read the notification object and update the row in database We update different values depending on what the server actually sent
        Parameters:
        notification -
        fetcherId -
        Returns:
      • markAllAsRead

        public int markAllAsRead​(long time,
                                 long fetcherId)
        Mark all notification received before a specified time as read
        Parameters:
        time -
        fetcherId -
        Returns:
      • markNotificationAsRead

        public void markNotificationAsRead​(java.lang.String notificationID)
        Mark a notification as read
        Parameters:
        notificationID - the notification identifier
      • markNotificationAsDeleted

        public void markNotificationAsDeleted​(java.lang.String notificationID)
        Mark a notification as deleted locally
        Parameters:
        notificationID - the notification identifier
      • deleteNotifications

        public boolean deleteNotifications​(java.util.List<java.lang.String> notificationIds)
        Delete notification by ID
        Parameters:
        notificationIds - IDs of the notifications to delete
        Returns:
        boolean
      • cleanDatabase

        public boolean cleanDatabase()
        Remove notifications older than 90 days Also remove related row in other tables