Skip to content

Commit 24c97f4

Browse files
committed
Bug fix for propagation of pstmtCacheSize and cstmtCacheSize from main to readOnly Datasource
Currently this propagation doesn't happen and when we reduce the pstmtCacheSize size on a main datasource this isn't propagated to the readonly one. This was picked up with a CI build failure with oracle, when the default pstmtCacheSize bumped to 300, this has meant it hits a too-many-cursors error with the CI Oracle build for ebean.
1 parent 25664f9 commit 24c97f4

2 files changed

Lines changed: 47 additions & 4 deletions

File tree

ebean-datasource-api/src/main/java/io/ebean/datasource/DataSourceConfig.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public class DataSourceConfig implements DataSourceBuilder.Settings {
7474
private int maxInactiveTimeSecs = 300;
7575
private int maxAgeMinutes = 0;
7676
private int trimPoolFreqSecs = 59;
77-
private int pstmtCacheSize = 300;
78-
private int cstmtCacheSize = 20;
77+
private int pstmtCacheSize = UNSET; // defaults to 300
78+
private int cstmtCacheSize = UNSET; // defaults to 20
7979
private int waitTimeoutMillis = 1000;
8080
private String poolListener;
8181
private boolean offline;
@@ -198,6 +198,12 @@ public DataSourceConfig setDefaults(DataSourceBuilder builder) {
198198
if (maxConnections == UNSET) {
199199
maxConnections = other.getMaxConnections();
200200
}
201+
if (pstmtCacheSize == UNSET) {
202+
pstmtCacheSize = other.getPstmtCacheSize();
203+
}
204+
if (cstmtCacheSize == UNSET) {
205+
cstmtCacheSize = other.getCstmtCacheSize();
206+
}
201207
if (!shutdownOnJvmExit && other.isShutdownOnJvmExit()) {
202208
shutdownOnJvmExit = true;
203209
}
@@ -576,7 +582,7 @@ public DataSourceConfig setLeakTimeMinutes(int leakTimeMinutes) {
576582

577583
@Override
578584
public int getPstmtCacheSize() {
579-
return pstmtCacheSize;
585+
return pstmtCacheSize == UNSET ? 300 : pstmtCacheSize;
580586
}
581587

582588
@Override
@@ -587,7 +593,7 @@ public DataSourceConfig setPstmtCacheSize(int pstmtCacheSize) {
587593

588594
@Override
589595
public int getCstmtCacheSize() {
590-
return cstmtCacheSize;
596+
return cstmtCacheSize == UNSET ? 20 : cstmtCacheSize;
591597
}
592598

593599
@Override

ebean-datasource-api/src/test/java/io/ebean/datasource/DataSourceConfigTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,43 @@ void setDefaults_when_explicit() {
198198
assertThat(readOnly.getMaxConnections()).isEqualTo(32);
199199
}
200200

201+
@Test
202+
void setDefaults_inheritsStatementCacheSizes_whenNotExplicit() {
203+
DataSourceConfig main = create();
204+
main.setPstmtCacheSize(50);
205+
main.setCstmtCacheSize(11);
206+
207+
DataSourceConfig readOnly = new DataSourceConfig();
208+
readOnly.setDefaults(main);
209+
210+
assertThat(readOnly.getPstmtCacheSize()).isEqualTo(50);
211+
assertThat(readOnly.getCstmtCacheSize()).isEqualTo(11);
212+
}
213+
214+
@Test
215+
void setDefaults_keepsExplicitStatementCacheSizes() {
216+
DataSourceConfig main = create();
217+
main.setPstmtCacheSize(50);
218+
main.setCstmtCacheSize(11);
219+
220+
DataSourceConfig readOnly = new DataSourceConfig();
221+
readOnly.setPstmtCacheSize(70);
222+
readOnly.setCstmtCacheSize(9);
223+
readOnly.setDefaults(main);
224+
225+
assertThat(readOnly.getPstmtCacheSize()).isEqualTo(70);
226+
assertThat(readOnly.getCstmtCacheSize()).isEqualTo(9);
227+
}
228+
229+
@Test
230+
void setDefaults_inheritsStatementCacheSizes_whenMainAlsoDefault() {
231+
DataSourceConfig readOnly = new DataSourceConfig();
232+
readOnly.setDefaults(create());
233+
234+
assertThat(readOnly.getPstmtCacheSize()).isEqualTo(300);
235+
assertThat(readOnly.getCstmtCacheSize()).isEqualTo(20);
236+
}
237+
201238
@Test
202239
void setDefaults_when_explicitSameAsNormalDefaults() {
203240
DataSourceConfig readOnly = new DataSourceConfig();

0 commit comments

Comments
 (0)