Re: DataMap.loadDataMap existing ObjectContext?

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

  • Next message: Mark Fischer: "Reengineer Database Schema not generating anything"

    Got it working, here is the code, note this code can probably be reduced,
    but it at least did the job

                DataDomain dd =
    Configuration.getSharedConfiguration().getDomain();

                MapLoader ml = new MapLoader();
                DataMap dataMap = ml.loadDataMap(new InputSource(new
    FileInputStream("C:\\eclipse_cayenne\\tutorial\\src\\main\\resources\\HelloWorld2Map.map.xml")));

                // Add the shared map to the target data domain
                dd.addMap(dataMap);

                // Add the shared map to the data node
                Collection nodes = dd.getDataNodes();

                if (nodes.size() != 1)
                {
                  System.out.println("Expected only one DataNode for DataDomain
    '" +
                                     "" +
                                     "' -- this DataDomain is not usable.");
                  return;
                }

                Iterator dataNodeIterator = nodes.iterator();

                // We are only getting one, though ...
                while (dataNodeIterator.hasNext())
                {
                  DataNode node = (DataNode) dataNodeIterator.next();

                  node.addDataMap(dataMap);
                }

                ObjectContext context = dd.createDataContext();

                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 archive was generated by hypermail 2.0.0 : Tue Nov 02 2010 - 18:34:14 UTC