Re: Dynamic Data Maps

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Jan 05 2006 - 03:28:21 EST

  • Next message: Andrus Adamchik: "Re: error committing new created object"

    On Jan 4, 2006, at 6:24 PM, Jonathan Carlson wrote:
    > I see how DbLoader will create a DataMap, but I don't see how I can
    > create a DataContext from a DataMap without using configuration files.

    ...

    > I noticed Configuration.getSharedConfiguration(), but that seems to
    > assume the use of configuration files.

    Assembling Cayenne stack via API is totally possible and you may
    still optionally use Configuration when doing that. This will allow
    to preserve DataContext creation procedure. But the main two classes
    in the stack you care about is DataNode and DataDomain. Here is how
    such procedure might look like:

    // create DataSource (from the connection data that users enter via UI?)
    DataSource ds = new org.objectstyle.cayenne.conn.PoolManager(...);

    // get DataMap via DbLoader
    DataMap map = ...;

    // assemble stack

    DataNode node = new DataNode("MyNode");
    node.setAdapter(new AutoAdapter(ds));
    node.setDataSource(ds);
    node.addDataMap(map);

    DataDomain domain = new DataDomain("MyDomain");
    domain.addNode(node);

    // you can use the domain above directly to create DataContexts,
    // if so you can ignore the code below.

    // Alternatively you can stick the domain in a shared
    // configuration for the static DataContext factory methods benefit.

    Configuration c = new DefaultConfiguration() {
        public void initialize() {
           // make noop to prevent config file loading
        }
    };

    c.addDomain(domain);
    Configuration.initializeSharedConfiguration(c);

    > I think there could be a whole new
    > class of Cayenne users if this were an easy thing to do (unless I just
    > missed how easy it is already!). If I can get this working nicely,
    > I'm
    > going to share this method of using Cayenne on the Groovy mailing list
    > (unless you don't want me to :-).

    If you have a way of bringing a whole new class of users to Cayenne,
    by all means do it :-)

    Andrus



    This archive was generated by hypermail 2.0.0 : Thu Jan 05 2006 - 03:28:30 EST