Optimized Entity Bean

From UrbanCode website: -- http://www.urbancode.com/projects/ejbbenchmark/idioms.jsp

"The Optimized Entity Bean idiom is almost the same as the CoarseGrainedEntityBean Idiom with one exception - the inherent persistence mechanism present in entity beans is optimized. This optimization is made in the ejbStore() method. Normally the ejbStore() method executes a database update query every time it is invoked. That means that normally an update query is executed every time the client application calls the getState() method (if we wrap the getState() method with a transaction as we most certainly should). So the database is being updated even though the state has not changed. The optimization in this idiom involves using an is dirty flag. If the flag is true then the ejbStore() method executes the update query. If the flag is false then the ejbStore() method does nothing. Mutator methods would set the dirty flag to true but accessor methods such as getState() method would leave the flag set to false."

EJB2.0 container managed persistence beans are optimized. Instead of accessing a field, setter and getter methods are used so the container knows when a method has modified any data (or to be more accurate called any setter method).

Many EJB 1.x containers have proprietary extensions to optimize CMP beans. Weblogic allows the coder to provide an isModified method, which is called after any EJB methods. This must return true if any modifications have been made.

WebSphere allows for a special "read-only" flag in its deployment descriptor extension. The container knows that if you call methods marked "read only" the bean is not dirtied, whereas calling any method not marked read-only dirties the bean.

See Also

View edit of October 11, 2014 or FindPage with title or text search