Re: vertical inheritance by templating

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Fri Jun 17 2005 - 14:42:46 EDT

  • Next message: Dhruti Ramani: "Re: Persisting a HashTable"

    Reading the wiki post, I realized the source of our earlier misunderstanding.

    I am looking at the vertical inheritance from the perspective of the base
    table ("PERSON" in this example). So to me vertical inheritance is just a
    special case of single table inheritance. I.e. queries can be performed on
    the inheritance hierarchy root and then Cayenne can determine which
    subclass to instantiate by applying entity qualifier returned data rows.

    You look at it from the perspective of the detail tables. And this is what
    makes it impossible to query across the hierarchy (at least not until we
    also implement horizontal inheritance).

    So I guess I am not ready to comment on this template approach right away
    as I need to digest this idea...

    Andrus

    > Andrus/Michael,
    >
    > Does the following method handle properly creating composite vertical
    > inheritance objects?
    > I'm especially curious to know how this compares to what Michael's
    > currently
    > using.
    > I've tried to consider every situation whereby an object could be created
    > and registered
    >
    > - external to a DataContext
    > - with createAndRegister
    > - with registerNewObject
    >
    >
    > [This situation is a child of SecRole with an inheritance relationship of
    > [s/g]etRole connecting the child to the parent.]
    >
    > I've also wrote up a wiki entry for CompositeVerticalInheritance and
    > inheritance in general.
    >
    > -Mike
    >
    >
    > public void setPersistenceState(int persistenceState)
    > {
    > super.setPersistenceState(persistenceState);
    >
    > if (PersistenceState.NEW == persistenceState) {
    > SecRole parent = getRole();
    > if (null == parent) { // parent does not exist
    > if (null != this.getDataContext()) { // child registered
    > in
    > a DataContext
    > parent =
    > (SecRole)dataContext.createAndRegisterNewObject(SecRole.class);
    > }
    > else {
    > parent = new SecRole();
    > parent.setPersistenceState(PersistenceState.NEW);
    > }
    >
    > this.setRole(parent);
    > }
    > else { // parent already exists
    > if (null != this.getDataContext()) { // child registered
    > in
    > a DataContext
    > if (null == parent.getDataContext()) {
    > dataContext.registerNewObject(parent);
    > }
    > else if (parent.getDataContext() !=
    > this.getDataContext()) {
    > throw new RuntimeException("entity and superEntity
    > are in different DataContexts.");
    > }
    > }
    > else { // there's no data context
    > parent = new SecRole();
    > parent.setPersistenceState(PersistenceState.NEW);
    > }
    > }
    > }
    > }
    >



    This archive was generated by hypermail 2.0.0 : Fri Jun 17 2005 - 14:42:47 EDT