Search in sources :

Example 1 with PropertyRecord

use of org.neo4j.kernel.impl.nioneo.store.PropertyRecord in project neo4j-mobile-android by neo4j-contrib.

the class BatchInserterImpl method createPropertyChain.

private long createPropertyChain(Map<String, Object> properties) {
    if (properties == null || properties.isEmpty()) {
        return Record.NO_NEXT_PROPERTY.intValue();
    }
    PropertyStore propStore = getPropertyStore();
    List<PropertyRecord> propRecords = new ArrayList<PropertyRecord>();
    PropertyRecord currentRecord = new PropertyRecord(propStore.nextId());
    currentRecord.setInUse(true);
    currentRecord.setCreated();
    propRecords.add(currentRecord);
    for (Entry<String, Object> entry : properties.entrySet()) {
        int keyId = indexHolder.getKeyId(entry.getKey());
        if (keyId == -1) {
            keyId = createNewPropertyIndex(entry.getKey());
        }
        PropertyBlock block = new PropertyBlock();
        propStore.encodeValue(block, keyId, entry.getValue());
        if (currentRecord.size() + block.getSize() > PropertyType.getPayloadSize()) {
            // Here it means the current block is done for
            PropertyRecord prevRecord = currentRecord;
            // Create new record
            long propertyId = propStore.nextId();
            currentRecord = new PropertyRecord(propertyId);
            currentRecord.setInUse(true);
            currentRecord.setCreated();
            // Set up links
            prevRecord.setNextProp(propertyId);
            currentRecord.setPrevProp(prevRecord.getId());
            propRecords.add(currentRecord);
        // Now current is ready to start picking up blocks
        }
        currentRecord.addPropertyBlock(block);
    }
    /*
         * Add the property records in reverse order, which means largest
         * id first. That is to make sure we expand the property store file
         * only once.
         */
    for (int i = propRecords.size() - 1; i >= 0; i--) {
        propStore.updateRecord(propRecords.get(i));
    }
    /*
         *  0 will always exist, if the map was empty we wouldn't be here
         *  and even one property will create at least one record.
         */
    return propRecords.get(0).getId();
}
Also used : PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) ArrayList(java.util.ArrayList) PropertyBlock(org.neo4j.kernel.impl.nioneo.store.PropertyBlock) PropertyStore.encodeString(org.neo4j.kernel.impl.nioneo.store.PropertyStore.encodeString) PropertyStore(org.neo4j.kernel.impl.nioneo.store.PropertyStore)

Example 2 with PropertyRecord

use of org.neo4j.kernel.impl.nioneo.store.PropertyRecord in project graphdb by neo4j-attic.

the class WriteTransaction method relAddProperty.

void relAddProperty(long relId, long propertyId, PropertyIndex index, Object value) {
    RelationshipRecord relRecord = getRelationshipRecord(relId);
    if (relRecord == null) {
        relRecord = getRelationshipStore().getRecord(relId);
        addRelationshipRecord(relRecord);
    }
    if (!relRecord.inUse()) {
        throw new IllegalStateException("Property add on relationship[" + relId + "] illegal since it has been deleted.");
    }
    PropertyRecord propertyRecord = new PropertyRecord(propertyId);
    propertyRecord.setInUse(true);
    propertyRecord.setCreated();
    propertyRecord.setRelId(relId);
    if (relRecord.getNextProp() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        PropertyRecord prevProp = getPropertyRecord(relRecord.getNextProp());
        if (prevProp == null) {
            prevProp = getPropertyStore().getLightRecord(relRecord.getNextProp());
            addPropertyRecord(prevProp);
        }
        assert prevProp.getPrevProp() == Record.NO_PREVIOUS_PROPERTY.intValue();
        prevProp.setPrevProp(propertyId);
        propertyRecord.setNextProp(prevProp.getId());
    }
    int keyIndexId = index.getKeyId();
    propertyRecord.setKeyIndexId(keyIndexId);
    getPropertyStore().encodeValue(propertyRecord, value);
    relRecord.setNextProp(propertyId);
    addPropertyRecord(propertyRecord);
}
Also used : PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)

Example 3 with PropertyRecord

use of org.neo4j.kernel.impl.nioneo.store.PropertyRecord in project graphdb by neo4j-attic.

the class WriteTransaction method relChangeProperty.

void relChangeProperty(long relId, long propertyId, Object value) {
    RelationshipRecord relRecord = getRelationshipRecord(relId);
    if (relRecord == null) {
        relRecord = getRelationshipStore().getRecord(relId);
    }
    if (!relRecord.inUse()) {
        throw new IllegalStateException("Property change on relationship[" + relId + "] illegal since it has been deleted.");
    }
    PropertyRecord propertyRecord = getPropertyRecord(propertyId);
    if (propertyRecord == null) {
        propertyRecord = getPropertyStore().getRecord(propertyId);
        addPropertyRecord(propertyRecord);
    }
    if (!propertyRecord.inUse()) {
        throw new IllegalStateException("Unable to change property[" + propertyId + "] since it is deleted.");
    }
    propertyRecord.setRelId(relId);
    if (propertyRecord.isLight()) {
        getPropertyStore().makeHeavy(propertyRecord);
    }
    propertyRecord.setChanged();
    if (propertyRecord.getType() == PropertyType.STRING) {
        for (DynamicRecord record : propertyRecord.getValueRecords()) {
            if (record.inUse()) {
                record.setInUse(false, PropertyType.STRING.intValue());
            }
        }
    } else if (propertyRecord.getType() == PropertyType.ARRAY) {
        for (DynamicRecord record : propertyRecord.getValueRecords()) {
            if (record.inUse()) {
                record.setInUse(false, PropertyType.ARRAY.intValue());
            }
        }
    }
    getPropertyStore().encodeValue(propertyRecord, value);
    addPropertyRecord(propertyRecord);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)

