Search in sources :

Example 1 with LockException

use of org.neo4j.kernel.impl.transaction.LockException in project neo4j-mobile-android by neo4j-contrib.

the class RelationshipImpl method delete.

public void delete(NodeManager nodeManager) {
    NodeImpl startNode = null;
    NodeImpl endNode = null;
    boolean startNodeLocked = false;
    boolean endNodeLocked = false;
    boolean thisLocked = false;
    boolean success = false;
    try {
        startNode = nodeManager.getLightNode(getStartNodeId());
        if (startNode != null) {
            nodeManager.acquireLock(startNode, LockType.WRITE);
            startNodeLocked = true;
        }
        endNode = nodeManager.getLightNode(getEndNodeId());
        if (endNode != null) {
            nodeManager.acquireLock(endNode, LockType.WRITE);
            endNodeLocked = true;
        }
        nodeManager.acquireLock(this, LockType.WRITE);
        thisLocked = true;
        // no need to load full relationship, all properties will be
        // deleted when relationship is deleted
        ArrayMap<Integer, PropertyData> skipMap = nodeManager.getCowPropertyRemoveMap(this, true);
        ArrayMap<Integer, PropertyData> removedProps = nodeManager.deleteRelationship(this);
        if (removedProps.size() > 0) {
            for (int index : removedProps.keySet()) {
                skipMap.put(index, removedProps.get(index));
            }
        }
        success = true;
        RelationshipType type = getType(nodeManager);
        long id = getId();
        if (startNode != null) {
            startNode.removeRelationship(nodeManager, type, id);
        }
        if (endNode != null) {
            endNode.removeRelationship(nodeManager, type, id);
        }
        success = true;
    } finally {
        boolean releaseFailed = false;
        try {
            if (thisLocked) {
                nodeManager.releaseLock(this, LockType.WRITE);
            }
        } catch (Exception e) {
            releaseFailed = true;
            e.printStackTrace();
        }
        try {
            if (startNodeLocked) {
                nodeManager.releaseLock(startNode, LockType.WRITE);
            }
        } catch (Exception e) {
            releaseFailed = true;
            e.printStackTrace();
        }
        try {
            if (endNodeLocked) {
                nodeManager.releaseLock(endNode, LockType.WRITE);
            }
        } catch (Exception e) {
            releaseFailed = true;
            e.printStackTrace();
        }
        if (!success) {
            nodeManager.setRollbackOnly();
        }
        if (releaseFailed) {
            throw new LockException("Unable to release locks [" + startNode + "," + endNode + "] in relationship delete->" + this);
        }
    }
}
Also used : PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData) LockException(org.neo4j.kernel.impl.transaction.LockException) RelationshipType(org.neo4j.graphdb.RelationshipType) NotFoundException(org.neo4j.graphdb.NotFoundException) LockException(org.neo4j.kernel.impl.transaction.LockException)

Aggregations

NotFoundException (org.neo4j.graphdb.NotFoundException)1 RelationshipType (org.neo4j.graphdb.RelationshipType)1 PropertyData (org.neo4j.kernel.impl.nioneo.store.PropertyData)1 LockException (org.neo4j.kernel.impl.transaction.LockException)1