public static String createFast() { return UuidFactoryFast.getInstance().create(); } }
@Override public String create() { long timestamp = System.currentTimeMillis(); byte[] uuidBytes = new byte[9]; // Only use lower 6 bytes of the timestamp (this will suffice beyond the year 10000): putLong(uuidBytes, timestamp, 0, 6); // Sequence number adds 3 bytes: putLong(uuidBytes, getSequenceNumber(), 6, 3); return byteArrayToHex(uuidBytes); }
@Test public void has_no_effect_if_group_does_not_exist() throws SQLException { String orgUuid = uuidFactoryFast.create(); insertDefaultOrganizationUuid(orgUuid); insertGroup(orgUuid, "sonar"); underTest.execute(); assertGroupRoles(); }
private EventComponentChangeDto generateEventComponentChange(EventDto event, ChangeCategory category, String name, String key, @Nullable String branch, String componentUuid) { return new EventComponentChangeDto() .setCategory(category) .setUuid(uuidFactoryFast.create()) .setComponentName(name) .setComponentKey(key) .setComponentBranchKey(branch) .setComponentUuid(componentUuid) .setEventUuid(event.getUuid()); }
private static String newUuid() { return UuidFactoryFast.getInstance().create(); } }
@Test public void create_missing_permissions() throws SQLException { String orgUuid = uuidFactoryFast.create(); insertDefaultOrganizationUuid(orgUuid); insertGroup(orgUuid, "sonar-administrators"); Long adminGroupId = getGroupId("sonar-administrators"); underTest.execute(); assertGroupRoles( tuple(orgUuid, adminGroupId, null, "applicationcreator"), tuple(orgUuid, adminGroupId, null, "portfoliocreator")); }
@Override public String create() { long timestamp = System.currentTimeMillis(); byte[] uuidBytes = new byte[9]; // Only use lower 6 bytes of the timestamp (this will suffice beyond the year 10000): putLong(uuidBytes, timestamp, 0, 6); // Sequence number adds 3 bytes: putLong(uuidBytes, getSequenceNumber(), 6, 3); return byteArrayToHex(uuidBytes); }
private String insertDefaultOrganization() { String uuid = UuidFactoryFast.getInstance().create(); dbTester.executeInsert( "INTERNAL_PROPERTIES", "KEE", "organization.default", "IS_EMPTY", "false", "TEXT_VALUE", uuid); return uuid; }
@Test public void is_reentrant() throws SQLException { String orgUuid = uuidFactoryFast.create(); insertDefaultOrganizationUuid(orgUuid); insertGroup(orgUuid, "sonar-administrators"); Long adminGroupId = getGroupId("sonar-administrators"); underTest.execute(); underTest.execute(); assertGroupRoles( tuple(orgUuid, adminGroupId, null, "applicationcreator"), tuple(orgUuid, adminGroupId, null, "portfoliocreator")); }
private void insertDefaultOrganization() { db.executeInsert( "ORGANIZATIONS", "UUID", DEFAULT_ORGANIZATION_UUID, "KEE", "default-organization", "NAME", "Default Organization", "GUARDED", true, "DEFAULT_PERM_TEMPLATE_VIEW", DEFAULT_PERM_TEMPLATE_VIEW, "DEFAULT_QUALITY_GATE_UUID", UuidFactoryFast.getInstance().create(), "NEW_PROJECT_PRIVATE", false, "SUBSCRIPTION", "SONARQUBE", "CREATED_AT", PAST.getTime(), "UPDATED_AT", PAST.getTime()); }
@Test public void has_no_effect_if_roles_are_already_present() throws SQLException { String orgUuid = uuidFactoryFast.create(); insertDefaultOrganizationUuid(orgUuid); insertGroup(orgUuid, "sonar-administrators"); Long adminGroupId = getGroupId("sonar-administrators"); insertGroupRole(orgUuid, adminGroupId, null, "applicationcreator"); insertGroupRole(orgUuid, adminGroupId, null, "portfoliocreator"); underTest.execute(); assertGroupRoles( tuple(orgUuid, adminGroupId, null, "applicationcreator"), tuple(orgUuid, adminGroupId, null, "portfoliocreator")); }
private long insertProperty(@Nullable Integer resourceId) { String key = UuidFactoryFast.getInstance().create(); db.executeInsert( TABLE_PROPERTIES, "PROP_KEY", key, "RESOURCE_ID", resourceId == null ? null : String.valueOf(resourceId), "IS_EMPTY", String.valueOf(random.nextBoolean())); return (Long) db.selectFirst("select id as \"ID\" from properties where prop_key='" + key + "'").get("ID"); }
.setDescription("")); EventComponentChangeDto changeDto1 = generateEventComponentChange(eventDto, FAILED_QUALITY_GATE, "My project", "app1", "master", project.uuid()); EventComponentChangeDto changeDto2 = generateEventComponentChange(eventDto, FAILED_QUALITY_GATE, "Another project", "app2", "master", uuidFactoryFast.create()); insertEventComponentChanges(project, a3, changeDto1, changeDto2);
private long insertManualMeasure(@Nullable String componentUuid) { String uuid = UuidFactoryFast.getInstance().create(); db.executeInsert( TABLE_MANUAL_MEASURES, "METRIC_ID", random.nextInt(), "COMPONENT_UUID", componentUuid, "TEXT_VALUE", uuid); return (Long) db.selectFirst("select id as \"ID\" from " + TABLE_MANUAL_MEASURES + " where text_value = '" + uuid + "'").get("ID"); }
private void insertCeTaskCharacteristic(String taskUuid, int i) { String uuid = UuidFactoryFast.getInstance().create(); db.executeInsert( "ce_task_characteristics", "UUID", uuid, "TASK_UUID", taskUuid, "KEE", "kee_" + uuid + i, "TEXT_VALUE", randomAlphanumeric(18)); }
private void insertCeTaskCharacteristics(String taskUuid) { for (int i = 0; i < 1 + random.nextInt(3); i++) { String uuid = UuidFactoryFast.getInstance().create(); db.executeInsert( "ce_task_characteristics", "UUID", uuid, "TASK_UUID", taskUuid, "KEE", "kee_" + uuid + i, "TEXT_VALUE", randomAlphanumeric(18)); } } }
@Test public void delete_unknown_EsQueueDto_does_not_throw_exception() { int nbOfInsert = 10 + new Random().nextInt(20); List<EsQueueDto> esQueueDtos = new ArrayList<>(); IntStream.rangeClosed(1, nbOfInsert).forEach( i -> esQueueDtos.add(EsQueueDto.create("foo", UuidFactoryFast.getInstance().create())) ); underTest.insert(dbSession, esQueueDtos); underTest.delete(dbSession, EsQueueDto.create("foo", UuidFactoryFast.getInstance().create())); assertThat(dbTester.countSql(dbSession, "select count(*) from es_queue")).isEqualTo(nbOfInsert); }
private String insertCeQueue() { String uuid = UuidFactoryFast.getInstance().create(); db.executeInsert( "ce_queue", "UUID", uuid, "TASK_TYPE", randomAlphanumeric(10), "STATUS", randomAlphanumeric(10), "EXECUTION_COUNT", random.nextInt(99), "CREATED_AT", random.nextInt(95654354), "UPDATED_AT", random.nextInt(95654354)); return uuid; }
@Test public void insert_data() { int nbOfInsert = 10 + new Random().nextInt(20); List<EsQueueDto> esQueueDtos = new ArrayList<>(); IntStream.rangeClosed(1, nbOfInsert).forEach( i -> esQueueDtos.add(EsQueueDto.create("foo", UuidFactoryFast.getInstance().create())) ); underTest.insert(dbSession, esQueueDtos); assertThat(dbTester.countSql(dbSession, "select count(*) from es_queue")).isEqualTo(nbOfInsert); }
private String insertComponent(String scope, String qualifier, @Nullable String projectUuid) { String uuid = UuidFactoryFast.getInstance().create(); db.executeInsert( "PROJECTS", "ORGANIZATION_UUID", randomAlphabetic(3), "UUID", uuid, "UUID_PATH", "path_" + uuid, "ROOT_UUID", randomAlphabetic(4), "PROJECT_UUID", projectUuid == null ? uuid : projectUuid, "SCOPE", scope, "QUALIFIER", qualifier, "PRIVATE", valueOf(random.nextBoolean()), "ENABLED", valueOf(random.nextBoolean())); return uuid; }