Search in sources :

Example 26 with NamedToken

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

the class TokenStore method readAllTokens.

private List<NamedToken> readAllTokens(boolean ignoreInconsistentTokens, CursorContext cursorContext) {
    long highId = getHighId();
    ArrayList<NamedToken> records = new ArrayList<>();
    records.ensureCapacity(Math.toIntExact(highId));
    RECORD record = newRecord();
    for (int i = 0; i < highId; i++) {
        if (!getRecord(i, record, RecordLoad.LENIENT_CHECK, cursorContext).inUse()) {
            continue;
        }
        if (record.getNameId() != Record.RESERVED.intValue()) {
            try {
                String name = getStringFor(record, cursorContext);
                records.add(new NamedToken(name, i, record.isInternal()));
            } catch (Exception e) {
                if (!ignoreInconsistentTokens) {
                    throw e;
                }
            }
        }
    }
    return records;
}
Also used : ArrayList(java.util.ArrayList) PropertyStore.decodeString(org.neo4j.kernel.impl.store.PropertyStore.decodeString) NamedToken(org.neo4j.token.api.NamedToken)

Example 27 with NamedToken

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

the class CacheInvalidationTransactionApplier method visitRelationshipTypeTokenCommand.

@Override
public boolean visitRelationshipTypeTokenCommand(RelationshipTypeTokenCommand command) {
    NamedToken type = relationshipTypeTokenStore.getToken(command.tokenId(), cursorContext);
    cacheAccess.addRelationshipTypeToken(type);
    return false;
}
Also used : NamedToken(org.neo4j.token.api.NamedToken)

Example 28 with NamedToken

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

the class CacheInvalidationTransactionApplier method visitPropertyKeyTokenCommand.

@Override
public boolean visitPropertyKeyTokenCommand(PropertyKeyTokenCommand command) {
    NamedToken index = propertyKeyTokenStore.getToken(command.tokenId(), cursorContext);
    cacheAccess.addPropertyKeyToken(index);
    return false;
}
Also used : NamedToken(org.neo4j.token.api.NamedToken)

Example 29 with NamedToken

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

the class LabelIT method shouldListAllLabels.

@Test
void shouldListAllLabels() throws Exception {
    // given
    KernelTransaction transaction = newTransaction(AnonymousContext.writeToken());
    int label1Id = transaction.tokenWrite().labelGetOrCreateForName("label1");
    int label2Id = transaction.tokenWrite().labelGetOrCreateForName("label2");
    // when
    Iterator<NamedToken> labelIdsBeforeCommit = transaction.tokenRead().labelsGetAllTokens();
    // then
    assertThat(asCollection(labelIdsBeforeCommit)).contains(new NamedToken("label1", label1Id), new NamedToken("label2", label2Id));
    // when
    commit();
    transaction = newTransaction();
    Iterator<NamedToken> labelIdsAfterCommit = transaction.tokenRead().labelsGetAllTokens();
    // then
    assertThat(asCollection(labelIdsAfterCommit)).contains(new NamedToken("label1", label1Id), new NamedToken("label2", label2Id));
    commit();
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NamedToken(org.neo4j.token.api.NamedToken) Test(org.junit.jupiter.api.Test)

Example 30 with NamedToken

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

the class PropertyIT method shouldListAllPropertyKeys.

@Test
void shouldListAllPropertyKeys() throws Exception {
    // given
    dbWithNoCache();
    KernelTransaction transaction = newTransaction(AnonymousContext.writeToken());
    int prop1 = transaction.tokenWrite().propertyKeyGetOrCreateForName("prop1");
    int prop2 = transaction.tokenWrite().propertyKeyGetOrCreateForName("prop2");
    // when
    Iterator<NamedToken> propIdsBeforeCommit = transaction.tokenRead().propertyKeyGetAllTokens();
    // then
    assertThat(asCollection(propIdsBeforeCommit)).contains(new NamedToken("prop1", prop1), new NamedToken("prop2", prop2));
    // when
    commit();
    transaction = newTransaction();
    Iterator<NamedToken> propIdsAfterCommit = transaction.tokenRead().propertyKeyGetAllTokens();
    // then
    assertThat(asCollection(propIdsAfterCommit)).contains(new NamedToken("prop1", prop1), new NamedToken("prop2", prop2));
    commit();
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) 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