Search in sources :

Example 11 with PropertyRecord

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

the class WriteTransaction method nodeAddProperty.

@Override
public PropertyData nodeAddProperty(long nodeId, PropertyIndex index, Object value) {
    NodeRecord nodeRecord = getNodeRecord(nodeId);
    if (nodeRecord == null) {
        nodeRecord = getNodeStore().getRecord(nodeId);
        addNodeRecord(nodeRecord);
    }
    if (!nodeRecord.inUse()) {
        throw new IllegalStateException("Property add on node[" + nodeId + "] illegal since it has been deleted.");
    }
    assert assertPropertyChain(nodeRecord);
    PropertyBlock block = new PropertyBlock();
    block.setCreated();
    /*
         * Encoding has to be set here before anything is changed,
         * since an exception could be thrown in encodeValue now and tx not marked
         * rollback only.
         */
    getPropertyStore().encodeValue(block, index.getKeyId(), value);
    PropertyRecord host = addPropertyBlockToPrimitive(block, nodeRecord, /*isNode*/
    true);
    assert assertPropertyChain(nodeRecord);
    return block.newPropertyData(host, value);
}
Also used : NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.nioneo.store.PropertyBlock)

Example 12 with PropertyRecord

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

the class DumpLogicalLog method readPropertyCommand.

static XaCommand readPropertyCommand(ReadableByteChannel byteChannel, ByteBuffer buffer) throws IOException {
    // id+in_use(byte)+type(int)+key_indexId(int)+prop_blockId(long)+
    // prev_prop_id(long)+next_prop_id(long)+nr_value_records(int)
    buffer.clear();
    buffer.limit(9);
    if (byteChannel.read(buffer) != buffer.limit()) {
        return null;
    }
    buffer.flip();
    int id = buffer.getInt();
    byte inUseFlag = buffer.get();
    boolean inUse = false;
    if ((inUseFlag & Record.IN_USE.byteValue()) == Record.IN_USE.byteValue()) {
        inUse = true;
    }
    boolean nodeProperty = true;
    if ((inUseFlag & Record.REL_PROPERTY.byteValue()) == Record.REL_PROPERTY.byteValue()) {
        nodeProperty = false;
    }
    int primitiveId = buffer.getInt();
    PropertyRecord record = new PropertyRecord(id);
    if (primitiveId != -1 && nodeProperty) {
        record.setNodeId(primitiveId);
    } else if (primitiveId != -1) {
        record.setRelId(primitiveId);
    }
    if (inUse) {
        buffer.clear();
        buffer.limit(32);
        if (byteChannel.read(buffer) != buffer.limit()) {
            return null;
        }
        buffer.flip();
        PropertyType type = getType(buffer.getInt());
        if (type == null) {
            return null;
        }
        record.setType(type);
        record.setInUse(inUse);
        record.setKeyIndexId(buffer.getInt());
        record.setPropBlock(buffer.getLong());
        record.setPrevProp(buffer.getLong());
        record.setNextProp(buffer.getLong());
    }
    buffer.clear();
    buffer.limit(4);
    if (byteChannel.read(buffer) != buffer.limit()) {
        return null;
    }
    buffer.flip();
    int nrValueRecords = buffer.getInt();
    for (int i = 0; i < nrValueRecords; i++) {
        DynamicRecord dr = readDynamicRecord(byteChannel, buffer);
        if (dr == null) {
            return null;
        }
        record.addValueRecord(dr);
    }
    return new Command(record);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) XaCommand(org.neo4j.kernel.impl.transaction.xaframework.XaCommand) PropertyType(org.neo4j.kernel.impl.nioneo.store.PropertyType)

Example 13 with PropertyRecord

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

the class BatchInserterImpl method deletePropertyChain.

private void deletePropertyChain(long nextProp) {
    PropertyStore propStore = getPropertyStore();
    while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
        PropertyRecord propRecord = propStore.getRecord(nextProp);
        for (PropertyBlock propBlock : propRecord.getPropertyBlocks()) {
            propStore.makeHeavy(propBlock);
            for (DynamicRecord rec : propBlock.getValueRecords()) {
                rec.setInUse(false);
                propRecord.addDeletedRecord(rec);
            }
        }
        propRecord.setInUse(false);
        nextProp = propRecord.getNextProp();
        propStore.updateRecord(propRecord);
    }
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.nioneo.store.PropertyBlock) PropertyStore(org.neo4j.kernel.impl.nioneo.store.PropertyStore)

Example 14 with PropertyRecord

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

the class BatchInserterImpl method getPropertyChain.

private Map<String, Object> getPropertyChain(long nextProp) {
    PropertyStore propStore = getPropertyStore();
    Map<String, Object> properties = new HashMap<String, Object>();
    while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
        PropertyRecord propRecord = propStore.getRecord(nextProp);
        for (PropertyBlock propBlock : propRecord.getPropertyBlocks()) {
            String key = indexHolder.getStringKey(propBlock.getKeyIndexId());
            PropertyData propertyData = propBlock.newPropertyData(propRecord);
            Object value = propertyData.getValue() != null ? propertyData.getValue() : propBlock.getType().getValue(propBlock, getPropertyStore());
            properties.put(key, value);
        }
        nextProp = propRecord.getNextProp();
    }
    return properties;
}
Also used : PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData) HashMap(java.util.HashMap) 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 15 with PropertyRecord

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

the class PropertyWriter method writeProperties.

/**
     * Transforms a mapping of key index ids to values into a property chain.
     * Mostly copied-pasted from BatchTransactionImpl.
     *
     * @param properties The mapping, as a list of Pairs of keys and values
     * @return a long value valid for a property record id that is the id of the
     *         head of the chain, suitable for a nextProp() value on a
     *         primitive.
     */
public long writeProperties(List<Pair<Integer, Object>> properties) {
    if (properties == null || properties.isEmpty()) {
        return Record.NO_NEXT_PROPERTY.intValue();
    }
    // To hold the records, we will write them out in reverse order
    List<PropertyRecord> propRecords = new ArrayList<PropertyRecord>();
    // There is at least one property, so we will create at least one record.
    PropertyRecord currentRecord = new PropertyRecord(propertyStore.nextId());
    currentRecord.setInUse(true);
    currentRecord.setCreated();
    propRecords.add(currentRecord);
    for (Pair<Integer, Object> propertyDatum : properties) {
        PropertyBlock block = new PropertyBlock();
        propertyStore.encodeValue(block, propertyDatum.first(), propertyDatum.other());
        if (currentRecord.size() + block.getSize() > PropertyType.getPayloadSize()) {
            // Here it means the current block is done for
            PropertyRecord prevRecord = currentRecord;
            // Create new record
            long propertyId = propertyStore.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--) {
        propertyStore.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)

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