Skip to content

Commit

Permalink
Don't check if property exist before adding
Browse files Browse the repository at this point in the history
  • Loading branch information
Torch3333 committed Dec 25, 2024
1 parent be71af5 commit bc66fee
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
6 changes: 1 addition & 5 deletions core/src/main/java/com/scalar/db/storage/jdbc/JdbcUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,8 @@ public static BasicDataSource initDataSource(
dataSource.setMaxTotal(config.getConnectionPoolMaxTotal());
dataSource.setPoolPreparedStatements(config.isPreparedStatementsPoolEnabled());
dataSource.setMaxOpenPreparedStatements(config.getPreparedStatementsPoolMaxOpen());
// Add connection properties if it doesn't already exist in the connection string to not
// override the user settings
for (Entry<String, String> entry : rdbEngine.getConnectionProperties().entrySet()) {
if (!dataSource.getUrl().contains(entry.getKey())) {
dataSource.addConnectionProperty(entry.getKey(), entry.getValue());
}
dataSource.addConnectionProperty(entry.getKey(), entry.getValue());
}

return dataSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ public void initDataSource_Transactional_ShouldReturnProperDataSource() throws S
}

@Test
public void
initDataSource_WithRdbEngineConnectionProperties_ShouldAddPropertiesOnlyIfNotInConnectionString() {
public void initDataSource_WithRdbEngineConnectionProperties_ShouldAddProperties() {
// Arrange
Properties properties = new Properties();
properties.setProperty(
Expand All @@ -147,7 +146,7 @@ JdbcUtils.class, withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS))) {
jdbcUtils.when(() -> JdbcUtils.initDataSource(config, rdbEngine)).thenCallRealMethod();

// Assert
verify(dataSource, never()).addConnectionProperty("prop1", "prop1Value");
verify(dataSource).addConnectionProperty("prop1", "prop1Value");
verify(dataSource).addConnectionProperty("prop2", "prop2Value");
verify(dataSource, never()).setConnectionProperties(anyString());
}
Expand Down

0 comments on commit bc66fee

Please sign in to comment.