use of org.neo4j.android.client.GraphDatabase in project neo4j-mobile-android by neo4j-contrib.
the class RelationshipPropertiesActivity method confirmDeletionOfProperty.
private void confirmDeletionOfProperty(final String key, final Object value) {
AlertDialog dialog = new AlertDialog.Builder(this).create();
dialog.setTitle(R.string.property_delete_title);
Formatter formatter = new Formatter();
formatter.format(getResources().getString(R.string.property_delete_from_relationship_question), key, value, relationshipId);
dialog.setMessage(formatter.toString());
dialog.setButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
GraphDatabase database = dbManager.getCurrentNeo4jDatabase();
database.beginTx();
try {
ParcelableRelationship relationship = database.getRelationshipById(relationshipId);
relationship.removeProperty(key);
database.updateRelationship(relationship);
database.txSuccess();
} finally {
database.txFinish();
}
} catch (Exception e) {
Ln.e(e, "failed to delete property with key '" + key + "' and value '" + value + "' from relationship with id '" + relationshipId + "'.");
showErrorDialog();
}
}
});
dialog.setButton2(getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
dialog.show();
formatter.close();
}
use of org.neo4j.android.client.GraphDatabase in project neo4j-mobile-android by neo4j-contrib.
the class RelationshipActivity method updateRelationshipsList.
private void updateRelationshipsList() {
try {
relationshipsLayout.removeAllViews();
GraphDatabase database = dbManager.getCurrentNeo4jDatabase();
database.beginTx();
try {
ParcelableNode centerNode = database.getNodeById(centerNodeId);
List<ParcelableRelationship> relationshipsFromCenterNode = new ArrayList<ParcelableRelationship>();
List<ParcelableRelationship> relationshipsToCenterNode = new ArrayList<ParcelableRelationship>();
for (ParcelableRelationship relationship : centerNode.getRelationships()) {
if ((centerNodeId == relationship.getStartNodeId()) && (peerNodeId == relationship.getEndNodeId())) {
relationshipsFromCenterNode.add(relationship);
}
if ((centerNodeId != peerNodeId) && (peerNodeId == relationship.getStartNodeId()) && (centerNodeId == relationship.getEndNodeId())) {
relationshipsToCenterNode.add(relationship);
}
}
Button nodeCenterButton = (Button) findViewById(R.id.nodeCenterButton);
nodeCenterButton.setText("" + centerNodeId);
nodeCenterButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showNodePropertyActivity(centerNodeId);
}
});
Button nodePeerButton = (Button) findViewById(R.id.nodePeerButton);
if (centerNodeId == peerNodeId) {
nodePeerButton.setVisibility(View.INVISIBLE);
} else {
nodePeerButton.setText("" + peerNodeId);
nodePeerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showNodePropertyActivity(peerNodeId);
}
});
}
for (ParcelableRelationship relationship : relationshipsFromCenterNode) {
addRelationshipsListItem(relationship, true);
}
for (ParcelableRelationship relationship : relationshipsToCenterNode) {
addRelationshipsListItem(relationship, false);
}
} finally {
database.txFinish();
}
} catch (Exception e) {
Ln.e(e, "database exception");
showErrorDialog();
}
}
use of org.neo4j.android.client.GraphDatabase in project neo4j-mobile-android by neo4j-contrib.
the class NodeActivity 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(centerNodeId);
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.client.GraphDatabase in project neo4j-mobile-android by neo4j-contrib.
the class RelationshipActivity method createRelationship.
private void createRelationship(String name, long endNodeId) throws RemoteException, Neo4jServiceException {
GraphDatabase database = dbManager.getCurrentNeo4jDatabase();
database.beginTx();
try {
ParcelableRelationship relationship = new ParcelableRelationship();
relationship.setStartNodeId(centerNodeId);
relationship.setEndNodeId(endNodeId);
relationship.setName(name);
long relationshipId = database.createRelationship(relationship);
database.txSuccess();
Ln.i("created relationship '" + relationship + "' with id '" + relationshipId + "'");
} finally {
database.txFinish();
}
}
use of org.neo4j.android.client.GraphDatabase 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();
}
}
Aggregations