Search in sources :

Example 16 with ArrayMap

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

the class WriteTransaction method relGetProperties.

public ArrayMap<Integer, PropertyData> relGetProperties(long relId, boolean light) {
    ArrayMap<Integer, PropertyData> propertyMap = new ArrayMap<Integer, PropertyData>(9, false, true);
    RelationshipRecord relRecord = getRelationshipRecord(relId);
    if (relRecord != null && relRecord.isCreated()) {
        return propertyMap;
    }
    if (relRecord != null) {
        if (!relRecord.inUse() && !light) {
            throw new IllegalStateException("Relationship[" + relId + "] has been deleted in this tx");
        }
    }
    relRecord = getRelationshipStore().getRecord(relId);
    if (!relRecord.inUse()) {
        throw new InvalidRecordException("Relationship[" + relId + "] not in use");
    }
    long nextProp = relRecord.getNextProp();
    while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
        PropertyRecord propRecord = getPropertyStore().getLightRecord(nextProp);
        propertyMap.put(propRecord.getKeyIndexId(), new PropertyData(propRecord.getId(), propertyGetValueOrNull(propRecord)));
        nextProp = propRecord.getNextProp();
    }
    return propertyMap;
}
Also used : PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 17 with ArrayMap

use of org.neo4j.kernel.impl.util.ArrayMap in project neo4j-mobile-android by neo4j-contrib.

the class WriteTransaction method getAndDeletePropertyChain.

private ArrayMap<Integer, PropertyData> getAndDeletePropertyChain(long startingAt) {
    ArrayMap<Integer, PropertyData> result = new ArrayMap<Integer, PropertyData>(9, false, true);
    long nextProp = startingAt;
    while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
        PropertyRecord propRecord = getPropertyRecord(nextProp, false, true);
        if (!propRecord.isCreated() && propRecord.isChanged()) {
            // Being here means a new value could be on disk. Re-read
            propRecord = getPropertyStore().getRecord(propRecord.getId());
        }
        for (PropertyBlock block : propRecord.getPropertyBlocks()) {
            if (block.isLight()) {
                getPropertyStore().makeHeavy(block);
            }
            if (!block.isCreated() && !propRecord.isChanged()) {
                result.put(block.getKeyIndexId(), block.newPropertyData(propRecord, propertyGetValueOrNull(block)));
            }
            // TODO: update count on property index record
            for (DynamicRecord valueRecord : block.getValueRecords()) {
                assert valueRecord.inUse();
                valueRecord.setInUse(false);
                propRecord.addDeletedRecord(valueRecord);
            }
        }
        nextProp = propRecord.getNextProp();
        propRecord.setInUse(false);
        propRecord.setChanged();
        // We do not remove them individually, but all together here
        propRecord.getPropertyBlocks().clear();
    }
    return result;
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.nioneo.store.PropertyBlock) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap)

Example 18 with ArrayMap

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

the class NeoStoresTest method validateNodeRel1.

private void validateNodeRel1(final long node, DefinedProperty prop1, DefinedProperty prop2, DefinedProperty prop3, long rel1, long rel2, final int relType1, final int relType2) throws IOException {
    assertTrue(nodeExists(node));
    ArrayMap<Integer, Pair<DefinedProperty, Long>> props = new ArrayMap<>();
    PropertyReceiver<DefinedProperty> receiver = newPropertyReceiver(props);
    propertyLoader.nodeLoadProperties(node, receiver);
    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("string1", data.value());
            nodeAddProperty(node, prop1.propertyKeyId(), "-string1");
        } else if (data.propertyKeyId() == prop2.propertyKeyId()) {
            assertEquals("prop2", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(1, data.value());
            nodeAddProperty(node, prop2.propertyKeyId(), -1);
        } else if (data.propertyKeyId() == prop3.propertyKeyId()) {
            assertEquals("prop3", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(true, data.value());
            nodeAddProperty(node, prop3.propertyKeyId(), false);
        } else {
            throw new IOException();
        }
        count++;
    }
    assertEquals(3, count);
    count = validateAndCountRelationships(node, rel1, rel2, relType1, relType2);
    assertEquals(2, count);
}
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 19 with ArrayMap

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

the class NeoStoresTest method validateRel1.

private void validateRel1(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("string1", data.value());
            relAddProperty(rel, prop1.propertyKeyId(), "-string1");
        } else if (data.propertyKeyId() == prop2.propertyKeyId()) {
            assertEquals("prop2", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(1, data.value());
            relAddProperty(rel, prop2.propertyKeyId(), -1);
        } else if (data.propertyKeyId() == prop3.propertyKeyId()) {
            assertEquals("prop3", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(true, data.value());
            relAddProperty(rel, prop3.propertyKeyId(), false);
        } 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 20 with ArrayMap

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

the class NeoStoresTest method deleteNode1.

private void deleteNode1(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("-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.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)

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