jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From SalmasCM <sal...@criticalmass.com>
Subject modified externally: node / when deleting node
Date Sun, 03 May 2009 03:36:18 GMT

I have been trying for weeks to get things working in my application and am
not making any progress.
I don't believe my use case is very unusual and I am hoping that you will be
able to help me.

1. I have a lot of legacy data that I load in using the XML import feature.
Each section is loaded under it's own top level node. The top level nodes
live directly under root.
2. I have 2 workspaces , preview and default. Changes and data loads happen
in preview and are cloned/merged into default.

Everything works if I bulk load the data with the XML import once but falls
apart if I load a all the sections into preview and then clone to default
and then later wish to reload a node with the XML import.

I am unable to reload since it thinks it's a new node so if I reload for
example employees then it creates employees[1] which is not what I want.

I have then 2 options. 
1. to force it to recognize the top node as the same node as previously
loaded, to do this I would have to indicate the UUID for the top node.
However, I have no idea how to make the UUID in the XML data file the same
as it would create when reloading?
2. So I tried to delete the node from both preview and default workspaces
before loading. I ran into many issues and finally succeeded in reloading
the data. However, I ran into issues when I modify any data in preview.

I get 

Item cannot be saved because it has been modified externally: node /
javax.jcr.InvalidItemStateException: Item cannot be saved because it has
been modified externally: node /

This is the sequence of events.

1.  load data using the XML loading under topNodeA in preview workspace
2. I modify some of the data under topNodeA in preview workspace.
3. I save the session etc.
4. I clone the topNodeA and its subtree to the default space.
4. I stop my application server and restart.
5. I get a new session into the preview workspace
6. I try to delete topNodeA in the preview workspace and then I get the
above error.

However, I do NOT receive this error when I do the following (do not get out
of the existing session for that workspace and then subsequently get a new
one but instead remain in the same session for the delete)

1.  load data using the XML loading under topNodeA in preview workspace
2. I modify some of the data under topNodeA in preview workspace.
3. I save the session etc.
4. I clone the topNodeA and its subtree to the default space.
5. I try to delete topNodeA in the preview workspace and then I DO NOT get
the above error.

I lock the node while making changes like so:

    /**
     * 
     * @param nodeToSet
     *            The node in which to set the property.
     * @param attribute
     * @param value
     */
    public static boolean saveAttribute(Node nodeToSet, String attribute,
Object value) {
        boolean success = false;
        if ((nodeToSet != null) && (attribute != null) && (value != null))
{
            try {
                synchronized (nodeToSet) {
                    boolean iLockedThis=false;
                    if (!nodeToSet.isLocked()) {
                        nodeToSet.addMixin("mix:lockable");
                        session.save();
                        nodeToSet.lock(true, true);
                        iLockedThis=true;
                    }
                    if (value instanceof InputStream) {
                        nodeToSet.setProperty(attribute, (InputStream)
value);
                        try {
                            ((InputStream) value).close();
                        } catch (IOException e) {
                            getInstance().logger.error("IOException
in:saveAttribute " + e);
                        }
                        success = true;
                    } else if (value instanceof Calendar) {
                        nodeToSet.setProperty(attribute, (Calendar) value);
                        success = true;
                    } else if (value instanceof String) {
                        String stringToSet = (String) value;
                        nodeToSet.setProperty(attribute, stringToSet);
                        success = true;
                    } else if (value instanceof Long) {
                        nodeToSet.setProperty(attribute, ((Long)
value).longValue());
                        success = true;
                    } else if (value instanceof Integer) {
                        nodeToSet.setProperty(attribute, ((Integer)
value).longValue());
                        success = true;
                    } else if (value instanceof Double) {
                        nodeToSet.setProperty(attribute, ((Double)
value).doubleValue());
                        success = true;
                    } else if (value instanceof Boolean) {
                        nodeToSet.setProperty(attribute, ((Boolean)
value).booleanValue());
                        success = true;
                    }
                    if (iLockedThis) {
                        session.save();
                        nodeToSet.unlock();
                    }
                }
            } catch (final javax.jcr.ValueFormatException e) {
                getInstance().logger.error("ValueFormatException
in:saveAttribute " + e);
            } catch (final javax.jcr.version.VersionException e) {
                getInstance().logger.error("VersionException
in:saveAttribute " + e);
            } catch (final javax.jcr.lock.LockException e) {
                getInstance().logger.error("LockException in:saveAttribute "
+ e);
            } catch (final javax.jcr.nodetype.ConstraintViolationException
e) {
               
getInstance().logger.error("javax.jcr.nodetype.ConstraintViolationException
in:saveAttribute " + e);
            } catch (final javax.jcr.RepositoryException e) {
                getInstance().logger.error("RepositoryException
in:saveAttribute " + e);
            }
        }
        return success;
    }
-- 
View this message in context: http://www.nabble.com/modified-externally%3A-node---when-deleting-node-tp23352361p23352361.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Mime
View raw message