private void validateCreationDateBounds(@Nullable Date createdBefore, @Nullable Date createdAfter) { Preconditions.checkArgument(createdAfter == null || createdAfter.before(new Date(system.now())), "Start bound cannot be in the future"); Preconditions.checkArgument(createdAfter == null || createdBefore == null || createdAfter.before(createdBefore), "Start bound cannot be larger or equal to end bound"); }
private Optional<Long> computeTimeOutOf(CeTask ceTask) { Long startTimestamp = startTimestampByCeTaskUuid.get(ceTask.getUuid()); checkState(startTimestamp != null, "No start time recorded for task %s", ceTask.getUuid()); long duration = system2.now() - startTimestamp; return Optional.of(duration) .filter(t -> t > taskTimeoutThreshold); }
public GroupDto update(DbSession session, GroupDto item) { item.setUpdatedAt(new Date(system.now())); mapper(session).update(item); return item; }
public void update(DbSession dbSession, QProfileDto profile, QProfileDto... otherProfiles) { QualityProfileMapper mapper = mapper(dbSession); long now = system.now(); doUpdate(mapper, profile, now); for (QProfileDto otherProfile : otherProfiles) { doUpdate(mapper, otherProfile, now); } }
/** * Similar to {@link #insertOrUpdate(DbSession, LiveMeasureDto)}, except that: * <ul> * <li>it is batch session friendly (single same statement for both updates and inserts)</li> * <li>it triggers a single SQL request</li> * </ul> * <p> * <strong>This method should not be called unless {@link Dialect#supportsUpsert()} is true</strong> */ public int upsert(DbSession dbSession, LiveMeasureDto dto) { return mapper(dbSession).upsert(dto, Uuids.create(), system2.now()); }
public void setDefaultTemplates(DbSession dbSession, String uuid, DefaultTemplates defaultTemplates) { checkUuid(uuid); checkDefaultTemplates(defaultTemplates); long now = system2.now(); getMapper(dbSession).updateDefaultTemplates(uuid, defaultTemplates, now); }
private void doInsert(QualityProfileMapper mapper, QProfileDto profile) { checkArgument(profile.getId() == null, "Quality profile is already persisted (got id %d)", profile.getId()); long now = system.now(); RulesProfileDto rulesProfile = RulesProfileDto.from(profile); mapper.insertRuleProfile(rulesProfile, new Date(now)); mapper.insertOrgQProfile(OrgQProfileDto.from(profile), now); profile.setId(rulesProfile.getId()); }
public void insert(DbSession dbSession, QProfileChangeDto dto) { checkState(dto.getCreatedAt() == 0L, "Date of QProfileChangeDto must be set by DAO only. Got %s.", dto.getCreatedAt()); dto.setUuid(uuidFactory.create()); dto.setCreatedAt(system2.now()); mapper(dbSession).insert(dto); }
@Override protected void execute(Context context) throws SQLException { context.prepareUpsert("update users set is_root=?, updated_at=? where is_root=?") .setBoolean(1, false) .setLong(2, system2.now()) .setBoolean(3, true) .execute() .commit(); } }
@Override public void execute(Context context) throws SQLException { MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select("SELECT u.id, u.login FROM users u WHERE external_identity_provider IS NULL OR external_identity IS NULL"); massUpdate.update("UPDATE users SET external_identity_provider=?, external_identity=?, updated_at=? WHERE id=?"); massUpdate.rowPluralName("users"); massUpdate.execute(new MigrationHandler(system2.now())); }
@Test public void delete() { when(uuidFactory.create()).thenReturn(A_UUID); when(system2.now()).thenReturn(DATE); underTest.insertOrUpdate(dbSession, GITHUB, A_OWNER, true, AN_INSTALL, null); underTest.delete(dbSession, GITHUB, A_OWNER); assertThatAlmAppInstall(GITHUB, A_OWNER).doesNotExist(); }
@Test public void selectByOwnerId() { when(uuidFactory.create()).thenReturn(A_UUID); when(system2.now()).thenReturn(DATE); underTest.insertOrUpdate(dbSession, GITHUB, A_OWNER, true, AN_INSTALL, null); assertThat(underTest.selectByOwnerId(dbSession, GITHUB, A_OWNER).get()) .extracting(AlmAppInstallDto::getUuid, AlmAppInstallDto::getAlm, AlmAppInstallDto::getInstallId, AlmAppInstallDto::getOwnerId, AlmAppInstallDto::getCreatedAt, AlmAppInstallDto::getUpdatedAt) .contains(A_UUID, GITHUB, A_OWNER, AN_INSTALL, DATE, DATE); assertThat(underTest.selectByOwnerId(dbSession, BITBUCKETCLOUD, A_OWNER)).isNotPresent(); assertThat(underTest.selectByOwnerId(dbSession, GITHUB, "Unknown owner")).isNotPresent(); }
private CeQueueDto insertInProgress(String uuid, String componentUuid) { CeQueueDto ceQueueDto = insertPending(uuid); CeQueueTesting.makeInProgress(db.getSession(), "workerUuid", System2.INSTANCE.now(), ceQueueDto); return underTest.selectByUuid(db.getSession(), uuid).get(); }
@Test public void clear() { when(system2.now()).thenReturn(DATE); underTest.put(dbSession, A_KEY_TYPE, A_KEY, PROJECT_UUID); assertThatProjectMapping(A_KEY_TYPE, A_KEY) .hasProjectUuid(PROJECT_UUID) .hasCreatedAt(DATE); underTest.clear(dbSession, A_KEY_TYPE, A_KEY); assertThat(underTest.get(dbSession, A_KEY_TYPE, A_KEY)).isEmpty(); }
public void delete(RuleKey ruleKey) { try (DbSession dbSession = dbClient.openSession(false)) { RuleDefinitionDto rule = dbClient.ruleDao().selectOrFailDefinitionByKey(dbSession, ruleKey); checkArgument(rule.isCustomRule(), "Rule '%s' cannot be deleted because it is not a custom rule", rule.getKey().toString()); qProfileRules.deleteRule(dbSession, rule); rule.setStatus(RuleStatus.REMOVED); rule.setUpdatedAt(system2.now()); dbClient.ruleDao().update(dbSession, rule); ruleIndexer.commitAndIndex(dbSession, rule.getId()); } } }
private EventDto newBaseEvent(Component component, Long analysisDate) { return new EventDto() .setUuid(uuidFactory.create()) .setAnalysisUuid(analysisMetadataHolder.getUuid()) .setComponentUuid(component.getUuid()) .setCreatedAt(system2.now()) .setDate(analysisDate); }
@Test public void setDefaultQualityGate() { when(system2.now()).thenReturn(DATE_3); OrganizationDto organization = db.organizations().insert(); QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization); underTest.setDefaultQualityGate(dbSession, organization, qualityGate); db.commit(); assertThat(dbClient.qualityGateDao().selectDefault(dbSession, organization).getUuid()).isEqualTo(qualityGate.getUuid()); verifyOrganizationUpdatedAt(organization.getUuid(), DATE_3); }
@Test public void saveAsEmpty_persist_property_without_textvalue_nor_clob_value_when_old_value_was_in_clob() { when(system2.now()).thenReturn(DATE_2, DATE_1); underTest.save(dbSession, A_KEY, VALUE_SIZE_4001); assertThatInternalProperty(A_KEY) .hasClobValue(VALUE_SIZE_4001) .hasCreatedAt(DATE_2); underTest.saveAsEmpty(dbSession, A_KEY); assertThatInternalProperty(A_KEY) .isEmpty() .hasCreatedAt(DATE_1); }
@Test public void putMultiple() { when(system2.now()).thenReturn(DATE); underTest.put(dbSession, A_KEY_TYPE, A_KEY, PROJECT_UUID); underTest.put(dbSession, A_KEY_TYPE, ANOTHER_KEY, OTHER_PROJECT_UUID); assertThatProjectMapping(A_KEY_TYPE, A_KEY) .hasProjectUuid(PROJECT_UUID) .hasCreatedAt(DATE); assertThatProjectMapping(A_KEY_TYPE, ANOTHER_KEY) .hasProjectUuid(OTHER_PROJECT_UUID) .hasCreatedAt(DATE); }
@Before public void setUp() throws Exception { when(system2.now()).thenReturn(NOW); group1 = db.users().insertGroup(db.getDefaultOrganization(), GROUP1); group2 = db.users().insertGroup(db.getDefaultOrganization(), GROUP2); sonarUsers = db.users().insertDefaultGroup(db.getDefaultOrganization(), "sonar-users"); }