import org.sonar.server.db.BaseDao;
import org.sonar.server.search.IndexDefinition;
+import java.util.Date;
import java.util.List;
/**
}
@Override
- public void synchronizeAfter(DbSession session, long timestamp) {
+ public void synchronizeAfter(DbSession session, Date time) {
}
}
import javax.annotation.CheckForNull;
import java.io.Serializable;
import java.util.Collection;
+import java.util.Date;
public interface Dao<E extends Dto<K>, K extends Serializable> extends ServerComponent {
void deleteByKey(DbSession session, K key);
- void synchronizeAfter(DbSession session, long timestamp);
+ void synchronizeAfter(DbSession session, Date date);
}
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
-import org.sonar.core.persistence.DaoComponent;
import org.sonar.api.ServerComponent;
import org.sonar.api.utils.System2;
import org.sonar.core.measure.db.MeasureDto;
import org.sonar.core.measure.db.MeasureKey;
import org.sonar.core.measure.db.MeasureMapper;
+import org.sonar.core.persistence.DaoComponent;
import org.sonar.core.persistence.DbSession;
import org.sonar.server.db.BaseDao;
import java.util.Collections;
+import java.util.Date;
import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
}
@Override
- public void synchronizeAfter(DbSession session, long timestamp) {
+ public void synchronizeAfter(DbSession session, Date date) {
throw new IllegalStateException("Not implemented yet");
}
}
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.System2;
import org.sonar.core.persistence.DbSession;
-import org.sonar.core.qualityprofile.db.*;
+import org.sonar.core.qualityprofile.db.ActiveRuleDto;
+import org.sonar.core.qualityprofile.db.ActiveRuleKey;
+import org.sonar.core.qualityprofile.db.ActiveRuleMapper;
+import org.sonar.core.qualityprofile.db.ActiveRuleParamDto;
+import org.sonar.core.qualityprofile.db.QualityProfileDao;
+import org.sonar.core.qualityprofile.db.QualityProfileKey;
import org.sonar.core.rule.RuleDto;
import org.sonar.server.db.BaseDao;
import org.sonar.server.rule.db.RuleDao;
import org.sonar.server.search.action.KeyIndexAction;
import javax.annotation.CheckForNull;
-
import java.sql.Timestamp;
+import java.util.Date;
import java.util.List;
import java.util.Map;
}
@Override
- public void synchronizeAfter(final DbSession session, long timestamp) {
- session.select("selectAllKeysAfterTimestamp", new Timestamp(timestamp), new ResultHandler() {
+ public void synchronizeAfter(final DbSession session, Date date) {
+ session.select("selectAllKeysAfterTimestamp", new Timestamp(date.getTime()), new ResultHandler() {
@Override
public void handleResult(ResultContext context) {
Map<String, Object> fields = (Map<String, Object>) context.getResultObject();
import org.sonar.server.search.action.KeyIndexAction;
import javax.annotation.CheckForNull;
-
import java.sql.Timestamp;
+import java.util.Date;
import java.util.List;
import java.util.Map;
@Override
- public void synchronizeAfter(final DbSession session, long timestamp) {
- session.select("selectKeysOfRulesUpdatedSince", new Timestamp(timestamp), new ResultHandler() {
+ public void synchronizeAfter(final DbSession session, Date date) {
+ session.select("selectKeysOfRulesUpdatedSince", new Timestamp(date.getTime()), new ResultHandler() {
@Override
public void handleResult(ResultContext context) {
Map<String, String> map = (Map) context.getResultObject();
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.core.persistence.DbSession;
+import org.sonar.server.activity.index.ActivityIndex;
+import org.sonar.server.db.Dao;
import org.sonar.server.db.DbClient;
+import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
+import org.sonar.server.rule.index.RuleIndex;
/**
* @since 4.4
DbSession session = db.openSession(true);
LOG.info("Starting DB to Index synchronization");
long start = System.currentTimeMillis();
- db.ruleDao().synchronizeAfter(session, 0);
- db.activeRuleDao().synchronizeAfter(session, 0);
- db.activityDao().synchronizeAfter(session, 0);
+ synchronize(session, db.ruleDao(), index.get(RuleIndex.class));
+ synchronize(session, db.activeRuleDao(), index.get(ActiveRuleIndex.class));
+ synchronize(session, db.activityDao(), index.get(ActivityIndex.class));
session.commit();
LOG.info("Synchronization done in {}ms...", System.currentTimeMillis()-start);
session.close();
}
+
+ private void synchronize(DbSession session, Dao dao, Index index) {
+ long start = System.currentTimeMillis();
+ dao.synchronizeAfter(session,
+ index.getLastSynchronization());
+ LOG.info("-- Synchronized {} in {}ms", index.getIndexType(), (System.currentTimeMillis() - start));
+ }
}
import org.sonar.server.tester.ServerTester;
import java.util.Collection;
+import java.util.Date;
import java.util.List;
import java.util.Map;
assertThat(index.getByKey(activeRule.getKey())).isNull();
// 1. Synchronize since 0
- db.activeRuleDao().synchronizeAfter(dbSession, 0);
+ db.activeRuleDao().synchronizeAfter(dbSession, new Date());
// 2. Assert that we have the rule in Index
assertThat(index.getByKey(activeRule.getKey())).isNotNull();