Package dev.crafty.core.storage
Class ProviderManager
java.lang.Object
dev.crafty.core.storage.ProviderManager
Manages storage provider instances, handling creation, caching, and configuration.
This class centralizes the provider management logic that was previously spread across
multiple classes.
- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Closes all storage providers.<T> PlayerDataProvider
<T> Gets a player data provider for the specified player ID and value type.static ProviderManager
Gets the singleton instance of the ProviderManager.<T> StorageProvider
<T, String> getMongoDbProvider
(Class<T> valueType, String tableName, String connectionUrl) Gets a MongoDb storage provider for the specified type.<T> StorageProvider
<T, String> getMySqlProvider
(Class<T> valueType, String tableName, String connectionUrl, String username, String password) Gets a MySQL storage provider for the specified type.<T> StorageProvider
<T, String> getPostgresProvider
(Class<T> valueType, String tableName, String connectionUrl, String username, String password) Gets a PostgreSQL storage provider for the specified type.<T> StorageProvider
<T, String> getProvider
(Class<T> valueType) Gets a storage provider using the default configuration.<T> StorageProvider
<T, String> getProvider
(Class<T> valueType, String identifier) Gets a storage provider using the default configuration.<T> StorageProvider
<T, String> getYamlProvider
(Class<T> valueType, String directory) Gets a YAML storage provider for the specified type.void
setDefaultMongoDbConfig
(String tableName, String connectionUrl) Sets the default MongoDB configuration.void
setDefaultMySqlConfig
(String tableName, String connectionUrl, String username, String password) Sets the default MySQL configuration.void
setDefaultPostgresConfig
(String tableName, String connectionUrl, String username, String password) Sets the default PostgreSQL configuration.void
setDefaultYamlConfig
(String directory) Sets the default YAML configuration.
-
Method Details
-
getInstance
Gets the singleton instance of the ProviderManager.- Returns:
- The ProviderManager instance
-
getYamlProvider
Gets a YAML storage provider for the specified type. If the provider doesn't exist, it will be created.- Type Parameters:
T
- The type of object to store- Parameters:
valueType
- The class of the value typedirectory
- The directory to store files in- Returns:
- The storage provider
-
getPostgresProvider
public <T> StorageProvider<T,String> getPostgresProvider(Class<T> valueType, String tableName, String connectionUrl, String username, String password) Gets a PostgreSQL storage provider for the specified type. If the provider doesn't exist, it will be created.- Type Parameters:
T
- The type of object to store- 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- Returns:
- The storage provider
-
getMongoDbProvider
public <T> StorageProvider<T,String> getMongoDbProvider(Class<T> valueType, String tableName, String connectionUrl) Gets a MongoDb storage provider for the specified type. If the provider doesn't exist, it will be created.- Type Parameters:
T
- The type of object to store- Parameters:
valueType
- The class of the value typetableName
- The name of the table to store objects inconnectionUrl
- The JDBC connection URL- Returns:
- The storage provider
-
getMySqlProvider
public <T> StorageProvider<T,String> getMySqlProvider(Class<T> valueType, String tableName, String connectionUrl, String username, String password) Gets a MySQL storage provider for the specified type. If the provider doesn't exist, it will be created.- Type Parameters:
T
- The type of object to store- 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- Returns:
- The storage provider
-
setDefaultYamlConfig
Sets the default YAML configuration.- Parameters:
directory
- The directory to store files in
-
setDefaultPostgresConfig
public void setDefaultPostgresConfig(String tableName, String connectionUrl, String username, String password) Sets the default PostgreSQL configuration.- Parameters:
tableName
- The base table name to useconnectionUrl
- The JDBC connection URLusername
- The database usernamepassword
- The database password
-
setDefaultMongoDbConfig
Sets the default MongoDB configuration.- Parameters:
tableName
- The base table name to useconnectionUrl
- The JDBC connection URL
-
setDefaultMySqlConfig
public void setDefaultMySqlConfig(String tableName, String connectionUrl, String username, String password) Sets the default MySQL configuration.- Parameters:
tableName
- The base table name to useconnectionUrl
- The JDBC connection URLusername
- The database usernamepassword
- The database password
-
getProvider
Gets a storage provider using the default configuration. The provider type is determined by the default storage type.- Type Parameters:
T
- The type of object to store- Parameters:
valueType
- The class of the value type- Returns:
- The storage provider
- Throws:
IllegalStateException
- If the default configuration for the selected storage type is not set
-
getProvider
Gets a storage provider using the default configuration. The provider type is determined by the default storage type.- Type Parameters:
T
- The type of object to store- Parameters:
valueType
- The class of the value typeidentifier
- A unique identifier for this provider (e.g., table name or directory suffix)- Returns:
- The storage provider
- Throws:
IllegalStateException
- If the default configuration for the selected storage type is not set
-
forPlayer
Gets a player data provider for the specified player ID and value type.- Type Parameters:
T
- The type of object to store- Parameters:
playerId
- The UUID of the playervalueType
- The class of the value type- Returns:
- The player data provider
-
closeAllProviders
public void closeAllProviders()Closes all storage providers. This should be called when the plugin is disabled.
-