Search in sources :

Example 1 with Token

use of org.neo4j.storageengine.api.Token in project neo4j by neo4j.

the class CacheInvalidationTransactionApplier method visitLabelTokenCommand.

@Override
public boolean visitLabelTokenCommand(LabelTokenCommand command) throws IOException {
    Token labelId = labelTokenStore.getToken((int) command.getKey());
    cacheAccess.addLabelToken(labelId);
    return false;
}
Also used : RelationshipTypeToken(org.neo4j.kernel.impl.core.RelationshipTypeToken) Token(org.neo4j.storageengine.api.Token)

Example 2 with Token

use of org.neo4j.storageengine.api.Token in project neo4j by neo4j.

the class LabelIT method shouldListAllLabels.

@Test
public void shouldListAllLabels() throws Exception {
    // given
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    int label1Id = statement.tokenWriteOperations().labelGetOrCreateForName("label1");
    int label2Id = statement.tokenWriteOperations().labelGetOrCreateForName("label2");
    // when
    Iterator<Token> labelIdsBeforeCommit = statement.readOperations().labelsGetAllTokens();
    // then
    assertThat(asCollection(labelIdsBeforeCommit), hasItems(new Token("label1", label1Id), new Token("label2", label2Id)));
    // when
    commit();
    ReadOperations readOperations = readOperationsInNewTransaction();
    Iterator<Token> labelIdsAfterCommit = readOperations.labelsGetAllTokens();
    // then
    assertThat(asCollection(labelIdsAfterCommit), hasItems(new Token("label1", label1Id), new Token("label2", label2Id)));
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) Statement(org.neo4j.kernel.api.Statement) Token(org.neo4j.storageengine.api.Token) Test(org.junit.Test)

Example 3 with Token

use of org.neo4j.storageengine.api.Token in project neo4j by neo4j.

the class PropertyIT method shouldListAllPropertyKeys.

@Test
public void shouldListAllPropertyKeys() throws Exception {
    // given
    dbWithNoCache();
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    int prop1 = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("prop1");
    int prop2 = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("prop2");
    // when
    Iterator<Token> propIdsBeforeCommit = statement.readOperations().propertyKeyGetAllTokens();
    // then
    assertThat(asCollection(propIdsBeforeCommit), hasItems(new Token("prop1", prop1), new Token("prop2", prop2)));
    // when
    commit();
    ReadOperations readOperations = readOperationsInNewTransaction();
    Iterator<Token> propIdsAfterCommit = readOperations.propertyKeyGetAllTokens();
    // then
    assertThat(asCollection(propIdsAfterCommit), hasItems(new Token("prop1", prop1), new Token("prop2", prop2)));
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) Statement(org.neo4j.kernel.api.Statement) Token(org.neo4j.storageengine.api.Token) Test(org.junit.Test)

Example 4 with Token

use of org.neo4j.storageengine.api.Token in project neo4j by neo4j.

the class NonIndexedConflictResolverTest method shouldCreateNewPropertyKeyTokenWhenItIsNotCreatedOnPreviousNodes.

@Test
public void shouldCreateNewPropertyKeyTokenWhenItIsNotCreatedOnPreviousNodes() throws IOException {
    // Given
    NonIndexedConflictResolver resolver = new NonIndexedConflictResolver(propertyKeyTokenStore, propertyStore);
    List<DuplicateCluster> clusterListA = new ArrayList<>();
    long propertyIdA = addDuplicateCluster(nodeIdA, clusterListA);
    List<DuplicateCluster> clusterListC = new ArrayList<>();
    long propertyIdC = addDuplicateCluster(nodeIdC, clusterListC);
    // When
    resolver.visited(0, clusterListA);
    resolver.visited(0, clusterListC);
    // Then
    Token duplicateTokenA1 = findTokenFor(propertyKeyTokenStore, "__DUPLICATE_keyA_1");
    Token duplicateTokenA2 = findTokenFor(propertyKeyTokenStore, "__DUPLICATE_keyA_2");
    Token duplicateTokenA3 = findTokenFor(propertyKeyTokenStore, "__DUPLICATE_keyA_3");
    Token duplicateTokenA4 = findTokenFor(propertyKeyTokenStore, "__DUPLICATE_keyA_4");
    assertNotNull(duplicateTokenA1);
    assertNotNull(duplicateTokenA2);
    assertNotNull(duplicateTokenA3);
    assertNotNull(duplicateTokenA4);
    Set<Integer> propertyKeyIdsA = collectPropertyKeyIds(propertyIdA);
    assertThat(propertyKeyIdsA, contains(tokenA.id(), duplicateTokenA1.id()));
    Set<Integer> propertyKeyIdsC = collectPropertyKeyIds(propertyIdC);
    assertThat(propertyKeyIdsC, contains(tokenA.id(), duplicateTokenA1.id(), duplicateTokenA2.id(), duplicateTokenA3.id(), duplicateTokenA4.id()));
}
Also used : ArrayList(java.util.ArrayList) Token(org.neo4j.storageengine.api.Token) Test(org.junit.Test)

Example 5 with Token

use of org.neo4j.storageengine.api.Token in project neo4j by neo4j.

the class NonIndexedConflictResolverTest method shouldRenameDuplicatedPropertyKeysOnANode.

@Test
public void shouldRenameDuplicatedPropertyKeysOnANode() throws Exception {
    // Given
    NonIndexedConflictResolver resolver = new NonIndexedConflictResolver(propertyKeyTokenStore, propertyStore);
    List<DuplicateCluster> clusters = new ArrayList<>();
    long propertyId = addDuplicateCluster(nodeIdA, clusters);
    // When
    resolver.visited(0, clusters);
    // Then
    Token duplicateTokenA = findTokenFor(propertyKeyTokenStore, "__DUPLICATE_keyA_1");
    assertNotNull(duplicateTokenA);
    Set<Integer> propertyKeyIdsA = collectPropertyKeyIds(propertyId);
    assertThat(propertyKeyIdsA, contains(tokenA.id(), duplicateTokenA.id()));
}
Also used : ArrayList(java.util.ArrayList) Token(org.neo4j.storageengine.api.Token) Test(org.junit.Test)

Aggregations

Token (org.neo4j.storageengine.api.Token)19 Test (org.junit.Test)8 RelationshipTypeToken (org.neo4j.kernel.impl.core.RelationshipTypeToken)8 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Before (org.junit.Before)2 ReadOperations (org.neo4j.kernel.api.ReadOperations)2 Statement (org.neo4j.kernel.api.Statement)2 UniquenessConstraint (org.neo4j.kernel.api.constraints.UniquenessConstraint)2 BatchTransactionApplier (org.neo4j.kernel.impl.api.BatchTransactionApplier)2 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)2 LabelTokenRecord (org.neo4j.kernel.impl.store.record.LabelTokenRecord)2 PropertyKeyTokenRecord (org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord)2 LabelTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand)2 PropertyKeyTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand)2 RelationshipTypeTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand)2 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 DependencyResolver (org.neo4j.graphdb.DependencyResolver)1