Search in sources :

Example 1 with SimpleRelationshipType

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;
    }
}
Also used : SimpleRelationshipType(org.neo4j.android.service.util.SimpleRelationshipType) ParcelableNode(org.neo4j.android.common.ParcelableNode) Node(org.neo4j.graphdb.Node) TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) ParcelableTraversalDescription(org.neo4j.android.common.ParcelableTraversalDescription) SimpleRelationshipType(org.neo4j.android.service.util.SimpleRelationshipType) RelationshipType(org.neo4j.graphdb.RelationshipType) Direction(org.neo4j.graphdb.Direction) RemoteException(android.os.RemoteException) InvalidTransactionException(org.neo4j.javax.transaction.InvalidTransactionException) SystemException(org.neo4j.javax.transaction.SystemException)

Example 2 with SimpleRelationshipType

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
    }
}
Also used : SimpleRelationshipType(org.neo4j.android.service.util.SimpleRelationshipType) ParcelableNode(org.neo4j.android.common.ParcelableNode) Node(org.neo4j.graphdb.Node) ParcelableRelationship(org.neo4j.android.common.ParcelableRelationship) Relationship(org.neo4j.graphdb.Relationship) RemoteException(android.os.RemoteException) InvalidTransactionException(org.neo4j.javax.transaction.InvalidTransactionException) SystemException(org.neo4j.javax.transaction.SystemException)

Aggregations

RemoteException (android.os.RemoteException)2 ParcelableNode (org.neo4j.android.common.ParcelableNode)2 SimpleRelationshipType (org.neo4j.android.service.util.SimpleRelationshipType)2 Node (org.neo4j.graphdb.Node)2 InvalidTransactionException (org.neo4j.javax.transaction.InvalidTransactionException)2 SystemException (org.neo4j.javax.transaction.SystemException)2 ParcelableRelationship (org.neo4j.android.common.ParcelableRelationship)1 ParcelableTraversalDescription (org.neo4j.android.common.ParcelableTraversalDescription)1 Direction (org.neo4j.graphdb.Direction)1 Relationship (org.neo4j.graphdb.Relationship)1 RelationshipType (org.neo4j.graphdb.RelationshipType)1 TraversalDescription (org.neo4j.graphdb.traversal.TraversalDescription)1