Search in sources :

Example 1 with NonUniqueTokenException

use of org.neo4j.token.api.NonUniqueTokenException 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;
}
Also used : NonUniqueTokenException(org.neo4j.token.api.NonUniqueTokenException) UnspecifiedKernelException(org.neo4j.exceptions.UnspecifiedKernelException) NamedToken(org.neo4j.token.api.NamedToken)

Example 2 with NonUniqueTokenException

use of org.neo4j.token.api.NonUniqueTokenException 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 3 with NonUniqueTokenException

use of org.neo4j.token.api.NonUniqueTokenException 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 4 with NonUniqueTokenException

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

the class TokenRegistryTest method puttingInternalTokenWithDuplicateNamedNotAllowed.

@Test
void puttingInternalTokenWithDuplicateNamedNotAllowed() {
    registry.put(new NamedToken(INBOUND1_TYPE, 1, true));
    registry.put(new NamedToken(INBOUND2_TYPE, 2, true));
    NamedToken token = new NamedToken(INBOUND1_TYPE, 3, true);
    NonUniqueTokenException exception = assertThrows(NonUniqueTokenException.class, () -> registry.put(token));
    assertThat(exception.getMessage()).contains(format("The testType %s is not unique", token));
}
Also used : NonUniqueTokenException(org.neo4j.token.api.NonUniqueTokenException) NamedToken(org.neo4j.token.api.NamedToken) Test(org.junit.jupiter.api.Test)

Example 5 with NonUniqueTokenException

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

the class TokenRegistryTest method puttingPublicTokenWithDuplicateNamedNotAllowed.

@Test
void puttingPublicTokenWithDuplicateNamedNotAllowed() {
    registry.put(new NamedToken(INBOUND1_TYPE, 1));
    registry.put(new NamedToken(INBOUND2_TYPE, 2));
    NamedToken token = new NamedToken(INBOUND1_TYPE, 3);
    NonUniqueTokenException exception = assertThrows(NonUniqueTokenException.class, () -> registry.put(token));
    assertThat(exception.getMessage()).contains(format("The testType %s is not unique", token));
}
Also used : NonUniqueTokenException(org.neo4j.token.api.NonUniqueTokenException) NamedToken(org.neo4j.token.api.NamedToken) Test(org.junit.jupiter.api.Test)

Aggregations

NamedToken (org.neo4j.token.api.NamedToken)6 NonUniqueTokenException (org.neo4j.token.api.NonUniqueTokenException)6 Test (org.junit.jupiter.api.Test)2 MutableIntSet (org.eclipse.collections.api.set.primitive.MutableIntSet)1 ObjectIntHashMap (org.eclipse.collections.impl.map.mutable.primitive.ObjectIntHashMap)1 IntHashSet (org.eclipse.collections.impl.set.mutable.primitive.IntHashSet)1 UnspecifiedKernelException (org.neo4j.exceptions.UnspecifiedKernelException)1