cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrey Razumovsky <razumovsky.and...@gmail.com>
Subject Re: Storing information in a join table
Date Fri, 18 Feb 2011 09:50:01 GMT
Hi,

What semantically is "isFresh" attribute? Is it a some business logic
attibute, or simple "autoset" variable, like timestamp etc.?
If former, you cannot live without ApplePlum ObjEntity. Is the problem
then in just setting its default value? Then you can simply set it at
database level.
If the default value is dynamic, like timestamp, you can try intercept
Cayenne's generating of queries:
http://cayenne.apache.org/doc30/custom-batchquerybuilder-factory.html

2011/2/18 Christian Grobmeier <grobmeier@gmail.com>:
> 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
>



-- 
Andrey

Mime
View raw message