Search in sources :

Example 16 with ParcelableNode

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

the class NodePropertiesActivity method createProperty.

private void createProperty(String key, String value) {
    try {
        GraphDatabase database = dbManager.getCurrentNeo4jDatabase();
        database.beginTx();
        try {
            ParcelableNode node = database.getNodeById(nodeId);
            if (!node.hasProperty(key)) {
                node.setProperty(key, value);
                database.updateNode(node);
                database.txSuccess();
            } else {
                showPropertyAlreadyExistsError(key, value);
            }
        } finally {
            database.txFinish();
        }
    } catch (Exception e) {
        Ln.e(e, "failed to create new property with key '" + key + "' and value '" + value + "' on node with id '" + nodeId + "'.");
        showErrorDialog();
    }
    updateNodePropertiesList();
}
Also used : GraphDatabase(org.neo4j.android.client.GraphDatabase) ParcelableNode(org.neo4j.android.common.ParcelableNode)

Example 17 with ParcelableNode

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

the class GraphDatabase method getNodeById.

public ParcelableNode getNodeById(long id) throws RemoteException, Neo4jServiceException {
    ParcelableError err = new ParcelableError();
    ParcelableNode result = mProxy.getNodeById(id, err);
    Util.throwServiceExceptionIfError(err);
    return result;
}
Also used : ParcelableNode(org.neo4j.android.common.ParcelableNode) ParcelableError(org.neo4j.android.common.ParcelableError)

Example 18 with ParcelableNode

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

the class DbWrapper method updateNode.

@Override
public void updateNode(ParcelableNode node, ParcelableError err) throws RemoteException {
    try {
        checkCallerHasWritePermission();
        resumeTrx();
        try {
            Node target = mDb.getNodeById(node.getId());
            if (target != null) {
                // remove existing properties
                for (String key : target.getPropertyKeys()) {
                    target.removeProperty(key);
                }
                // set new properties
                for (String key : node.getPropertyKeys()) {
                    target.setProperty(key, node.getProperty(key));
                }
            } else {
                String message = "node not found. node '" + node + "'";
                Log.e(TAG, message);
                err.setError(Errors.TRANSACTION, message);
            }
        } finally {
            suspendCurrentTrx("updateNode");
        }
    } catch (Exception e) {
        Log.e(TAG, "Failed to update node", e);
        err.setError(Errors.TRANSACTION, e.getMessage());
    }
}
Also used : ParcelableNode(org.neo4j.android.common.ParcelableNode) Node(org.neo4j.graphdb.Node) RemoteException(android.os.RemoteException) InvalidTransactionException(org.neo4j.javax.transaction.InvalidTransactionException) SystemException(org.neo4j.javax.transaction.SystemException)

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