use of org.neo4j.android.service.util.SimpleRelationshipType in project neo4j-mobile-android by neo4j-contrib.
the class DbWrapper method traverse.
@Override
public INodeIterator traverse(ParcelableTraversalDescription desc, long startNodeId, ParcelableError err) throws RemoteException {
try {
resumeTrxIfExists();
try {
Node startNode = mDb.getNodeById(startNodeId);
if (startNode == null) {
throw new IllegalArgumentException("Illegal start node for traversal");
}
TraversalDescription traversalDesc = Traversal.description();
// map order
switch(desc.getOrder()) {
case BREADTH_FIRST:
traversalDesc = traversalDesc.breadthFirst();
break;
case DEPTH_FIRST:
traversalDesc = traversalDesc.depthFirst();
break;
}
// map uniqueness
switch(desc.getUniqueness()) {
case NONE:
traversalDesc = traversalDesc.uniqueness(Uniqueness.NONE);
break;
case NODE_GLOBAL:
traversalDesc = traversalDesc.uniqueness(Uniqueness.NODE_GLOBAL);
break;
case NODE_RECENT:
traversalDesc = traversalDesc.uniqueness(Uniqueness.NODE_RECENT);
break;
case NODE_PATH:
traversalDesc = traversalDesc.uniqueness(Uniqueness.NODE_PATH);
break;
case RELATIONSHIP_GLOBAL:
traversalDesc = traversalDesc.uniqueness(Uniqueness.RELATIONSHIP_GLOBAL);
break;
case RELATIONSHIP_PATH:
traversalDesc = traversalDesc.uniqueness(Uniqueness.RELATIONSHIP_PATH);
break;
case RELATIONSHIP_RECENT:
traversalDesc = traversalDesc.uniqueness(Uniqueness.RELATIONSHIP_RECENT);
break;
}
// map relationships
for (String name : desc.getRelationships().keySet()) {
RelationshipType type = new SimpleRelationshipType(name);
Direction direction = Direction.valueOf(desc.getRelationships().get(name).name());
traversalDesc = traversalDesc.relationships(type, direction);
}
// TODO: support paths
Iterator<Node> nodeIterator = traversalDesc.traverse(startNode).nodes().iterator();
return new NodeIteratorWrapper(nodeIterator);
} finally {
suspendCurrentTrx("traverse");
}
} catch (Exception e) {
err.setError(Errors.TRANSACTION, e.getMessage());
return null;
}
}
use of org.neo4j.android.service.util.SimpleRelationshipType in project neo4j-mobile-android by neo4j-contrib.
the class DbWrapper method createRelationship.
@Override
public long createRelationship(ParcelableRelationship rel, ParcelableError err) throws RemoteException {
try {
checkCallerHasWritePermission();
resumeTrx();
try {
Node startNode = mDb.getNodeById(rel.getStartNodeId());
Node endNode = mDb.getNodeById(rel.getEndNodeId());
Relationship newRel = startNode.createRelationshipTo(endNode, new SimpleRelationshipType(rel.getName()));
for (String key : rel.getPropertyKeys()) {
newRel.setProperty(key, rel.getProperty(key));
}
return newRel.getId();
} finally {
suspendCurrentTrx("createRelationship");
}
} catch (Exception e) {
Log.e(TAG, "Error creating relationship", e);
err.setError(Errors.TRANSACTION, e.getMessage());
// we need to return something, caller checks error
return -1;
// object
}
}
Aggregations