On Wed, Sep 16, 2009 at 9:19 AM, freak182 <[email protected]> wrote:
>
> Hello,
>
> I have problem retreiving the uuid?
> here is the scenario:
>
> when i save the file, here is the code:
>
> .................................
>
> Node file = folder.addNode(name, "nt:file");
> Node fileContent = file.addNode("jcr:content", "nt:resource");
> fileContent.addMixin(JcrConstants.MIX_REFERENCEABLE);
>
> session.save();
> uuid = fileContent.getUUID();
>
> ..this save fine and some metadata save in DB also including the uuid.
>
> Now i want to delete the file:
>
> Node nodeToRemove = session.getRootNode().getNode(path.substring(1));
> String uuid = nodeToRemove.getUUID(); ---> error here
> if (nodeToRemove != null)
> {
> nodeToRemove.remove();
> session.save();
>
> //
> jcrFileStorageDao.delete(jcrFileStorageDao.loadByUUID(uuid));
> }
>
> javax.jcr.UnsupportedRepositoryOperationException
> at org.apache.jackrabbit.core.NodeImpl.getUUID(NodeImpl.java:3040)
nodeToRemove is probably not mix:referenceable. you can test this by
adding
assert(node.isNodeType(JcrConstants.MIX_REFERENCEABLE));
cheers
stefan
>
> how can i resolve this?
>
> thanks a lot.
> cheers.
>
>
> Christoph Kiehl-3 wrote:
>>
>> Michal Hybler wrote:
>>
>>> I have this method
>>>
>>> ws = session.getWorkspace();
>>> manager = ws.getQueryManager();
>>> query = manager.createQuery("select * from
>>> nt:unstructured where
>>> jcr:uuid
>>> = '"+id+"'",Query.SQL);
>>> QueryResult result = query.execute();
>>> NodeIterator it = result.getNodes();
>>> return it.nextNode();
>>> with Id which I remembered when I insert file into jackrabbit.
>>>
>>> after that I run this code
>>>
>>> HashMap<String,String> properties = new HashMap<String,String>();
>>> try {
>>> PropertyIterator iter = node.getProperties();
>>> while(iter.hasNext()){
>>> Property prop = iter.nextProperty();
>>> if (!prop.getDefinition().isMultiple()) {
>>> properties.put(prop.getName(),
>>> prop.getValue().getString());
>>> }
>>>
>>> }
>>> if (getResNode(node) != null) {
>>> Node resNode = getResNode(node);
>>> iter = resNode.getProperties();
>>> while(iter.hasNext()){
>>> Property prop = iter.nextProperty();
>>> if
>>> (!prop.getDefinition().isMultiple()) {
>>> properties.put(prop.getName(),
>>> prop.getValue().getString());
>>> }
>>> }
>>> }
>>
>> I don't know what getResNode(node) does, but I suppose it loads some other
>> node
>> which is different to the one retrieved by the query. If you remove this
>> if-block the uuids should be equal as far as I can see.
>> And as Brian already wrote: you should be better off using
>> session.getNodeByUUID() instead of using a query. This method performs
>> much
>> faster than a query.
>>
>> Cheers,
>> Christoph
>>
>>
>>
>
> --
> View this message in context:
> http://www.nabble.com/UUID-tp9616867p25467222.html
> Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
>
>