[Yanel-dev] Yarep delete method
Michael Wechner
michael.wechner at wyona.com
Tue Jul 24 11:21:09 CEST 2007
Josias Thöny wrote:
> Michael Wechner wrote:
>
>> Josias Thöny wrote:
>>
>>> Michael Wechner wrote:
>>>
>>>> Hi
>>>>
>>>> I have noticed that according to the API calling delete also is
>>>> supposed to delete all children resp. also non-empty collections
>>>>
>>>> src/core/java/org/wyona/yarep/core/Node.java
>>>>
>>>> /**
>>>> * Deletes this node and all subnodes.
>>>> * The root node cannot be deleted.
>>>> * @throws RepositoryException if this node is the root node or
>>>> if a repository error occurs.
>>>> */
>>>> public void delete() throws RepositoryException;
>>>>
>>>>
>>>> Shouldn't we introduce something like
>>>>
>>>>
>>>> delete(boolean recursive)
>>>>
>>>> which would allow to block the deletion of non-empty collections
>>>> when being set to delete(false)
>>>>
>>>
>>> IIUC this would mean that a caller of delete(false) has to check
>>> afterwards if the operation has been successful.
>>> Then you could as well check if the node has any child nodes before
>>> you call delete().
>>> Where do you see the advantage of using delete(false)?
>>
>>
>>
>> I think it's a bit more convenient
>>
>> node.delete(false)
>>
>> versus
>>
>> if (node.getNodes().length == 0) node.delete()
>
>
> Hm, but you also have to handle the case where the node has some
> children.
> Then the first option becomes something like:
>
> boolean success = node.delete(false);
> if (!success) {
> throw new Exception("cannot delete node, maybe it has some
> child-nodes");
> }
>
> and the second option:
>
> if (node.getNodes().length == 0) {
> node.delete();
> } else {
> throw new Exception("cannot delete node because it has child-nodes");
> }
>
> So you need the "if" in both cases and the complexity is about the same.
> Personally I like the second one better, because in the first one you
> don't know why a node could not be deleted if the method returns false.
ok, so let's leave it as it is :-)
Cheers
Michi
>
> Josias
>
>>
>> but I am also fine with it as it is, because one could argue that
>> when using delete() within a program, one
>> normally doesn't do things by accident, whereas when using the "rm"
>> on the command line one often deletes stuff by accident.
>>
>> Cheers
>>
>> Michi
>>
>>>
>>> josias
>>>
>>>> ?
>>>>
>>>> This would corrspond to rm -r
>>>>
>>>> WDYT?
>>>>
>>>> Cheers
>>>>
>>>> Michi
>>>>
>>>
>>> _______________________________________________
>>> Yanel-development mailing list
>>> Yanel-development at wyona.com
>>> http://lists.wyona.org/cgi-bin/mailman/listinfo/yanel-development
>>
>>
>>
>>
>
> _______________________________________________
> Yanel-development mailing list
> Yanel-development at wyona.com
> http://lists.wyona.org/cgi-bin/mailman/listinfo/yanel-development
--
Michael Wechner
Wyona - Open Source Content Management - Yanel, Yulup
http://www.wyona.com
michael.wechner at wyona.com, michi at apache.org
+41 44 272 91 61
More information about the Yanel-development
mailing list