Thanks for your reply. I think you are right about naming the pseudo-method
"ejbCreate()" - makes good sence. I could not help noticing, though, how you
set states=null in some of your methods... I don't think that is necessary.
If you'd like the Vector called "states" not to be stored just declare it as

transient Vector states;

Actually I found a place in my own code where I forgot to put the transient
keyword in front of a variable which should not be persisted by Orion and it
works anyway, but it should be corrected, as the fact that it works may very
well be Orion specific.


See section 6.4.1 of the specification (I looked it up in the 2.0 spec but I
think it is the same in 1.0).


Yours
Randahl

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Conrad Chan
Sent: 20. februar 2001 02:17
To: Orion-Interest
Subject: RE: Best practices: How to initialize state in EntityBean's
super class


I am doing something very similar to what you described.  My base class is
actually coded like a Entity bean so that it has all the ejbActivate,
ejbLoad, ejbStore etc.  Hence it is a self-contained entity bean which
handles its own state information nicely and my subclasses are not required
to re-declare those dummy functions if they do not need to.

Something like the following: -

abstract class MyBase implements EntityBean {
        protected transient EntityContext ctx;

        Vector states;

        /** My pseudo ejbCreate function */
        public void ejbCreate()

                states = new Vector();
        }

        public void setEntityContext(EntityContext ctx) { this.ctx = ctx; }

        public void unsetEntityContext() { this.ctx = null; }

        public void ejbActivate() {
                states = new Vector();
        }

        public void ejbPassivate() {
                states = null;
        }

        public void ejbRemove() {
                stats = null;
        }

        public void ejbLoad() { }

        public void ejbStore() { }
}

public class MySubclass extends MyBase implements EntityBean {

        String value;

        public Integer ejbCreate(String value) {
                super.ejbCreate();

                this.value = value;

                return null;
        }
}

Conrad

-----Original Message-----
From: Randahl Fink Isaksen [mailto:[EMAIL PROTECTED]]
Sent: Monday, February 19, 2001 4:18 PM
To: Orion-Interest
Subject: Best practices: How to initialize state in EntityBean's
superclass


Suppose you have two EntityBean classes A and B which share some common
functionality and state by inheriting from the same superclass S. Then, if S
has some member variable, say a java.util.Vector called "foos", which is
part of the persistent state of both A and B, my question is this: When
should "foos" be initialized?

I am positive that the ejbCreate methods of A and B could include an
instantiation like "foos = new Vector();" but if I use this model, I have to
remember to write this instantiation into every subclass of S, and if S has
many member variables (and many subclasses) that becomes error prone. - Not
to mention that if I add a new member variable to S I have to modify all
subclasses A, B, etc. to make their ejbCreate(...) instantiate this new
variable.

My own suggestion is to define a method in S, lets call it "void
instantiateS()" and have subclasses A, B, etc. invoke this method in their
ejbCreate(...).
I believe this method should *not* be the (no-arg) constructor of S as I
expect this contructor will be called everytime an instance of A or B is
loaded from persistant storage (which is unnecessary).

What are your suggestions?
What do you do when using inheritance in your beans?

Any comments would be appreciated.

Randahl.


Reply via email to