use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.
the class RecordLoading method safeLoadTokens.
static <RECORD extends TokenRecord> List<NamedToken> safeLoadTokens(TokenStore<RECORD> tokenStore, CursorContext cursorContext) {
long highId = tokenStore.getHighId();
List<NamedToken> tokens = new ArrayList<>();
DynamicStringStore nameStore = tokenStore.getNameStore();
List<DynamicRecord> nameRecords = new ArrayList<>();
MutableLongSet seenRecordIds = new LongHashSet();
int nameBlockSize = nameStore.getRecordDataSize();
try (RecordReader<RECORD> tokenReader = new RecordReader<>(tokenStore, true, cursorContext);
RecordReader<DynamicRecord> nameReader = new RecordReader<>(nameStore, false, cursorContext)) {
for (long id = 0; id < highId; id++) {
RECORD record = tokenReader.read(id);
nameRecords.clear();
if (record.inUse()) {
String name;
if (!NULL_REFERENCE.is(record.getNameId()) && safeLoadDynamicRecordChain(r -> nameRecords.add(r.copy()), nameReader, seenRecordIds, record.getNameId(), nameBlockSize)) {
record.addNameRecords(nameRecords);
name = tokenStore.getStringFor(record, cursorContext);
} else {
name = format("<name not loaded due to token(%d) referencing unused name record>", id);
}
tokens.add(new NamedToken(name, toIntExact(id), record.isInternal()));
}
}
}
return tokens;
}
use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.
the class PlainOperationsTest method indexedBackedConstraintCreateMustThrowOnRelationshipSchemas.
@Test
void indexedBackedConstraintCreateMustThrowOnRelationshipSchemas() throws Exception {
// given
when(tokenHolders.relationshipTypeTokens().getTokenById(anyInt())).thenReturn(new NamedToken("RelType", 123));
when(tokenHolders.propertyKeyTokens().getTokenById(anyInt())).thenReturn(new NamedToken("prop", 456));
SchemaDescriptor schema = SchemaDescriptor.forRelType(this.schema.getEntityTokenIds()[0], this.schema.getPropertyIds());
IndexPrototype prototype = IndexPrototype.uniqueForSchema(schema).withName("constraint name").withIndexProvider(GenericNativeIndexProvider.DESCRIPTOR);
IndexDescriptor constraintIndex = prototype.materialise(42);
when(constraintIndexCreator.createUniquenessConstraintIndex(any(), any(), eq(prototype))).thenReturn(constraintIndex);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexProxy.getDescriptor()).thenReturn(constraintIndex);
when(indexingService.getIndexProxy(constraintIndex)).thenReturn(indexProxy);
when(storageReader.constraintsGetForSchema(schema)).thenReturn(Collections.emptyIterator());
when(storageReader.indexGetForSchema(schema)).thenReturn(Collections.emptyIterator());
// when
var e = assertThrows(KernelException.class, () -> operations.uniquePropertyConstraintCreate(prototype));
assertThat(e.getUserMessage(tokenHolders)).contains("relationship type schema");
}
use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.
the class SchemaRuleMigrationTest method mustOverwritePreviousDefaultConstraintNames.
@Test
void mustOverwritePreviousDefaultConstraintNames() throws KernelException {
SchemaRule rule = ConstraintDescriptorFactory.uniqueForSchema(SchemaDescriptor.forLabel(1, 2)).withId(1).withName("constraint_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 mustOverwritePreviousDefaultIndexNames.
@Test
void mustOverwritePreviousDefaultIndexNames() throws KernelException {
SchemaRule rule = IndexPrototype.forSchema(SchemaDescriptor.forLabel(1, 2)).withName("index_1").materialise(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("index_c3fbd584", writtenRules.get(0).getName());
}
use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.
the class DelegatingTokenHolder method createToken.
/**
* Create and put new token in cache.
*
* @param name token name
* @return newly created token id
*/
@Override
protected synchronized int createToken(String name, boolean internal) throws KernelException {
Integer id = internal ? tokenRegistry.getIdInternal(name) : tokenRegistry.getId(name);
if (id != null) {
return id;
}
id = tokenCreator.createToken(name, internal);
try {
tokenRegistry.put(new NamedToken(name, id, internal));
} catch (NonUniqueTokenException e) {
throw new UnspecifiedKernelException(Status.General.UnknownError, e, "Newly created token should be unique.");
}
return id;
}
Aggregations