/** * Get UUID from database if it exists, otherwise generate a new one. */ @Override public String getOrCreateForKey(String key) { return uuidsByKey.computeIfAbsent(key, k -> Uuids.create()); } }
/** * Get UUID from component having the same key in database if it exists, otherwise look for migrated keys, and finally generate a new one. */ @Override public String getOrCreateForKey(String key) { return uuidsByDbKey.computeIfAbsent(key, k1 -> uuidsByMigratedKey.computeIfAbsent(k1, k2 -> Uuids.create())); } }
Object of(Object component, Logger log) { if (component instanceof Class) { return component; } String key = component.toString(); if (IDENTITY_HASH_PATTERN.matcher(key).matches()) { if (!objectsWithoutToString.add(component.getClass())) { log.warn(String.format("Bad component key: %s. Please implement toString() method on class %s", key, component.getClass().getName())); } key += Uuids.create(); } return new StringBuilder().append(component.getClass().getCanonicalName()).append("-").append(key).toString(); } }
/** * 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 insert(DbSession dbSession, LiveMeasureDto dto) { mapper(dbSession).insert(dto, Uuids.create(), system2.now()); }
public void insertOrUpdate(DbSession dbSession, LiveMeasureDto dto) { LiveMeasureMapper mapper = mapper(dbSession); long now = system2.now(); if (mapper.update(dto, now) == 0) { mapper.insert(dto, Uuids.create(), now); } }
@Test public void create_unique() { Set<String> all = new HashSet<>(); for (int i = 0; i < 50; i++) { String uuid = Uuids.create(); assertThat(uuid).isNotEmpty(); all.add(uuid); } assertThat(all).hasSize(50); }
public static DefaultIssueComment create(String issueKey, @Nullable String userUuid, String markdownText) { DefaultIssueComment comment = new DefaultIssueComment(); comment.setIssueKey(issueKey); comment.setKey(Uuids.create()); Date now = new Date(); comment.setUserUuid(userUuid); comment.setMarkdownText(markdownText); comment.setCreatedAt(now).setUpdatedAt(now); comment.setNew(true); return comment; }
public void copyExistingOpenIssueFromLongLivingBranch(DefaultIssue raw, DefaultIssue base, String fromLongBranchName) { raw.setKey(Uuids.create()); raw.setNew(false); copyAttributesOfIssueFromOtherBranch(raw, base); raw.setFieldChange(changeContext, IssueFieldsSetter.FROM_LONG_BRANCH, fromLongBranchName, analysisMetadataHolder.getBranch().getName()); }
@Test public void create_from_scratch_creates_ServerId_from_JDBC_URL_and_new_uuid() { String jdbcUrl = "jdbc"; String uuid = Uuids.create(); String sanitizedJdbcUrl = "sanitized_jdbc"; settings.setProperty(JDBC_URL.getKey(), jdbcUrl); when(uuidFactory.create()).thenReturn(uuid); when(jdbcUrlSanitizer.sanitize(jdbcUrl)).thenReturn(sanitizedJdbcUrl); ServerId serverId = underTest.create(); assertThat(serverId.getDatabaseId().get()).isEqualTo(crc32Hex(sanitizedJdbcUrl)); assertThat(serverId.getDatasetId()).isEqualTo(uuid); }
public void initNewOpenIssue(DefaultIssue issue) { Preconditions.checkArgument(issue.isFromExternalRuleEngine() != (issue.type() == null), "At this stage issue type should be set for and only for external issues"); issue.setKey(Uuids.create()); issue.setCreationDate(changeContext.date()); issue.setUpdateDate(changeContext.date()); issue.setStatus(Issue.STATUS_OPEN); issue.setEffort(debtCalculator.calculate(issue)); setType(issue); }
private static DefaultIssue newIssue(String severity, RuleType type) { return new DefaultIssue() .setKey(Uuids.create()) .setSeverity(severity) .setType(type) .setCreationDate(new Date(1000l)); }
public static PermissionTemplateDto newPermissionTemplateDto() { return new PermissionTemplateDto() .setName(randomAlphanumeric(60)) .setDescription(randomAscii(500)) .setOrganizationUuid(randomAlphanumeric(40)) .setUuid(Uuids.create()) .setCreatedAt(new Date()) .setUpdatedAt(new Date()); }
private static DefaultIssue newIssue(String severity, RuleType type) { return new DefaultIssue() .setKey(Uuids.create()) .setSeverity(severity) .setType(type) .setCreationDate(DEFAULT_ISSUE_CREATION_DATE); }
private PermissionTemplateDto insertTemplate(DbSession dbSession, OrganizationDto org, CreateTemplateRequest request) { Date now = new Date(system.now()); PermissionTemplateDto template = dbClient.permissionTemplateDao().insert(dbSession, new PermissionTemplateDto() .setUuid(Uuids.create()) .setOrganizationUuid(org.getUuid()) .setName(request.getName()) .setDescription(request.getDescription()) .setKeyPattern(request.getProjectKeyPattern()) .setCreatedAt(now) .setUpdatedAt(now)); dbSession.commit(); return template; }
/** * Copy a comment from another issue */ private static DefaultIssueComment copyComment(String issueKey, DefaultIssueComment c) { DefaultIssueComment comment = new DefaultIssueComment(); comment.setIssueKey(issueKey); comment.setKey(Uuids.create()); comment.setUserUuid(c.userUuid()); comment.setMarkdownText(c.markdownText()); comment.setCreatedAt(c.createdAt()).setUpdatedAt(c.updatedAt()); comment.setNew(true); return comment; }
@Test public void insertOrUpdate_updates_row_when_exists() { OrganizationDto org = dbTester.organizations().insert(); String previousQProfileUuid = Uuids.create(); DefaultQProfileDto dto = new DefaultQProfileDto() .setLanguage("java") .setOrganizationUuid(org.getUuid()) .setQProfileUuid(previousQProfileUuid); underTest.insertOrUpdate(dbSession, dto); dbSession.commit(); String newQProfileUuid = Uuids.create(); dto.setQProfileUuid(newQProfileUuid); underTest.insertOrUpdate(dbSession, dto); dbSession.commit(); assertThat(countRows()).isEqualTo(1); assertThat(selectUuidOfDefaultProfile(org, dto.getLanguage())).hasValue(newQProfileUuid); }
private ComponentDto createRootComponent(DbSession session, NewComponent newComponent) { checkBranchFormat(newComponent.qualifier(), newComponent.deprecatedBranch()); String keyWithBranch = ComponentKeys.createKey(newComponent.key(), newComponent.deprecatedBranch()); checkRequest(!dbClient.componentDao().selectByKey(session, keyWithBranch).isPresent(), "Could not create %s, key already exists: %s", getQualifierToDisplay(newComponent.qualifier()), keyWithBranch); String uuid = Uuids.create(); ComponentDto component = new ComponentDto() .setOrganizationUuid(newComponent.getOrganizationUuid()) .setUuid(uuid) .setUuidPath(ComponentDto.UUID_PATH_OF_ROOT) .setRootUuid(uuid) .setModuleUuid(null) .setModuleUuidPath(ComponentDto.UUID_PATH_SEPARATOR + uuid + ComponentDto.UUID_PATH_SEPARATOR) .setProjectUuid(uuid) .setDbKey(keyWithBranch) .setName(newComponent.name()) .setLongName(newComponent.name()) .setScope(Scopes.PROJECT) .setQualifier(newComponent.qualifier()) .setPrivate(newComponent.isPrivate()) .setCreatedAt(new Date(system2.now())); dbClient.componentDao().insert(session, component); return component; }
@Override protected void execute(Context context) throws SQLException { long now = system2.now(); // reentrancy of migration context.prepareUpsert("TRUNCATE TABLE live_measures").execute(); MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select("SELECT p.uuid, p.project_uuid, pm.metric_id, pm.value, pm.text_value, pm.variation_value_1, pm.measure_data " + "FROM project_measures pm " + "INNER JOIN projects p on p.uuid = pm.component_uuid " + "INNER JOIN snapshots s on s.uuid = pm.analysis_uuid " + "WHERE s.islast = ? and pm.person_id is null") .setBoolean(1, true); massUpdate.update("INSERT INTO live_measures " + "(uuid, component_uuid, project_uuid, metric_id, value, text_value, variation, measure_data, created_at, updated_at) " + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); massUpdate.rowPluralName("live measures"); massUpdate.execute((row, update) -> { update.setString(1, Uuids.create()); update.setString(2, row.getString(1)); update.setString(3, row.getString(2)); update.setInt(4, row.getInt(3)); update.setDouble(5, row.getNullableDouble(4)); update.setString(6, row.getNullableString(5)); update.setDouble(7, row.getNullableDouble(6)); update.setBytes(8, row.getNullableBytes(7)); update.setLong(9, now); update.setLong(10, now); return true; }); }
@Test public void selectQProfilesByRuleProfileUuid() { OrganizationDto org1 = db.organizations().insert(); OrganizationDto org2 = db.organizations().insert(); RulesProfileDto ruleProfile1 = QualityProfileTesting.newRuleProfileDto(); OrgQProfileDto profile1InOrg1 = new OrgQProfileDto().setOrganizationUuid(org1.getUuid()).setRulesProfileUuid(ruleProfile1.getKee()).setUuid(Uuids.create()); OrgQProfileDto profile1InOrg2 = new OrgQProfileDto().setOrganizationUuid(org2.getUuid()).setRulesProfileUuid(ruleProfile1.getKee()).setUuid(Uuids.create()); RulesProfileDto ruleProfile2 = QualityProfileTesting.newRuleProfileDto(); OrgQProfileDto profile2InOrg1 = new OrgQProfileDto().setOrganizationUuid(org1.getUuid()).setRulesProfileUuid(ruleProfile2.getKee()).setUuid(Uuids.create()); db.getDbClient().qualityProfileDao().insert(db.getSession(), ruleProfile1); db.getDbClient().qualityProfileDao().insert(db.getSession(), profile1InOrg1); db.getDbClient().qualityProfileDao().insert(db.getSession(), profile1InOrg2); db.getDbClient().qualityProfileDao().insert(db.getSession(), ruleProfile2); db.getDbClient().qualityProfileDao().insert(db.getSession(), profile2InOrg1); List<QProfileDto> result = db.getDbClient().qualityProfileDao().selectQProfilesByRuleProfile(db.getSession(), ruleProfile1); assertThat(result).extracting(QProfileDto::getKee).containsExactlyInAnyOrder(profile1InOrg1.getUuid(), profile1InOrg2.getUuid()); result = db.getDbClient().qualityProfileDao().selectQProfilesByRuleProfile(db.getSession(), ruleProfile2); assertThat(result).extracting(QProfileDto::getKee).containsExactlyInAnyOrder(profile2InOrg1.getUuid()); }