Search in sources :

Example 51 with RelationshipType

use of org.neo4j.graphdb.RelationshipType in project neo4j-mobile-android by neo4j-contrib.

the class NodeImpl method getSingleRelationship.

public Relationship getSingleRelationship(NodeManager nodeManager, RelationshipType type, Direction dir) {
    DirectionWrapper direction = RelIdArray.wrap(dir);
    RelationshipType[] types = new RelationshipType[] { type };
    Iterator<Relationship> rels = new IntArrayIterator(getAllRelationshipsOfType(nodeManager, direction, types), this, direction, nodeManager, types, !hasMoreRelationshipsToLoad());
    if (!rels.hasNext()) {
        return null;
    }
    Relationship rel = rels.next();
    if (rels.hasNext()) {
        throw new NotFoundException("More than one relationship[" + type + ", " + dir + "] found for " + this);
    }
    return rel;
}
Also used : DirectionWrapper(org.neo4j.kernel.impl.util.RelIdArray.DirectionWrapper) Relationship(org.neo4j.graphdb.Relationship) RelationshipType(org.neo4j.graphdb.RelationshipType) NotFoundException(org.neo4j.graphdb.NotFoundException)

Example 52 with RelationshipType

use of org.neo4j.graphdb.RelationshipType in project neo4j-mobile-android by neo4j-contrib.

the class StandardExpander method create.

static StandardExpander create(RelationshipType type1, Direction dir1, RelationshipType type2, Direction dir2, Object... more) {
    Map<Direction, Collection<RelationshipType>> tempMap = temporaryTypeMap();
    tempMap.get(dir1).add(type1);
    tempMap.get(dir2).add(type2);
    for (int i = 0; i < more.length; i++) {
        RelationshipType type = (RelationshipType) more[i++];
        Direction direction = (Direction) more[i];
        tempMap.get(direction).add(type);
    }
    return new RegularExpander(toTypeMap(tempMap));
}
Also used : RelationshipType(org.neo4j.graphdb.RelationshipType) Collection(java.util.Collection) Direction(org.neo4j.graphdb.Direction)

Example 53 with RelationshipType

use of org.neo4j.graphdb.RelationshipType in project neo4j-mobile-android by neo4j-contrib.

the class NodeManager method getRelationshipById.

public Relationship getRelationshipById(long relId) throws NotFoundException {
    RelationshipImpl relationship = relCache.get(relId);
    if (relationship != null) {
        return new RelationshipProxy(relId, this);
    }
    ReentrantLock loadLock = lockId(relId);
    try {
        relationship = relCache.get(relId);
        if (relationship != null) {
            return new RelationshipProxy(relId, this);
        }
        RelationshipRecord data = persistenceManager.loadLightRelationship(relId);
        if (data == null) {
            throw new NotFoundException("Relationship[" + relId + "]");
        }
        int typeId = data.getType();
        RelationshipType type = getRelationshipTypeById(typeId);
        if (type == null) {
            throw new NotFoundException("Relationship[" + data.getId() + "] exist but relationship type[" + typeId + "] not found.");
        }
        final long startNodeId = data.getFirstNode();
        final long endNodeId = data.getSecondNode();
        relationship = newRelationshipImpl(relId, startNodeId, endNodeId, type, typeId, false);
        relCache.put(relId, relationship);
        return new RelationshipProxy(relId, this);
    } finally {
        loadLock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) RelationshipType(org.neo4j.graphdb.RelationshipType) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) NotFoundException(org.neo4j.graphdb.NotFoundException)

Example 54 with RelationshipType

use of org.neo4j.graphdb.RelationshipType in project neo4j-mobile-android by neo4j-contrib.

the class NodeManager method getRelForProxy.