Example 4 with PropertyRecord

use of org.neo4j.kernel.impl.nioneo.store.PropertyRecord in project graphdb by neo4j-attic.

the class WriteTransaction method relRemoveProperty.

void relRemoveProperty(long relId, long propertyId) {
    RelationshipRecord relRecord = getRelationshipRecord(relId);
    if (relRecord == null) {
        relRecord = getRelationshipStore().getRecord(relId);
    }
    if (!relRecord.inUse()) {
        throw new IllegalStateException("Property remove on relationship[" + relId + "] illegal since it has been deleted.");
    }
    PropertyRecord propRecord = getPropertyRecord(propertyId);
    if (propRecord == null) {
        propRecord = getPropertyStore().getRecord(propertyId);
        addPropertyRecord(propRecord);
    }
    if (!propRecord.inUse()) {
        throw new IllegalStateException("Unable to delete property[" + propertyId + "] since it is already deleted.");
    }
    propRecord.setRelId(relId);
    if (propRecord.isLight()) {
        getPropertyStore().makeHeavy(propRecord);
    }
    propRecord.setInUse(false);
    // TODO: update count on property index record
    for (DynamicRecord valueRecord : propRecord.getValueRecords()) {
        if (valueRecord.inUse()) {
            valueRecord.setInUse(false, propRecord.getType().intValue());
        }
    }
    long prevProp = propRecord.getPrevProp();
    long nextProp = propRecord.getNextProp();
    if (relRecord.getNextProp() == propertyId) {
        relRecord.setNextProp(nextProp);
        // re-adding not a problem
        addRelationshipRecord(relRecord);
    }
    if (prevProp != Record.NO_PREVIOUS_PROPERTY.intValue()) {
        PropertyRecord prevPropRecord = getPropertyRecord(prevProp);
        if (prevPropRecord == null) {
            prevPropRecord = getPropertyStore().getLightRecord(prevProp);
            addPropertyRecord(prevPropRecord);
        }
        assert prevPropRecord.inUse();
        prevPropRecord.setNextProp(nextProp);
    }
    if (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
        PropertyRecord nextPropRecord = getPropertyRecord(nextProp);
        if (nextPropRecord == null) {
            nextPropRecord = getPropertyStore().getLightRecord(nextProp);
            addPropertyRecord(nextPropRecord);
        }
        assert nextPropRecord.inUse();
        nextPropRecord.setPrevProp(prevProp);
    }
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)

Example 5 with PropertyRecord

use of org.neo4j.kernel.impl.nioneo.store.PropertyRecord in project graphdb by neo4j-attic.

the class WriteTransaction method nodeGetProperties.

ArrayMap<Integer, PropertyData> nodeGetProperties(long nodeId, boolean light) {
    ArrayMap<Integer, PropertyData> propertyMap = new ArrayMap<Integer, PropertyData>(9, false, true);
    NodeRecord nodeRecord = getNodeRecord(nodeId);
    if (nodeRecord != null && nodeRecord.isCreated()) {
        return propertyMap;
    }
    if (nodeRecord != null) {
        if (!nodeRecord.inUse() && !light) {
            throw new IllegalStateException("Node[" + nodeId + "] has been deleted in this tx");
        }
    }
    nodeRecord = getNodeStore().getRecord(nodeId);
    if (!nodeRecord.inUse()) {
        throw new InvalidRecordException("Node[" + nodeId + "] not in use");
    }
    long nextProp = nodeRecord.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 : NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Aggregations

PropertyRecord (org.neo4j.kernel.impl.nioneo.store.PropertyRecord)36 DynamicRecord (org.neo4j.kernel.impl.nioneo.store.DynamicRecord)15 PropertyBlock (org.neo4j.kernel.impl.nioneo.store.PropertyBlock)13 NodeRecord (org.neo4j.kernel.impl.nioneo.store.NodeRecord)12 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)12 PropertyData (org.neo4j.kernel.impl.nioneo.store.PropertyData)8 InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)7 ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)7 PropertyStore (org.neo4j.kernel.impl.nioneo.store.PropertyStore)6 XAException (javax.transaction.xa.XAException)4 PropertyIndexRecord (org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord)4 RelationshipTypeRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord)4 ArrayList (java.util.ArrayList)3 XaCommand (org.neo4j.kernel.impl.transaction.xaframework.XaCommand)3 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 PropertyStore.encodeString (org.neo4j.kernel.impl.nioneo.store.PropertyStore.encodeString)2 PropertyCommand (org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand)2 PropertyType (org.neo4j.kernel.impl.nioneo.store.PropertyType)1