cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From caden whitaker <caden.whita...@gmail.com>
Subject Re: DataMap.loadDataMap existing ObjectContext?
Date Tue, 02 Nov 2010 18:33:44 GMT
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();

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message