use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.
the class SchemaRuleMigrationTest method constraintsWithoutNamesMustBeGivenGeneratedOnes.
@Test
void constraintsWithoutNamesMustBeGivenGeneratedOnes() throws KernelException {
SchemaRule rule = ConstraintDescriptorFactory.uniqueForSchema(SchemaDescriptor.forLabel(1, 2)).withId(1);
srcTokenHolders.labelTokens().setInitialTokens(List.of(new NamedToken("Label", 1)));
srcTokenHolders.propertyKeyTokens().setInitialTokens(List.of(new NamedToken("prop", 2)));
when(src.getAll(any())).thenReturn(List.of(rule));
RecordStorageMigrator.migrateSchemaRules(srcTokenHolders, src, dst, NULL);
assertEquals(1, writtenRules.size());
assertEquals("constraint_952591e6", writtenRules.get(0).getName());
}
use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.
the class SchemaRuleMigrationTest method mustEnsureThatMigratedSchemaRuleNamesAreUnique.
@Test
void mustEnsureThatMigratedSchemaRuleNamesAreUnique() throws KernelException {
SchemaRule rule1 = IndexPrototype.forSchema(SchemaDescriptor.forLabel(1, 2)).withName("a").materialise(1);
SchemaRule rule2 = IndexPrototype.forSchema(SchemaDescriptor.forLabel(1, 3)).withName("a").materialise(2);
srcTokenHolders.labelTokens().setInitialTokens(List.of(new NamedToken("Label", 1)));
srcTokenHolders.propertyKeyTokens().setInitialTokens(List.of(new NamedToken("a", 2), new NamedToken("b", 3)));
when(src.getAll(any())).thenReturn(List.of(rule1, rule2));
RecordStorageMigrator.migrateSchemaRules(srcTokenHolders, src, dst, NULL);
long distinctNames = writtenRules.stream().map(SchemaRule::getName).distinct().count();
assertEquals(2, distinctNames);
}
use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.
the class SchemaRuleMigrationTest method mustEnsureUniqueNamesEvenWhenOldNamesMatchesNewDefaults.
@Test
void mustEnsureUniqueNamesEvenWhenOldNamesMatchesNewDefaults() throws KernelException {
SchemaRule rule1 = ConstraintDescriptorFactory.uniqueForSchema(SchemaDescriptor.forLabel(1, 2)).withId(1);
SchemaRule rule2 = ConstraintDescriptorFactory.uniqueForSchema(SchemaDescriptor.forLabel(1, 2)).withId(2);
srcTokenHolders.labelTokens().setInitialTokens(List.of(new NamedToken("Label", 1)));
srcTokenHolders.propertyKeyTokens().setInitialTokens(List.of(new NamedToken("prop", 2), new NamedToken("bla", 3)));
when(src.getAll(any())).thenReturn(List.of(rule1, rule2));
RecordStorageMigrator.migrateSchemaRules(srcTokenHolders, src, dst, NULL);
assertEquals(2, writtenRules.size());
Set<String> names = writtenRules.stream().map(SchemaRule::getName).collect(Collectors.toSet());
// Collisions in generated names (however fantastically unlikely) must be resolved by appending a count.
assertEquals(Set.of("constraint_952591e6", "constraint_952591e6_1"), names);
}
use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.
the class FulltextIndexProvider method validateIndexRef.
private void validateIndexRef(IndexRef<?> ref) {
String providerName = getProviderDescriptor().name();
if (ref.getIndexType() != IndexType.FULLTEXT) {
throw new IllegalArgumentException("The '" + providerName + "' index provider only supports FULLTEXT index types: " + ref);
}
if (!ref.schema().isFulltextSchemaDescriptor()) {
throw new IllegalArgumentException("The " + ref.schema() + " index schema is not a full-text index schema, " + "which it is required to be for the '" + providerName + "' index provider to be able to create an index.");
}
Value value = ref.getIndexConfig().get(ANALYZER);
if (value != null) {
if (value.valueGroup() == ValueGroup.TEXT) {
String analyzerName = ((TextValue) value).stringValue();
Optional<AnalyzerProvider> analyzerProvider = listAvailableAnalyzers().filter(analyzer -> analyzer.getName().equals(analyzerName)).findFirst();
if (analyzerProvider.isPresent()) {
// Verify that the analyzer provider works.
Analyzer analyzer = analyzerProvider.get().createAnalyzer();
Objects.requireNonNull(analyzer, "The '" + analyzerName + "' analyzer returned a 'null' analyzer.");
} else {
throw new IllegalArgumentException("No such full-text analyzer: '" + analyzerName + "'.");
}
} else {
throw new IllegalArgumentException("Wrong index setting value type for fulltext analyzer: '" + value + "'.");
}
}
TokenHolder propertyKeyTokens = tokenHolders.propertyKeyTokens();
for (int propertyId : ref.schema().getPropertyIds()) {
try {
NamedToken token = propertyKeyTokens.getTokenById(propertyId);
if (token.name().equals(LuceneFulltextDocumentStructure.FIELD_ENTITY_ID)) {
throw new IllegalArgumentException("Unable to index the property, the name is reserved for internal use " + LuceneFulltextDocumentStructure.FIELD_ENTITY_ID);
}
} catch (TokenNotFoundException e) {
throw new IllegalArgumentException("Schema references non-existing property key token id: " + propertyId + ".", e);
}
}
}
use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.
the class SchemaCalculator method addNamesToCollection.
private static void addNamesToCollection(Iterator<NamedToken> labelIterator, Map<Integer, String> collection) {
while (labelIterator.hasNext()) {
NamedToken label = labelIterator.next();
collection.put(label.id(), label.name());
}
}
Aggregations