Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 - additional postgres parameters support added
  • Loading branch information
Kiss Attila 2 committed Oct 19, 2018
1 parent d0a65e6 commit 4e0f3f5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class EmbeddedPostgres implements AutoCloseable {
"--locale=C",
"--lc-collate=C",
"--lc-ctype=C");
private static final List<String> DEFAULT_POSTGRES_PARAMS = asList();
private final String dataDir;
private final IVersion version;
private PostgresProcess process;
Expand Down Expand Up @@ -161,14 +162,34 @@ public String start(IRuntimeConfig runtimeConfig) throws IOException {
*/
public String start(IRuntimeConfig runtimeConfig, String host, int port, String dbName, String user, String password,
List<String> additionalParams) throws IOException {
return start(runtimeConfig, host, port, dbName, user, password, additionalParams, DEFAULT_POSTGRES_PARAMS);
}

/**
* Starts up the embedded postgres
*
* @param runtimeConfig required runtime configuration
* @param host host to bind to
* @param port port to bind to
* @param dbName name of the database to initialize
* @param user username to connect
* @param password password for the provided username
* @param additionalInitDbParams additional database init params (if required)
* @param additionalPostgresParams additional postgresql params (if required)
* @return connection url for the initialized postgres instance
* @throws IOException if an I/O error occurs during the process startup
*/
public String start(IRuntimeConfig runtimeConfig, String host, int port, String dbName, String user, String password,
List<String> additionalInitDbParams, List<String> additionalPostgresParams) throws IOException {
final PostgresStarter<PostgresExecutable, PostgresProcess> runtime = PostgresStarter.getInstance(runtimeConfig);
config = new PostgresConfig(version,
new AbstractPostgresConfig.Net(host, port),
new AbstractPostgresConfig.Storage(dbName, dataDir),
new AbstractPostgresConfig.Timeout(),
new AbstractPostgresConfig.Credentials(user, password)
);
config.getAdditionalInitDbParams().addAll(additionalParams);
config.getAdditionalInitDbParams().addAll(additionalInitDbParams);
config.getAdditionalPostgresParams().addAll(additionalPostgresParams);
PostgresExecutable exec = runtime.prepare(config);
this.process = exec.start();
return formatConnUrl(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ protected List<String> getCommandLine(Distribution distribution, PostgresConfig
"-h", config.net().host(),
"-D", config.storage().dbDir().getAbsolutePath()
));
ret.addAll(config.getAdditionalPostgresParams());
break;
case "pg_ctl": //NOSONAR
ret.addAll(asList(exe.executable().getAbsolutePath(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public abstract class AbstractPostgresConfig<C extends AbstractPostgresConfig> e
protected final Credentials credentials;
protected List<String> args = new ArrayList<>();
protected List<String> additionalInitDbParams = new ArrayList<>();
protected List<String> additionalPostgresParams = new ArrayList<>();

protected AbstractPostgresConfig(AbstractPostgresConfig config, Command postgres) {
this(config.version, config.net(), config.storage, config.timeout(), config.credentials, new SupportConfig(postgres));
Expand Down Expand Up @@ -78,7 +79,6 @@ public C withAdditionalInitDbParams(List<String> additionalInitDbParams) {
return (C) this;
}


/**
* You may add here additional arguments for the {@code initdb} executable.<br/>
* <p>
Expand All @@ -100,6 +100,25 @@ public List<String> getAdditionalInitDbParams() {
return additionalInitDbParams;
}

/**
* You may add here additional arguments for the {@code postgres} executable.<br/>
* <p>
* Example.<br>
* to use custom number of maximum connection.<br/>
* <pre>
* getAdditionalPostgresParams().addAll(
* java.util.Arrays.asList(
* "-c", "max_connections=11"
* )
* </pre>
* @return The list of additional parameters for the {@code postgres} executable.<br/>
* Not {@code null}.<br>
* @see <a href="https://www.postgresql.org/docs/9.6/static/config-setting.html#AEN32659">Parameter Interaction via the Shell</a>
*/
public List<String> getAdditionalPostgresParams() {
return additionalPostgresParams;
}

public static class Storage {
private final File dbDir;
private final String dbName;
Expand Down

0 comments on commit 4e0f3f5

Please sign in to comment.