vertical inheritance by templating

From: Mike Kienenberger (mkienen..laska.net)
Date: Fri Jun 17 2005 - 13:42:23 EDT

  • Next message: Andrus Adamchik: "Re: vertical inheritance by templating"

    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 - 13:39:46 EDT