Package dev.crafty.core.storage
Class ProviderManager
java.lang.Object
dev.crafty.core.storage.ProviderManager
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Closes all storage providers.generatePlayerDataKey
(UUID playerId, String identifier) <K,
T> StorageProvider <K, T> getMongoDbProvider
(Class<K> keyType, Class<T> valueType, String tableName, String connectionUrl) Gets a MongoDb storage provider for the specified type with generic key type.<T> StorageProvider
<String, T> getMongoDbProvider
(Class<T> valueType, String tableName, String connectionUrl) Gets a MongoDb storage provider for the specified type with String keys.<K,
T> StorageProvider <K, T> getMySqlProvider
(Class<K> keyType, Class<T> valueType, String tableName, String connectionUrl, String username, String password) Gets a MySQL storage provider for the specified type with generic key type.<T> StorageProvider
<String, T> getMySqlProvider
(Class<T> valueType, String tableName, String connectionUrl, String username, String password) Gets a MySQL storage provider for the specified type with String keys.<K,
T> StorageProvider <K, T> getPostgresProvider
(Class<K> keyType, Class<T> valueType, String tableName, String connectionUrl, String username, String password) Gets a PostgreSQL storage provider for the specified type with generic key type.<T> StorageProvider
<String, T> getPostgresProvider
(Class<T> valueType, String tableName, String connectionUrl, String username, String password) Gets a PostgreSQL storage provider for the specified type with String keys.<K,
T> StorageProvider <K, T> getProvider
(Class<K> keyType, Class<T> valueType, String identifier) Gets a storage provider using the default configuration with generic key type.<T> StorageProvider
<String, T> getProvider
(Class<T> valueType) Gets a storage provider using the default configuration with String keys.<T> StorageProvider
<String, T> getProvider
(Class<T> valueType, String identifier) Gets a storage provider using the default configuration with String keys.<K,
T> StorageProvider <K, T> getYamlProvider
(Class<K> keyType, Class<T> valueType, String directory) Gets a YAML storage provider for the specified type with generic key type.<T> StorageProvider
<String, T> getYamlProvider
(Class<T> valueType, String directory) Gets a YAML storage provider for the specified type with String keys.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.
-
Constructor Details
-
ProviderManager
public ProviderManager()
-
-
Method Details
-
getYamlProvider
Gets a YAML storage provider for the specified type with String keys. 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
-
getYamlProvider
public <K,T> StorageProvider<K,T> getYamlProvider(Class<K> keyType, Class<T> valueType, String directory) Gets a YAML storage provider for the specified type with generic key type. If the provider doesn't exist, it will be created.- Type Parameters:
K
- The type of key used to identify objectsT
- The type of object to store- Parameters:
keyType
- The class of the key typevalueType
- The class of the value typedirectory
- The directory to store files in- Returns:
- The storage provider
-
getPostgresProvider
public <T> StorageProvider<String,T> getPostgresProvider(Class<T> valueType, String tableName, String connectionUrl, String username, String password) Gets a PostgreSQL storage provider for the specified type with String keys. 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
-
getPostgresProvider
public <K,T> StorageProvider<K,T> getPostgresProvider(Class<K> keyType, Class<T> valueType, String tableName, String connectionUrl, String username, String password) Gets a PostgreSQL storage provider for the specified type with generic key type. If the provider doesn't exist, it will be created.- Type Parameters:
K
- The type of key used to identify objectsT
- The type of object to store- Parameters:
keyType
- The class of the key typevalueType
- 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<String,T> getMongoDbProvider(Class<T> valueType, String tableName, String connectionUrl) Gets a MongoDb storage provider for the specified type with String keys. 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
-
getMongoDbProvider
public <K,T> StorageProvider<K,T> getMongoDbProvider(Class<K> keyType, Class<T> valueType, String tableName, String connectionUrl) Gets a MongoDb storage provider for the specified type with generic key type. If the provider doesn't exist, it will be created.- Type Parameters:
K
- The type of key used to identify objectsT
- The type of object to store- Parameters:
keyType
- The class of the key typevalueType
- 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<String,T> getMySqlProvider(Class<T> valueType, String tableName, String connectionUrl, String username, String password) Gets a MySQL storage provider for the specified type with String keys. 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
-
getMySqlProvider
public <K,T> StorageProvider<K,T> getMySqlProvider(Class<K> keyType, Class<T> valueType, String tableName, String connectionUrl, String username, String password) Gets a MySQL storage provider for the specified type with generic key type. If the provider doesn't exist, it will be created.- Type Parameters:
K
- The type of key used to identify objectsT
- The type of object to store- Parameters:
keyType
- The class of the key typevalueType
- 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 with String keys. 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 with String keys. 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
-
getProvider
public <K,T> StorageProvider<K,T> getProvider(Class<K> keyType, Class<T> valueType, String identifier) Gets a storage provider using the default configuration with generic key type. The provider type is determined by the default storage type.- Type Parameters:
K
- The type of key used to identify objectsT
- The type of object to store- Parameters:
keyType
- The class of the key typevalueType
- 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
-
generatePlayerDataKey
-
closeAllProviders
public void closeAllProviders()Closes all storage providers. This should be called when the plugin is disabled.
-