Search in sources :

Example 1 with ArrayMap

use of org.neo4j.kernel.impl.util.ArrayMap in project neo4j by neo4j.

the class NeoStoresTest method validateRel2.

private void validateRel2(long rel, DefinedProperty prop1, DefinedProperty prop2, DefinedProperty prop3, long firstNode, long secondNode, int relType) throws IOException {
    ArrayMap<Integer, Pair<DefinedProperty, Long>> props = new ArrayMap<>();
    propertyLoader.relLoadProperties(rel, newPropertyReceiver(props));
    int count = 0;
    for (int keyId : props.keySet()) {
        long id = props.get(keyId).other();
        PropertyRecord record = getRecord(pStore, id);
        PropertyBlock block = record.getPropertyBlock(props.get(keyId).first().propertyKeyId());
        DefinedProperty data = block.newPropertyData(pStore);
        if (data.propertyKeyId() == prop1.propertyKeyId()) {
            assertEquals("prop1", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals("string2", data.value());
            relAddProperty(rel, prop1.propertyKeyId(), "-string2");
        } else if (data.propertyKeyId() == prop2.propertyKeyId()) {
            assertEquals("prop2", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(2, data.value());
            relAddProperty(rel, prop2.propertyKeyId(), -2);
        } else if (data.propertyKeyId() == prop3.propertyKeyId()) {
            assertEquals("prop3", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(false, data.value());
            relAddProperty(rel, prop3.propertyKeyId(), true);
        } else {
            throw new IOException();
        }
        count++;
    }
    assertEquals(3, count);
    assertRelationshipData(rel, firstNode, secondNode, relType);
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) Pair(org.neo4j.helpers.collection.Pair)

Example 2 with ArrayMap

use of org.neo4j.kernel.impl.util.ArrayMap in project neo4j by neo4j.

the class NeoStoresTest method deleteNode2.

private void deleteNode2(long node, DefinedProperty prop1, DefinedProperty prop2, DefinedProperty prop3) throws IOException {
    ArrayMap<Integer, Pair<DefinedProperty, Long>> props = new ArrayMap<>();
    propertyLoader.nodeLoadProperties(node, newPropertyReceiver(props));
    int count = 0;
    for (int keyId : props.keySet()) {
        long id = props.get(keyId).other();
        PropertyRecord record = pStore.getRecord(id, pStore.newRecord(), NORMAL);
        PropertyBlock block = record.getPropertyBlock(props.get(keyId).first().propertyKeyId());
        DefinedProperty data = block.newPropertyData(pStore);
        if (data.propertyKeyId() == prop1.propertyKeyId()) {
            assertEquals("prop1", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals("-string2", data.value());
        } else if (data.propertyKeyId() == prop2.propertyKeyId()) {
            assertEquals("prop2", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(-2, data.value());
        } else if (data.propertyKeyId() == prop3.propertyKeyId()) {
            assertEquals("prop3", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(true, data.value());
            transaction.nodeDoRemoveProperty(node, prop3);
        } else {
            throw new IOException();
        }
        count++;
    }
    assertEquals(3, count);
    CountingPropertyReceiver propertyCounter = new CountingPropertyReceiver();
    propertyLoader.nodeLoadProperties(node, propertyCounter);
    assertEquals(3, propertyCounter.count);
    assertHasRelationships(node);
    transaction.nodeDoDelete(node);
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) Pair(org.neo4j.helpers.collection.Pair)

Example 3 with ArrayMap

use of org.neo4j.kernel.impl.util.ArrayMap in project neo4j by neo4j.

the class NeoStoresTest method deleteRel1.

private void deleteRel1(long rel, DefinedProperty prop1, DefinedProperty prop2, DefinedProperty prop3, long firstNode, long secondNode, int relType) throws Exception {
    ArrayMap<Integer, Pair<DefinedProperty, Long>> props = new ArrayMap<>();
    propertyLoader.relLoadProperties(rel, newPropertyReceiver(props));
    int count = 0;
    for (int keyId : props.keySet()) {
        long id = props.get(keyId).other();
        PropertyRecord record = pStore.getRecord(id, pStore.newRecord(), NORMAL);
        PropertyBlock block = record.getPropertyBlock(props.get(keyId).first().propertyKeyId());
        DefinedProperty data = block.newPropertyData(pStore);
        if (data.propertyKeyId() == prop1.propertyKeyId()) {
            assertEquals("prop1", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals("-string1", data.value());
        } else if (data.propertyKeyId() == prop2.propertyKeyId()) {
            assertEquals("prop2", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(-1, data.value());
        } else if (data.propertyKeyId() == prop3.propertyKeyId()) {
            assertEquals("prop3", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(false, data.value());
            transaction.relationshipDoRemoveProperty(rel, prop3);
        } else {
            throw new IOException();
        }
        count++;
    }
    assertEquals(3, count);
    CountingPropertyReceiver propertyCounter = new CountingPropertyReceiver();
    propertyLoader.relLoadProperties(rel, propertyCounter);
    assertEquals(3, propertyCounter.count);
    assertRelationshipData(rel, firstNode, secondNode, relType);
    relDelete(rel);
    assertHasRelationships(firstNode);
    assertHasRelationships(secondNode);
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) Pair(org.neo4j.helpers.collection.Pair)

Example 4 with ArrayMap

use of org.neo4j.kernel.impl.util.ArrayMap in project neo4j by neo4j.

the class NeoStoresTest method deleteRel2.

private void deleteRel2(long rel, DefinedProperty prop1, DefinedProperty prop2, DefinedProperty prop3, long firstNode, long secondNode, int relType) throws Exception {
    ArrayMap<Integer, Pair<DefinedProperty, Long>> props = new ArrayMap<>();
    propertyLoader.relLoadProperties(rel, newPropertyReceiver(props));
    int count = 0;
    for (int keyId : props.keySet()) {
        long id = props.get(keyId).other();
        PropertyRecord record = pStore.getRecord(id, pStore.newRecord(), NORMAL);
        PropertyBlock block = record.getPropertyBlock(props.get(keyId).first().propertyKeyId());
        DefinedProperty data = block.newPropertyData(pStore);
        if (data.propertyKeyId() == prop1.propertyKeyId()) {
            assertEquals("prop1", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals("-string2", data.value());
        } else if (data.propertyKeyId() == prop2.propertyKeyId()) {
            assertEquals("prop2", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(-2, data.value());
        } else if (data.propertyKeyId() == prop3.propertyKeyId()) {
            assertEquals("prop3", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(true, data.value());
            transaction.relationshipDoRemoveProperty(rel, prop3);
        } else {
            throw new IOException();
        }
        count++;
    }
    assertEquals(3, count);
    CountingPropertyReceiver propertyCounter = new CountingPropertyReceiver();
    propertyLoader.relLoadProperties(rel, propertyCounter);
    assertEquals(3, propertyCounter.count);
    assertRelationshipData(rel, firstNode, secondNode, relType);
    relDelete(rel);
    assertHasRelationships(firstNode);
    assertHasRelationships(secondNode);
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) Pair(org.neo4j.helpers.collection.Pair)

Example 5 with ArrayMap

use of org.neo4j.kernel.impl.util.ArrayMap in project neo4j by neo4j.

the class NeoStoresTest method validateNodeRel2.

private void validateNodeRel2(final long node, DefinedProperty prop1, DefinedProperty prop2, DefinedProperty prop3, long rel1, long rel2, final int relType1, final int relType2) throws IOException, RuntimeException {
    assertTrue(nodeExists(node));
    ArrayMap<Integer, Pair<DefinedProperty, Long>> props = new ArrayMap<>();
    propertyLoader.nodeLoadProperties(node, newPropertyReceiver(props));
    int count = 0;
    for (int keyId : props.keySet()) {
        long id = props.get(keyId).other();
        PropertyRecord record = getRecord(pStore, id);
        PropertyBlock block = record.getPropertyBlock(props.get(keyId).first().propertyKeyId());
        DefinedProperty data = block.newPropertyData(pStore);
        if (data.propertyKeyId() == prop1.propertyKeyId()) {
            assertEquals("prop1", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals("string2", data.value());
            nodeAddProperty(node, prop1.propertyKeyId(), "-string2");
        } else if (data.propertyKeyId() == prop2.propertyKeyId()) {
            assertEquals("prop2", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(2, data.value());
            nodeAddProperty(node, prop2.propertyKeyId(), -2);
        } else if (data.propertyKeyId() == prop3.propertyKeyId()) {
            assertEquals("prop3", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(false, data.value());
            nodeAddProperty(node, prop3.propertyKeyId(), true);
        } else {
            throw new IOException();
        }
        count++;
    }
    assertEquals(3, count);
    count = 0;
    try (KernelStatement statement = (KernelStatement) tx.acquireStatement();
        Cursor<NodeItem> nodeCursor = statement.getStoreStatement().acquireSingleNodeCursor(node)) {
        nodeCursor.next();
        NodeItem nodeItem = nodeCursor.get();
        try (Cursor<RelationshipItem> relationships = statement.getStoreStatement().acquireNodeRelationshipCursor(nodeItem.isDense(), nodeItem.id(), nodeItem.nextRelationshipId(), BOTH, ALWAYS_TRUE_INT)) {
            while (relationships.next()) {
                long rel = relationships.get().id();
                if (rel == rel1) {
                    assertEquals(node, relationships.get().endNode());
                    assertEquals(relType1, relationships.get().type());
                } else if (rel == rel2) {
                    assertEquals(node, relationships.get().startNode());
                    assertEquals(relType2, relationships.get().type());
                } else {
                    throw new IOException();
                }
                count++;
            }
        }
    }
    assertEquals(2, count);
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) NodeItem(org.neo4j.storageengine.api.NodeItem) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem) Pair(org.neo4j.helpers.collection.Pair)

Aggregations

ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)20 IOException (java.io.IOException)8 InterruptedIOException (java.io.InterruptedIOException)8 Pair (org.neo4j.helpers.collection.Pair)8 DefinedProperty (org.neo4j.kernel.api.properties.DefinedProperty)8 PropertyBlock (org.neo4j.kernel.impl.store.record.PropertyBlock)8 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)8 PropertyData (org.neo4j.kernel.impl.nioneo.store.PropertyData)7 PropertyRecord (org.neo4j.kernel.impl.nioneo.store.PropertyRecord)7 RelIdArray (org.neo4j.kernel.impl.util.RelIdArray)5 Map (java.util.Map)4 DynamicRecord (org.neo4j.kernel.impl.nioneo.store.DynamicRecord)3 InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)3 NodeRecord (org.neo4j.kernel.impl.nioneo.store.NodeRecord)3 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)3 HashMap (java.util.HashMap)1 RelationshipType (org.neo4j.graphdb.RelationshipType)1 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)1 PropertyBlock (org.neo4j.kernel.impl.nioneo.store.PropertyBlock)1 RelationshipChainPosition (org.neo4j.kernel.impl.nioneo.store.RelationshipChainPosition)1