Class PostgresConfig
java.lang.Object
net.blockhost.commons.database.postgres.PostgresConfig
- All Implemented Interfaces:
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPostgresConfig(String host, int port, String database, String username, String password, int connectionTimeoutSeconds, int maxPoolSize, int minIdle) -
Method Summary
Modifier and TypeMethodDescriptionfinal intfinal Stringdatabase()final Stringhost()jdbcUrl()Constructs the JDBC URL for PostgreSQL connections.final intGets the maximum number of connections in the pool.final intminIdle()Gets the minimum number of idle connections in the pool.final Stringpassword()final intport()Converts this configuration to database credentials.final Stringusername()final @NonNull PostgresConfigwithConnectionTimeoutSeconds(int connectionTimeoutSeconds) final @NonNull PostgresConfigwithDatabase(String database) final @NonNull PostgresConfigfinal @NonNull PostgresConfigwithMaxPoolSize(int maxPoolSize) final @NonNull PostgresConfigwithMinIdle(int minIdle) final @NonNull PostgresConfigwithPassword(String password) final @NonNull PostgresConfigwithPort(int port) final @NonNull PostgresConfigwithUsername(String username)
-
Field Details
-
DRIVER_CLASS
-
-
Constructor Details
-
PostgresConfig
public PostgresConfig() -
PostgresConfig
-
-
Method Details
-
toCredentials
Description copied from interface:PooledDatabaseConfigConverts this configuration to database credentials.- Specified by:
toCredentialsin interfacePooledDatabaseConfig- Returns:
- a new DatabaseCredentials instance
-
jdbcUrl
Constructs the JDBC URL for PostgreSQL connections.- Returns:
- the JDBC URL string
-
host
-
port
public final int port() -
database
-
username
-
password
-
connectionTimeoutSeconds
public final int connectionTimeoutSeconds() -
maxPoolSize
public final int maxPoolSize()Description copied from interface:PooledDatabaseConfigGets the maximum number of connections in the pool.- Specified by:
maxPoolSizein interfacePooledDatabaseConfig- Returns:
- the maximum pool size
-
minIdle
public final int minIdle()Description copied from interface:PooledDatabaseConfigGets the minimum number of idle connections in the pool.- Specified by:
minIdlein interfacePooledDatabaseConfig- Returns:
- the minimum idle connections
-
withHost
- Returns:
this.
-
withPort
- Returns:
this.
-
withDatabase
- Returns:
this.
-
withUsername
- Returns:
this.
-
withPassword
- Returns:
this.
-
withConnectionTimeoutSeconds
- Returns:
this.
-
withMaxPoolSize
- Returns:
this.
-
withMinIdle
- Returns:
this.
-