Class StorageProviderFactory

java.lang.Object
dev.crafty.core.storage.StorageProviderFactory

public class StorageProviderFactory extends Object
Factory for creating storage providers.
Since:
1.0.0
  • Constructor Details

    • StorageProviderFactory

      public StorageProviderFactory()
  • Method Details

    • createYamlProvider

      public static <T> StorageProvider<T,String> createYamlProvider(Class<T> valueType, String directory)
      Creates a YAML storage provider.
      Type Parameters:
      T - The type of object to store
      Parameters:
      valueType - The class of the value type
      directory - The directory to store files in
      Returns:
      The storage provider
    • createYamlProvider

      public static <T> StorageProvider<T,String> createYamlProvider(Class<T> valueType, Path directory)
      Creates a YAML storage provider.
      Type Parameters:
      T - The type of object to store
      Parameters:
      valueType - The class of the value type
      directory - The directory to store files in
      Returns:
      The storage provider
    • createCachedProvider

      public static <T, K> StorageProvider<T,K> createCachedProvider(StorageProvider<T,K> provider)
      Creates a cached storage provider that wraps the given provider.
      Type Parameters:
      T - The type of object to store
      K - The type of key used to identify objects
      Parameters:
      provider - The provider to wrap
      Returns:
      The cached storage provider
    • createPostgresProvider

      public static <T> StorageProvider<T,String> createPostgresProvider(Class<T> valueType, String tableName, String connectionUrl, String username, String password)
      Creates a PostgreSQL storage provider.
      Type Parameters:
      T - The type of object to store
      Parameters:
      valueType - The class of the value type
      tableName - The name of the table to store objects in
      connectionUrl - The JDBC connection URL
      username - The database username
      password - The database password
      Returns:
      The storage provider
    • createMySqlProvider

      public static <T> StorageProvider<T,String> createMySqlProvider(Class<T> valueType, String tableName, String connectionUrl, String username, String password)
      Creates a MySQL storage provider.
      Type Parameters:
      T - The type of object to store
      Parameters:
      valueType - The class of the value type
      tableName - The name of the table to store objects in
      connectionUrl - The JDBC connection URL
      username - The database username
      password - The database password
      Returns:
      The storage provider
    • createMongoDbProvider

      public static <T> StorageProvider<T,String> createMongoDbProvider(Class<T> valueType, String tableName, String connectionUrl)
      Creates a MongoDb storage provider.
      Type Parameters:
      T - The type of object to store
      Parameters:
      valueType - The class of the value type
      tableName - The name of the table to store objects in
      connectionUrl - The JDBC connection URL
      Returns:
      The storage provider
    • createProvider

      public static <T> StorageProvider<T,String> createProvider(StorageProviderFactory.StorageType type, Class<T> valueType, StorageProviderFactory.StorageConfig config)
      Creates a storage provider based on the specified type.
      Type Parameters:
      T - The type of object to store
      Parameters:
      type - The type of storage provider to create
      valueType - The class of the value type
      config - The configuration for the storage provider
      Returns:
      The storage provider