[ 
https://issues.apache.org/jira/browse/SLING-5017?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Alexander Klimetschek updated SLING-5017:
-----------------------------------------
    Description: 
When moving a JCR node via the JCR API behind a resource, Resource.getPath() 
and Resource.getName() will still return the old path and name:

{code:java}
// e.g. "/some/oldname"
Resource resource = request.getResource();

// move via JCR API (no move available in resource API)
Node node = resource.adaptTo(Node.class);
node.getSession().move(node.getPath(), node.getParent().getPath() + "newname");
node.getSession().save();

resource.getName(); // returns "oldname"
resource.getPath(); // returns "/some/oldname"
{code}

This is because the path is [cached in 
JcrItemResource|https://github.com/apache/sling/blob/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java#L83]
 and it uses the getPath() and [getName() implementation of 
AbstractResource|https://github.com/apache/sling/blob/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java#L53]
 which are based on the cached path.

To ensure the correct transient JCR semantics, the resource should pass 
getPath() and getName() through to the underlying Node (respectively Item).

  was:
When moving a JCR node via the JCR API behind a resource, Resource.getPath() 
and Resource.getName() will still return the old path and name:

{code:java}
// e.g. "/some/oldname"
Resource resource = request.getResource();

// move via JCR API (no move available in resource API)
Node node = resource.adaptTo(Node.class);
node.getSession().move(node.getPath(), node.getParent().getPath() + "newname");
node.getSession().save();

resource.getName(); // returns "oldname"
{code}

This is because the path is [cached in 
JcrItemResource|https://github.com/apache/sling/blob/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java#L83]
 and it uses the getPath() and [getName() implementation of 
AbstractResource|https://github.com/apache/sling/blob/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java#L53]
 which are based on the cached path.

To ensure the correct transient JCR semantics, the resource should pass 
getPath() and getName() through to the underlying Node (respectively Item).


> Moving a JCR node not reflected in JcrNodeResource
> --------------------------------------------------
>
>                 Key: SLING-5017
>                 URL: https://issues.apache.org/jira/browse/SLING-5017
>             Project: Sling
>          Issue Type: Bug
>          Components: JCR
>            Reporter: Alexander Klimetschek
>
> When moving a JCR node via the JCR API behind a resource, Resource.getPath() 
> and Resource.getName() will still return the old path and name:
> {code:java}
> // e.g. "/some/oldname"
> Resource resource = request.getResource();
> // move via JCR API (no move available in resource API)
> Node node = resource.adaptTo(Node.class);
> node.getSession().move(node.getPath(), node.getParent().getPath() + 
> "newname");
> node.getSession().save();
> resource.getName(); // returns "oldname"
> resource.getPath(); // returns "/some/oldname"
> {code}
> This is because the path is [cached in 
> JcrItemResource|https://github.com/apache/sling/blob/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java#L83]
>  and it uses the getPath() and [getName() implementation of 
> AbstractResource|https://github.com/apache/sling/blob/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java#L53]
>  which are based on the cached path.
> To ensure the correct transient JCR semantics, the resource should pass 
> getPath() and getName() through to the underlying Node (respectively Item).



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to