* are executed.
*/
public PersistentSettings saveProperty(DbSession dbSession, String key, @Nullable String value) {
- dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(key).setValue(value));
- // refresh the cache of settings
- delegate.setProperty(key, value);
-
+ savePropertyImpl(dbSession, key, value);
changeNotifier.onGlobalPropertyChange(key, value);
return this;
}
*/
public PersistentSettings saveProperty(String key, @Nullable String value) {
try (DbSession dbSession = dbClient.openSession(false)) {
- saveProperty(dbSession, key, value);
+ savePropertyImpl(dbSession, key, value);
dbSession.commit();
+ changeNotifier.onGlobalPropertyChange(key, value);
return this;
}
}
+ private void savePropertyImpl(DbSession dbSession, String key, @Nullable String value) {
+ if (value == null) {
+ dbClient.propertiesDao().deleteGlobalProperty(key, dbSession);
+ } else {
+ dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(key).setValue(value));
+ }
+ // refresh the cache of settings
+ delegate.setProperty(key, value);
+ }
+
public Settings getSettings() {
return delegate;
}
import org.sonar.api.config.Settings;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
-import org.sonar.db.property.PropertyDto;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
underTest.saveProperty("foo", null);
assertThat(underTest.getString("foo")).isNull();
- PropertyDto dto = dbTester.getDbClient().propertiesDao().selectGlobalProperty("foo");
- assertThat(dto.getValue()).isEmpty();
+ assertThat(dbTester.getDbClient().propertiesDao().selectGlobalProperty("foo")).isNull();
verify(changeNotifier).onGlobalPropertyChange("foo", null);
}