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