Class AlpineDriver<K,D>

java.lang.Object
co.crystaldev.alpinecore.framework.storage.driver.AlpineDriver<K,D>
Type Parameters:
K - The type of the key
D - The type of the data
Direct Known Subclasses:
FlatfileDriver, MongoDriver, MySqlDriver

public abstract class AlpineDriver<K,D> extends Object
Responsible for saving key-data pairs to a backend source. Used to back an AlpineStore.
Since:
0.1.0
  • Field Details

  • Constructor Details

    • AlpineDriver

      public AlpineDriver(@NotNull @NotNull AlpinePlugin plugin)
  • Method Details

    • persistEntry

      public abstract boolean persistEntry(@NotNull K key, @NotNull D data)
      Save data under a given key.

      Any exceptions generated by this method are swallowed.

      Parameters:
      key - The key
      data - The data to save
      Returns:
      Whether the operation was successful
    • persistEntries

      public boolean persistEntries(@NotNull @NotNull Map<K,D> entries)
      Save multiple data entries under their respective keys.

      This method allows you to save multiple data entries at once by providing a map of key-value pairs. It iterates through the map and calls the persistEntry(Object, Object) method for each entry. Any exceptions generated during the saving process are swallowed for individual entries.

      Parameters:
      entries - A map containing key-value pairs to be saved.
    • deleteEntry

      public abstract boolean deleteEntry(@NotNull K key)
      Delete data under a given key.
      Parameters:
      key - The key
      Returns:
      Whether the operation was successful
    • hasEntry

      public abstract boolean hasEntry(@NotNull K key)
      Check if a key has any saved data.

      Any exceptions generated by this method are swallowed.

      Parameters:
      key - The key
      Returns:
      Whether there is an entry for they key
    • retrieveEntry

      @NotNull public abstract D retrieveEntry(@NotNull K key) throws Exception
      Retrieve data for a given key.

      Due to limitations of the caching layer, this method must never return null.

      Always use hasEntry(Object) before attempting to retrieve an entry.

      Any exceptions generated by this method are NOT swallowed.

      Parameters:
      key - The key
      Returns:
      The data associated with the key
      Throws:
      Exception
    • getAllEntries

      @NotNull public abstract @NotNull Collection<D> getAllEntries() throws Exception
      Retrieve all stored values in the data storage.

      This method retrieves all values stored in the data storage and returns them as a collection. It is a blocking task, and it may take some time to complete depending on the size of the data storage. If the data storage is empty, an empty collection is returned.

      Any exceptions generated by this method are NOT swallowed.

      Returns:
      A collection containing all stored values.
      Throws:
      Exception - If an exception occurs while retrieving the values.
    • getAllEntries

      @NotNull public abstract @NotNull Collection<D> getAllEntries(@Nullable @Nullable Consumer<Exception> exceptionHandler)
      Retrieve all stored values in the data storage.

      This method retrieves all values stored in the data storage and returns them as a collection. It is a blocking task, and it may take some time to complete depending on the size of the data storage. If the data storage is empty, an empty collection is returned.

      Parameters:
      exceptionHandler - A function for handling errors.
      Returns:
      A collection containing all stored values.
    • shutdown

      public void shutdown()
      Shut down the data storage system.

      This method gracefully shuts down the data storage system, ensuring that all pending write operations are completed and any resources held by the storage system are properly released.