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>
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
-
Field Summary
Fields inherited from class dev.crafty.core.storage.AbstractStorageProvider
valueType
-
Constructor Summary
ConstructorsConstructorDescriptionMongoDbStorageProvider
(Class<T> valueType, String tableName, String connectionUrl) Constructs a new AsyncMongoStorageProvider. -
Method Summary
Modifier and TypeMethodDescriptionDeletes an object from 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.Methods inherited from class dev.crafty.core.storage.AbstractStorageProvider
close, exists
-
Constructor Details
-
MongoDbStorageProvider
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
Initializes the storage provider. This method should be called before using the provider.- Specified by:
initialize
in interfaceStorageProvider<T,
String> - Overrides:
initialize
in classAbstractStorageProvider<T,
String> - Returns:
- A CompletableFuture that completes when initialization is done
-
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
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
-