use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.
the class KernelToken method labelsGetAllTokens.
@Override
public Iterator<NamedToken> labelsGetAllTokens() {
ktx.assertOpen();
AccessMode mode = ktx.securityContext().mode();
return Iterators.stream(tokenHolders.labelTokens().getAllTokens().iterator()).filter(label -> mode.allowsTraverseNode(label.id())).iterator();
}
use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.
the class KernelToken method propertyKeyGetAllTokens.
@Override
public Iterator<NamedToken> propertyKeyGetAllTokens() {
ktx.assertOpen();
AccessMode mode = ktx.securityContext().mode();
return Iterators.stream(tokenHolders.propertyKeyTokens().getAllTokens().iterator()).filter(propKey -> mode.allowsSeePropertyKeyToken(propKey.id())).iterator();
}
use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.
the class KernelToken method relationshipTypesGetAllTokens.
@Override
public Iterator<NamedToken> relationshipTypesGetAllTokens() {
ktx.assertOpen();
AccessMode mode = ktx.securityContext().mode();
return Iterators.stream(tokenHolders.relationshipTypeTokens().getAllTokens().iterator()).filter(relType -> mode.allowsTraverseRelType(relType.id())).iterator();
}
use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.
the class PlainOperationsTest method shouldReleaseAcquiredSchemaWriteLockIfNodePropertyExistenceConstraintCreationFails.
@Test
void shouldReleaseAcquiredSchemaWriteLockIfNodePropertyExistenceConstraintCreationFails() throws Exception {
// given
NodeExistenceConstraintDescriptor constraint = existsForSchema(schema);
storageReaderWithConstraints(constraint);
int labelId = schema.getLabelId();
int propertyId = schema.getPropertyId();
when(tokenHolders.labelTokens().getTokenById(labelId)).thenReturn(new NamedToken("Label", labelId));
when(tokenHolders.propertyKeyTokens().getTokenById(propertyId)).thenReturn(new NamedToken("prop", labelId));
// when
try {
operations.nodePropertyExistenceConstraintCreate(schema, "constraint name");
fail("Expected an exception because this schema should already be constrained.");
} catch (AlreadyConstrainedException ignore) {
// Good.
}
// then
order.verify(locks).acquireExclusive(LockTracer.NONE, ResourceTypes.LABEL, labelId);
order.verify(storageReader).constraintsGetForSchema(schema);
order.verify(locks).releaseExclusive(ResourceTypes.LABEL, labelId);
}
use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.
the class PlainOperationsTest method mustAssignNameToIndexesThatDoNotHaveUserSuppliedName.
@Test
void mustAssignNameToIndexesThatDoNotHaveUserSuppliedName() throws Exception {
when(creationContext.reserveSchema()).thenReturn(1L, 2L, 3L);
when(tokenHolders.labelTokens().getTokenById(1)).thenReturn(new NamedToken("LabelA", 1));
when(tokenHolders.labelTokens().getTokenById(2)).thenReturn(new NamedToken("LabelB", 1));
when(tokenHolders.labelTokens().getTokenById(3)).thenReturn(new NamedToken("LabelC", 1));
when(tokenHolders.propertyKeyTokens().getTokenById(1)).thenReturn(new NamedToken("PropA", 1));
when(tokenHolders.propertyKeyTokens().getTokenById(2)).thenReturn(new NamedToken("PropB", 2));
storageReaderWithoutConstraints();
when(storageReader.indexGetForSchema(any())).thenReturn(Collections.emptyIterator());
operations.indexCreate(SchemaDescriptor.forLabel(1, 1), null);
operations.indexCreate(IndexPrototype.forSchema(SchemaDescriptor.fulltext(NODE, new int[] { 2, 3 }, new int[] { 1, 2 })).withIndexType(IndexType.FULLTEXT));
operations.indexCreate(SchemaDescriptor.forLabel(3, 1), "provider-1.0", IndexConfig.empty(), null);
IndexDescriptor[] indexDescriptors = txState.indexChanges().getAdded().stream().sorted(Comparator.comparing(d -> d.schema().getEntityTokenIds()[0])).toArray(IndexDescriptor[]::new);
assertThat(indexDescriptors.length).as(Arrays.toString(indexDescriptors)).isEqualTo(3);
assertThat(indexDescriptors[0].getId()).as(indexDescriptors[0].toString()).isEqualTo(1L);
assertThat(indexDescriptors[1].getId()).as(indexDescriptors[1].toString()).isEqualTo(2L);
assertThat(indexDescriptors[2].getId()).as(indexDescriptors[2].toString()).isEqualTo(3L);
assertThat(indexDescriptors[0].getName()).as(indexDescriptors[0].toString()).isEqualTo("index_5c81a58e");
assertThat(indexDescriptors[1].getName()).as(indexDescriptors[1].toString()).isEqualTo("index_2813986a");
assertThat(indexDescriptors[2].getName()).as(indexDescriptors[2].toString()).isEqualTo("index_edb2dfd3");
}
Aggregations