Re: Cleaning up inheritance tests

From: Kevin Menard (kmenar..ervprise.com)
Date: Fri Mar 28 2008 - 21:39:27 EDT

  • Next message: Andrus Adamchik: "Re: Cleaning up inheritance tests"

    I'm just jotting some notes down as I go in case someone else wants to dig
    in or can offer some insight. Apologies if it just seems like rambling.

    On 3/28/08 10:10 AM, "Andrus Adamchik" <andru..bjectstyle.org> wrote:

    >
    > On Mar 28, 2008, at 4:03 PM, Kevin Menard wrote:
    >
    >> If I understand correctly, you'de rather see the null returned and let
    >> EntityResolver investigate more itself at that point?
    >
    > Yes. Here is why:
    >
    > * As we discussed, relationships targeting subclass and superclass are
    > two different things

    I think that part of the issue is that Cayenne seems to be inconsistent in
    how it handles this.

    A runtime relationship is not created if a subclass is missing a
    relationship. ObjEntity will try to use the base class's relationship if it
    can. Locally I've tested creating a new relationship for the subclass on
    the fly [1], using the subclass as the source entity, rather than the base
    class.

    While this doesn't fix the issue of CAY-1008, it gets a little closer I
    think. Now there is a direct match found for the type of entity being
    called. I.e., I have the following results:

            RelatedEntity related = context.newObject(RelatedEntity.class);

            BaseEntity base = context.newObject(BaseEntity.class);
            base.setToRelatedEntity(related);

            assertEquals(1, related.getBaseEntities().size()); // 1. PASS
            assertEquals(0, related.getSubEntities().size()); // 2. PASS

            SubEntity sub = context.newObject(SubEntity.class);
            sub.setToRelatedEntity(related);

            assertEquals(2, related.getBaseEntities().size()); // 3. FAIL
            assertEquals(1, related.getSubEntities().size()); // 4. PASS

    Prior to these modifications, tests #1, #2, #3 would pass, while #4 would
    fail. So, the mod allows updating the subclass list, whereas previously
    only the base class list would ever be modified. If we're able to propagate
    the change back up the inheritance hierarchy, we may have something here.

    -- 
    Kevin
    

    [1] The really messy mod is:

    ObjEntity:

    ..verride public Relationship getRelationship(String name) { ObjRelationship relationship = (ObjRelationship) super.getRelationship(name); if (relationship != null) { return relationship; }

    if (superEntityName == null) { return null; }

    ObjEntity superEntity = getSuperEntity(); ObjRelationship superRelationship = (ObjRelationship) superEntity.getRelationship(name);

    if (superRelationship != null) { ObjRelationship childRelationship = new ObjRelationship(name); childRelationship.setCollectionType(superRelationship.getCollectionType()); childRelationship.setDbRelationshipPath(superRelationship.getDbRelationshipP ath()); childRelationship.setDeleteRule(superRelationship.getDeleteRule()); childRelationship.setMapKey(superRelationship.getMapKey()); childRelationship.setParent(superRelationship.getParent()); childRelationship.setRuntime(superRelationship.isRuntime()); childRelationship.setSourceEntity(this); childRelationship.setTargetEntity(superRelationship.getTargetEntity()); childRelationship.setTargetEntityName(superRelationship.getTargetEntityName( )); childRelationship.setUsedForLocking(superRelationship.isUsedForLocking());

    addRelationship(childRelationship);

    return childRelationship; }

    return null; }



    This archive was generated by hypermail 2.0.0 : Fri Mar 28 2008 - 21:40:07 EDT