org.sonar.server.platform.PersistentSettings Maven / Gradle / Ivy
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform;
import com.google.common.collect.Maps;
import org.picocontainer.Startable;
import org.sonar.api.config.Settings;
import org.sonar.db.property.PropertiesDao;
import org.sonar.db.property.PropertyDto;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Map;
/**
* @since 3.2
*/
public class PersistentSettings implements Startable {
private final PropertiesDao propertiesDao;
private final ServerSettings serverSettings;
public PersistentSettings(PropertiesDao propertiesDao, ServerSettings serverSettings) {
this.propertiesDao = propertiesDao;
this.serverSettings = serverSettings;
}
@Override
public void start() {
Map databaseProperties = Maps.newHashMap();
for (PropertyDto property : getGlobalProperties()) {
databaseProperties.put(property.getKey(), property.getValue());
}
serverSettings.activateDatabaseSettings(databaseProperties);
}
@Override
public void stop() {
// nothing to do
}
public PersistentSettings saveProperty(String key, @Nullable String value) {
serverSettings.setProperty(key, value);
propertiesDao.insertProperty(new PropertyDto().setKey(key).setValue(value));
return this;
}
public PersistentSettings deleteProperty(String key) {
serverSettings.removeProperty(key);
propertiesDao.deleteGlobalProperty(key);
return this;
}
public PersistentSettings deleteProperties() {
serverSettings.clear();
propertiesDao.deleteGlobalProperties();
return this;
}
public PersistentSettings saveProperties(Map properties) {
serverSettings.addProperties(properties);
propertiesDao.insertGlobalProperties(properties);
return this;
}
public String getString(String key) {
return serverSettings.getString(key);
}
public Map getProperties() {
return serverSettings.getProperties();
}
public Settings getSettings() {
return serverSettings.getSettings();
}
public List getGlobalProperties() {
return propertiesDao.selectGlobalProperties();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy