Search in sources :

Example 1 with Property

use of org.neo4j.kernel.api.properties.Property in project neo4j by neo4j.

the class StateOperationsAutoIndexingTest method shouldSignalNodePropertyChangedToAutoIndex.

@Test
public void shouldSignalNodePropertyChangedToAutoIndex() throws Exception {
    // Given
    DefinedProperty property = property(1, "Hello!");
    PropertyItem existingProperty = mock(PropertyItem.class);
    when(existingProperty.propertyKeyId()).thenReturn(property.propertyKeyId());
    when(existingProperty.value()).thenReturn("Goodbye!");
    NodeItem node = mock(NodeItem.class);
    when(node.labels()).thenReturn(PrimitiveIntCollections.emptySet());
    when(storeStmt.acquireSingleNodeCursor(1337)).thenReturn(cursor(node));
    when(storeLayer.nodeGetProperty(eq(storeStmt), any(NodeItem.class), eq(property.propertyKeyId()))).thenReturn(cursor(existingProperty));
    // When
    context.nodeSetProperty(stmt, 1337, property);
    // Then
    verify(nodeOps).propertyChanged(eq(writeOps), eq(1337L), any(Property.class), eq(property));
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) NodeItem(org.neo4j.storageengine.api.NodeItem) PropertyItem(org.neo4j.storageengine.api.PropertyItem) Property(org.neo4j.kernel.api.properties.Property) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) Test(org.junit.Test)

Example 2 with Property

use of org.neo4j.kernel.api.properties.Property in project neo4j by neo4j.

the class StateHandlingStatementOperations method graphSetProperty.

@Override
public Property graphSetProperty(KernelStatement state, DefinedProperty property) {
    Object existingPropertyValue = graphGetProperty(state, property.propertyKeyId());
    Property existingProperty = existingPropertyValue == null ? Property.noGraphProperty(property.propertyKeyId()) : Property.property(property.propertyKeyId(), existingPropertyValue);
    state.txState().graphDoReplaceProperty(existingProperty, property);
    return existingProperty;
}
Also used : Property(org.neo4j.kernel.api.properties.Property) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) StorageProperty(org.neo4j.storageengine.api.StorageProperty)

Example 3 with Property

use of org.neo4j.kernel.api.properties.Property in project neo4j by neo4j.

the class StateHandlingStatementOperations method relationshipRemoveProperty.

@Override
public Property relationshipRemoveProperty(KernelStatement state, long relationshipId, int propertyKeyId) throws EntityNotFoundException, InvalidTransactionTypeKernelException, AutoIndexingKernelException {
    DataWriteOperations ops = state.dataWriteOperations();
    try (Cursor<RelationshipItem> cursor = relationshipCursorById(state, relationshipId)) {
        RelationshipItem relationship = cursor.get();
        Property existingProperty;
        try (Cursor<PropertyItem> properties = relationshipGetPropertyCursor(state, relationship, propertyKeyId)) {
            if (!properties.next()) {
                existingProperty = Property.noProperty(propertyKeyId, EntityType.RELATIONSHIP, relationship.id());
            } else {
                existingProperty = Property.property(properties.get().propertyKeyId(), properties.get().value());
                autoIndexing.relationships().propertyRemoved(ops, relationshipId, propertyKeyId);
                state.txState().relationshipDoRemoveProperty(relationship.id(), (DefinedProperty) existingProperty);
            }
        }
        return existingProperty;
    }
}
Also used : DataWriteOperations(org.neo4j.kernel.api.DataWriteOperations) PropertyItem(org.neo4j.storageengine.api.PropertyItem) Property(org.neo4j.kernel.api.properties.Property) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) StorageProperty(org.neo4j.storageengine.api.StorageProperty) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem)

Example 4 with Property

use of org.neo4j.kernel.api.properties.Property in project neo4j by neo4j.

the class StateHandlingStatementOperations method relationshipSetProperty.

