cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Kienenberger <mkien...@gmail.com>
Subject Re: a setter for addToManyTarget ?
Date Tue, 16 Dec 2014 14:14:26 GMT
Jurgen described the correct process if you want to make this change
for all entities.

I generally use ant to generate my custom templates.

If you only want it for a single relationship, just add the method to
your entity subclass directly.

For set*(), I'm pretty sure you're going to want to implement it by
calling addTo*() and removeFrom(() internally until the relationship
list matches your argument list.

Feel free to ask about any part of this if it's not clear.

On Tue, Dec 16, 2014 at 2:46 AM,  <dollj@xsinet.co.za> wrote:
> Hi Johannes
>
> Although this functionality isn't built into Cayenne there is a possible way
> to do it.
> I must first say though that I've not done this myself yet, and so this is
> merely theory from my side.
>
> Cayenne uses templates to generate the classes, so the idea is to modify the
> template so that a method like *setCategories(List<Category>)* is generated.
> It'll do this for ALL your relationships though.
>
> The process involves 3 steps:
>
> 1.  Modify the template (this is the most complicated and time consuming
> step)
>     a.  Look inside the CayenneModeler.jar file, go to the /templates/v1_2
> folder, and copy the appropriate superclass vm file from there.
>     b.  Rename the vm file you copied.
>     c.  Open your vm file and edit the section that handles relationships to
> also generate the method you want. You'll start with something like:
>
> public void set${stringUtils.capitalized($rel.Name)}(
> List<$importUtils.formatJavaType(${rel.TargetEntity.ClassName})> changeList
> )
> {
>    //  and then put your code here
> }
>
> 2.  Add the template to Cayenne Modeler:
>     a.  Open Cayenne Modeler and select Tools from the menu, and then
> Preferences.
>     b.  Select Templates on the left, and then click Add Template on the
> right.
>
> 3.  Using the template in the Modeler:
>     a.  Select Tools from the menu, and then Generate Classses.
>     b.  Change Type to Advanced.
>     c.  Change Superclass Template to use yours.
>
> Should be fun :-)
> Regards
> Jurgen
>
>
>
> -----Original Message----- From: Michael Gentry
> Sent: Monday, December 15, 2014 4:22 PM
> To: Cayenne Users
> Subject: Re: a setter for addToManyTarget ?
>
>
> Hi Johannes,
>
> I'm not aware of one built into Cayenne that does this yet.  I know I've
> had to write similar functionality a couple times in the past, too.
>
> mrg
>
>
> On Sat, Dec 13, 2014 at 1:41 AM, Johannes <jotpe.osm@gmail.com> wrote:
>>
>>
>> try again
>>
>>
>> -------- Weitergeleitete Nachricht --------
>> Betreff: a setter for addToManyTarget ?
>> Datum: Sat, 13 Dec 2014 07:36:55 +0100
>> Von: Johannes <jotpe.osm@gmail.com>
>> An: cayenne >> user@cayenne.apache.org
>>
>> Hello,
>>
>> my object model has 2 toMany relationships. Cayenne Modeler generated
>> next to addToManyTarget(String, DataObject, boolean) methods like
>> addToCategories(Category) or addToTags(Tag) for me. Fine.
>>
>> In some use cases it would be wonderful to call a method like
>> *setCategories(List<Category>)*, which would add only new and remove
>> only missing Categories. Existing Categories aren't touch of course.
>>
>> This would save much work, because the setter is written by me multiple
>> times in different projects.
>> Or does such a method exist today?
>>
>> Best regards Johannes
>>
>>
>>
>>
>>
>>
>

Mime
View raw message