You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Vincent Giguère <vi...@gmail.com> on 2008/06/09 02:59:25 UTC

OCM : Mapping a java.util.Map of referenced beans

Hi,

Is there a possibility to map a java.util.Map property containing REFERENCED
content (Map<String, SomeBeanStoredAsReferences>)
I am attempting to do so and I keep on running on problems.

I am working with the trunk of jackrabbit-ocm since I have seen support for
maps (ManageableMap & ManageableMapImpl). However, I do not find the
equivalent
of the BeanReferenceCollectionConverterImpl for maps
(BeanReferenceMapConverterImpl?).

In the example below: the map property is annotated with
@Collection(collectionConverter=BeanReferenceCollectionConverterImpl.class).

The BeanReferenceCollectionConverterImpl fails at restoring the Map content
because the ManageableObject associated to the Map property is not an
instance of ManageableCollection (it is in fact a ManageableMap).


My test is quite simple:

MODEL:

@Node(jcrMixinTypes = "mix:versionable")
public class Parent extends AbstractReferenceableEntity {

    @Field(uuid = true, id = true)
    private String id;

    @Field(path = true)
    private String path = defaultPath();


    @Collection(collectionConverter =
BeanReferenceCollectionConverterImpl.class)
    private Map<String, Child> childRefs = new HashMap<String, Child>();

getters and setters...

}

@Node(jcrMixinTypes = "mix:versionable")
public class Child extends AbstractReferenceableEntity {

    @Field(path=true)
    private String path = defaultPath();

    @Field(uuid = true)
    private String id;

getters and setters...

}


TEST:

    @Test
    public void persisting_and_restoring_child_references_in_map() {

        Parent parent = new Parent();

        parent.getChildRefs().put("c1", (Child)this.childDao.persist(new
Child()));
        parent.getChildRefs().put("c2", (Child)this.childDao.persist(new
Child()));
        parent.getChildRefs().put("c3", (Child)this.childDao.persist(new
Child()));

        this.parentDao.persist(parent);

        Parent reloaded  = (Parent) this.parentDao.loadById(parent.getId());

        assertThat(reloaded.getId(), is(notNullValue()));

        assertThat(reloaded.getChildRefs(), is(notNullValue()));
        assertThat(reloaded.getChildRefs().size(), is(equalTo(3)));

        assertThat(reloaded.getChildRefs().get("c1"), is(notNullValue()));
        assertThat(reloaded.getChildRefs().get("c2"), is(notNullValue()));
        assertThat(reloaded.getChildRefs().get("c3"), is(notNullValue()));

    }


I would really appreciate your help.

Also, if you know of a working alternative that would make my unit test
pass, I would be grateful.

Thanks in advance :)
Vincent Giguère

Re: OCM : Mapping a java.util.Map of referenced beans

Posted by Vincent Giguère <vi...@gmail.com>.
Hi Christophe,

I have created a Jira issue for this new feature:
https://issues.apache.org/jira/browse/JCR-1645

Regards,

Vincent

2008/6/9 Christophe Lombart <ch...@gmail.com>:

> Hi Vincent,
>
> This feature is not yet supported. We have to change the converter
> BeanReferenceCollectionConverterImpl (mainly the method doGetCollection).
> If you have time, you can review the code in the
> DefaultCollectionConverterImpl. We have to make almost same for the
> doGetCollection.
>
> Please, create a new jira issue. I can't work on this week but I will
> review
> this problem next week.
>
>
> Thanks,
> Christophe
>
> On Mon, Jun 9, 2008 at 2:59 AM, Vincent Giguère <vincent.giguere@gmail.com
> >
> wrote:
>
> > Hi,
> >
> > Is there a possibility to map a java.util.Map property containing
> > REFERENCED
> > content (Map<String, SomeBeanStoredAsReferences>)
> > I am attempting to do so and I keep on running on problems.
> >
> > I am working with the trunk of jackrabbit-ocm since I have seen support
> for
> > maps (ManageableMap & ManageableMapImpl). However, I do not find the
> > equivalent
> > of the BeanReferenceCollectionConverterImpl for maps
> > (BeanReferenceMapConverterImpl?).
> >
> > In the example below: the map property is annotated with
> >
> >
> @Collection(collectionConverter=BeanReferenceCollectionConverterImpl.class).
> >
> > The BeanReferenceCollectionConverterImpl fails at restoring the Map
> content
> > because the ManageableObject associated to the Map property is not an
> > instance of ManageableCollection (it is in fact a ManageableMap).
> >
> >
> > My test is quite simple:
> >
> > MODEL:
> >
> > @Node(jcrMixinTypes = "mix:versionable")
> > public class Parent extends AbstractReferenceableEntity {
> >
> >    @Field(uuid = true, id = true)
> >    private String id;
> >
> >    @Field(path = true)
> >    private String path = defaultPath();
> >
> >
> >    @Collection(collectionConverter =
> > BeanReferenceCollectionConverterImpl.class)
> >    private Map<String, Child> childRefs = new HashMap<String, Child>();
> >
> > getters and setters...
> >
> > }
> >
> > @Node(jcrMixinTypes = "mix:versionable")
> > public class Child extends AbstractReferenceableEntity {
> >
> >    @Field(path=true)
> >    private String path = defaultPath();
> >
> >    @Field(uuid = true)
> >    private String id;
> >
> > getters and setters...
> >
> > }
> >
> >
> > TEST:
> >
> >    @Test
> >    public void persisting_and_restoring_child_references_in_map() {
> >
> >        Parent parent = new Parent();
> >
> >        parent.getChildRefs().put("c1", (Child)this.childDao.persist(new
> > Child()));
> >        parent.getChildRefs().put("c2", (Child)this.childDao.persist(new
> > Child()));
> >        parent.getChildRefs().put("c3", (Child)this.childDao.persist(new
> > Child()));
> >
> >        this.parentDao.persist(parent);
> >
> >        Parent reloaded  = (Parent)
> this.parentDao.loadById(parent.getId());
> >
> >        assertThat(reloaded.getId(), is(notNullValue()));
> >
> >        assertThat(reloaded.getChildRefs(), is(notNullValue()));
> >        assertThat(reloaded.getChildRefs().size(), is(equalTo(3)));
> >
> >        assertThat(reloaded.getChildRefs().get("c1"), is(notNullValue()));
> >        assertThat(reloaded.getChildRefs().get("c2"), is(notNullValue()));
> >        assertThat(reloaded.getChildRefs().get("c3"), is(notNullValue()));
> >
> >    }
> >
> >
> > I would really appreciate your help.
> >
> > Also, if you know of a working alternative that would make my unit test
> > pass, I would be grateful.
> >
> > Thanks in advance :)
> > Vincent Giguère
> >
>

