Class MongoDbStorageProvider<T>

java.lang.Object
dev.crafty.core.storage.AbstractStorageProvider<T,String>
dev.crafty.core.storage.providers.MongoDbStorageProvider<T>
Type Parameters:
T - The type of objects to store.
All Implemented Interfaces:
StorageProvider<T,String>

public class MongoDbStorageProvider<T> extends AbstractStorageProvider<T,String>
An asynchronous MongoDB storage provider implementation using the Reactive Streams driver. Handles serialization and deserialization of objects to and from MongoDB documents.
Since:
1.0.0
  • Constructor Details

    • MongoDbStorageProvider

      public MongoDbStorageProvider(Class<T> valueType, String tableName, String connectionUrl)
      Constructs a new AsyncMongoStorageProvider.
      Parameters:
      valueType - The class type of the value to store.
      tableName - The name of the MongoDB collection.
      connectionUrl - The MongoDB connection URL.
  • Method Details

    • initialize

      public CompletableFuture<Void> initialize()
      Initializes the storage provider. This method should be called before using the provider.
      Specified by:
      initialize in interface StorageProvider<T,String>
      Overrides:
      initialize in class AbstractStorageProvider<T,String>
      Returns:
      A CompletableFuture that completes when initialization is done
    • save

      public CompletableFuture<Void> save(String key, T value)
      Saves an object to the storage.
      Parameters:
      key - The key to identify the object
      value - The object to save
      Returns:
      A CompletableFuture that completes when the operation is done
    • get

      public CompletableFuture<Optional<T>> get(String key)
      Retrieves an object from the storage.
      Parameters:
      key - The key of the object to retrieve
      Returns:
      A CompletableFuture that completes with the retrieved object, or empty if not found
    • getAll

      public CompletableFuture<Collection<T>> getAll()
      Retrieves all objects from the storage.
      Returns:
      A CompletableFuture that completes with a collection of all objects
    • delete

      public CompletableFuture<Void> delete(String key)
      Deletes an object from the storage.
      Parameters:
      key - The key of the object to delete
      Returns:
      A CompletableFuture that completes when the operation is done