This is my code:
Transaction tx = dbInstance.beginTx();
try {
Iterator<Relationship> relIt;
Relationship rel;
for ( String label: dbLabels ) {
for ( Node n: GlobalGraphOperations.at(dbInstance).
getAllNodesWithLabel(DynamicLabel.label(label)) ) {
relIt = n.getRelationships().iterator();
while ( relIt.hasNext() ) {
rel = relIt.next();
rel.delete();
}
n.delete();
}
}
tx.success();
} finally {
tx.finish();
}
Where dbLabels is a list of string (List<String>). It is as Stefan
suggested or am I missing something?
Thanks,
Alireza
On Saturday, August 30, 2014 1:27:00 AM UTC+2, Michael Hunger wrote:
>
> If you didn't miss tx.success() and used the same try-with-resource
> pattern as Stefan it must work.
>
> Except if you're swallowing an exception.
>
> Michael
>
> Am 30.08.2014 um 01:16 schrieb Alireza Rezaei Mahdiraji <
> [email protected] <javascript:>>:
>
> Hi Michael,
>
> Yeah I printed the nodes' info before deleting and it shows them. I have
> not
> print the relationships though, I think nodes would be enough, right?
>
> Thanks,
> Alireza
>
> On Saturday, August 30, 2014 12:25:20 AM UTC+2, Michael Hunger wrote:
>>
>> Can you print out the node-ids and rel-ids that it iterates over?
>>
>> Did you use the correct label name
>>
>> Michael
>>
>> Am 30.08.2014 um 00:22 schrieb Alireza Rezaei Mahdiraji <alire...@
>> gmail.com>:
>>
>>
>> Hi Stefan,
>>
>> I tied the Java code, it seems running but the nodes and relationships
>> are not getting deleted.
>> Also, there is no error. Any idea?
>>
>> Thanks,
>> Alireza
>>
>> On Friday, August 29, 2014 4:59:32 PM UTC+2, Stefan Armbruster wrote:
>>>
>>> Since you can run cypher from java the following would be a valid (but
>>> probably not expected) answer:
>>> new ExecutionEngine(graphDb).execute("match (n:MyLabel) optional
>>> match(n)-[r]-() delete r,n");
>>>
>>> In pure Java:
>>>
>>> try (Transaction tx=graphDb.beginTx()) {
>>> for (Node n:
>>> GlobalGraphOperations.at <http://globalgraphoperations.at/>
>>> (graphDb).getAllNodesWithLabel(DynamicLabel.label("MyLabel")))
>>> {
>>> for (Relationship r: n.getRelationships()) {
>>> r.delete();
>>> }
>>> n.delete();
>>> }
>>>
>>> tx.success();
>>> }
>>>
>>> NB: didn't test code above it's more a dump from /dev/brain ;-)
>>>
>>> /Stefan
>>>
>>>
>>> 2014-08-29 12:35 GMT+02:00 Alireza Rezaei Mahdiraji <[email protected]
>>> >:
>>> >
>>> > Hi All,
>>> >
>>> > How can I remove all nodes (and their relationships) with a given label
>>>
>>> > using Java?
>>> >
>>> > Thanks,
>>> > Alireza
>>> >
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> Groups
>>> > "Neo4j" group.
>>> > To unsubscribe from this group and stop receiving emails from it, send
>>> an
>>> > email to [email protected].
>>> > For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Neo4j" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Neo4j" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected] <javascript:>.
> For more options, visit https://groups.google.com/d/optout.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.