dao.upsert(dbSession, lm); } else { dao.insertOrUpdate(dbSession, lm);
.forEach(m -> dbClient.liveMeasureDao().insertOrUpdate(dbSession, m)); projectIndexer.commitAndIndex(dbSession, singleton(project), ProjectIndexer.Cause.MEASURE_CHANGE);
@Test public void deleteByComponentUuidExcludingMetricIds_with_empty_metrics() { LiveMeasureDto measure1 = newLiveMeasure().setComponentUuid("C1").setMetricId(1); LiveMeasureDto measure2 = newLiveMeasure().setComponentUuid("C1").setMetricId(2); LiveMeasureDto measureOnOtherComponent = newLiveMeasure().setComponentUuid("C2").setMetricId(2); underTest.insertOrUpdate(db.getSession(), measure1); underTest.insertOrUpdate(db.getSession(), measure2); underTest.insertOrUpdate(db.getSession(), measureOnOtherComponent); int count = underTest.deleteByComponentUuidExcludingMetricIds(db.getSession(), "C1", Collections.emptyList()); assertThat(count).isEqualTo(2); verifyTableSize(1); verifyPersisted(measureOnOtherComponent); }
@Test public void deleteByComponentUuidExcludingMetricIds() { LiveMeasureDto measure1 = newLiveMeasure().setComponentUuid("C1").setMetricId(1); LiveMeasureDto measure2 = newLiveMeasure().setComponentUuid("C1").setMetricId(2); LiveMeasureDto measure3 = newLiveMeasure().setComponentUuid("C1").setMetricId(3); LiveMeasureDto measureOtherComponent = newLiveMeasure().setComponentUuid("C2").setMetricId(3); underTest.insertOrUpdate(db.getSession(), measure1); underTest.insertOrUpdate(db.getSession(), measure2); underTest.insertOrUpdate(db.getSession(), measure3); underTest.insertOrUpdate(db.getSession(), measureOtherComponent); int count = underTest.deleteByComponentUuidExcludingMetricIds(db.getSession(), "C1", Arrays.asList(1, 2)); verifyTableSize(3); verifyPersisted(measure1); verifyPersisted(measure2); verifyPersisted(measureOtherComponent); assertThat(count).isEqualTo(1); }
@Test public void insertOrUpdate() { // insert LiveMeasureDto dto = newLiveMeasure(); underTest.insertOrUpdate(db.getSession(), dto); verifyPersisted(dto); verifyTableSize(1); // update dto.setValue(dto.getValue() + 1); dto.setVariation(dto.getVariation() + 10); dto.setData(dto.getDataAsString() + "_new"); underTest.insertOrUpdate(db.getSession(), dto); verifyPersisted(dto); verifyTableSize(1); }
private LiveMeasureDto insertMeasure(String componentUuid, String projectUuid, Metric metric) { LiveMeasureDto measure = newLiveMeasure() .setComponentUuid(componentUuid) .setProjectUuid(projectUuid) .setMetricId(metricRepository.getByKey(metric.getKey()).getId()); dbClient.liveMeasureDao().insertOrUpdate(db.getSession(), measure); return measure; }
@Test public void etag_should_be_different_if_quality_gate_is_different() { ComponentDto project = db.components().insertPublicProject(); userSession.registerComponents(project); MetricDto metric = createQualityGateMetric(); LiveMeasureDto liveMeasure = db.measures().insertLiveMeasure(project, metric, m -> m.setData(OK.name())); TestResponse response = ws.newRequest() .setParam("project", project.getKey()) .execute(); String eTagOK = response.getHeader("ETag"); liveMeasure.setData(ERROR.name()); db.getDbClient().liveMeasureDao().insertOrUpdate(db.getSession(), liveMeasure); db.commit(); response = ws.newRequest() .setParam("project", project.getKey()) .execute(); String eTagERROR = response.getHeader("ETag"); assertThat(Arrays.asList(eTagOK, eTagERROR)) .doesNotContainNull() .doesNotHaveDuplicates(); }
@Override public void visitAny(Component component) { int count = 0; LiveMeasureDao dao = dbClient.liveMeasureDao(); Multimap<String, Measure> measures = measureRepository.getRawMeasures(component); for (Map.Entry<String, Collection<Measure>> measuresByMetricKey : measures.asMap().entrySet()) { String metricKey = measuresByMetricKey.getKey(); if (NOT_TO_PERSIST_ON_FILE_METRIC_KEYS.contains(metricKey) && component.getType() == Component.Type.FILE) { continue; } Metric metric = metricRepository.getByKey(metricKey); Predicate<Measure> notBestValueOptimized = BestValueOptimization.from(metric, component).negate(); Iterator<LiveMeasureDto> liveMeasures = measuresByMetricKey.getValue().stream() .filter(NonEmptyMeasure.INSTANCE) .filter(notBestValueOptimized) .map(measure -> measureToMeasureDto.toLiveMeasureDto(measure, metric, component)) .iterator(); while (liveMeasures.hasNext()) { dao.insertOrUpdate(dbSession, liveMeasures.next(), marker); count++; if (count % 100 == 0) { // use short transactions to avoid potential deadlocks on MySQL // https://jira.sonarsource.com/browse/SONAR-10117?focusedCommentId=153555&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-153555 dbSession.commit(); } } } } }
matrix.getChanged().forEach(m -> dbClient.liveMeasureDao().insertOrUpdate(dbSession, m, null)); projectIndexer.commitAndIndex(dbSession, singleton(project), ProjectIndexer.Cause.MEASURE_CHANGE);