Package dev.crafty.core.storage
Interface StorageProvider<T,K>
- Type Parameters:
T
- The type of object to storeK
- The type of key used to identify objects
- All Known Implementing Classes:
AbstractStorageProvider
,CachedStorageProvider
,MongoDbStorageProvider
,MySqlStorageProvider
,PostgresStorageProvider
,YamlStorageProvider
public interface StorageProvider<T,K>
Base interface for all storage providers.
Provides methods for CRUD operations on data objects.
- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptionclose()
Closes the storage provider and releases any resources.Deletes an object from the storage.Checks if an object exists in the storage.Retrieves an object from the storage.getAll()
Retrieves all objects from the storage.Initializes the storage provider.Saves an object to the storage.
-
Method Details
-
save
Saves an object to the storage.- Parameters:
key
- The key to identify the objectvalue
- The object to save- Returns:
- A CompletableFuture that completes when the operation is done
-
get
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
CompletableFuture<Collection<T>> getAll()Retrieves all objects from the storage.- Returns:
- A CompletableFuture that completes with a collection of all objects
-
delete
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
-
exists
Checks if an object exists in the storage.- Parameters:
key
- The key to check- Returns:
- A CompletableFuture that completes with true if the object exists, false otherwise
-
initialize
CompletableFuture<Void> initialize()Initializes the storage provider. This method should be called before using the provider.- Returns:
- A CompletableFuture that completes when initialization is done
-
close
CompletableFuture<Void> close()Closes the storage provider and releases any resources. This method should be called when the provider is no longer needed.- Returns:
- A CompletableFuture that completes when the provider is closed
-