RelationshipImpl getRelForProxy(long relId) {
    RelationshipImpl relationship = relCache.get(relId);
    if (relationship != null) {
        return relationship;
    }
    ReentrantLock loadLock = lockId(relId);
    try {
        relationship = relCache.get(relId);
        if (relationship != null) {
            return relationship;
        }
        RelationshipRecord data = persistenceManager.loadLightRelationship(relId);
        if (data == null) {
            throw new NotFoundException("Relationship[" + relId + "] not found.");
        }
        int typeId = data.getType();
        RelationshipType type = getRelationshipTypeById(typeId);
        if (type == null) {
            throw new NotFoundException("Relationship[" + data.getId() + "] exist but relationship type[" + typeId + "] not found.");
        }
        relationship = newRelationshipImpl(relId, data.getFirstNode(), data.getSecondNode(), type, typeId, false);
        relCache.put(relId, relationship);
        return relationship;
    } finally {
        loadLock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) RelationshipType(org.neo4j.graphdb.RelationshipType) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) NotFoundException(org.neo4j.graphdb.NotFoundException)

Example 55 with RelationshipType

use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.

the class Mkrel method exec.

@Override
protected Continuation exec(AppCommandParser parser, Session session, Output out) throws ShellException, RemoteException {
    assertCurrentIsNode(session);
    boolean createNode = parser.options().containsKey("c");
    boolean suppliedNode = !parser.arguments().isEmpty();
    Node node = null;
    if (createNode) {
        node = getServer().getDb().createNode(parseLabels(parser));
        session.set(KEY_LAST_CREATED_NODE, "" + node.getId());
        setProperties(node, parser.options().get("np"));
    } else if (suppliedNode) {
        node = getNodeById(Long.parseLong(parser.arguments().get(0)));
    } else {
        throw new ShellException("Must either create node (-c)" + " or supply node id as the first argument");
    }
    if (parser.options().get("t") == null) {
        throw new ShellException("Must supply relationship type " + "(-t <relationship-type-name>)");
    }
    RelationshipType type = getRelationshipType(parser.options().get("t"));
    Direction direction = getDirection(parser.options().get("d"));
    NodeOrRelationship current = getCurrent(session);
    Node currentNode = current.asNode();
    Node startNode = direction == Direction.OUTGOING ? currentNode : node;
    Node endNode = direction == Direction.OUTGOING ? node : currentNode;
    Relationship relationship = startNode.createRelationshipTo(endNode, type);
    setProperties(relationship, parser.options().get("rp"));
    session.set(KEY_LAST_CREATED_RELATIONSHIP, relationship.getId());
    boolean verbose = parser.options().containsKey("v");
    if (createNode && verbose) {
        out.println("Node " + getDisplayName(getServer(), session, node, false) + " created");
    }
    if (verbose) {
        out.println("Relationship " + getDisplayName(getServer(), session, relationship, true, false) + " created");
    }
    if (parser.options().containsKey("cd")) {
        cdTo(session, node);
    }
    return Continuation.INPUT_COMPLETE;
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipType(org.neo4j.graphdb.RelationshipType) ShellException(org.neo4j.shell.ShellException) Direction(org.neo4j.graphdb.Direction)

Aggregations

RelationshipType (org.neo4j.graphdb.RelationshipType)97 Node (org.neo4j.graphdb.Node)53 Test (org.junit.Test)45 Relationship (org.neo4j.graphdb.Relationship)38 Transaction (org.neo4j.graphdb.Transaction)18 Direction (org.neo4j.graphdb.Direction)15 Traverser (org.neo4j.graphdb.Traverser)10 NotFoundException (org.neo4j.graphdb.NotFoundException)9 DynamicRelationshipType (org.neo4j.graphdb.DynamicRelationshipType)7 Label (org.neo4j.graphdb.Label)7 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)7 Collection (java.util.Collection)6 HashSet (java.util.HashSet)6 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)6 Path (org.neo4j.graphdb.Path)6 StopEvaluator (org.neo4j.graphdb.StopEvaluator)6 TraversalPosition (org.neo4j.graphdb.TraversalPosition)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)4