jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sunil Dhage <sunil.dh...@coreobjects.com>
Subject RE: Unable to lock Exception.
Date Mon, 23 Nov 2009 13:06:07 GMT
Hi Alex,

Please find the code for verifyAndAdd();

 public Node verifyAndAddNode(Session session,Node parent,String... parameters) throws RepositoryException
    {   Node node2Add = null;
        //code review comment - to ensure parameters size is either 2 or 3.
        if(parameters.length < 2 || parameters.length > 3)
        {   throw new IllegalArgumentException("Number of parameters to verify/add node invalid
");
        }
        NodeIterator iterator = queryForPath(session,parameters[0]);
        if(iterator.hasNext())
        {   log.info("Node exists in this path...");
            node2Add = iterator.nextNode();
        }else
        {   if(parameters.length == 2)
                node2Add = parent.addNode(parameters[1]);
            else
               node2Add = parent.addNode(parameters[1],parameters[2]);
        }
        return node2Add;
    }

    protected NodeIterator queryForPath(Session session, String path) throws RepositoryException
    {   log.info("Querying for path : "+path);
        Workspace workspace = session.getWorkspace();
        QueryManager queryManager = workspace.getQueryManager();
        Query query = queryManager.createQuery(path, Query.XPATH);
        QueryResult result = query.execute();
        return result.getNodes();
    }


Regards,
Sunil
________________________________________
From: Alexander Klimetschek [aklimets@day.com]
Sent: Monday, November 23, 2009 4:50 PM
To: users@jackrabbit.apache.org
Subject: Re: Unable to lock Exception.

On Mon, Nov 23, 2009 at 07:30, Sunil Dhage <sunil.dhage@coreobjects.com> wrote:
> xyz.cnd contains these node type definitions.
>
> [lc:account] > nt:folder, mix:lockable
> -lc:accountid (string) mandatory primary
>
>  /**
>     * Registers custom node types for the application
>     */
>    protected void registerCustomNodeTypes(Workspace workspace) throws RepositoryException
>    {   try
>        {   ClassLoader loader = Thread.currentThread().getContextClassLoader();
>            InputStream in = loader.getResourceAsStream("xyz.cnd");
>            NodeTypeManagerImpl nodeTypeManager = (NodeTypeManagerImpl) workspace.getNodeTypeManager();
>            // Registors the custom node types and namespaces
>            nodeTypeManager.registerNodeTypes(in, JackrabbitNodeTypeManager.TEXT_X_JCR_CND,
true);
>        }catch (NamespaceException nse)
>        {   log.error("[contentCallback] Namespace registration issue : " + nse.getMessage());
>        }catch (RepositoryException repse)
>        {   log.error("[contentCallback] Repository registeration issue : " + repse.getMessage());
>        } catch (IOException ex)
>        {  log.error("[contentCallback] Error reading custom node definitions. Check dms-lc.cnd
is in classpath: " + ex.getMessage());
>        }
>    }

Looks good to me, if you didn't get any errors here. Maybe you changed
the nodetype (adding mix:lockable) and restarted your repository and
the above code failed with an cannot update nodetypes exception (or
similar)?

>           Node account = verifyAndAddNode(session,candidatedocs,path,"lc:account");

What about this method? We can only help when seeing what exact JCR
API calls you are doing. (I can imagine what that method does, but
maybe there is a slight error there).

Regards,
Alex

--
Alexander Klimetschek
alexander.klimetschek@day.com

Mime
View raw message