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;
}
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));
}
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();
}
}
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();
}
}
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;
}
Aggregations