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();
}
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;
}
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;
}
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();
}
}
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
}
}
Aggregations