@Override
public Property relationshipSetProperty(KernelStatement state, long relationshipId, DefinedProperty property) throws EntityNotFoundException, InvalidTransactionTypeKernelException, AutoIndexingKernelException {
    DataWriteOperations ops = state.dataWriteOperations();
    try (Cursor<RelationshipItem> cursor = relationshipCursorById(state, relationshipId)) {
        RelationshipItem relationship = cursor.get();
        Property existingProperty;
        try (Cursor<PropertyItem> properties = relationshipGetPropertyCursor(state, relationship, property.propertyKeyId())) {
            if (!properties.next()) {
                autoIndexing.relationships().propertyAdded(ops, relationshipId, property);
                existingProperty = Property.noProperty(property.propertyKeyId(), EntityType.RELATIONSHIP, relationship.id());
            } else {
                existingProperty = Property.property(properties.get().propertyKeyId(), properties.get().value());
                autoIndexing.relationships().propertyChanged(ops, relationshipId, existingProperty, property);
            }
        }
        state.txState().relationshipDoReplaceProperty(relationship.id(), existingProperty, property);
        return existingProperty;
    }
}
Also used : DataWriteOperations(org.neo4j.kernel.api.DataWriteOperations) PropertyItem(org.neo4j.storageengine.api.PropertyItem) Property(org.neo4j.kernel.api.properties.Property) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) StorageProperty(org.neo4j.storageengine.api.StorageProperty) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem)

Example 5 with Property

use of org.neo4j.kernel.api.properties.Property in project neo4j by neo4j.

the class LuceneSchemaIndexUniquenessVerificationIT method verifyUniqueness.

private void verifyUniqueness(Collection<PropertyValue> data) throws IOException, IndexEntryConflictException {
    Object[] propertyValues = data.stream().map(property -> property.value).toArray();
    PropertyAccessor propertyAccessor = new TestPropertyAccessor(propertyValues);
    index.verifyUniqueness(propertyAccessor, new int[] { PROPERTY_KEY_ID });
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) SchemaIndex(org.neo4j.kernel.api.impl.schema.SchemaIndex) IOUtils(org.neo4j.io.IOUtils) Exceptions(org.neo4j.helpers.Exceptions) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) Property(org.neo4j.kernel.api.properties.Property) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) LuceneDocumentStructure(org.neo4j.kernel.api.impl.schema.LuceneDocumentStructure) Document(org.apache.lucene.document.Document) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) Randoms(org.neo4j.test.Randoms) LuceneSchemaIndexBuilder(org.neo4j.kernel.api.impl.schema.LuceneSchemaIndexBuilder) After(org.junit.After) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Strings(org.neo4j.helpers.Strings) Assert.fail(org.junit.Assert.fail) ArrayUtil(org.neo4j.helpers.ArrayUtil) Parameterized(org.junit.runners.Parameterized) Collectors.toSet(java.util.stream.Collectors.toSet) Before(org.junit.Before) Parameter(org.junit.runners.Parameterized.Parameter) Collection(java.util.Collection) Set(java.util.Set) NewIndexDescriptorFactory(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory) TestDirectory(org.neo4j.test.rule.TestDirectory) Test(org.junit.Test) IOException(java.io.IOException) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) PropertyAccessor(org.neo4j.kernel.api.index.PropertyAccessor) Objects(java.util.Objects) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) Rule(org.junit.Rule) DefaultFileSystemRule(org.neo4j.test.rule.fs.DefaultFileSystemRule) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) PropertyAccessor(org.neo4j.kernel.api.index.PropertyAccessor)

Aggregations

Property (org.neo4j.kernel.api.properties.Property)10 DefinedProperty (org.neo4j.kernel.api.properties.DefinedProperty)6 Test (org.junit.Test)4 PropertyItem (org.neo4j.storageengine.api.PropertyItem)4 RelationshipItem (org.neo4j.storageengine.api.RelationshipItem)4 Document (org.apache.lucene.document.Document)3 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)3 StorageProperty (org.neo4j.storageengine.api.StorageProperty)3 DataWriteOperations (org.neo4j.kernel.api.DataWriteOperations)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 Objects (java.util.Objects)1 Set (java.util.Set)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 IntStream (java.util.stream.IntStream)1 RandomStringUtils (org.apache.commons.lang3.RandomStringUtils)1