org.sonar.db.measure.custom.CustomMeasureDao Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sonar-db Show documentation
Show all versions of sonar-db Show documentation
Create and request SonarQube schema
/*
* 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.db.measure.custom;
import com.google.common.base.Function;
import java.util.List;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.apache.ibatis.session.RowBounds;
import org.sonar.api.server.ServerSide;
import org.sonar.db.Dao;
import org.sonar.db.DatabaseUtils;
import org.sonar.db.DbSession;
import org.sonar.db.RowNotFoundException;
@ServerSide
public class CustomMeasureDao implements Dao {
public void insert(DbSession session, CustomMeasureDto customMeasureDto) {
mapper(session).insert(customMeasureDto);
}
public void update(DbSession session, CustomMeasureDto customMeasure) {
mapper(session).update(customMeasure);
}
public void delete(DbSession session, long id) {
mapper(session).delete(id);
}
public void deleteByMetricIds(final DbSession session, final List metricIds) {
DatabaseUtils.executeLargeInputsWithoutOutput(metricIds, new Function, Void>() {
@Override
public Void apply(@Nonnull List input) {
mapper(session).deleteByMetricIds(metricIds);
return null;
}
});
}
@CheckForNull
public CustomMeasureDto selectById(DbSession session, long id) {
return mapper(session).selectById(id);
}
public CustomMeasureDto selectOrFail(DbSession session, long id) {
CustomMeasureDto customMeasure = selectById(session, id);
if (customMeasure == null) {
throw new RowNotFoundException(String.format("Custom measure '%d' not found.", id));
}
return customMeasure;
}
public List selectByMetricId(DbSession session, int metricId) {
return mapper(session).selectByMetricId(metricId);
}
public int countByComponentIdAndMetricId(DbSession session, String componentUuid, int metricId) {
return mapper(session).countByComponentIdAndMetricId(componentUuid, metricId);
}
public List selectByComponentUuid(DbSession session, String componentUuid, int offset, int limit) {
return mapper(session).selectByComponentUuid(componentUuid, new RowBounds(offset, limit));
}
public List selectByComponentUuid(DbSession session, String componentUuid) {
return mapper(session).selectByComponentUuid(componentUuid);
}
/**
* Used by Views plugin
*/
public List selectByMetricKeyAndTextValue(DbSession session, String metricKey, String textValue) {
return mapper(session).selectByMetricKeyAndTextValue(metricKey, textValue);
}
private CustomMeasureMapper mapper(DbSession session) {
return session.getMapper(CustomMeasureMapper.class);
}
public int countByComponentUuid(DbSession dbSession, String uuid) {
return mapper(dbSession).countByComponentUuid(uuid);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy