Search in sources :

Example 6 with ParcelableRelationship

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

the class RelationshipPropertiesActivity method confirmDeletionOfRelationship.

private void confirmDeletionOfRelationship() {
    AlertDialog dialog = new AlertDialog.Builder(this).create();
    dialog.setTitle(R.string.relationship_delete_title);
    Formatter formatter = new Formatter();
    formatter.format(getResources().getString(R.string.relationship_delete_question), relationshipId);
    dialog.setMessage(formatter.toString());
    dialog.setButton(getResources().getString(android.R.string.yes), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            try {
                GraphDatabase database = dbManager.getCurrentNeo4jDatabase();
                database.beginTx();
                try {
                    ParcelableRelationship relationship = database.getRelationshipById(relationshipId);
                    database.deleteRelationship(relationship.getId());
                    database.txSuccess();
                } finally {
                    database.txFinish();
                }
                Intent data = new Intent();
                data.putExtra(DBInspectorConstants.INTENTEXTRA_RELATIONSHIP_DELETED, true);
                setResult(RESULT_OK, data);
                finish();
            } catch (Exception e) {
                Ln.e(e, "failed to delete relationship with id '" + relationshipId + "'.");
                showErrorDialog();
            }
        }
    });
    dialog.setButton2(getResources().getString(android.R.string.no), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    dialog.show();
    formatter.close();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) GraphDatabase(org.neo4j.android.client.GraphDatabase) Formatter(java.util.Formatter) ParcelableRelationship(org.neo4j.android.common.ParcelableRelationship) Intent(android.content.Intent)

Example 7 with ParcelableRelationship

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

the class GraphDatabase method getRelationshipById.

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

Example 8 with ParcelableRelationship

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

the class ParcelableFactory method makeParcelableNode.

public static ParcelableNode makeParcelableNode(Node node) {
    ParcelableNode pNode = new ParcelableNode();
    pNode.setId(node.getId());
    // shallow copy of properties
    for (String key : node.getPropertyKeys()) {
        pNode.setProperty(key, node.getProperty(key));
    }
    // shallow copy of relationships
    for (Relationship rel : node.getRelationships()) {
        ParcelableRelationship pRel = makeParcelableRelationship(rel);
        pNode.getRelationships().add(pRel);
    }
    return pNode;
}
Also used : ParcelableRelationship(org.neo4j.android.common.ParcelableRelationship) Relationship(org.neo4j.graphdb.Relationship) ParcelableRelationship(org.neo4j.android.common.ParcelableRelationship) ParcelableNode(org.neo4j.android.common.ParcelableNode)

Example 9 with ParcelableRelationship

use of org.neo4j.android.common.ParcelableRelationship 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 10 with ParcelableRelationship

use of org.neo4j.android.common.ParcelableRelationship 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

ParcelableRelationship (org.neo4j.android.common.ParcelableRelationship)17 GraphDatabase (org.neo4j.android.client.GraphDatabase)11 ParcelableNode (org.neo4j.android.common.ParcelableNode)7 AlertDialog (android.app.AlertDialog)4 DialogInterface (android.content.DialogInterface)4 RemoteException (android.os.RemoteException)4 View (android.view.View)4 ContentView (roboguice.inject.ContentView)4 InjectView (roboguice.inject.InjectView)4 Formatter (java.util.Formatter)3 Relationship (org.neo4j.graphdb.Relationship)3 Intent (android.content.Intent)2 Button (android.widget.Button)2 ImageButton (android.widget.ImageButton)2 TextView (android.widget.TextView)2 Neo4jServiceException (org.neo4j.android.client.Neo4jServiceException)2 InvalidTransactionException (org.neo4j.javax.transaction.InvalidTransactionException)2 SystemException (org.neo4j.javax.transaction.SystemException)2 EditText (android.widget.EditText)1 ArrayList (java.util.ArrayList)1