Re: command line mapping generation

From: Tomi N/A (hefes..mail.com)
Date: Sat Mar 22 2008 - 08:46:36 EDT

  • Next message: Damian Johnson: "GSOC Submission Process?"

    2008/3/14, Andrus Adamchik <andru..bjectstyle.org>:
    > You are on the right track. You can write a simple Java tool (or an
    > Ant task) based on DbLoader class. Then use
    > DataMap.encodeAsXML(XMLEncoder) to store the result in an XML file.

    Thanks for the comment, Andrus.
    This is what I have so far and it works as expected:

                            dataSource = new PoolManager("org.postgresql.Driver",
                                    "jdbc:postgresql://localhost:5432/mydb",
                                    1,
                                    5,
                                    "myuser",
                                    "mypassword");
                            Connection connection = dataSource.getConnection();
                            DbLoaderDelegate delegate = null;
                            PostgresAdapter adapter = new PostgresAdapter();
                            DbLoader dl = new DbLoader(connection, adapter, delegate);
                            DataMap dataMap = new DataMap("datamap name");
                            dl.loadDataMapFromDB("myschema", "%", dataMap);
                            
                            PrintWriter pw = new PrintWriter("/tmp/mapping.xml");
                            dataMap.encodeAsXML(pw );

    I would like to take this a couple of steps further:
    1.) generalize it so that it isn't specific to Postgresql, reads
    connection parameters from a file (the datanode XML file might be a
    good choice) etc.
    2.) see if there would be interest for code of that purpose in the
    official cayenne source and integrate it there
    3.) create a maven2 (ant? is one preferred?) task to run it from the CLI
    4.) use a XML diff tool like VM Tools, 3DM, diffxml, xmlunit to merge
    (what now might seem like) simpler differences (added/removed table
    attribute, a type or name change, dropped table, added table etc.)

    Once the project is set up, a part of our everyday coding routine
    might look something like this:
    1.) apply a change to the database model whichever way you do choose
    2.) execute a maven/ant task (from the console, the IDE or which ever
    way you're comfortable with) and voila: 9 out of 10 times, all the
    artifacts that should reflect the change in the database have been
    regenerated: the mapping (while preserving your manual changes via
    xmldiff and merge), the classes and possibly other artifacts people
    tend to generate via the velocity templates!

    Opinions are obviuosly very welcome. :)

    Cheers,
    Tomislav



    This archive was generated by hypermail 2.0.0 : Sat Mar 22 2008 - 08:47:11 EDT