cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Grobmeier <grobme...@gmail.com>
Subject Storing information in a join table
Date Fri, 18 Feb 2011 09:38:43 GMT
Hello,

I have the following scenario:

Apple 1 -> n ApplePlum n : 1 Plum

I want store an additional flag in ApplePlum (lets say isFresh = true/false

How can I do this? I know I should not use flattened relations, but
they are so nice, I would like to keep them. At least it would lead to
the Method getApplePlum->getPlum which is not very neat.

In order to do so I have thought I could create a custom method in my
Apple class, which copies some code from the _Apple class.

Like this:

public void addToAppleAsFreshPlum(Plum value) {
        String relName = "ApplePlum";
        if (value == null) {
            throw new NullPointerException("Attempt to add null target
DataObject.");
        }

        willConnect(relName, value);
        Object holder = readProperty("ApplePlum");

// Now I would like to get the object created by the holder:
        ((ApplePlum)holder).setFresh(true);

        getObjectContext().propertyChanged(this, relName, null, value);

        if (holder instanceof Collection) {
            ((Collection<Object>) holder).add(value);
        }
        else if (holder instanceof Map) {
            ((Map<Object, Object>) holder).put(getMapKey(relName,
value), value);
        }

        setReverseRelationship(relName, value);
    }

Of course this does not work. I wonder if there is another option for
me? Any ideas?

Thanks in advance
Christian

Mime
View raw message