Search in sources :

Example 31 with DefinedProperty

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

the class TransactionRecordStateTest method shouldConvertChangedPropertyToNodePropertyUpdates.

@Test
public void shouldConvertChangedPropertyToNodePropertyUpdates() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    int nodeId = 0;
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    recordState.nodeCreate(nodeId);
    DefinedProperty property1 = recordState.nodeAddProperty(nodeId, propertyId1, value1);
    DefinedProperty property2 = recordState.nodeAddProperty(nodeId, propertyId2, value2);
    apply(neoStores, transactionRepresentationOf(recordState));
    // WHEN
    String newValue1 = "new", newValue2 = "new 2";
    recordState = newTransactionRecordState(neoStores);
    recordState.nodeChangeProperty(nodeId, property1.propertyKeyId(), newValue1);
    recordState.nodeChangeProperty(nodeId, property2.propertyKeyId(), newValue2);
    Iterable<NodeUpdates> indexUpdates = indexUpdatesOf(neoStores, recordState);
    // THEN
    NodeUpdates expected = NodeUpdates.forNode(nodeId).changed(property1.propertyKeyId(), property1.value(), newValue1).changed(property2.propertyKeyId(), property2.value(), newValue2).build();
    assertEquals(expected, Iterables.single(indexUpdates));
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

Example 32 with DefinedProperty

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

the class TransactionRecordStateTest method shouldConvertRemovedPropertyToNodePropertyUpdates.

@Test
public void shouldConvertRemovedPropertyToNodePropertyUpdates() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    int nodeId = 0;
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    recordState.nodeCreate(nodeId);
    addLabelsToNode(recordState, nodeId, oneLabelId);
    DefinedProperty property1 = recordState.nodeAddProperty(nodeId, propertyId1, value1);
    DefinedProperty property2 = recordState.nodeAddProperty(nodeId, propertyId2, value2);
    apply(neoStores, transactionRepresentationOf(recordState));
    // WHEN
    recordState = newTransactionRecordState(neoStores);
    recordState.nodeRemoveProperty(nodeId, property1.propertyKeyId());
    recordState.nodeRemoveProperty(nodeId, property2.propertyKeyId());
    Iterable<NodeUpdates> indexUpdates = indexUpdatesOf(neoStores, recordState);
    // THEN
    NodeUpdates expected = NodeUpdates.forNode(nodeId, oneLabelId).removed(property1.propertyKeyId(), property1.value()).removed(property2.propertyKeyId(), property2.value()).build();
    assertEquals(expected, Iterables.single(indexUpdates));
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

Example 33 with DefinedProperty

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

the class LockingStatementOperationsTest method shouldAcquireEntityWriteLockBeforeSettingPropertyOnNode.

@Test
public void shouldAcquireEntityWriteLockBeforeSettingPropertyOnNode() throws Exception {
    // given
    DefinedProperty property = Property.property(8, 9);
    // when
    lockingOps.nodeSetProperty(state, 123, property);
    // then
    order.verify(locks).acquireExclusive(LockTracer.NONE, ResourceTypes.NODE, 123);
    order.verify(entityWriteOps).nodeSetProperty(state, 123, property);
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) Test(org.junit.Test)

Example 34 with DefinedProperty

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

the class PropertyIT method shouldRemoveSetExistingProperty.

@Test
public void shouldRemoveSetExistingProperty() throws Exception {
    // GIVEN
    dbWithNoCache();
    int propertyKeyId;
    long nodeId;
    {
        Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
        nodeId = statement.dataWriteOperations().nodeCreate();
        propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("clown");
        statement.dataWriteOperations().nodeSetProperty(nodeId, stringProperty(propertyKeyId, "bozo"));
        commit();
    }
    DefinedProperty newProperty = stringProperty(propertyKeyId, "ozob");
    {
        Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
        // WHEN
        statement.dataWriteOperations().nodeRemoveProperty(nodeId, propertyKeyId);
        statement.dataWriteOperations().nodeSetProperty(nodeId, newProperty);
        // THEN
        assertThat(statement.readOperations().nodeGetProperty(nodeId, propertyKeyId), equalTo(newProperty.value()));
        // WHEN
        commit();
    }
    // THEN
    {
        ReadOperations readOperations = readOperationsInNewTransaction();
        assertThat(readOperations.nodeGetProperty(nodeId, propertyKeyId), equalTo(newProperty.value()));
        assertThat(toList(readOperations.nodeGetPropertyKeys(nodeId)), equalTo(asList(newProperty.propertyKeyId())));
    }
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 35 with DefinedProperty

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

the class PropertyIT method shouldBeAbleToSetAndReadLargeByteArray.

@Test
public void shouldBeAbleToSetAndReadLargeByteArray() throws Exception {
    // GIVEN
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    long nodeId = statement.dataWriteOperations().nodeCreate();
    // WHEN
    int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("clown");
    DefinedProperty property = byteArrayProperty(propertyKeyId, new byte[100_000]);
    statement.dataWriteOperations().nodeSetProperty(nodeId, property);
    // WHEN
    commit();
    ReadOperations readOperations = readOperationsInNewTransaction();
    // THEN
    readOperations.nodeGetProperty(nodeId, propertyKeyId);
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Aggregations

DefinedProperty (org.neo4j.kernel.api.properties.DefinedProperty)47 Test (org.junit.Test)23 Pair (org.neo4j.helpers.collection.Pair)9 IOException (java.io.IOException)8 InterruptedIOException (java.io.InterruptedIOException)8 PropertyBlock (org.neo4j.kernel.impl.store.record.PropertyBlock)8 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)8 ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)8 PropertyItem (org.neo4j.storageengine.api.PropertyItem)8 NodeItem (org.neo4j.storageengine.api.NodeItem)7 RelationshipItem (org.neo4j.storageengine.api.RelationshipItem)7 Property (org.neo4j.kernel.api.properties.Property)6 PropertyEntry (org.neo4j.graphdb.event.PropertyEntry)4 DataWriteOperations (org.neo4j.kernel.api.DataWriteOperations)4 NodeUpdates (org.neo4j.kernel.api.index.NodeUpdates)4 NeoStores (org.neo4j.kernel.impl.store.NeoStores)4 StorageProperty (org.neo4j.storageengine.api.StorageProperty)4 Node (org.neo4j.graphdb.Node)3 Relationship (org.neo4j.graphdb.Relationship)3 Statement (org.neo4j.kernel.api.Statement)3