Search in sources :

Example 6 with NodeRecord

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

the class BatchInserterImpl method createNode.

public void createNode(long id, Map<String, Object> properties) {
    if (id < 0 || id > MAX_NODE_ID) {
        throw new IllegalArgumentException("id=" + id);
    }
    if (id == IdGeneratorImpl.INTEGER_MINUS_ONE) {
        throw new IllegalArgumentException("id " + id + " is reserved for internal use");
    }
    long nodeId = id;
    NodeStore nodeStore = neoStore.getNodeStore();
    if (neoStore.getNodeStore().loadLightNode(nodeId)) {
        throw new IllegalArgumentException("id=" + id + " already in use");
    }
    long highId = nodeStore.getHighId();
    if (highId <= id) {
        nodeStore.setHighId(nodeId + 1);
    }
    NodeRecord nodeRecord = new NodeRecord(nodeId);
    nodeRecord.setInUse(true);
    nodeRecord.setCreated();
    nodeRecord.setNextProp(createPropertyChain(properties));
    getNodeStore().updateRecord(nodeRecord);
}
Also used : NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) NodeStore(org.neo4j.kernel.impl.nioneo.store.NodeStore)

Example 7 with NodeRecord

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

the class BatchInserterImpl method createNode.

public long createNode(Map<String, Object> properties) {
    long nodeId = getNodeStore().nextId();
    NodeRecord nodeRecord = new NodeRecord(nodeId);
    nodeRecord.setInUse(true);
    nodeRecord.setCreated();
    nodeRecord.setNextProp(createPropertyChain(properties));
    getNodeStore().updateRecord(nodeRecord);
    return nodeId;
}
Also used : NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord)

Example 8 with NodeRecord

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

the class BatchInserterImpl method setNodeProperties.

public void setNodeProperties(long node, Map<String, Object> properties) {
    NodeRecord record = getNodeRecord(node);
    if (record.getNextProp() != Record.NO_NEXT_PROPERTY.intValue()) {
        deletePropertyChain(record.getNextProp());
        /*
             * Batch inserter does not make any attempt to maintain the store's
             * integrity. It makes sense however to keep some things intact where
             * the cost is relatively low. So here, when we delete the property
             * chain we first make sure that the node record (or the relationship
             * record below) does not point anymore to the deleted properties. This
             * way, if during creation, something goes wrong, it will not have the properties
             * expected instead of throwing invalid record exceptions.
             */
        record.setNextProp(Record.NO_NEXT_PROPERTY.intValue());
        getNodeStore().updateRecord(record);
    }
    record.setNextProp(createPropertyChain(properties));
    getNodeStore().updateRecord(record);
}
Also used : NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord)

Example 9 with NodeRecord

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

the class BatchInserterImpl method getRelationships.

public Iterable<SimpleRelationship> getRelationships(long nodeId) {
    NodeRecord nodeRecord = getNodeRecord(nodeId);
    long nextRel = nodeRecord.getNextRel();
    List<SimpleRelationship> rels = new ArrayList<SimpleRelationship>();
    while (nextRel != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        RelationshipRecord relRecord = getRelationshipRecord(nextRel);
        RelationshipType type = new RelationshipTypeImpl(typeHolder.getName(relRecord.getType()));
        rels.add(new SimpleRelationship(relRecord.getId(), relRecord.getFirstNode(), relRecord.getSecondNode(), type));
        long firstNode = relRecord.getFirstNode();
        long secondNode = relRecord.getSecondNode();
        if (firstNode == nodeId) {
            nextRel = relRecord.getFirstNextRel();
        } else if (secondNode == nodeId) {
            nextRel = relRecord.getSecondNextRel();
        } else {
            throw new InvalidRecordException("Node[" + nodeId + "] not part of firstNode[" + firstNode + "] or secondNode[" + secondNode + "]");
        }
    }
    return rels;
}
Also used : NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) ArrayList(java.util.ArrayList) RelationshipType(org.neo4j.graphdb.RelationshipType) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 10 with NodeRecord

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

the class WriteTransaction method updateNodes.

private void updateNodes(RelationshipRecord rel) {
    if (rel.getFirstPrevRel() == Record.NO_PREV_RELATIONSHIP.intValue()) {
        NodeRecord firstNode = getNodeRecord(rel.getFirstNode());
        if (firstNode == null) {
            firstNode = getNodeStore().getRecord(rel.getFirstNode());
            addNodeRecord(firstNode);
        }
        firstNode.setNextRel(rel.getFirstNextRel());
    }
    if (rel.getSecondPrevRel() == Record.NO_PREV_RELATIONSHIP.intValue()) {
        NodeRecord secondNode = getNodeRecord(rel.getSecondNode());
        if (secondNode == null) {
            secondNode = getNodeStore().getRecord(rel.getSecondNode());
            addNodeRecord(secondNode);
        }
        secondNode.setNextRel(rel.getSecondNextRel());
    }
}
Also used : NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord)

Aggregations

NodeRecord (org.neo4j.kernel.impl.nioneo.store.NodeRecord)36 PropertyRecord (org.neo4j.kernel.impl.nioneo.store.PropertyRecord)12 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)12 InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)10 DynamicRecord (org.neo4j.kernel.impl.nioneo.store.DynamicRecord)6 ArrayList (java.util.ArrayList)4 XAException (javax.transaction.xa.XAException)4 PropertyData (org.neo4j.kernel.impl.nioneo.store.PropertyData)4 PropertyIndexRecord (org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord)4 RelationshipTypeRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord)4 PropertyBlock (org.neo4j.kernel.impl.nioneo.store.PropertyBlock)3 XaCommand (org.neo4j.kernel.impl.transaction.xaframework.XaCommand)3 ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)3 IOException (java.io.IOException)2 RelationshipType (org.neo4j.graphdb.RelationshipType)2 NodeStore (org.neo4j.kernel.impl.nioneo.store.NodeStore)2 RelationshipChainPosition (org.neo4j.kernel.impl.nioneo.store.RelationshipChainPosition)2 PropertyCommand (org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand)2 ByteBuffer (java.nio.ByteBuffer)1 PrefetchingIterator (org.neo4j.helpers.collection.PrefetchingIterator)1