FAQ
Dear list,

I'm trying to modify projects in Java code (mainly to migrate old
schemas automatically) and I can't save project with DataNodes.

Here is the simplest expression of my need :

File projectFile = new File("src/cayenne.xml");
ApplicationProject project = new ApplicationProject(projectFile);
ProjectConfiguration config = (ProjectConfiguration) project.getConfiguration();
project.save();

It works well as long as the projet doesn't have any DataNode. Here is
the relevant part of the stack trace:

Caused by: java.lang.ClassCastException: org.apache.cayenne.access.DataNode$TransactionDataSource cannot be cast to org.apache.cayenne.project.ProjectDataSource
at org.apache.cayenne.project.DataNodeFile.save(DataNodeFile.java:64)

I don't get how the modeler manages to get it working (it looks pretty
straightforward so I must be missing something).

I'm currently working by removing DataNodes from the project and adding
them back, so it is not very... fun. Can someone please point me at
least ways to solve the issue ?

I had it "working" by setting every node's DataSourceFactory to
ProjectDataSourceFactory *but* it destroys their data...

Thanks !

--
Mikaël Cluseau

Search Discussions

  • Andrus Adamchik at Jul 14, 2007 at 7:14 pm

    On Jul 13, 2007, at 1:30 AM, Mikaël Cluseau wrote:

    Caused by: java.lang.ClassCastException:
    org.apache.cayenne.access.DataNode$TransactionDataSource cannot be
    cast to org.apache.cayenne.project.ProjectDataSource
    at org.apache.cayenne.project.DataNodeFile.save(DataNodeFile.java:64)

    I don't get how the modeler manages to get it working (it looks pretty
    straightforward so I must be missing something).
    To work around a bad decision made a long time ago to use Cayenne
    runtime objects (DataDomain, DataNode) as CayenneModeler model beans,
    modeler often uses inner subclasses to suppress various runtime
    behavior aspects. Here is how i handles the problem above:


    class ModelerProjectLoadDelegate extends RuntimeLoadDelegate {
    ....
    protected DataNode createDataNode(String nodeName) {
    return new DataNode(nodeName) {

    public DataSource getDataSource() {
    return dataSource;
    }
    };
    }
    ...
    }

    Andrus
  • Mikaël Cluseau at Jul 16, 2007 at 1:09 am
    Hi Andrus, and thanks for your answer.

    Le samedi 14 juillet 2007 à 22:13 +0300, Andrus Adamchik a écrit :
    To work around a bad decision made a long time ago to use Cayenne
    runtime objects (DataDomain, DataNode) as CayenneModeler model beans,
    modeler often uses inner subclasses to suppress various runtime
    behavior aspects.
    This design decision is something I liked, and is one of the reasons
    that made me choose Cayenne: it allows for coded-style project
    transformation, which is very interesting when it come to batch
    processing. I'm using it to convert client's conventions to an coherent
    objet model, instead of mapping tables one by one using the modeler (you
    guessed it, I'm not a GUI person ;-)).

    I think that the only problem with the current design is that it is
    reversed: you extends run-time objects to modeler objets (ie
    Configuration vs ProjectConfiguration). I *feel* it would be much better
    to use a descriptive model suitable for the modeler and *then* to extend
    the run-time model to it, using a kind of "meta-model" interface:

    // Loads the (meta-)model
    Configuration config = new Configuration("cayenne.xml");
    // Build a run-time model
    RuntimeConfiguration rtc = config.instanciate();
    // Get back the (meta-)model
    assert config == rtc.getMetaModel();

    I'm very tight on my deadlines theses days but I would be happy to help
    you get rid of this "pain" (you seem to call it this way ;-)) in a month
    or two.

    --
    Mikaël Cluseau <mc.isi.nc@gmail.com>
    ISI.NC
  • Andrus Adamchik at Jul 16, 2007 at 6:44 am

    On Jul 16, 2007, at 1:22 AM, Mikaël Cluseau wrote:

    Hi Andrus, and thanks for your answer.

    Le samedi 14 juillet 2007 à 22:13 +0300, Andrus Adamchik a écrit :
    To work around a bad decision made a long time ago to use Cayenne
    runtime objects (DataDomain, DataNode) as CayenneModeler model beans,
    modeler often uses inner subclasses to suppress various runtime
    behavior aspects.
    This design decision is something I liked, and is one of the reasons
    that made me choose Cayenne: it allows for coded-style project
    transformation, which is very interesting when it come to batch
    processing. I'm using it to convert client's conventions to an
    coherent
    objet model, instead of mapping tables one by one using the modeler
    (you
    guessed it, I'm not a GUI person ;-)).
    Ah, glad somebody finds it useful :-)

    I think that the only problem with the current design is that it is
    reversed: you extends run-time objects to modeler objets (ie
    Configuration vs ProjectConfiguration). I *feel* it would be much
    better
    to use a descriptive model suitable for the modeler and *then* to
    extend
    the run-time model to it, using a kind of "meta-model" interface:

    // Loads the (meta-)model
    Configuration config = new Configuration("cayenne.xml");
    // Build a run-time model
    RuntimeConfiguration rtc = config.instanciate();
    // Get back the (meta-)model
    assert config == rtc.getMetaModel();

    I'm very tight on my deadlines theses days but I would be happy to
    help
    you get rid of this "pain" (you seem to call it this way ;-)) in a
    month
    or two.
    Great! Let's discuss it once you have spare cycles.

    Andrus
  • Mikaël Cluseau at Sep 18, 2007 at 12:53 pm

    Le lundi 16 juillet 2007 à 09:44 +0300, Andrus Adamchik a écrit :

    I'm very tight on my deadlines theses days but I would be happy to help
    you get rid of this "pain" (you seem to call it this way ;-)) in a month
    or two.
    Great! Let's discuss it once you have spare cycles.
    Sorry, still hard to get some time... I hope to have some in 2/3 weeks.
    Would these changes in the model still useful ? (I suppose yes) For
    Cayenne 2 or 3 ? (I suppose 3)

    About my uses of the model, there some old code of mine at
    http://cayenne-tools.sourceforge.net/ (XUL has been forgotten...).

    Cheers,

    --
    Mikaël Cluseau <mc.isi.nc@gmail.com>
    ISI.NC
  • Aristedes Maniatis at Sep 18, 2007 at 11:43 pm

    On 18/09/2007, at 10:52 PM, Mikaël Cluseau wrote:

    About my uses of the model, there some old code of mine at
    http://cayenne-tools.sourceforge.net/ (XUL has been forgotten...).
    It can be a little hard to find, but if others are looking for the
    source code, it can be seen here:

    http://cayenne-tools.cvs.sourceforge.net/cayenne-tools/cayenne-tools/

    But in my poking around, I've not found the part which refers to the
    Cayenne model.


    Ari Maniatis




    -------------------------->
    Aristedes Maniatis
    phone +61 2 9660 9700
    PGP fingerprint 08 57 20 4B 80 69 59 E2 A9 BF 2D 48 C2 20 0C C8
  • Mikaël Cluseau at Sep 19, 2007 at 5:32 am
    Sorry, I should have been more precise... People should look at
    cayennetools.dbsync.core (*Informator) and
    cayennetools.dia_modeller.cayenne.CayenneObjectModeller.

    It was a very fast deployment, and I didn't touched it for a long time
    (I have more up-to-date implementations).

    Sorry for your time, Ari.

    Le mercredi 19 septembre 2007 à 09:42 +1000, Aristedes Maniatis a
    écrit :
    On 18/09/2007, at 10:52 PM, Mikaël Cluseau wrote:

    About my uses of the model, there some old code of mine at
    http://cayenne-tools.sourceforge.net/ (XUL has been forgotten...).
    It can be a little hard to find, but if others are looking for the
    source code, it can be seen here:

    http://cayenne-tools.cvs.sourceforge.net/cayenne-tools/cayenne-tools/

    But in my poking around, I've not found the part which refers to the
    Cayenne model.


    Ari Maniatis




    -------------------------->
    Aristedes Maniatis
    phone +61 2 9660 9700
    PGP fingerprint 08 57 20 4B 80 69 59 E2 A9 BF 2D 48 C2 20 0C C8
    --
    Mikaël Cluseau <mc.isi.nc@gmail.com>
    ISI.NC

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedJul 12, '07 at 10:30p
activeSep 19, '07 at 5:32a
posts7
users4
websitecayenne.apache.org

People

Translate

site design / logo © 2022 Grokbase