Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ default DataSourceBuilder readOnly(boolean readOnly) {
DataSourceBuilder setReadOnly(boolean readOnly);

/**
* Set the minimum number of connections the pool should maintain.
* Set the minimum number of connections the pool should maintain. Defaults to 2 when not set.
*/
default DataSourceBuilder minConnections(int minConnections) {
return setMinConnections(minConnections);
Expand All @@ -330,7 +330,7 @@ default DataSourceBuilder minConnections(int minConnections) {
DataSourceBuilder setMinConnections(int minConnections);

/**
* Set the maximum number of connections the pool can reach.
* Set the maximum number of connections the pool can reach. Defaults to 200 when not set.
*/
default DataSourceBuilder maxConnections(int maxConnections) {
return setMaxConnections(maxConnections);
Expand Down Expand Up @@ -892,12 +892,12 @@ default String driverClassName() {
boolean isReadOnly();

/**
* Return the minimum number of connections the pool should maintain.
* Return the minimum number of connections the pool should maintain. Defaults to 2.
*/
int getMinConnections();

/**
* Return the maximum number of connections the pool can reach.
* Return the maximum number of connections the pool can reach. Defaults to 200.
*/
int getMaxConnections();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
@SuppressWarnings("removal")
public class DataSourceConfig implements DataSourceBuilder.Settings {

private static final int UNSET = -1;
private static final String POSTGRES = "postgres";

private String name = "";
Expand Down Expand Up @@ -54,8 +55,8 @@ public class DataSourceConfig implements DataSourceBuilder.Settings {
* The optional database owner password (for running InitDatabase).
*/
private String ownerPassword;
private int minConnections = 2;
private int maxConnections = 200;
private int minConnections = UNSET; // defaults to 2
private int maxConnections = UNSET; // defaults to 200
private int isolationLevel = Connection.TRANSACTION_READ_COMMITTED;
private boolean autoCommit;
private boolean readOnly;
Expand Down Expand Up @@ -182,10 +183,10 @@ public DataSourceConfig setDefaults(DataSourceBuilder builder) {
if (catalog == null) {
catalog = other.catalog();
}
if (minConnections == 2 && other.getMinConnections() < 2) {
if (minConnections == UNSET) {
minConnections = other.getMinConnections();
}
if (maxConnections == 200 && other.getMaxConnections() != 200) {
if (maxConnections == UNSET) {
maxConnections = other.getMaxConnections();
}
if (!shutdownOnJvmExit && other.isShutdownOnJvmExit()) {
Expand Down Expand Up @@ -413,7 +414,7 @@ public DataSourceConfig setReadOnly(boolean readOnly) {

@Override
public int getMinConnections() {
return minConnections;
return minConnections == UNSET ? 2 : minConnections;
}

@Override
Expand All @@ -424,7 +425,7 @@ public DataSourceConfig setMinConnections(int minConnections) {

@Override
public int getMaxConnections() {
return maxConnections;
return maxConnections == UNSET ? 200 : maxConnections;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,19 @@ void setDefaults_when_explicit() {
assertThat(readOnly.getMaxConnections()).isEqualTo(22);
}

@Test
void setDefaults_when_explicitSameAsNormalDefaults() {
DataSourceConfig readOnly = new DataSourceConfig();
readOnly.setMinConnections(2);
readOnly.setMaxConnections(200);

// act
readOnly.setDefaults(create());

assertThat(readOnly.getMinConnections()).isEqualTo(2);
assertThat(readOnly.getMaxConnections()).isEqualTo(200);
}

@Test
public void defaults_someOverride() {
DataSourceConfig readOnly = new DataSourceConfig();
Expand Down
Loading