jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mitziuro <mitzi...@gmail.com>
Subject Re: Delete problem
Date Thu, 03 Sep 2009 18:15:09 GMT
So, I have the following code for deleting a node:


VersionHistory vh = null;
        boolean versionable = false;
        String uuid = node.getUUID();

        try {
            // check if node is versionable
            if (((NodeImpl) node).isNodeType(NameConstants.MIX_VERSIONABLE))
{
                node.checkout();
                logger.debug("node is versionable...get version history");
                vh = node.getVersionHistory();
                versionable = true;

            }
        } catch (Exception e) {
            // just log the exception...don't throw it
            logger.debug("Error at getting the version history for node: "
                    .concat(uuid), e);
        }

        Node child = null;

        // before removing the node, first remove all its children and their
versions
        NodeIterator nit = node.getNodes();
        while(nit.hasNext()){
            child = nit.nextNode();
            // check if the child is rep:policy
            if (child.getPrimaryNodeType().isNodeType(NODE_TYPE_ACL)) {
                //no op. rep:policy children are deleted automatically
            } else{
                // delete the child and its subtree and their versions
                delete(session, child);
            }
        }

        node.remove();
        session.save();

        //DMETransaction.getInstance().commit(session);

        try {
            // check if node is versionable
            if (versionable) {

                logger.debug("node is versionable...delete all versions");
                // delete version history
                VersionIterator vit = vh.getAllVersions();
                // skip the root version(it cannot be deleted)
                vit.skip(1);
                Version v = null;
                while (vit.hasNext()) {
                    v = vit.nextVersion();
                    vh.removeVersion(v.getName());
                }
            }
        } catch (Exception e) {
            // just log the exception...don't throw it
            logger.error("Error at deleting versions for node:
".concat(uuid),
                    e);
        }

On Thu, Sep 3, 2009 at 11:52 AM, Alexander Klimetschek <aklimets@day.com>wrote:

> On Thu, Sep 3, 2009 at 10:51 AM, Alexander Klimetschek<aklimets@day.com>
> wrote:
> > AFAIK, deleting the root node is not possible.
>
> Deleting the root *version* that is ;-)
>
> Regards,
> Alex
>
> --
> Alexander Klimetschek
> alexander.klimetschek@day.com
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message