Package 

Class ModelStore

  • All Implemented Interfaces:
    com.onesignal.common.events.IEventNotifier , com.onesignal.common.modeling.IModelChangedHandler , com.onesignal.common.modeling.IModelStore

    
    public abstract class ModelStore<TModel extends Model>
     implements IEventNotifier<IModelStoreChangeHandler<TModel>>, IModelStore<TModel>, IModelChangedHandler
                        

    The abstract implementation of a model store. Implements all but the create method, which must be implemented by the concrete class as this abstract implementation is not able to derive and instantiate the concrete model type being stored.

    Persistence

    -----------

    When persistence is enabled for this model store (i.e. a name and _prefs parameters are provided on initialization) any Model that has been added to the model store will be persisted, including any update to that model, when that property update drives a IModelChangedHandler.onChanged event. If a model property update does not drive a IModelChangedHandler.onChanged event but persistence is still desired, there is a persist method that can be called at any time.

    Instantiating this model store with persistence will load any previously persisted models as part of its initialization process.

    • Method Detail

      • getName

         final String getName()

        The persistable name of the model store. If not specified no persisting will occur.

      • add

         Unit add(TModel model, String tag)

        Add a new model to this model store. Once added, any changes to the model will trigger calls to an IModelStoreChangeHandler that has subscribed to this model store. This same instance is also retrievable via get based on Model.id.

        Parameters:
        model - The model being added to the model store.
        tag - The tag which identifies how/why the model is being added.
      • add

         Unit add(Integer index, TModel model, String tag)

        Add a new model to this model store. Once added, any changes to the model will trigger calls to an IModelStoreChangeHandler that has subscribed to this model store. This same instance is also retrievable via get based on Model.id.

        Parameters:
        index - The index to add it under
        model - The model being added to the model store.
        tag - The tag which identifies how/why the model is being added.
      • get

         TModel get(String id)

        Retrieve the model associated to the id provided.

        Parameters:
        id - The unique identifier for the model to retrieve.
      • remove

         Unit remove(String id, String tag)

        Remove the model associated to the id provided from the model store.

        Parameters:
        id - The unique identifier to the model to remove.
        tag - The tag which identifies how/why the model is being removed.
      • onChanged

         Unit onChanged(ModelChangedArgs args, String tag)

        Called when the subscribed model has been changed.

        Parameters:
        args - Information related to what has changed.
        tag - The tag which identifies how/why the model was changed.
      • replaceAll

         Unit replaceAll(List<TModel> models, String tag)

        Replace all models in the store with the provided models.

        Parameters:
        models - The models to track in the model store.
        tag - The tag which identifies how/why the model store is being replaced.
      • clear

         Unit clear(String tag)

        Remove all models from the store.

        Parameters:
        tag - The tag which identifies how/why the model store is being cleared.
      • persist

         final Unit persist()

        Any models added or changed before load is called are not persisted, to avoid overwriting the cache. The time between any changes and loading from cache should be minuscule so lack of persistence is safe. This is primarily to address operations which can enqueue before load() is called.