Search in sources :

Example 6 with NamedToken

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

the class DelegatingTokenHolder method createMissingTokens.

private synchronized void createMissingTokens(String[] names, int[] ids, boolean internal) throws KernelException {
    // We redo the resolving under the lock, to make sure that these ids are really missing, and won't be
    // created concurrently with us.
    MutableIntSet unresolvedIndexes = new IntHashSet();
    resolveIds(names, ids, internal, i -> !unresolvedIndexes.add(i));
    if (!unresolvedIndexes.isEmpty()) {
        // We still have unresolved ids to create.
        ObjectIntHashMap<String> createdTokens = createUnresolvedTokens(unresolvedIndexes, names, ids, internal);
        List<NamedToken> createdTokensList = new ArrayList<>(createdTokens.size());
        createdTokens.forEachKeyValue((name, index) -> createdTokensList.add(new NamedToken(name, ids[index], internal)));
        tokenRegistry.putAll(createdTokensList);
    }
}
Also used : MutableIntSet(org.eclipse.collections.api.set.primitive.MutableIntSet) IntHashSet(org.eclipse.collections.impl.set.mutable.primitive.IntHashSet) ArrayList(java.util.ArrayList) NamedToken(org.neo4j.token.api.NamedToken)

Example 7 with NamedToken

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

the class TokenRegistry method put.

public synchronized void put(NamedToken token) {
    Registries reg = this.registries;
    if (reg.idToToken.containsKey(token.id())) {
        NamedToken existingToken = reg.idToToken.get(token.id());
        throw new NonUniqueTokenException(tokenType, token, existingToken);
    }
    reg = reg.copy();
    if (token.isInternal()) {
        checkNameUniqueness(reg.internalNameToId, token, reg);
        reg.internalNameToId.put(token.name(), token.id());
    } else {
        checkNameUniqueness(reg.publicNameToId, token, reg);
        reg.publicNameToId.put(token.name(), token.id());
    }
    reg.idToToken.put(token.id(), token);
    this.registries = reg;
}
Also used : NonUniqueTokenException(org.neo4j.token.api.NonUniqueTokenException) NamedToken(org.neo4j.token.api.NamedToken)

Example 8 with NamedToken

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

the class TokenRegistry method checkNameUniqueness.

private void checkNameUniqueness(MutableObjectIntMap<String> namesToId, NamedToken token, Registries registries) {
    if (namesToId.containsKey(token.name())) {
        int existingKey = namesToId.get(token.name());
        NamedToken existingToken = registries.idToToken.get(existingKey);
        throw new NonUniqueTokenException(tokenType, token, existingToken);
    }
}
Also used : NonUniqueTokenException(org.neo4j.token.api.NonUniqueTokenException) NamedToken(org.neo4j.token.api.NamedToken)

Example 9 with NamedToken

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

the class TokenRegistry method allTokens.

public Collection<NamedToken> allTokens() {
    // Likely nearly all tokens are returned here.
    Registries reg = this.registries;
    List<NamedToken> list = new ArrayList<>(reg.idToToken.size());
    for (NamedToken token : reg.idToToken) {
        if (!token.isInternal()) {
            list.add(token);
        }
    }
    return unmodifiableCollection(list);
}
Also used : ArrayList(java.util.ArrayList) NamedToken(org.neo4j.token.api.NamedToken)

Example 10 with NamedToken

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

the class TokenRegistryTest method puttingInternalTokenBySameNameAsPublicTokenMustNotConflict.

@Test
void puttingInternalTokenBySameNameAsPublicTokenMustNotConflict() {
    registry.put(new NamedToken(INBOUND1_TYPE, 1));
    // This mustn't throw:
    registry.put(new NamedToken(INBOUND1_TYPE, 2, true));
}
Also used : NamedToken(org.neo4j.token.api.NamedToken) Test(org.junit.jupiter.api.Test)

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