Search in sources :

Example 1 with PrimitiveIntSet

use of org.neo4j.collection.primitive.PrimitiveIntSet in project neo4j by neo4j.

the class PrimitiveLongSetTest method intVisitorShouldNotSeeEntriesAfterRequestingBreakOut.

@Test
public void intVisitorShouldNotSeeEntriesAfterRequestingBreakOut() {
    // GIVEN
    PrimitiveIntSet map = Primitive.intSet();
    map.add(1);
    map.add(2);
    map.add(3);
    map.add(4);
    final AtomicInteger counter = new AtomicInteger();
    // WHEN
    map.visitKeys(new PrimitiveIntVisitor<RuntimeException>() {

        @Override
        public boolean visited(int value) {
            return counter.incrementAndGet() > 2;
        }
    });
    // THEN
    assertThat(counter.get(), is(3));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PrimitiveIntSet(org.neo4j.collection.primitive.PrimitiveIntSet) Test(org.junit.Test)

Example 2 with PrimitiveIntSet

use of org.neo4j.collection.primitive.PrimitiveIntSet in project neo4j by neo4j.

the class PrimitiveLongSetTest method intVisitorShouldSeeAllEntriesIfItDoesNotBreakOut.

@SuppressWarnings("unchecked")
@Test
public void intVisitorShouldSeeAllEntriesIfItDoesNotBreakOut() {
    // GIVEN
    PrimitiveIntSet set = Primitive.intSet();
    set.add(1);
    set.add(2);
    set.add(3);
    PrimitiveIntVisitor<RuntimeException> visitor = mock(PrimitiveIntVisitor.class);
    // WHEN
    set.visitKeys(visitor);
    // THEN
    verify(visitor).visited(1);
    verify(visitor).visited(2);
    verify(visitor).visited(3);
    verifyNoMoreInteractions(visitor);
}
Also used : PrimitiveIntSet(org.neo4j.collection.primitive.PrimitiveIntSet) Test(org.junit.Test)

Example 3 with PrimitiveIntSet

use of org.neo4j.collection.primitive.PrimitiveIntSet in project neo4j by neo4j.

the class PrimitiveLongSetTest method longVisitorShouldNotSeeEntriesAfterRequestingBreakOut.

@Test
public void longVisitorShouldNotSeeEntriesAfterRequestingBreakOut() {
    // GIVEN
    PrimitiveIntSet map = Primitive.intSet();
    map.add(1);
    map.add(2);
    map.add(3);
    map.add(4);
    final AtomicInteger counter = new AtomicInteger();
    // WHEN
    map.visitKeys(new PrimitiveIntVisitor<RuntimeException>() {

        @Override
        public boolean visited(int value) {
            return counter.incrementAndGet() > 2;
        }
    });
    // THEN
    assertThat(counter.get(), is(3));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PrimitiveIntSet(org.neo4j.collection.primitive.PrimitiveIntSet) Test(org.junit.Test)

Example 4 with PrimitiveIntSet

use of org.neo4j.collection.primitive.PrimitiveIntSet in project neo4j by neo4j.

the class StateHandlingStatementOperations method relationshipTypes.

@Override
public PrimitiveIntSet relationshipTypes(KernelStatement statement, NodeItem node) {
    if (statement.hasTxStateWithChanges() && statement.txState().nodeIsAddedInThisTx(node.id())) {
        return statement.txState().getNodeState(node.id()).relationshipTypes();
    }
    // Read types in the current transaction
    PrimitiveIntSet types = statement.hasTxStateWithChanges() ? statement.txState().getNodeState(node.id()).relationshipTypes() : Primitive.intSet();
    // Augment with types stored on disk, minus any types where all rels of that type are deleted
    // in current tx.
    types.addAll(filter(storeLayer.relationshipTypes(statement.getStoreStatement(), node).iterator(), (current) -> !types.contains(current) && degree(statement, node, Direction.BOTH, current) > 0));
    return types;
}
Also used : LegacyIndexStore(org.neo4j.kernel.impl.index.LegacyIndexStore) InternalIndexState(org.neo4j.kernel.api.index.InternalIndexState) Arrays(java.util.Arrays) Iterators.iterator(org.neo4j.helpers.collection.Iterators.iterator) Iterators.singleOrNull(org.neo4j.helpers.collection.Iterators.singleOrNull) EMPTY(org.neo4j.storageengine.api.txstate.TxStateVisitor.EMPTY) GENERAL(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor.Filter.GENERAL) Statement(org.neo4j.kernel.api.Statement) Cursor(org.neo4j.cursor.Cursor) Direction(org.neo4j.storageengine.api.Direction) Map(java.util.Map) StorageStatement(org.neo4j.storageengine.api.StorageStatement) SchemaReadOperations(org.neo4j.kernel.impl.api.operations.SchemaReadOperations) Registers.newDoubleLongRegister(org.neo4j.register.Registers.newDoubleLongRegister) EntityOperations(org.neo4j.kernel.impl.api.operations.EntityOperations) InvalidTransactionTypeKernelException(org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException) CountsOperations(org.neo4j.kernel.impl.api.operations.CountsOperations) IndexTxStateUpdater(org.neo4j.kernel.impl.api.state.IndexTxStateUpdater) PrimitiveIntCollection(org.neo4j.collection.primitive.PrimitiveIntCollection) PropertyKeyIdNotFoundKernelException(org.neo4j.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException) LegacyIndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.legacyindex.LegacyIndexNotFoundKernelException) Primitive(org.neo4j.collection.primitive.Primitive) DataWriteOperations(org.neo4j.kernel.api.DataWriteOperations) Predicates.any(org.neo4j.function.Predicates.any) LegacyIndex(org.neo4j.kernel.api.LegacyIndex) LegacyIndexHits(org.neo4j.kernel.api.LegacyIndexHits) PrimitiveLongCollections.single(org.neo4j.collection.primitive.PrimitiveLongCollections.single) LegacyIndexWriteOperations(org.neo4j.kernel.impl.api.operations.LegacyIndexWriteOperations) Cursors.count(org.neo4j.kernel.impl.util.Cursors.count) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) PrimitiveIntCollections.filter(org.neo4j.collection.primitive.PrimitiveIntCollections.filter) IllegalTokenNameException(org.neo4j.kernel.api.exceptions.schema.IllegalTokenNameException) UNIQUE(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor.Filter.UNIQUE) PopulationProgress(org.neo4j.storageengine.api.schema.PopulationProgress) KeyWriteOperations(org.neo4j.kernel.impl.api.operations.KeyWriteOperations) CreateConstraintFailureException(org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem) AutoIndexingKernelException(org.neo4j.kernel.api.exceptions.legacyindex.AutoIndexingKernelException) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) ReadableDiffSets(org.neo4j.storageengine.api.txstate.ReadableDiffSets) REMOVED_LABEL(org.neo4j.kernel.impl.api.state.IndexTxStateUpdater.LabelChangeType.REMOVED_LABEL) NewIndexDescriptorFactory(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) DoubleLongRegister(org.neo4j.register.Register.DoubleLongRegister) ConstraintDescriptorFactory(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptorFactory) KeyReadOperations(org.neo4j.kernel.impl.api.operations.KeyReadOperations) NodeItem(org.neo4j.storageengine.api.NodeItem) Iterators.filter(org.neo4j.helpers.collection.Iterators.filter) NO_SUCH_PROPERTY(org.neo4j.kernel.api.properties.DefinedProperty.NO_SUCH_PROPERTY) AlreadyConstrainedException(org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException) ConstraintValidationException(org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException) Property(org.neo4j.kernel.api.properties.Property) PrimitiveIntIterator(org.neo4j.collection.primitive.PrimitiveIntIterator) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) PrimitiveLongResourceIterator(org.neo4j.collection.primitive.PrimitiveLongResourceIterator) NodePropertyDescriptor(org.neo4j.kernel.api.schema.NodePropertyDescriptor) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) IndexBrokenKernelException(org.neo4j.kernel.api.exceptions.schema.IndexBrokenKernelException) RelationTypeSchemaDescriptor(org.neo4j.kernel.api.schema_new.RelationTypeSchemaDescriptor) PrimitiveLongCollections.resourceIterator(org.neo4j.collection.primitive.PrimitiveLongCollections.resourceIterator) OrderedPropertyValues(org.neo4j.kernel.api.schema_new.OrderedPropertyValues) LabelNotFoundKernelException(org.neo4j.kernel.api.exceptions.LabelNotFoundKernelException) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) String.format(java.lang.String.format) NO_SUCH_NODE(org.neo4j.kernel.api.StatementConstants.NO_SUCH_NODE) ADDED_LABEL(org.neo4j.kernel.impl.api.state.IndexTxStateUpdater.LabelChangeType.ADDED_LABEL) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) IndexEntityType(org.neo4j.kernel.impl.index.IndexEntityType) RelationshipTypeIdNotFoundKernelException(org.neo4j.kernel.api.exceptions.RelationshipTypeIdNotFoundKernelException) StorageProperty(org.neo4j.storageengine.api.StorageProperty) PrimitiveIntStack(org.neo4j.collection.primitive.PrimitiveIntStack) PropertyItem(org.neo4j.storageengine.api.PropertyItem) IndexNotApplicableKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) NodeExistenceConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.NodeExistenceConstraintDescriptor) SchemaBoundary(org.neo4j.kernel.api.schema_new.SchemaBoundary) EntityType(org.neo4j.storageengine.api.EntityType) DropIndexFailureException(org.neo4j.kernel.api.exceptions.schema.DropIndexFailureException) Token(org.neo4j.storageengine.api.Token) NotFoundException(org.neo4j.graphdb.NotFoundException) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) PropertyKeyIdIterator(org.neo4j.kernel.api.properties.PropertyKeyIdIterator) TransactionCountingStateVisitor(org.neo4j.kernel.api.txstate.TransactionCountingStateVisitor) SchemaUtil(org.neo4j.kernel.api.schema_new.SchemaUtil) SchemaDescriptor(org.neo4j.kernel.api.schema_new.SchemaDescriptor) AutoIndexing(org.neo4j.kernel.api.legacyindex.AutoIndexing) PrimitiveIntSet(org.neo4j.collection.primitive.PrimitiveIntSet) LegacyIndexReadOperations(org.neo4j.kernel.impl.api.operations.LegacyIndexReadOperations) NodeState(org.neo4j.storageengine.api.txstate.NodeState) Iterator(java.util.Iterator) Cursors.empty(org.neo4j.kernel.impl.util.Cursors.empty) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) TooManyLabelsException(org.neo4j.kernel.api.exceptions.schema.TooManyLabelsException) SchemaWriteOperations(org.neo4j.kernel.impl.api.operations.SchemaWriteOperations) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) RelExistenceConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.RelExistenceConstraintDescriptor) UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) RelationshipIterator(org.neo4j.kernel.impl.api.store.RelationshipIterator) PrimitiveIntSet(org.neo4j.collection.primitive.PrimitiveIntSet)

