Search in sources :

Example 21 with DynamicRecord

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

the class WriteTransaction method relationshipTypeAdd.

void relationshipTypeAdd(int id, String name) {
    RelationshipTypeRecord record = new RelationshipTypeRecord(id);
    record.setInUse(true);
    record.setCreated();
    int blockId = (int) getRelationshipTypeStore().nextBlockId();
    record.setTypeBlock(blockId);
    int length = name.length();
    char[] chars = new char[length];
    name.getChars(0, length, chars, 0);
    Collection<DynamicRecord> typeNameRecords = getRelationshipTypeStore().allocateTypeNameRecords(blockId, chars);
    for (DynamicRecord typeRecord : typeNameRecords) {
        record.addTypeRecord(typeRecord);
    }
    addRelationshipTypeRecord(record);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) RelationshipTypeRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord)

Example 22 with DynamicRecord

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

the class WriteTransaction method doRollback.

public void doRollback() throws XAException {
    if (committed) {
        throw new XAException("Cannot rollback partialy commited " + "transaction[" + getIdentifier() + "]. Recover and " + "commit");
    }
    try {
        for (RelationshipTypeRecord record : relTypeRecords.values()) {
            if (record.isCreated()) {
                getRelationshipTypeStore().freeId(record.getId());
                for (DynamicRecord dynamicRecord : record.getTypeRecords()) {
                    if (dynamicRecord.isCreated()) {
                        getRelationshipTypeStore().freeBlockId((int) dynamicRecord.getId());
                    }
                }
            }
            removeRelationshipTypeFromCache(record.getId());
        }
        for (NodeRecord record : nodeRecords.values()) {
            if (record.isCreated()) {
                getNodeStore().freeId(record.getId());
            }
            removeNodeFromCache(record.getId());
        }
        for (RelationshipRecord record : relRecords.values()) {
            if (record.isCreated()) {
                getRelationshipStore().freeId(record.getId());
            }
            removeRelationshipFromCache(record.getId());
        }
        for (PropertyIndexRecord record : propIndexRecords.values()) {
            if (record.isCreated()) {
                getPropertyStore().getIndexStore().freeId(record.getId());
                for (DynamicRecord dynamicRecord : record.getKeyRecords()) {
                    if (dynamicRecord.isCreated()) {
                        getPropertyStore().getIndexStore().freeBlockId((int) dynamicRecord.getId());
                    }
                }
            }
        }
        for (PropertyRecord record : propertyRecords.values()) {
            if (record.getNodeId() != -1) {
                removeNodeFromCache(record.getNodeId());
            } else if (record.getRelId() != -1) {
                removeRelationshipFromCache(record.getRelId());
            }
            if (record.isCreated()) {
                getPropertyStore().freeId(record.getId());
                for (DynamicRecord dynamicRecord : record.getValueRecords()) {
                    if (dynamicRecord.isCreated()) {
                        if (dynamicRecord.getType() == PropertyType.STRING.intValue()) {
                            getPropertyStore().freeStringBlockId(dynamicRecord.getId());
                        } else if (dynamicRecord.getType() == PropertyType.ARRAY.intValue()) {
                            getPropertyStore().freeArrayBlockId(dynamicRecord.getId());
                        } else {
                            throw new InvalidRecordException("Unknown type on " + dynamicRecord);
                        }
                    }
                }
            }
        }
    } finally {
        nodeRecords.clear();
        propertyRecords.clear();
        relRecords.clear();
        relTypeRecords.clear();
        propIndexRecords.clear();
        nodeCommands.clear();
        propCommands.clear();
        propIndexCommands.clear();
        relCommands.clear();
        relTypeCommands.clear();
        if (!isRecovered()) {
            lockReleaser.rollback();
        }
    }
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) XAException(javax.transaction.xa.XAException) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) PropertyIndexRecord(org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord) RelationshipTypeRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 23 with DynamicRecord

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

the class WriteTransaction method createRelationshipType.

@Override
public void createRelationshipType(int id, String name) {
    RelationshipTypeRecord record = new RelationshipTypeRecord(id);
    record.setInUse(true);
    record.setCreated();
    int blockId = (int) getRelationshipTypeStore().nextBlockId();
    record.setTypeBlock(blockId);
    //        int length = name.length();
    //        char[] chars = new char[length];
    //        name.getChars( 0, length, chars, 0 );
    Collection<DynamicRecord> typeNameRecords = getRelationshipTypeStore().allocateTypeNameRecords(blockId, encodeString(name));
    for (DynamicRecord typeRecord : typeNameRecords) {
        record.addTypeRecord(typeRecord);
    }
    addRelationshipTypeRecord(record);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) RelationshipTypeRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord)

