Re: DataMap.loadDataMap existing ObjectContext?

From: caden whitaker (caden.whitake..mail.com)
Date: Tue Nov 02 2010 - 18:03:38 UTC

  • Next message: Mike Kienenberger: "Re: DataMap.loadDataMap existing ObjectContext?"

    Gotcha, right now the static xml is just for testing purposes, so I tossed
    that in there but I'm getting an error, is this the correct way to use the
    DataDomain:

                MapLoader ml = new MapLoader();
                DataMap dataMap = ml.loadDataMap(new InputSource(new
    FileInputStream("C:\\eclipse_cayenne\\tutorial\\src\\main\\resources\\HelloWorld2Map.map.xml")));
                DataDomain dd =
    Configuration.getSharedConfiguration().getDomain();
                dd.addMap(dataMap);
                ObjectContext context = dd.createDataContext(false);

                System.out.println("START CREATE");
                Artist picasso = context.newObject(Artist.class);
                picasso.setName("Pablo Picasso");

                Painting girl = context.newObject(Painting.class);
                girl.setName("Girl Reading at a Table");
                girl.setArtist(picasso);

                Painting stein = context.newObject(Painting.class);
                stein.setName("Gertrude Stein");
                stein.setArtist(picasso);

                context.commitChanges();

    This throws an error, here is the stack:

    Nov 2, 2010 1:00:57 PM org.apache.cayenne.conf.RuntimeLoadDelegate
    startedLoading
    INFO: started configuration loading.
    Nov 2, 2010 1:00:57 PM org.apache.cayenne.conf.RuntimeLoadDelegate
    shouldLoadDataDomain
    INFO: loaded domain: HelloWorld1
    Nov 2, 2010 1:00:57 PM org.apache.cayenne.conf.RuntimeLoadDelegate
    loadDataMap
    INFO: loaded <map name='HelloWorld1Map' location='HelloWorld1Map.map.xml'>.
    Nov 2, 2010 1:00:57 PM org.apache.cayenne.conf.RuntimeLoadDelegate
    shouldLoadDataNode
    INFO: loading <node name='HelloWorld1Node'
    datasource='HelloWorld1Node.driver.xml'
    factory='org.apache.cayenne.conf.DriverDataSourceFactory'
    schema-update-strategy='org.apache.cayenne.access.dbsync.CreateIfNoSchemaStrategy'>.
    Nov 2, 2010 1:00:57 PM org.apache.cayenne.conf.RuntimeLoadDelegate
    shouldLoadDataNode
    INFO: using factory: org.apache.cayenne.conf.DriverDataSourceFactory
    Nov 2, 2010 1:00:57 PM org.apache.cayenne.conf.DriverDataSourceFactory load
    INFO: loading driver information from 'HelloWorld1Node.driver.xml'.
    Nov 2, 2010 1:00:57 PM
    org.apache.cayenne.conf.DriverDataSourceFactory$DriverHandler init
    INFO: loading driver org.apache.derby.jdbc.EmbeddedDriver
    Nov 2, 2010 1:00:57 PM
    org.apache.cayenne.conf.DriverDataSourceFactory$LoginHandler init
    INFO: loading user name and password.
    Nov 2, 2010 1:00:57 PM org.apache.cayenne.access.QueryLogger logPoolCreated
    INFO: Created connection pool: jdbc:derby:memory:testdb;create=true
        Driver class: org.apache.derby.jdbc.EmbeddedDriver
        Min. connections in the pool: 1
        Max. connections in the pool: 1
    Nov 2, 2010 1:00:57 PM org.apache.cayenne.conf.RuntimeLoadDelegate
    shouldLoadDataNode
    INFO: loaded datasource.
    Nov 2, 2010 1:00:57 PM org.apache.cayenne.conf.RuntimeLoadDelegate
    initAdapter
    INFO: no adapter set, using automatic adapter.
    Nov 2, 2010 1:00:57 PM org.apache.cayenne.conf.RuntimeLoadDelegate
    shouldLinkDataMap
    INFO: loaded map-ref: HelloWorld1Map.
    Nov 2, 2010 1:00:57 PM org.apache.cayenne.conf.RuntimeLoadDelegate
    finishedLoading
    INFO: finished configuration loading in 234 ms.
    START CREATE
    org.apache.cayenne.CayenneRuntimeException: [v.3.0RC2 Feb 03 2010 13:38:54]
    Commit Exception
        at
    org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:1134)
        at
    org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:1045)
        at
    main.java.org.example.cayenne.ut.CayenneUnitTest.testBuild(CayenneUnitTest.java:71)

    On Tue, Nov 2, 2010 at 12:55 PM, Mike Kienenberger <mkienen..mail.com>wrote:

    > yourDataDomain.addMap(DataMap map)
    >
    > I'd also suggest creating the DataMap programmically unless you have
    > some reason to want to do it from a static xml file.
    >
    > You used to be able to use the following code to fetch the data domain.
    >
    > DataDomain yourDataDomain =
    > Configuration.getSharedConfiguration().getDomain();
    >
    >
    >
    > On Tue, Nov 2, 2010 at 9:59 AM, caden whitaker <caden.whitake..mail.com>
    > wrote:
    > > Hey all,
    > >
    > > I'm still on my quest to get this stuff loaded dynamically. Here's what
    > I'm
    > > doing now, first I gutted the map xml file so that it looks like this:
    > >
    > > TestProjectSourceMap.map.xml
    > > <?xml version="1.0" encoding="utf-8"?>
    > > <data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap"
    > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    > > xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap
    > > http://cayenne.apache.org/schema/3.0/modelMap.xsd"
    > > project-version="3.0.0.1">
    > > <property name="defaultPackage"
    > value="org.example.cayenne.persistent"/>
    > >
    > > </data-map>
    > >
    > >
    > > Built a new Map xml file that had all of the real class associations and
    > put
    > > it someplace else, that file looks like this
    > >
    > > TestProjectNewMap.map.xml
    > > <?xml version="1.0" encoding="utf-8"?>
    > > <data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap"
    > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    > > xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap
    > > http://cayenne.apache.org/schema/3.0/modelMap.xsd"
    > > project-version="3.0.0.1">
    > > <property name="defaultPackage"
    > value="org.example.cayenne.persistent"/>
    > > <db-entity name="ARTIST">
    > > <db-attribute name="ArtistID" type="BIGINT" isPrimaryKey="true"
    > > isMandatory="true"/>
    > > <db-attribute name="Name" type="VARCHAR" length="255"/>
    > > </db-entity>
    > > ....
    > > <obj-relationship name="artist" source="Painting" target="Artist"
    > > deleteRule="Nullify" db-relationship-path="artist"/>
    > > </data-map>
    > >
    > >
    > > All I want to do is load in this OTHER xml file, right now I'm getting
    > > "Class is not mapped with Cayenne:
    > > main.java.org.example.cayenne.persistent.Artist" which is because it has
    > not
    > > loaded my other xml file. Here is what I'm doing:
    > >
    > >
    > > ObjectContext context = DataContext.createDataContext();
    > >
    > > MapLoader ml = new MapLoader();
    > >
    > > DataMap dataMap = ml.loadDataMap(new InputSource(new
    > >
    > FileInputStream("C:\\eclipse_cayenne\\tutorial\\src\\main\\resources\\Map.map.xml")));
    > >
    > > //This will bomb because I havent DONE anything with the
    > datamap
    > >
    > > Artist picasso = context.newObject(Artist.class);
    > >
    > > So what do I do with that DataMap to get it loaded into the context? I've
    > > been looking but I Don't see the method call I need to make to push that
    > > DataMap anywhere. Note the other files (cayenne.xml,
    > > TestProjectNode.driver.xml) remain unchanged.
    > >
    > > Any help would be greatly appreciated.
    > >
    >



    This archive was generated by hypermail 2.0.0 : Tue Nov 02 2010 - 18:04:09 UTC