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

Maxim Zinal updated OCM-65:
---------------------------

    Description: 
When trying to use ObjectContentManager.copy() service to create a copy of 
JCR-OCM serialized object containing bean collections, I have found that this 
method retains only the last collection entry.

After some investigation I found that private static method 
ObjectContentManagerImpl.copy() does not properly handle indexed JCR nodes. 
Here are the relevant lines of code from current Subversion trunk:

{noformat}
1119            for (NodeIterator iter = srcNode.getNodes(); iter.hasNext(); ) {
1120                Node node = iter.nextNode();
1121                Node child;
1122                // check if the subnode is autocreated
1123                if (!node.getDefinition().isAutoCreated() && 
destNode.hasNode(node.getName())) {
1124                    child = destNode.getNode(node.getName());
1125                } else {
1126                    child = destNode.addNode(node.getName(), 
node.getPrimaryNodeType().getName());
1127                }
1128                copy(node, child);
1129            }
{noformat}

At line 1123 isAutoCreated() returns false for our case, and hasNode() always 
returns true for all but the first indexed node. So it ends with replacing 
every previous node with the next one, up to the last indexed node.

I have added an additional condition to line 1123, to check for indexed nodes, 
so that it looks like this:

{noformat}
if (!node.getDefinition().isAutoCreated() && node.getIndex()==1 &&
          destNode.hasNode(node.getName()))
{noformat}

In that case ObjectContentManager.copy() performs properly.

  was:
When trying to use ObjectContentManager.copy() service to create a copy of 
JCR-OCM serialized object containing bean collections, I have found that this 
method retains only the last collection entry.

After some investigation I found that private static method 
ObjectContentManagerImpl.copy() does not properly handle indexed JCR nodes. 
Here are the relevant lines of code from current Subversion trunk:

1119            for (NodeIterator iter = srcNode.getNodes(); iter.hasNext(); ) {
1120                Node node = iter.nextNode();
1121                Node child;
1122                // check if the subnode is autocreated
1123                if (!node.getDefinition().isAutoCreated() && 
destNode.hasNode(node.getName())) {
1124                    child = destNode.getNode(node.getName());
1125                } else {
1126                    child = destNode.addNode(node.getName(), 
node.getPrimaryNodeType().getName());
1127                }
1128                copy(node, child);
1129            }

At line 1123 isAutoCreated() returns false for our case, and hasNode() always 
returns true for all but the first indexed node. So it ends with replacing 
every previous node with the next one, up to the last indexed node.

I have added an additional condition to line 1123, to check for indexed nodes, 
so that it looks like this:

if (!node.getDefinition().isAutoCreated() && node.getIndex()==1 &&
          destNode.hasNode(node.getName()))

In that case ObjectContentManager.copy() performs properly.


> ObjectContentManager.copy() does not work properly for objects containing 
> collections
> -------------------------------------------------------------------------------------
>
>                 Key: OCM-65
>                 URL: https://issues.apache.org/jira/browse/OCM-65
>             Project: Jackrabbit OCM
>          Issue Type: Bug
>    Affects Versions: 2.0.0, 2.0.1
>         Environment: Debian/GNU Linux 7.2
> Oracle JDK 7
>            Reporter: Maxim Zinal
>
> When trying to use ObjectContentManager.copy() service to create a copy of 
> JCR-OCM serialized object containing bean collections, I have found that this 
> method retains only the last collection entry.
> After some investigation I found that private static method 
> ObjectContentManagerImpl.copy() does not properly handle indexed JCR nodes. 
> Here are the relevant lines of code from current Subversion trunk:
> {noformat}
> 1119          for (NodeIterator iter = srcNode.getNodes(); iter.hasNext(); ) {
> 1120              Node node = iter.nextNode();
> 1121              Node child;
> 1122              // check if the subnode is autocreated
> 1123              if (!node.getDefinition().isAutoCreated() && 
> destNode.hasNode(node.getName())) {
> 1124                  child = destNode.getNode(node.getName());
> 1125              } else {
> 1126                  child = destNode.addNode(node.getName(), 
> node.getPrimaryNodeType().getName());
> 1127              }
> 1128              copy(node, child);
> 1129          }
> {noformat}
> At line 1123 isAutoCreated() returns false for our case, and hasNode() always 
> returns true for all but the first indexed node. So it ends with replacing 
> every previous node with the next one, up to the last indexed node.
> I have added an additional condition to line 1123, to check for indexed 
> nodes, so that it looks like this:
> {noformat}
> if (!node.getDefinition().isAutoCreated() && node.getIndex()==1 &&
>           destNode.hasNode(node.getName()))
> {noformat}
> In that case ObjectContentManager.copy() performs properly.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to