Search in sources :

Example 11 with ParcelableNode

use of org.neo4j.android.common.ParcelableNode in project neo4j-mobile-android by neo4j-contrib.

the class RelationshipActivity method getAllNodeIds.

private List<Long> getAllNodeIds() throws RemoteException, Neo4jServiceException {
    GraphDatabase database = dbManager.getCurrentNeo4jDatabase();
    database.beginTx();
    try {
        NodeIterator iterator = database.getAllNodes();
        List<Long> nodeIds = new ArrayList<Long>();
        while (iterator.hasNext()) {
            ParcelableNode node = iterator.next();
            nodeIds.add(node.getId());
        }
        return nodeIds;
    } finally {
        database.txFinish();
    }
}
Also used : NodeIterator(org.neo4j.android.client.NodeIterator) GraphDatabase(org.neo4j.android.client.GraphDatabase) ArrayList(java.util.ArrayList) ParcelableNode(org.neo4j.android.common.ParcelableNode)

Example 12 with ParcelableNode

use of org.neo4j.android.common.ParcelableNode in project neo4j-mobile-android by neo4j-contrib.

the class RootNodeActivity method updateNodesList.

private void updateNodesList() {
    try {
        referenceNodeLayout.removeAllViews();
        rootNodesLayout.removeAllViews();
        cycleNodesLayout.removeAllViews();
        GraphDatabase database = dbManager.getCurrentNeo4jDatabase();
        database.beginTx();
        try {
            ParcelableNode referenceNode = database.getReferenceNode();
            addNodeListItem(referenceNodeLayout, referenceNode);
            List<ParcelableNode> rootNodes = new ArrayList<ParcelableNode>();
            NodeIterator nodeIterator = database.getAllNodes();
            while (nodeIterator.hasNext()) {
                ParcelableNode node = nodeIterator.next();
                if (!node.hasRelationship(Direction.INCOMING)) {
                    rootNodes.add(node);
                }
            }
            for (ParcelableNode rootNode : rootNodes) {
                addNodeListItem(rootNodesLayout, rootNode);
            }
        // TODO: [eRiC] what happens if all graphs are circular? ->
        // pick
        // one node per graph:
        } finally {
            database.txFinish();
        }
    } catch (Exception e) {
        Ln.e(e, "database exception");
        showErrorDialog();
    }
}
Also used : NodeIterator(org.neo4j.android.client.NodeIterator) GraphDatabase(org.neo4j.android.client.GraphDatabase) ArrayList(java.util.ArrayList) ParcelableNode(org.neo4j.android.common.ParcelableNode) Neo4jServiceException(org.neo4j.android.client.Neo4jServiceException) RemoteException(android.os.RemoteException)

Example 13 with ParcelableNode

use of org.neo4j.android.common.ParcelableNode in project neo4j-mobile-android by neo4j-contrib.

the class RootNodeActivity method retrieveReferenceNodeId.

private void retrieveReferenceNodeId() {
    try {
        GraphDatabase database = dbManager.getCurrentNeo4jDatabase();
        database.beginTx();
        try {
            ParcelableNode referenceNode = database.getReferenceNode();
            referenceNodeId = referenceNode.getId();
        } finally {
            database.txFinish();
        }
    } catch (Exception e) {
        Ln.e(e, "database exception");
        showErrorDialog();
    }
}
Also used : GraphDatabase(org.neo4j.android.client.GraphDatabase) ParcelableNode(org.neo4j.android.common.ParcelableNode) Neo4jServiceException(org.neo4j.android.client.Neo4jServiceException) RemoteException(android.os.RemoteException)

Example 14 with ParcelableNode

use of org.neo4j.android.common.ParcelableNode in project neo4j-mobile-android by neo4j-contrib.

the class RootNodeActivity method createNode.

private void createNode(boolean createDefaultRelationship) throws RemoteException, Neo4jServiceException {
    GraphDatabase database = dbManager.getCurrentNeo4jDatabase();
    database.beginTx();
    try {
        ParcelableNode node = new ParcelableNode();
        long nodeId = database.createNode(node);
        Ln.i("created node '" + node + "' with id '" + nodeId + "'");
        if (createDefaultRelationship) {
            ParcelableRelationship relationship = new ParcelableRelationship();
            relationship.setStartNodeId(referenceNodeId);
            relationship.setEndNodeId(nodeId);
            relationship.setName(defaultRelationshipName);
            long relationshipId = database.createRelationship(relationship);
            Ln.i("created relationship '" + relationship + "' with id '" + relationshipId + "'");
        }
        database.txSuccess();
    } finally {
        database.txFinish();
    }
}
Also used : GraphDatabase(org.neo4j.android.client.GraphDatabase) ParcelableRelationship(org.neo4j.android.common.ParcelableRelationship) ParcelableNode(org.neo4j.android.common.ParcelableNode)

