Neo4j - 2.0.0.5M OS - Ubunut 12.04LTS
我在删除有效关系时遇到问题。 当我尝试它时会抛出异常'交易标记为回滚'。 任何想法我在哪里做错了..
这是代码
@Name( "acceptLogicalFilter" )
@Description( "Through this function user accepts logical filters" )
@PluginTarget( GraphDatabaseService.class )
public String acceptLogicalFilter( @Source GraphDatabaseService graphDb , @Parameter( name = "arguments" ) String filterInsertData)
{
JsonObject filterInsertValues = MyUtils.getJsonObject(filterInsertData);
// ReturnMe
Map<Object , Object> returnMe = new HashMap<Object, Object>();
// get graph IT IS MY REUSABLE CLASSES
getGraph = new GetGraph(graphDb);
setGraph = new SetGraph(graphDb);
long userId = filterInsertValues.get("userId").getAsLong();
long filterId = filterInsertValues.get("filterId").getAsLong();
String filterValue = filterInsertValues.get("filterValue").getAsString();
Transaction txFilterInsert = graphDb.beginTx();
try {
// Take filter node with given filterId
Iterator<Node> filterIterator = getGraph.getNodesInIndex(GetGraph.IndexName.indexFilter, "indexType", "filter");
Node myFilterNode = null;
Node myUserNode = null;
// HERE DETERMINE FILTERNODE FOR GIVEN FILTER ID .. FILTER ID IS a Property in filterNode
while (filterIterator.hasNext()) {
myFilterNode = (Node) filterIterator.next();
if ((long)myFilterNode.getProperty("filterId") == filterId) {
break;
}
} // while close
// Take userNode with given userId
Iterator<Node> userIterator = getGraph.getNodesInIndex(GetGraph.IndexName.indexUser, "indexType", "user");
// TAKE USERNODE FOR GIVEN USER ID
while (userIterator.hasNext()) {
myUserNode = (Node) userIterator.next();
if ((long)myUserNode.getProperty("userId") == userId) {
break;
}
} // while close
// Now filter_ref_pending relationship between myUserNode and myFilterNode
// TODO: To identify relationship to delete between given user and filter is costly. Need to optimize
// Done : Now instead of taking all realtionships from filterNode , taking relationships from usernode pointing toward given
filter
Iterable<Relationship> relationShipIterator =
myUserNode.getRelationships(Direction.INCOMING,
GetGraph.RelationshipTypes.filter_ref_user_pending);
Iterator<Relationship> it = relationShipIterator.iterator();
// Now find the relationship whose end node is given myUserNode
Relationship myRelationship = null;
while (it.hasNext()) {
myRelationship = it.next();
if (myRelationship.getStartNode().getProperty("filterId") == myFilterNode.getProperty("filterId")) {
break;
}
} // while close
// Now delete relationship
// HERE DELETE RELATIONSHIP CAUSING ME PROBLEM . YES I AM GETTING LEGITIMATE RELATIONSHIP (REL:11943) BETWEEN FILTER NODE AND USER NODE
if (myRelationship != null) {
myRelationship.delete(); ------------ THROWS EXCEPTION : TRANSACTION MARKED FOR ROLLBACK.
}