Stanislav Markin wrote:
> 
> Hello!
> 
> Should I write the code like this:
> 
> private transient boolean loaded = false;
> public void ejbLoad(){
>   if(loaded)
>     return;
>   loaded = true;
>   // load data
> }

No, not exactly.

For an entity with bean-managed persistence, the data access in the
database is completely done and controled by the bean.
The idea is to optimize the ejbStore() fonction, and store the 
entity in the database, only if its state have been changed.

Here is a bean's code example to do this kind of optimization.
- add those methods in your bean:
        private transient boolean isDirty;
        boolean isModified() {
                return isDirty;
        }
        void setModified(boolean flag) {
                isDirty = flag;
        }
- the ejbLoad() and ejbStore() methods can look like:
        void ejbLoad() {
                // load data
                ......
                setModified(false);
        }
        void ejbStore() {
                if (isModified()) {
                        // store data
                        .......
                }
                setModified(false);
        }
- of course, the bean must set the isDirty flag to true in any place
where the state changes.
So every bean's method which changes its state, but also the
setEntityContext(...), ejbActivate(), ejbPassivate() and ejbRemove()    
methods, must call setModified(true).

> 
> Will this code work correct if the container passivate/activate my bean?

Yes, if you take care about the setting of the isDirty flag.

> 
> It seems that container works like this:
> <remote method call>;
> ejbStore();
> ejbLoad();
> 

No.
ejbLoad() is called at the beginning of every transaction,
at the first bussiness method call (inside the transaction).
ejbStore() is called at the end of every transaction,
at the last bussiness method call (inside the transaction).

> Could  you  explain  why  it  is  necessary  for the container to call
> ejbLoad() after each ejbStore()?
> 

See above.

> With best regards,

Kind regards.
Hélène.

>  Stanislav Markin                       mailto:[EMAIL PROTECTED]
> 
> HJ> Hi,
> 
> HJ> This feature is only for entity bean with container-managed persistence.
> HJ> Indeed, entity bean with bean-managed persistence can itself
> HJ> implement this kind of optimization. In BMP case, the data access
> HJ> in the database are completely done and controled by the bean.
> 
> HJ> Kind regards.
> HJ> Hélène.
> 
> HJ> Stanislav Markin wrote:
> >>
> >> Hello!
> >>
> >>   I've  got  problem using isModified extension. I have BMP bean which
> >>   is "read-only".
> >>
> >>   As described in JOnAS docs, I declared isModified method:
> >>
> >>   public boolean isModified(){
> >>     Log.log("enter", "ClassifMetadataEJB.isModified()");
> >>     return false;
> >>   }
> >>
> >>   and modified jonas xml descriptor:
> >>
> >> <!DOCTYPE jonas-ejb-jar SYSTEM "jonas-ejb-jar.dtd">
> >> <jonas-ejb-jar>
> >>   <jonas-entity>
> >>     <ejb-name>ClassifMetadata</ejb-name>
> >>     <is-modified-method-name>isModified</is-modified-method-name>
> >>     <jndi-name>com.ulterwest.server.core.ClassifMetadataHome</jndi-name>
> >>   </jonas-entity>
> >> </jonas-ejb-jar>
> >>
> >>   And  method  isModified  is  never called. Instead after each remote
> >>   call ejbStore and ejbLoad are called. I want to prevent ejbLoad call
> >>   after each remote call.
> >>
> >>   Maybe  I  need  to  place isModified method in remote interface (not
> >>   only in Impl class)?
> >>

-- 
-=- Hélène JOANIN -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  mailto:[EMAIL PROTECTED]    http://www-frec.bull.com
  Phone: 33.4.76.29.73.53          Fax: 33.4.76.29.76.00
 Download our EJB Server JOnAS at http://www.bullsoft.com/ejb
_______________________________________________________________
----
To unsubscribe, send email to [EMAIL PROTECTED] and
include in the body of the message "unsubscribe jonas-users".
For general help, send email to [EMAIL PROTECTED] and
include in the body of the message "help".

Reply via email to