Example 5 with PrimitiveIntSet

use of org.neo4j.collection.primitive.PrimitiveIntSet in project neo4j by neo4j.

the class StorageLayer method relationshipTypes.

@Override
public PrimitiveIntSet relationshipTypes(StorageStatement statement, NodeItem node) {
    PrimitiveIntSet set = intSet();
    if (node.isDense()) {
        RelationshipGroupRecord groupRecord = relationshipGroupStore.newRecord();
        RecordCursor<RelationshipGroupRecord> cursor = statement.recordCursors().relationshipGroup();
        for (long id = node.nextGroupId(); id != NO_NEXT_RELATIONSHIP.intValue(); id = groupRecord.getNext()) {
            if (cursor.next(id, groupRecord, FORCE)) {
                set.add(groupRecord.getType());
            }
        }
    } else {
        nodeGetRelationships(statement, node, Direction.BOTH).forAll(relationship -> set.add(relationship.type()));
    }
    return set;
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) PrimitiveIntSet(org.neo4j.collection.primitive.PrimitiveIntSet)

Aggregations

PrimitiveIntSet (org.neo4j.collection.primitive.PrimitiveIntSet)14 Test (org.junit.Test)4 LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)3 NodeItem (org.neo4j.storageengine.api.NodeItem)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Before (org.junit.Before)2 Statement (org.neo4j.kernel.api.Statement)2 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)2 EntityReadOperations (org.neo4j.kernel.impl.api.operations.EntityReadOperations)2 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)2 String.format (java.lang.String.format)1 Arrays (java.util.Arrays)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Primitive (org.neo4j.collection.primitive.Primitive)1 PrimitiveIntCollection (org.neo4j.collection.primitive.PrimitiveIntCollection)1 PrimitiveIntCollections.filter (org.neo4j.collection.primitive.PrimitiveIntCollections.filter)1 PrimitiveIntIterator (org.neo4j.collection.primitive.PrimitiveIntIterator)1 PrimitiveIntStack (org.neo4j.collection.primitive.PrimitiveIntStack)1 PrimitiveLongCollections.resourceIterator (org.neo4j.collection.primitive.PrimitiveLongCollections.resourceIterator)1