Re: OCM : Mapping a java.util.Map of referenced beans

Posted by Christophe Lombart <ch...@gmail.com>.
Hi Vincent,

This feature is not yet supported. We have to change the converter
BeanReferenceCollectionConverterImpl (mainly the method doGetCollection).
If you have time, you can review the code in the
DefaultCollectionConverterImpl. We have to make almost same for the
doGetCollection.

Please, create a new jira issue. I can't work on this week but I will review
this problem next week.


Thanks,
Christophe

On Mon, Jun 9, 2008 at 2:59 AM, Vincent Giguère <vi...@gmail.com>
wrote:

> Hi,
>
> Is there a possibility to map a java.util.Map property containing
> REFERENCED
> content (Map<String, SomeBeanStoredAsReferences>)
> I am attempting to do so and I keep on running on problems.
>
> I am working with the trunk of jackrabbit-ocm since I have seen support for
> maps (ManageableMap & ManageableMapImpl). However, I do not find the
> equivalent
> of the BeanReferenceCollectionConverterImpl for maps
> (BeanReferenceMapConverterImpl?).
>
> In the example below: the map property is annotated with
>
> @Collection(collectionConverter=BeanReferenceCollectionConverterImpl.class).
>
> The BeanReferenceCollectionConverterImpl fails at restoring the Map content
> because the ManageableObject associated to the Map property is not an
> instance of ManageableCollection (it is in fact a ManageableMap).
>
>
> My test is quite simple:
>
> MODEL:
>
> @Node(jcrMixinTypes = "mix:versionable")
> public class Parent extends AbstractReferenceableEntity {
>
>    @Field(uuid = true, id = true)
>    private String id;
>
>    @Field(path = true)
>    private String path = defaultPath();
>
>
>    @Collection(collectionConverter =
> BeanReferenceCollectionConverterImpl.class)
>    private Map<String, Child> childRefs = new HashMap<String, Child>();
>
> getters and setters...
>
> }
>
> @Node(jcrMixinTypes = "mix:versionable")
> public class Child extends AbstractReferenceableEntity {
>
>    @Field(path=true)
>    private String path = defaultPath();
>
>    @Field(uuid = true)
>    private String id;
>
> getters and setters...
>
> }
>
>
> TEST:
>
>    @Test
>    public void persisting_and_restoring_child_references_in_map() {
>
>        Parent parent = new Parent();
>
>        parent.getChildRefs().put("c1", (Child)this.childDao.persist(new
> Child()));
>        parent.getChildRefs().put("c2", (Child)this.childDao.persist(new
> Child()));
>        parent.getChildRefs().put("c3", (Child)this.childDao.persist(new
> Child()));
>
>        this.parentDao.persist(parent);
>
>        Parent reloaded  = (Parent) this.parentDao.loadById(parent.getId());
>
>        assertThat(reloaded.getId(), is(notNullValue()));
>
>        assertThat(reloaded.getChildRefs(), is(notNullValue()));
>        assertThat(reloaded.getChildRefs().size(), is(equalTo(3)));
>
>        assertThat(reloaded.getChildRefs().get("c1"), is(notNullValue()));
>        assertThat(reloaded.getChildRefs().get("c2"), is(notNullValue()));
>        assertThat(reloaded.getChildRefs().get("c3"), is(notNullValue()));
>
>    }
>
>
> I would really appreciate your help.
>
> Also, if you know of a working alternative that would make my unit test
> pass, I would be grateful.
>
> Thanks in advance :)
> Vincent Giguère
>