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

Andrus Adamchik <[email protected]>
Newsgroups gmane.comp.java.cayenne.user
Message-ID <[email protected]>
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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.