Re: Interface, abstract classes and Cayenne

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Sun Apr 18 2004 - 13:18:24 EDT

  • Next message: Andrus Adamchik: "Re: Interface, abstract classes and Cayenne"

    Hi Eddy,

    On Apr 18, 2004, at 6:41 AM, Eddy Young wrote:
    > 1. Is it possible to use interfaces with Cayenne?

    Yes, it should be possible to do that. As long as the ObjEntity "Java
    Class" is mapped to the right implementation, so that Cayenne knows
    what to instantiate for a given entity. Also, if you want to totally
    rid your code from dependencies on concrete implementations, all select
    queries should use String entity name as "root" in constructor, not the
    Java class:
    http://objectstyle.org/cayenne/api/cayenne/org/objectstyle/cayenne/
    query/SelectQuery.html

    I guess the only thing that may require some tweaking is automating
    class generation for this scenario (
    http://objectstyle.org/cayenne/userguide/javagen.html ). Since Cayenne
    uses Velocity templates for class generation and allows to choose a
    custom template, a fair amount of customization is possible already (I
    think - just enough to do the trick). However, you will need 3
    templates (interface, superclass, subclass) for each entity, while
    "cgen" task (and the Modeler) support only up to 2. So you will have to
    do a separate cgen run (just another piece of ant code "<cgen map=...")
    to generate the interfaces.

    Actually it was suggested by Mike Kienenberger some time back
    (http://objectstyle.org/cayenne/lists/cayenne-devel/2004/01/0016.html)
    to allow an arbitrary number of templates, which makes sense more and
    more to me now.

    > 2. Is it possible to map object attributes to the same table? For
    > example:

    Yes, it is possible. Separation of the mapping metadata into
    ObjEntities and DbEntities (basically descriptors for object and
    database layers, loosely tied together) makes it possible. However I
    don't understand your example - you have Address and ContactEntity that
    has Address as a property, both mapped to the same table?

    Andrus



    This archive was generated by hypermail 2.0.0 : Sun Apr 18 2004 - 13:18:29 EDT