Search in sources :

Example 61 with NamedToken

use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.

the class TokenStoreTestTemplate method tokensMustPreserveTheirInternalFlag.

@Test
void tokensMustPreserveTheirInternalFlag() {
    R tokenRecord = createInUseRecord(allocateNameRecords("MyInternalToken"));
    tokenRecord.setInternal(true);
    storeToken(tokenRecord);
    R readBack = store.getRecord(tokenRecord.getId(), store.newRecord(), NORMAL, NULL);
    store.ensureHeavy(readBack, NULL);
    assertThat(readBack).isEqualTo(tokenRecord);
    assertThat(tokenRecord.isInternal()).isEqualTo(true);
    assertThat(readBack.isInternal()).isEqualTo(true);
    NamedToken token = store.getToken(toIntExact(tokenRecord.getId()), NULL);
    assertThat(token.name()).isEqualTo("MyInternalToken");
    assertThat(token.id()).isIn(toIntExact(tokenRecord.getId()));
    assertTrue(token.isInternal());
}
Also used : NamedToken(org.neo4j.token.api.NamedToken) Test(org.junit.jupiter.api.Test)

Example 62 with NamedToken

use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.

the class GraphCountsSection method relationshipCounts.

private static List<Map<String, Object>> relationshipCounts(TokenRead tokens, Read read, Anonymizer anonymizer) {
    List<Map<String, Object>> relationshipCounts = new ArrayList<>();
    Map<String, Object> relationshipCount = new HashMap<>();
    relationshipCount.put("count", read.countsForRelationshipWithoutTxState(-1, -1, -1));
    relationshipCounts.add(relationshipCount);
    List<NamedToken> labels = Iterators.asList(tokens.labelsGetAllTokens());
    tokens.relationshipTypesGetAllTokens().forEachRemaining(t -> {
        long count = read.countsForRelationshipWithoutTxState(-1, t.id(), -1);
        Map<String, Object> relationshipTypeCount = new HashMap<>();
        relationshipTypeCount.put("relationshipType", anonymizer.relationshipType(t.name(), t.id()));
        relationshipTypeCount.put("count", count);
        relationshipCounts.add(relationshipTypeCount);
        for (NamedToken label : labels) {
            long startCount = read.countsForRelationshipWithoutTxState(label.id(), t.id(), -1);
            if (startCount > 0) {
                Map<String, Object> x = new HashMap<>();
                x.put("relationshipType", anonymizer.relationshipType(t.name(), t.id()));
                x.put("startLabel", anonymizer.label(label.name(), label.id()));
                x.put("count", startCount);
                relationshipCounts.add(x);
            }
            long endCount = read.countsForRelationshipWithoutTxState(-1, t.id(), label.id());
            if (endCount > 0) {
                Map<String, Object> x = new HashMap<>();
                x.put("relationshipType", anonymizer.relationshipType(t.name(), t.id()));
                x.put("endLabel", anonymizer.label(label.name(), label.id()));
                x.put("count", endCount);
                relationshipCounts.add(x);
            }
        }
    });
    return relationshipCounts;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NamedToken(org.neo4j.token.api.NamedToken) HashMap(java.util.HashMap) Map(java.util.Map)

Example 63 with NamedToken

use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.

the class CacheInvalidationTransactionApplier method visitLabelTokenCommand.

@Override
public boolean visitLabelTokenCommand(LabelTokenCommand command) {
    NamedToken labelId = labelTokenStore.getToken(command.tokenId(), cursorContext);
    cacheAccess.addLabelToken(labelId);
    return false;
}
Also used : NamedToken(org.neo4j.token.api.NamedToken)

Aggregations

NamedToken (org.neo4j.token.api.NamedToken)63 Test (org.junit.jupiter.api.Test)41 ArrayList (java.util.ArrayList)6 TokenNotFoundException (org.neo4j.token.api.TokenNotFoundException)6 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)5 SchemaRule (org.neo4j.internal.schema.SchemaRule)5 NonUniqueTokenException (org.neo4j.token.api.NonUniqueTokenException)5 TokenHolder (org.neo4j.token.api.TokenHolder)5 AlreadyConstrainedException (org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException)4 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 IntSupplier (java.util.function.IntSupplier)3 KernelException (org.neo4j.exceptions.KernelException)3 Iterators (org.neo4j.internal.helpers.collection.Iterators)3 IdCapacityExceededException (org.neo4j.internal.id.IdCapacityExceededException)3 Token (org.neo4j.internal.kernel.api.Token)3 TokenWrite.checkValidTokenName (org.neo4j.internal.kernel.api.TokenWrite.checkValidTokenName)3 LabelNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.LabelNotFoundKernelException)3 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)3 RelationshipTypeIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.RelationshipTypeIdNotFoundKernelException)3