Class FlatfileDriver<K,D>

java.lang.Object
co.crystaldev.alpinecore.framework.storage.driver.AlpineDriver<K,D>
co.crystaldev.alpinecore.framework.storage.driver.FlatfileDriver<K,D>

public final class FlatfileDriver<K,D> extends AlpineDriver<K,D>
Implements a simple flatfile storage system where each key is serialized into a separate JSON file with the corresponding data as content.
Since:
0.1.0
  • Method Details

    • persistEntry

      public boolean persistEntry(@NotNull K key, @NotNull D data)
      Description copied from class: AlpineDriver
      Save data under a given key.

      Any exceptions generated by this method are swallowed.

      Specified by:
      persistEntry in class AlpineDriver<K,D>
      Parameters:
      key - The key
      data - The data to save
      Returns:
      Whether the operation was successful
    • deleteEntry

      public boolean deleteEntry(@NotNull K key)
      Description copied from class: AlpineDriver
      Delete data under a given key.
      Specified by:
      deleteEntry in class AlpineDriver<K,D>
      Parameters:
      key - The key
      Returns:
      Whether the operation was successful
    • hasEntry

      public boolean hasEntry(@NotNull K key)
      Description copied from class: AlpineDriver
      Check if a key has any saved data.

      Any exceptions generated by this method are swallowed.

      Specified by:
      hasEntry in class AlpineDriver<K,D>
      Parameters:
      key - The key
      Returns:
      Whether there is an entry for they key
    • retrieveEntry

      @NotNull public D retrieveEntry(@NotNull K key) throws Exception
      Description copied from class: AlpineDriver
      Retrieve data for a given key.

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

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

      Any exceptions generated by this method are NOT swallowed.

      Specified by:
      retrieveEntry in class AlpineDriver<K,D>
      Parameters:
      key - The key
      Returns:
      The data associated with the key
      Throws:
      Exception
    • getAllEntries

      @NotNull public @NotNull Collection<D> getAllEntries() throws Exception
      Description copied from class: AlpineDriver
      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.

      Specified by:
      getAllEntries in class AlpineDriver<K,D>
      Returns:
      A collection containing all stored values.
      Throws:
      Exception - If an exception occurs while retrieving the values.
    • getAllEntries

      @NotNull public @NotNull Collection<D> getAllEntries(@Nullable @Nullable Consumer<Exception> exceptionConsumer)
      Description copied from class: AlpineDriver
      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.

      Specified by:
      getAllEntries in class AlpineDriver<K,D>
      Parameters:
      exceptionConsumer - A function for handling errors.
      Returns:
      A collection containing all stored values.
    • builder

      public static <K, D> FlatfileDriver.Builder<K,D> builder()
      Helper method to return a new builder instance.
      Returns:
      New builder for this class
      See Also: