Class PostgresStorageProvider<T>
java.lang.Object
dev.crafty.core.storage.AbstractStorageProvider<T,String>
dev.crafty.core.storage.providers.PostgresStorageProvider<T>
- Type Parameters:
T
- The type of object to store
- All Implemented Interfaces:
StorageProvider<T,
String>
A storage provider that stores objects in a PostgreSQL database.
Objects are serialized to JSON before storage.
- Since:
- 1.0.0
-
Field Summary
Fields inherited from class dev.crafty.core.storage.AbstractStorageProvider
valueType
-
Constructor Summary
Constructors -
Method Summary
Methods inherited from class dev.crafty.core.storage.AbstractStorageProvider
exists
-
Constructor Details
-
PostgresStorageProvider
public PostgresStorageProvider(Class<T> valueType, String tableName, String connectionUrl, String username, String password) Creates a new PostgresStorageProvider.- Parameters:
valueType
- The class of the value typetableName
- The name of the table to store objects inconnectionUrl
- The JDBC connection URLusername
- The database usernamepassword
- The database password
-
-
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
-
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 interfaceStorageProvider<T,
String> - Overrides:
close
in classAbstractStorageProvider<T,
String> - Returns:
- A CompletableFuture that completes when the provider is closed
-