Example 24 with DynamicRecord

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

the class WriteTransaction method createPropertyIndex.

@Override
public void createPropertyIndex(String key, int id) {
    PropertyIndexRecord record = new PropertyIndexRecord(id);
    record.setInUse(true);
    record.setCreated();
    PropertyIndexStore propIndexStore = getPropertyStore().getIndexStore();
    int keyBlockId = propIndexStore.nextKeyBlockId();
    record.setKeyBlockId(keyBlockId);
    Collection<DynamicRecord> keyRecords = propIndexStore.allocateKeyRecords(keyBlockId, encodeString(key));
    for (DynamicRecord keyRecord : keyRecords) {
        record.addKeyRecord(keyRecord);
    }
    addPropertyIndexRecord(record);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) PropertyIndexRecord(org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord) PropertyIndexStore(org.neo4j.kernel.impl.nioneo.store.PropertyIndexStore)

Example 25 with DynamicRecord

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

the class WriteTransaction method primitiveChangeProperty.

private PropertyData primitiveChangeProperty(PrimitiveRecord primitive, PropertyData propertyData, Object value, boolean isNode) {
    assert assertPropertyChain(primitive);
    long propertyId = propertyData.getId();
    PropertyRecord propertyRecord = getPropertyRecord(propertyId, true, true);
    if (!propertyRecord.inUse()) {
        throw new IllegalStateException("Unable to change property[" + propertyId + "] since it has been deleted.");
    }
    if (isNode) {
        propertyRecord.setNodeId(primitive.getId());
    } else {
        propertyRecord.setRelId(primitive.getId());
    }
    PropertyBlock block = propertyRecord.getPropertyBlock(propertyData.getIndex());
    if (block == null) {
        throw new IllegalStateException("Property with index[" + propertyData.getIndex() + "] is not present in property[" + propertyId + "]");
    }
    if (block.isLight()) {
        getPropertyStore().makeHeavy(block);
    }
    propertyRecord.setChanged();
    for (DynamicRecord record : block.getValueRecords()) {
        assert record.inUse();
        record.setInUse(false, block.getType().intValue());
        propertyRecord.addDeletedRecord(record);
    }
    getPropertyStore().encodeValue(block, propertyData.getIndex(), value);
    if (propertyRecord.size() > PropertyType.getPayloadSize()) {
        propertyRecord.removePropertyBlock(propertyData.getIndex());
        /*
             * The record should never, ever be above max size. Less obviously, it should
             * never remain empty. If removing a property because it won't fit when changing
             * it leaves the record empty it means that this block was the last one which
             * means that it doesn't fit in an empty record. Where i come from, we call this
             * weird.
             *
             assert propertyRecord.size() <= PropertyType.getPayloadSize() : propertyRecord;
             assert propertyRecord.size() > 0 : propertyRecord;
             */
        propertyRecord = addPropertyBlockToPrimitive(block, primitive, isNode);
    }
    assert assertPropertyChain(primitive);
    return block.newPropertyData(propertyRecord, value);
}
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)

Aggregations

DynamicRecord (org.neo4j.kernel.impl.nioneo.store.DynamicRecord)30 PropertyRecord (org.neo4j.kernel.impl.nioneo.store.PropertyRecord)15 PropertyBlock (org.neo4j.kernel.impl.nioneo.store.PropertyBlock)7 PropertyIndexRecord (org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord)7 RelationshipTypeRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord)7 NodeRecord (org.neo4j.kernel.impl.nioneo.store.NodeRecord)6 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)6 IOException (java.io.IOException)5 PropertyIndexStore (org.neo4j.kernel.impl.nioneo.store.PropertyIndexStore)4 PropertyData (org.neo4j.kernel.impl.nioneo.store.PropertyData)3 XaCommand (org.neo4j.kernel.impl.transaction.xaframework.XaCommand)3 ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)3 XAException (javax.transaction.xa.XAException)2 InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)2 PropertyStore (org.neo4j.kernel.impl.nioneo.store.PropertyStore)2 RelationshipTypeStore (org.neo4j.kernel.impl.nioneo.store.RelationshipTypeStore)2 PropertyType (org.neo4j.kernel.impl.nioneo.store.PropertyType)1