import org.apache.ibatis.session.SqlSession;
import java.io.Serializable;
-import java.util.Collection;
public interface Dao<E extends Dto<K>, K extends Serializable> {
void deleteByKey(K key, SqlSession session);
- Collection<K> insertsSince(Long timestamp);
+ Iterable<K> keysOfRowsUpdatedAfter(long timestamp);
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.core.db;
+
+import javax.annotation.ParametersAreNonnullByDefault;
package org.sonar.core.rule;
import com.google.common.collect.Lists;
+import org.apache.ibatis.session.ResultContext;
+import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.SqlSession;
import org.sonar.api.BatchComponent;
import org.sonar.api.ServerComponent;
import org.sonar.core.persistence.MyBatis;
import javax.annotation.CheckForNull;
-
+import java.sql.Timestamp;
import java.util.Collection;
import java.util.List;
+import java.util.Map;
import static com.google.common.collect.Lists.newArrayList;
}
@Override
- public Collection<RuleKey> insertsSince(Long timestamp) {
- // TODO Auto-generated method stub
- return null;
+ public Collection<RuleKey> keysOfRowsUpdatedAfter(long timestamp) {
+ SqlSession session = mybatis.openSession();
+ try {
+ final List<RuleKey> keys = Lists.newArrayList();
+ session.select("selectKeysOfRulesUpdatedSince", new Timestamp(timestamp), new ResultHandler() {
+ @Override
+ public void handleResult(ResultContext context) {
+ Map<String, String> map = (Map) context.getResultObject();
+ keys.add(RuleKey.of(map.get("repo"), map.get("rule")));
+ }
+ });
+ return keys;
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
}
}
void updateTag(RuleRuleTagDto existingTag);
List<RuleRuleTagDto> selectTagsByRuleIds(@Param("ruleIds") List<Integer> ruleIds);
+
}
DELETE FROM rules_rule_tags WHERE id=#{tagId}
</update>
+
+ <select id="selectKeysOfRulesUpdatedSince" resultType="map">
+ SELECT r.plugin_name as "repo", r.plugin_rule_key as "rule"
+ FROM rules r
+ WHERE r.updated_at IS NULL or r.updated_at >= #{id}
+ </select>
</mapper>
import org.sonar.check.Cardinality;
import org.sonar.core.persistence.AbstractDaoTestCase;
+import java.util.Arrays;
import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
assertThat(dao.selectTagsByRuleIds(newArrayList(3, 4))).hasSize(3);
}
+ @Test
+ public void keysOfRowsUpdatedAfter() throws Exception {
+ setupData("empty");
+
+ RuleDto rule1 = new RuleDto()
+ .setId(1)
+ .setRepositoryKey("foo")
+ .setRuleKey("R1")
+ .setName("ROne")
+ .setCreatedAt(DateUtils.parseDate("2013-12-16"))
+ .setUpdatedAt(DateUtils.parseDate("2013-12-16"));
+ RuleDto rule2 = new RuleDto()
+ .setId(2)
+ .setRepositoryKey("foo")
+ .setRuleKey("R2")
+ .setName("RTwo")
+ .setCreatedAt(DateUtils.parseDate("2014-01-28"))
+ .setUpdatedAt(DateUtils.parseDate("2014-05-19"));
+ dao.insert(Arrays.asList(rule1, rule2));
+
+ assertThat(dao.keysOfRowsUpdatedAfter(DateUtils.parseDate("2014-06-01").getTime())).isEmpty();
+ assertThat(dao.keysOfRowsUpdatedAfter(DateUtils.parseDate("2012-01-01").getTime())).hasSize(2);
+ Iterable<RuleKey> keys = dao.keysOfRowsUpdatedAfter(DateUtils.parseDate("2014-05-17").getTime());
+ assertThat(keys).hasSize(1);
+ assertThat(Iterables.getFirst(keys, null).rule()).isEqualTo("R2");
+ }
+
private List<Integer> idsFromRuleDtos(List<RuleDto> ruleDtos){
return newArrayList(Iterables.transform(ruleDtos, new Function<RuleDto, Integer>() {
@Override
json
.prop("key", rule.ruleKey().toString())
.prop("name", rule.name())
- .prop("description", rule.description())
- ;
+ .prop("description", rule.description());
addLanguage(rule, json);
addNote(rule, json);
addDate(rule.createdAt(), "createdAt", json);
Language language = languages.get(languageKey);
json.prop("language", language == null ? languageKey : language.getName());
}
-
}
private void addNote(Rule rule, JsonWriter json) {
action
.createParam("activation")
- .setDescription("Only if 'qProfile' is set. Possible values are: true | false | all")
+ .setDescription("Used only if 'qProfile' is set. Possible values are: true | false | all")
.setExampleValue("java:Sonar way");
}
.setSince("4.4")
.setHandler(this);
+ action
+ .createParam("repo")
+ .setDescription("Repository key")
+ .setRequired(true)
+ .setExampleValue("javascript");
+
action
.createParam("key")
.setDescription("Rule key")
.setRequired(true)
- .setExampleValue("javascript:EmptyBlock");
+ .setExampleValue("EmptyBlock");
}
@Override