You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Francisco Carriedo Scher <fc...@gmail.com> on 2012/05/06 09:41:17 UTC

Varying the node primary type

Hi there,

in a given point after creating a nt:file node i need to change the node
type to nt:linkedFile. Sometimes such node will already have it's proper
sons (a node called jcr:content and property called jcr:data inside this
last one) and sometimes not.

Always before performing the save operation i need to be able to change the
nodetype as described if necessary, but i can not achieve it, since i call
the node.setPrimaryType("nt:linkedFile"); method and after it returns, the
nodetype for that node is still nt:file... If it helps, i perform this
operation inside the NodeImpl class on setProperty (when setting the binary
property of the jcr:content node of the nt:file, and i reach the nt:file
through calls to .getParent() method on jcr:content node).

My guess is that setPrimaryType operation is just enqueued and not
effective inmediately...

Any ideas to make this operation inmediately effective?

Thanks in advance for your attention, regards!

Re: Varying the node primary type

Posted by Francisco Carriedo Scher <fc...@gmail.com>.
Thanks you both for your responses.

This is it, i saw that setPrimaryType is defined in the JCR spec, it seems
to be supported. Anyway, i expected a different behaviour. Let me explain
in deeper detail the scenario.

This first code snippet is successfully executed:

        Node fileNode = folderNode.addNode(file.getName(), "nt:file");
        fileNode.addMixin("mix:referenceable");

        // Standard properties
        Node resNode = fileNode.addNode("jcr:content", "nt:resource");
        resNode.addMixin("mix:referenceable");
        *resNode.setProperty("jcr:data", binary);*

Then, the internal behaviour of the line in bold has been modified as
follows:

public Property setProperty(String name, Binary value) throws
RepositoryException {

   if (someCondition) { // This branch creates a reference instead of
adding a binary property

     Node ntFileNode = this.getParent();

     // Undo already added properties before turning this node on to
nt:linkedFile node type
     ntFileNode.removeMixin("mix:referenceable");

     // FROM NOW ON NOT A nt:file ANYMORE, BUT A nt:linkedFile
     ntFileNode.setPrimaryType(JcrConstants.NT_LINKEDFILE);
*// AT THIS POINT I EXPECTED THE PRIMARY TYPE TO BE nt:linkedFile, BUT IT
IS NOT*
     Property theReferenceProperty = ntFileNode.setProperty("jcr:content",
existingFile);

     // Remove the jcr:content node
     this.remove();

     return theReferenceProperty;

     } else {
     // This is the original code flow
     Value v = (value == null ? null :
session.getValueFactory().createValue(value));
     return setProperty(name, v, PropertyType.BINARY);
     }
}

The real problem is that i am trying to achieve this change of nodetype
being transparent to the JCR API user.

Any insight?

Thank you very much for your time!


2012/5/7 Stefan Guggisberg <st...@gmail.com>

> On Sun, May 6, 2012 at 9:46 AM, Lukas Kahwe Smith <ml...@pooteeweet.org>
> wrote:
> >
> > On May 6, 2012, at 09:41 , Francisco Carriedo Scher wrote:
> >
> >> Hi there,
> >>
> >> in a given point after creating a nt:file node i need to change the node
> >> type to nt:linkedFile. Sometimes such node will already have it's proper
> >> sons (a node called jcr:content and property called jcr:data inside this
> >> last one) and sometimes not.
> >
> >
> > the JCR specification does not allow changing the primary node type once
> a node has been created.
>
> wrong, as of JCR 2.0 the primary node type of a node can be set [1].
>
> cheers
> stefan
>
> [1]
> http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/Node.html#setPrimaryType(java.lang.String)
>
> > not sure if there is an established pattern for this case, but all you
> could do is remove the old node and create a new node.
> >
> > regards,
> > Lukas Kahwe Smith
> > mls@pooteeweet.org
> >
> >
> >
>

Re: Varying the node primary type

Posted by Stefan Guggisberg <st...@gmail.com>.
On Sun, May 6, 2012 at 9:46 AM, Lukas Kahwe Smith <ml...@pooteeweet.org> wrote:
>
> On May 6, 2012, at 09:41 , Francisco Carriedo Scher wrote:
>
>> Hi there,
>>
>> in a given point after creating a nt:file node i need to change the node
>> type to nt:linkedFile. Sometimes such node will already have it's proper
>> sons (a node called jcr:content and property called jcr:data inside this
>> last one) and sometimes not.
>
>
> the JCR specification does not allow changing the primary node type once a node has been created.

wrong, as of JCR 2.0 the primary node type of a node can be set [1].

cheers
stefan

[1] http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/Node.html#setPrimaryType(java.lang.String)

> not sure if there is an established pattern for this case, but all you could do is remove the old node and create a new node.
>
> regards,
> Lukas Kahwe Smith
> mls@pooteeweet.org
>
>
>

Re: Varying the node primary type

Posted by Lukas Kahwe Smith <ml...@pooteeweet.org>.
On May 6, 2012, at 09:41 , Francisco Carriedo Scher wrote:

> Hi there,
> 
> in a given point after creating a nt:file node i need to change the node
> type to nt:linkedFile. Sometimes such node will already have it's proper
> sons (a node called jcr:content and property called jcr:data inside this
> last one) and sometimes not.


the JCR specification does not allow changing the primary node type once a node has been created. not sure if there is an established pattern for this case, but all you could do is remove the old node and create a new node.

regards,
Lukas Kahwe Smith
mls@pooteeweet.org