Example 15 with ParcelableNode

use of org.neo4j.android.common.ParcelableNode in project neo4j-mobile-android by neo4j-contrib.

the class NodeActivity method updateNodesList.

private void updateNodesList() {
    try {
        nodeRelationshipsLayout.removeAllViews();
        GraphDatabase database = dbManager.getCurrentNeo4jDatabase();
        database.beginTx();
        try {
            ParcelableNode centerNode = database.getNodeById(centerNodeId);
            List<ParcelableRelationship> relationships = centerNode.getRelationships();
            final Set<Long> pointingToCenterNodeNodeIds = new TreeSet<Long>();
            Set<ParcelableNode> peerNodes = new TreeSet<ParcelableNode>(new Comparator<ParcelableNode>() {

                @Override
                public int compare(ParcelableNode firstNode, ParcelableNode secondNode) {
                    if (firstNode.getId() < secondNode.getId()) {
                        return -1;
                    } else if (firstNode.getId() > secondNode.getId()) {
                        return 1;
                    } else {
                        return 0;
                    }
                }
            });
            int loopRelationshipsCount = 0;
            String lastLoopRelationshipName = "";
            for (ParcelableRelationship relationship : relationships) {
                if (relationship.getStartNodeId() == relationship.getEndNodeId()) {
                    loopRelationshipsCount++;
                    lastLoopRelationshipName = relationship.getName();
                } else {
                    if (centerNodeId == relationship.getStartNodeId()) {
                        peerNodes.add(database.getNodeById(relationship.getEndNodeId()));
                    } else {
                        pointingToCenterNodeNodeIds.add(relationship.getStartNodeId());
                        peerNodes.add(database.getNodeById(relationship.getStartNodeId()));
                    }
                }
            }
            nodeCenterButton.setText("" + centerNodeId);
            nodeCenterButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (pointingToCenterNodeNodeIds.isEmpty()) {
                    // do nothing.
                    } else if (pointingToCenterNodeNodeIds.size() == 1) {
                        showNodeActivity(pointingToCenterNodeNodeIds.iterator().next(), true);
                    } else {
                        showRelatedStartNodes(pointingToCenterNodeNodeIds);
                    }
                }
            });
            String text = getResources().getString(R.string.node_relationships_loop_button);
            if (loopRelationshipsCount == 0) {
                nodeLoopRelationshipsButton.setText(text);
            } else if (loopRelationshipsCount == 1) {
                nodeLoopRelationshipsButton.setText(text + "\n" + lastLoopRelationshipName);
            } else {
                nodeLoopRelationshipsButton.setText(text + "\n# " + loopRelationshipsCount);
            }
            nodeLoopRelationshipsButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    showRelationshipActivity(centerNodeId, centerNodeId);
                }
            });
            for (ParcelableNode peerNode : peerNodes) {
                addNodeRelationshipsListItem(peerNode);
            }
        } finally {
            database.txFinish();
        }
    } catch (Exception e) {
        Ln.e(e, "database exception");
        showErrorDialog();
    }
}
Also used : GraphDatabase(org.neo4j.android.client.GraphDatabase) ParcelableNode(org.neo4j.android.common.ParcelableNode) ContentView(roboguice.inject.ContentView) View(android.view.View) InjectView(roboguice.inject.InjectView) Neo4jServiceException(org.neo4j.android.client.Neo4jServiceException) RemoteException(android.os.RemoteException) TreeSet(java.util.TreeSet) ParcelableRelationship(org.neo4j.android.common.ParcelableRelationship)

Aggregations

ParcelableNode (org.neo4j.android.common.ParcelableNode)18 GraphDatabase (org.neo4j.android.client.GraphDatabase)12 RemoteException (android.os.RemoteException)6 ParcelableRelationship (org.neo4j.android.common.ParcelableRelationship)6 Neo4jServiceException (org.neo4j.android.client.Neo4jServiceException)4 AlertDialog (android.app.AlertDialog)3 DialogInterface (android.content.DialogInterface)3 View (android.view.View)3 ArrayList (java.util.ArrayList)3 ParcelableError (org.neo4j.android.common.ParcelableError)3 ContentView (roboguice.inject.ContentView)3 InjectView (roboguice.inject.InjectView)3 TextView (android.widget.TextView)2 Formatter (java.util.Formatter)2 NodeIterator (org.neo4j.android.client.NodeIterator)2 Node (org.neo4j.graphdb.Node)2 InvalidTransactionException (org.neo4j.javax.transaction.InvalidTransactionException)2 SystemException (org.neo4j.javax.transaction.SystemException)2 Intent (android.content.Intent)1 Button (android.widget.Button)1