Re: POJO in Cayenne

From: André Luiz do Nascimento Sousa (andresous..aixaseguros.com.br)
Date: Fri Jan 21 2005 - 17:44:06 EST

  • Next message: Andrus Adamchik: "Any volunteers with DocBook knowledge?"

    Hello, Andrus,

           Like I said before, I'm attempting to build a small application
    in which we could test all the issues related to POJO in Cayenne. Let me
    just make some notes about my experience until here.

            Remembering the initial design idea, showing the layers:

    *==================================
    Presentation Layer (Struts / JSF) \
    ================================== \
    Businness Logic (Not EJB) \
    ================================== \
    Businness Model (POJO/JavaBeans) > Binding by Spring Framework style
    ================================== /
    DAO Interfaces /
    ================================== /
     {My Adapter/Conversors} /
    -----------------------------------
       Cayenne | ...
    -----------------------------------*

           For the time being, my simple model is:

        * Uf (State)
        * Cidade (City)
        * Bairro (District)

    * |----------|1 |--------|1 |---------|
        | Uf |-------<| Cidade |-------<| Bairro |
        |----------| n|--------| n|---------|

    * This model is represented as 3 POJO classes at the package
    called: "br.org.scout23.modelo."
           I have these tables created at a MS SQL Server 2000 (and more
    others 45!). I did a reverse reenginer and generation of the classes
    without any problems. These classes are at the
    "br.org.scout23.persistencia.cayenne" package.

           There are some DAO interfaces which deal only with model classes
    (UfDAO, CidadeDAO, BairroDAO). The "persistent providers (ORM)"
    implement those interfaces. I used Spring config files to bind the
    beans. I implemented a base Cayenne DAO class which provides the basic
    functions to other Cayenne DAO classes. This base Cayenne DAO class used
    the Cayenne-Spring template facilities.

           The challenge was to make the "translation between the worlds:
    POJO <=> Cayenne Data Contexts", for the CRUD operations.

           I implemented a utility class called "ConversorPOJOCayenne". This
    one has the mission of to make the bridge between the worlds, converting
    a POJO in a DataObject, and vice-versa. It does the same for the
    Collections, converting the objects inside of them. I did not use the
    "Commons BeanUtils" facilities 'cause I had not only to instrospect all
    the properties and set in each other, but to make the type conversions
    too. Here is the point I wanted to get. See the problems and temporary
    solution I got:

       1. I needed to keep the same class names for the classes model and
          the Cayenne ObjEntities classes. The full packages names should be
          specified when doing the runtime class instatiation. Only for the
          tests, I left them at 2 static final variables;
       2. When doing queries. Converting Cayenne DataObjects to POJOs:
              * a) As expected, at the moment of a simple query, when
                introspecting all the DataObject properties, the fault
                relationships are triggered and all the above tree is
                mounted. For some kind of relationships with big tables,
                it'll be a problem. When doing this conversion, we need a
                way to define which relationships should be mounted or not;
              * b) When converting the "toOne" relationship properties, the
                application got in loop until a StackOverFlowException.
                Because of the recursive instrospection, it reached a
                circular relationship;
       3. To solve temporary the a) and b) problems I included a boolean
          parameter when reading and converting a "toOne" relationship, so
          that it's defined to not read its "toMany" relationships again;
       4. When Inserting, Updating and Deleting a simple object, I have no
          problems until now.

          
           Sorry for the long message, but I just tried to share some of the
    doubts I have and give some idea. I'm sending my utility conversion
    class. I hope it helps.

           Thanks and Happy weekend 4 all.

           Bye,

    Andre Luiz - Brasil





    This archive was generated by hypermail 2.0.0 : Fri Jan 21 2005 - 16:42:21 EST