Search in sources :

Example 21 with InvalidRecordException

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

the class WriteTransaction method nodeLoadProperties.

@Override
public ArrayMap<Integer, PropertyData> nodeLoadProperties(long nodeId, boolean light) {
    NodeRecord nodeRecord = getNodeRecord(nodeId);
    if (nodeRecord != null && nodeRecord.isCreated()) {
        return null;
    }
    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");
    }
    return ReadTransaction.loadProperties(getPropertyStore(), nodeRecord.getNextProp());
}
Also used : NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 22 with InvalidRecordException

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

the class WriteTransaction method doRollback.

@Override
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 (PropertyBlock block : record.getPropertyBlocks()) {
                    for (DynamicRecord dynamicRecord : block.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();
    }
}
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) PropertyBlock(org.neo4j.kernel.impl.nioneo.store.PropertyBlock) 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 InvalidRecordException

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

the class BatchGraphDatabaseImpl method getNodeById.

public Node getNodeById(long id) {
    NodeBatchImpl node = nodes.get(id);
    if (node == null) {
        try {
            node = new NodeBatchImpl(id, this, batchInserter.getNodeProperties(id));
            nodes.put(id, node);
        } catch (InvalidRecordException e) {
            throw new NotFoundException(e);
        }
    }
    return node;
}
Also used : NotFoundException(org.neo4j.graphdb.NotFoundException) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 24 with InvalidRecordException

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

the class BatchGraphDatabaseImpl method getRelationshipById.

public Relationship getRelationshipById(long id) {
    RelationshipBatchImpl rel = rels.get(id);
    if (rel == null) {
        try {
            SimpleRelationship simpleRel = batchInserter.getRelationshipById(id);
            Map<String, Object> props = batchInserter.getRelationshipProperties(id);
            rel = new RelationshipBatchImpl(simpleRel, this, props);
            rels.put(id, rel);
        } catch (InvalidRecordException e) {
            throw new NotFoundException(e);
        }
    }
    return rel;
}
Also used : NotFoundException(org.neo4j.graphdb.NotFoundException) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 25 with InvalidRecordException

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

the class ReadTransaction method relGetProperties.

public ArrayMap<Integer, PropertyData> relGetProperties(long relId) {
    RelationshipRecord relRecord = getRelationshipStore().getRecord(relId);
    if (!relRecord.inUse()) {
        throw new InvalidRecordException("Relationship[" + relId + "] not in use");
    }
    long nextProp = relRecord.getNextProp();
    ArrayMap<Integer, PropertyData> propertyMap = new ArrayMap<Integer, PropertyData>(9, false, true);
    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) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Aggregations

InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)29 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)20 NodeRecord (org.neo4j.kernel.impl.nioneo.store.NodeRecord)10 ArrayList (java.util.ArrayList)7 PropertyRecord (org.neo4j.kernel.impl.nioneo.store.PropertyRecord)7 XAException (javax.transaction.xa.XAException)4 NotFoundException (org.neo4j.graphdb.NotFoundException)4 Relationship (org.neo4j.graphdb.Relationship)4 PropertyIndexRecord (org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord)4 RelationshipTypeRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord)4 ByteBuffer (java.nio.ByteBuffer)3 PropertyData (org.neo4j.kernel.impl.nioneo.store.PropertyData)3 ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)3 RelationshipType (org.neo4j.graphdb.RelationshipType)2 DynamicRecord (org.neo4j.kernel.impl.nioneo.store.DynamicRecord)2 RelationshipData (org.neo4j.kernel.impl.nioneo.store.RelationshipData)2 PropertyCommand (org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand)2 XaCommand (org.neo4j.kernel.impl.transaction.xaframework.XaCommand)2 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1