import java.util.Collection;
import java.util.List;
import java.util.Map;
+import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.lang.StringUtils;
-import org.apache.ibatis.session.SqlSession;
import org.sonar.api.resources.Scopes;
import org.sonar.db.Dao;
import org.sonar.db.DatabaseUtils;
* @return the list of logins (maybe be empty - obviously)
*/
public List<String> selectUsersForNotification(String notificationDispatcherKey, String notificationChannelKey,
- @Nullable String projectUuid) {
- SqlSession session = mybatis.openSession(false);
+ @Nullable String projectUuid) {
+ DbSession session = mybatis.openSession(false);
PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
try {
return mapper.findUsersForNotification(NOTIFICATION_PREFIX + notificationDispatcherKey + "." + notificationChannelKey, projectUuid);
}
public List<String> selectNotificationSubscribers(String notificationDispatcherKey, String notificationChannelKey, @Nullable String componentKey) {
- SqlSession session = mybatis.openSession(false);
+ DbSession session = mybatis.openSession(false);
PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
try {
return mapper.findNotificationSubscribers(NOTIFICATION_PREFIX + notificationDispatcherKey + "." + notificationChannelKey, componentKey);
}
public List<PropertyDto> selectGlobalProperties() {
- SqlSession session = mybatis.openSession(false);
+ DbSession session = mybatis.openSession(false);
try {
return selectGlobalProperties(session);
} finally {
}
}
- public List<PropertyDto> selectGlobalProperties(SqlSession session) {
+ public List<PropertyDto> selectGlobalProperties(DbSession session) {
return session.getMapper(PropertiesMapper.class).selectGlobalProperties();
}
+ @CheckForNull
+ public PropertyDto selectGlobalProperty(DbSession session, String propertyKey) {
+ return session.getMapper(PropertiesMapper.class).selectByKey(new PropertyDto().setKey(propertyKey));
+ }
+
+ @CheckForNull
public PropertyDto selectGlobalProperty(String propertyKey) {
- SqlSession session = mybatis.openSession(false);
- PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
+ DbSession session = mybatis.openSession(false);
try {
- return mapper.selectByKey(new PropertyDto().setKey(propertyKey));
+ return selectGlobalProperty(session, propertyKey);
} finally {
MyBatis.closeQuietly(session);
}
}
}
- public List<PropertyDto> selectEnabledDescendantModuleProperties(String moduleUuid, SqlSession session) {
+ public List<PropertyDto> selectEnabledDescendantModuleProperties(String moduleUuid, DbSession session) {
return session.getMapper(PropertiesMapper.class).selectDescendantModuleProperties(moduleUuid, Scopes.PROJECT, true);
}
+ @CheckForNull
public PropertyDto selectProjectProperty(long resourceId, String propertyKey) {
- SqlSession session = mybatis.openSession(false);
+ DbSession session = mybatis.openSession(false);
PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
try {
return mapper.selectByKey(new PropertyDto().setKey(propertyKey).setResourceId(resourceId));
return session.getMapper(PropertiesMapper.class).selectByQuery(query);
}
- public void insertProperty(SqlSession session, PropertyDto property) {
+ public void insertProperty(DbSession session, PropertyDto property) {
PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
PropertyDto persistedProperty = mapper.selectByKey(property);
if (persistedProperty != null && !StringUtils.equals(persistedProperty.getValue(), property.getValue())) {
}
public void insertProperty(PropertyDto property) {
- SqlSession session = mybatis.openSession(false);
+ DbSession session = mybatis.openSession(false);
try {
insertProperty(session, property);
session.commit();
}
public void deleteProjectProperty(String key, Long projectId) {
- SqlSession session = mybatis.openSession(false);
+ DbSession session = mybatis.openSession(false);
try {
deleteProjectProperty(key, projectId, session);
session.commit();
}
}
- public void deleteProjectProperty(String key, Long projectId, SqlSession session) {
+ public void deleteProjectProperty(String key, Long projectId, DbSession session) {
PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
mapper.deleteProjectProperty(key, projectId);
}
- public void deleteProjectProperties(String key, String value, SqlSession session) {
+ public void deleteProjectProperties(String key, String value, DbSession session) {
PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
mapper.deleteProjectProperties(key, value);
}
public void deleteProjectProperties(String key, String value) {
- SqlSession session = mybatis.openSession(false);
+ DbSession session = mybatis.openSession(false);
try {
deleteProjectProperties(key, value, session);
session.commit();
}
public void deleteGlobalProperties() {
- SqlSession session = mybatis.openSession(false);
+ DbSession session = mybatis.openSession(false);
PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
try {
mapper.deleteGlobalProperties();
}
}
- public void deleteGlobalProperty(String key, SqlSession session) {
+ public void deleteGlobalProperty(String key, DbSession session) {
PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
mapper.deleteGlobalProperty(key);
}
public void deleteGlobalProperty(String key) {
- SqlSession session = mybatis.openSession(false);
+ DbSession session = mybatis.openSession(false);
try {
deleteGlobalProperty(key, session);
session.commit();
}
public void deleteAllProperties(String key) {
- SqlSession session = mybatis.openSession(false);
+ DbSession session = mybatis.openSession(false);
PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
try {
mapper.deleteAllProperties(key);
Preconditions.checkArgument(!Strings.isNullOrEmpty(newKey), "New property key must not be empty");
if (!newKey.equals(oldKey)) {
- SqlSession session = mybatis.openSession(false);
+ DbSession session = mybatis.openSession(false);
PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
try {
mapper.renamePropertyKey(oldKey, newKey);
* Update all properties (global and projects ones) with a given key and value to a new value
*/
public void updateProperties(String key, String oldValue, String newValue) {
- SqlSession session = mybatis.openSession(false);
+ DbSession session = mybatis.openSession(false);
try {
updateProperties(key, oldValue, newValue, session);
session.commit();
}
}
- public void updateProperties(String key, String oldValue, String newValue, SqlSession session) {
+ public void updateProperties(String key, String oldValue, String newValue, DbSession session) {
PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
mapper.updateProperties(key, oldValue, newValue);
}