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;
}
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;
}
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);
}
}
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));
}
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));
}
Aggregations