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:20:01 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();

        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);

and after that i'm commiting the transaction started before:

DMETransaction.getInstance().commit((Session) args[0]) with the code

public void commit(Session s) {
        logger.debug("-----< comit transaction >-------");
        Xid xid = null;
        try {
            XASession session = (XASession) s;

            // get XAResource
            XAResource xares = session.getXAResource();
            xid = xids.get(s.toString());

            //commit transaction
            xares.end(xid, XAResource.TMSUCCESS);
            xares.prepare(xid);
            xares.commit(xid, false);

            //remove xid that unique identifies this transaction
            xids.remove(s.toString());
        } catch(Exception e) {
            logger.error("", e);
        }
    }

and i've got this:

javax.jcr.ReferentialIntegrityException:
feea1825-175a-4579-a894-efb217b1a779: the node cannot be removed because it
is still being referenced.

Is there a way to include the version delete process in the same transaction
with the node ?

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