You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Hugi Thordarson <hu...@karlmenn.is> on 2020/09/05 09:14:14 UTC

Programmatically adding (db/obj) attributes to a model and saving

Hi all,
I'm adding some standard attributes to a few dozen tables. Since they all look more or less the same, I'd like to do it programmatically.
That's easy enough, but I'm wondering what the best way would be for me to write out the project after adding the attributes.

I've currently got something like:

XMLEncoder encoder = new XMLEncoder( new PrintWriter( new File( "new.map.xml" ) ) );
map.encodeAsXML( encoder, new EmptyConfigurationNodeVisitor() );

…which works kinda-sorta. But I imagine there's a better or more idiomatic way using something like ProjectLoader or ProjectSaver?

Cheers,
- hugi

Re: Programmatically adding (db/obj) attributes to a model and saving

Posted by Andrus Adamchik <an...@objectstyle.org>.
Yeah, that's as good as it gets. ProjectLoader/Saver deal with multi-file projects. If you need to modidy a single existing DataMap, XMLEncoder is what you need.

Andrus

> On Sep 6, 2020, at 12:25 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
> 
> Well that's no fun when you have this nice purpose-build API right at your hands :).
> I ended up doping the encodeAsXML-thing. It worked well enough that it only took a couple of seconds to fix up the resulting XML file, et voila — 250 new attributes in 50 entities :).
> 
> Cheers,
> - hugi
> 
> 
>> On 5 Sep 2020, at 14:11, Michael Gentry <bl...@gmail.com> wrote:
>> 
>> I'm naive enough that I'd just use a macro in Emacs to modify the mapping...
>> 
>> 
>> On Sat, Sep 5, 2020 at 5:14 AM Hugi Thordarson <hu...@karlmenn.is> wrote:
>> 
>>> Hi all,
>>> I'm adding some standard attributes to a few dozen tables. Since they all
>>> look more or less the same, I'd like to do it programmatically.
>>> That's easy enough, but I'm wondering what the best way would be for me to
>>> write out the project after adding the attributes.
>>> 
>>> I've currently got something like:
>>> 
>>> XMLEncoder encoder = new XMLEncoder( new PrintWriter( new File(
>>> "new.map.xml" ) ) );
>>> map.encodeAsXML( encoder, new EmptyConfigurationNodeVisitor() );
>>> 
>>> …which works kinda-sorta. But I imagine there's a better or more idiomatic
>>> way using something like ProjectLoader or ProjectSaver?
>>> 
>>> Cheers,
>>> - hugi
> 


Re: Programmatically adding (db/obj) attributes to a model and saving

Posted by Hugi Thordarson <hu...@karlmenn.is>.
Well that's no fun when you have this nice purpose-build API right at your hands :).
I ended up doping the encodeAsXML-thing. It worked well enough that it only took a couple of seconds to fix up the resulting XML file, et voila — 250 new attributes in 50 entities :).

Cheers,
- hugi


> On 5 Sep 2020, at 14:11, Michael Gentry <bl...@gmail.com> wrote:
> 
> I'm naive enough that I'd just use a macro in Emacs to modify the mapping...
> 
> 
> On Sat, Sep 5, 2020 at 5:14 AM Hugi Thordarson <hu...@karlmenn.is> wrote:
> 
>> Hi all,
>> I'm adding some standard attributes to a few dozen tables. Since they all
>> look more or less the same, I'd like to do it programmatically.
>> That's easy enough, but I'm wondering what the best way would be for me to
>> write out the project after adding the attributes.
>> 
>> I've currently got something like:
>> 
>> XMLEncoder encoder = new XMLEncoder( new PrintWriter( new File(
>> "new.map.xml" ) ) );
>> map.encodeAsXML( encoder, new EmptyConfigurationNodeVisitor() );
>> 
>> …which works kinda-sorta. But I imagine there's a better or more idiomatic
>> way using something like ProjectLoader or ProjectSaver?
>> 
>> Cheers,
>> - hugi


Re: Programmatically adding (db/obj) attributes to a model and saving

Posted by Michael Gentry <bl...@gmail.com>.
I'm naive enough that I'd just use a macro in Emacs to modify the mapping...


On Sat, Sep 5, 2020 at 5:14 AM Hugi Thordarson <hu...@karlmenn.is> wrote:

> Hi all,
> I'm adding some standard attributes to a few dozen tables. Since they all
> look more or less the same, I'd like to do it programmatically.
> That's easy enough, but I'm wondering what the best way would be for me to
> write out the project after adding the attributes.
>
> I've currently got something like:
>
> XMLEncoder encoder = new XMLEncoder( new PrintWriter( new File(
> "new.map.xml" ) ) );
> map.encodeAsXML( encoder, new EmptyConfigurationNodeVisitor() );
>
> …which works kinda-sorta. But I imagine there's a better or more idiomatic
> way using something like ProjectLoader or ProjectSaver?
>
> Cheers,
> - hugi