Class AbstractStorageProvider<T,K>

java.lang.Object
dev.crafty.core.storage.AbstractStorageProvider<T,K>
Type Parameters:
T - The type of object to store
K - The type of key used to identify objects
All Implemented Interfaces:
StorageProvider<T,K>
Direct Known Subclasses:
MongoDbStorageProvider, MySqlStorageProvider, PostgresStorageProvider, YamlStorageProvider

public abstract class AbstractStorageProvider<T,K> extends Object implements StorageProvider<T,K>
Abstract base implementation of StorageProvider that provides common functionality.
Since:
1.0.0
  • Field Details

    • valueType

      protected final Class<T> valueType
  • Constructor Details

    • AbstractStorageProvider

      protected AbstractStorageProvider(Class<T> valueType)
      Creates a new AbstractStorageProvider.
      Parameters:
      valueType - The class of the value type
  • Method Details

    • exists

      public CompletableFuture<Boolean> exists(K key)
      Checks if an object exists in the storage.
      Specified by:
      exists in interface StorageProvider<T,K>
      Parameters:
      key - The key to check
      Returns:
      A CompletableFuture that completes with true if the object exists, false otherwise
    • 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,K>
      Returns:
      A CompletableFuture that completes when initialization is done
    • close

      public CompletableFuture<Void> close()
      Closes the storage provider and releases any resources. This method should be called when the provider is no longer needed.
      Specified by:
      close in interface StorageProvider<T,K>
      Returns:
      A CompletableFuture that completes when the provider is closed