<select id="selectAllKeysAfterTimestamp" parameterType="Date" resultType="map">
SELECT
- rule.plugin_rule_key as ruleField,
- rule.plugin_name as repositoryField,
- profile.name as profileField,
- profile.language as languageField
+ r.plugin_rule_key as ruleField,
+ r.plugin_name as repositoryField,
+ qp.name as profileField,
+ qp.language as languageField
FROM active_rules a
<include refid="activeRuleKeyJoin"/>
<where>
- WHERE a.updated_at IS NULL or a.updated_at >= #{id}
+ a.updated_at IS NULL or a.updated_at >= #{id}
</where>
</select>
startupContainer.addSingleton(CleanPreviewAnalysisCache.class);
startupContainer.addSingleton(CopyRequirementsFromCharacteristicsToRules.class);
+ /** Index startup Synchronization */
+ startupContainer.addSingleton(IndexSynchronizer.class);
+
DoPrivileged.execute(new DoPrivileged.Task() {
@Override
protected void doPrivileged() {
import org.sonar.core.rule.RuleDto;
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 org.sonar.server.search.IndexDefinition;
import org.sonar.server.search.action.IndexAction;
import org.sonar.server.search.action.KeyIndexAction;
@VisibleForTesting
public ActiveRuleDao(QualityProfileDao profileDao, RuleDao ruleDao, System2 system) {
- super(new ActiveRuleIndexDefinition(), ActiveRuleMapper.class, system);
+ super(IndexDefinition.ACTIVE_RULE, ActiveRuleMapper.class, system);
this.ruleDao = ruleDao;
this.profileDao = profileDao;
}
session.enqueue(new KeyIndexAction<ActiveRuleKey>(getIndexType(), IndexAction.Method.UPSERT, key));
}
});
+ session.commit();
}
@Override
protected void doDeleteByKey(ActiveRuleKey key, DbSession session) {
ActiveRuleDto rule = this.getByKey(key, session);
+ mapper(session).deleteParameters(rule.getId());
mapper(session).delete(rule.getId());
}
public void deleteByProfileKey(QualityProfileKey profileKey, DbSession session) {
/** Functional cascade for params */
- this.removeParamByProfileKey(profileKey, session);
for (ActiveRuleDto activeRule : this.findByProfileKey(profileKey, session)) {
this.delete(activeRule, session);
}
*/
package org.sonar.server.search;
- import org.sonar.server.db.DbClient;
+import org.picocontainer.Startable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.server.db.DbClient;
/**
* @since 4.4
*/
-public class IndexSynchronizer {
+public class IndexSynchronizer implements Startable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(IndexSynchronizer.class);
private final DbClient db;
private final IndexClient index;
this.db = db;
this.index = index;
}
+
+ @Override
+ public void start() {
+ /* synchronize all activeRules until we have mng tables in INDEX */
+ DbSession session = db.openSession(true);
+ LOG.info("Starting DB to Index synchronization");
+ long start = System.currentTimeMillis();
+ db.activeRuleDao().synchronizeAfter(0, session);
+ LOG.info("Synchronization done in {}ms...", (System.currentTimeMillis()-start));
+ session.close();
+ }
+
+ @Override
+ public void stop() {
+
+ }
}