LEFT JOIN active_rules active_rule_parent ON active_rule_parent.profile_id=profile_parent.id AND a.rule_id=active_rule_parent.rule_id
</sql>
+ <select id="selectAllKeysAfterTimestamp" parameterType="Date" resultType="map">
+ SELECT
+ rule.plugin_rule_key as rule,
+ rule.plugin_name as repository,
+ profile.name as profile,
+ profile.language as language
+ FROM active_rules a
+ <include refid="activeRuleKeyJoin"/>
+ <where>
+ AND profile.name = #{profile}
+ AND profile.language = #{language}
+ AND rule.plugin_rule_key = #{rule}
+ AND rule.plugin_name = #{repository}
+ </where>
+ </select>
+
<insert id="insert" parameterType="ActiveRule" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
INSERT INTO active_rules (profile_id, rule_id, failure_level, inheritance)
VALUES (#{profileId}, #{ruleId}, #{severity}, #{inheritance})
package org.sonar.server.db;
import org.sonar.api.ServerComponent;
-import org.sonar.core.persistence.Dto;
import org.sonar.core.persistence.DbSession;
+import org.sonar.core.persistence.Dto;
import javax.annotation.CheckForNull;
import java.io.Serializable;
void deleteByKey(K key, DbSession session);
- Iterable<K> keysOfRowsUpdatedAfter(long timestamp, DbSession session);
+ void synchronizeAfter(long timestamp, DbSession session);
}
List<ActiveRuleChange> changes = activate(activation, dbSession);
if (!changes.isEmpty()) {
dbSession.commit();
- previewCache.reportGlobalModification();
- }
- return changes;
- } finally {
- dbSession.close();
- }
+ previewCache.reportGlobalModification();
+ }
+ return changes;
+} finally {
+ dbSession.close();
+ }
}
/**
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
+import org.apache.ibatis.session.ResultContext;
+import org.apache.ibatis.session.ResultHandler;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.System2;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.qualityprofile.db.QualityProfileDto;
import org.sonar.core.qualityprofile.db.QualityProfileKey;
import org.sonar.core.rule.RuleDto;
-import org.sonar.core.rule.RuleParamDto;
import org.sonar.server.db.BaseDao;
import org.sonar.server.qualityprofile.QProfile;
import org.sonar.server.qualityprofile.index.ActiveRuleIndexDefinition;
import org.sonar.server.rule2.persistence.RuleDao;
+import java.util.Date;
import java.util.List;
-
-import static com.google.common.collect.Lists.newArrayList;
+import java.util.Map;
public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, ActiveRuleKey> {
}
@Override
- public Iterable<ActiveRuleKey> keysOfRowsUpdatedAfter(long timestamp, DbSession session) {
- throw new UnsupportedOperationException("Need to implement ActiveRuleDto.doGetByKey() method");
+ public void synchronizeAfter(long timestamp, DbSession session) {
+ session.select("selectAllKeysAfterTimestamp",new Date(timestamp), new ResultHandler() {
+ @Override
+ public void handleResult(ResultContext context) {
+ Map<String, Object> resultObject = (Map<String, Object>) context.getResultObject();
+ resultObject.get(|TOTO);
+ //session.enqueue();
+ }
+ });
}
.field(RuleNormalizer.RuleField.LANGUAGE.key())
.order(Terms.Order.count(false))
.size(10)
- .minDocCount(0));
+ .minDocCount(1));
/* the Tag facet */
query.addAggregation(AggregationBuilders
.field(RuleNormalizer.RuleField._TAGS.key())
.order(Terms.Order.count(false))
.size(10)
- .minDocCount(0));
+ .minDocCount(1));
/* the Repo facet */
query.addAggregation(AggregationBuilders
.field(RuleNormalizer.RuleField.REPOSITORY.key())
.order(Terms.Order.count(false))
.size(10)
- .minDocCount(0));
+ .minDocCount(1));
}
}
}
+ public Long getLastUpdate(String indexType){
+ for(Index<?,?,?> index:indexComponents.values()){
+ if(index.getIndexType().equals(indexType)){
+ return index.getLastSynchronization();
+ }
+ }
+ throw new IllegalStateException("no index for type '"+indexType+"' is registered");
+ }
+
public <K extends Index> K get(Class<K> clazz){
return (K) this.indexComponents.get(clazz);
}
return (K) index;
}
}
- throw new IllegalStateException("no index for tyle '"+indexType+"' is registered");
+ throw new IllegalStateException("no index for type '"+indexType+"' is registered");
}
}
--- /dev/null
+package org.sonar.server.search;
+
+import org.sonar.server.db.DbClient;
+
+/**
+ * @since 4.4
+ */
+public class IndexSynchronizer {
+
+ private final DbClient db;
+ private final IndexClient index;
+
+ public IndexSynchronizer(DbClient db, IndexClient index) {
+ this.db = db;
+ this.index = index;
+ }
+}