Class PostgresConfig

java.lang.Object
net.blockhost.commons.database.postgres.PostgresConfig
All Implemented Interfaces:
PooledDatabaseConfig

public class PostgresConfig extends Object implements PooledDatabaseConfig

ConfigLib-compatible PostgreSQL database configuration class.

This class can be embedded in your plugin's configuration to provide database connection settings. It uses ConfigLib annotations for YAML serialization with helpful comments.

Example usage in a plugin configuration:

@Configuration
public class PluginConfig {
    @Comment("Database connection settings")
    private PostgresConfig database = new PostgresConfig();

    public PostgresConfig database() {
        return database;
    }
}

To use with SQLManager directly:

SQLManager sqlManager = SQLManager.create(config.database())
    .poolName("MyPlugin-Pool")
    .logger(logger)
    .build();

Use withers to create modified copies for specific use cases:

PostgresConfig analyticsConfig = config.database()
    .withDatabase("analytics")
    .withMaxPoolSize(5);
See Also:
  • Field Details

  • Constructor Details

    • PostgresConfig

      public PostgresConfig()
    • PostgresConfig

      public PostgresConfig(String host, int port, String database, String username, String password, int connectionTimeoutSeconds, int maxPoolSize, int minIdle)
  • Method Details

    • toCredentials

      public DatabaseCredentials toCredentials()
      Description copied from interface: PooledDatabaseConfig
      Converts this configuration to database credentials.
      Specified by:
      toCredentials in interface PooledDatabaseConfig
      Returns:
      a new DatabaseCredentials instance
    • jdbcUrl

      public String jdbcUrl()
      Constructs the JDBC URL for PostgreSQL connections.
      Returns:
      the JDBC URL string
    • host

      public final String host()
    • port

      public final int port()
    • database

      public final String database()
    • username

      public final String username()
    • password

      public final String password()
    • connectionTimeoutSeconds

      public final int connectionTimeoutSeconds()
    • maxPoolSize

      public final int maxPoolSize()
      Description copied from interface: PooledDatabaseConfig
      Gets the maximum number of connections in the pool.
      Specified by:
      maxPoolSize in interface PooledDatabaseConfig
      Returns:
      the maximum pool size
    • minIdle

      public final int minIdle()
      Description copied from interface: PooledDatabaseConfig
      Gets the minimum number of idle connections in the pool.
      Specified by:
      minIdle in interface PooledDatabaseConfig
      Returns:
      the minimum idle connections
    • withHost

      public final @NonNull PostgresConfig withHost(String host)
      Returns:
      this.
    • withPort

      public final @NonNull PostgresConfig withPort(int port)
      Returns:
      this.
    • withDatabase

      public final @NonNull PostgresConfig withDatabase(String database)
      Returns:
      this.
    • withUsername

      public final @NonNull PostgresConfig withUsername(String username)
      Returns:
      this.
    • withPassword

      public final @NonNull PostgresConfig withPassword(String password)
      Returns:
      this.
    • withConnectionTimeoutSeconds

      public final @NonNull PostgresConfig withConnectionTimeoutSeconds(int connectionTimeoutSeconds)
      Returns:
      this.
    • withMaxPoolSize

      public final @NonNull PostgresConfig withMaxPoolSize(int maxPoolSize)
      Returns:
      this.
    • withMinIdle

      public final @NonNull PostgresConfig withMinIdle(int minIdle)
      Returns:
      this.