This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Manipulating Entity Beans: Strategy vs. Facade Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Manipulating Entity Beans: Strategy vs. Facade" Watch "Manipulating Entity Beans: Strategy vs. Facade" New topic
Author

Manipulating Entity Beans: Strategy vs. Facade

James MacLean
Greenhorn

Joined: Oct 27, 2003
Posts: 2
I recently attempted manipulating entity beans using the GoF Strategy Pattern, and it worked! Instead of hiding my entities behind a stateless session facade, I used a stateful session strategy. My question is: "How will this impact performance, and by how much?" Naturally, it will be much easier to add and/or remove entity beans; however, if there is a significant performance cut associated with this then I would not bother. I have posted the bean class below. Thanks in advance!

PersistenceManagerBean.java:
package ejb;
import framework.*;
import interfaces.*;
import vo.*;
import util.*;
import java.rmi.*;
import javax.rmi.*;
import javax.ejb.*;
import java.util.*;
import java.security.*;
import org.apache.log4j.*;
public class PersistenceManagerBean implements IPersistenceManager, SessionBean {

private SessionContext context;
private Logger log = Logger.getLogger(PersistenceManagerBean.class);

private IPersistenceAppService pas;
private String pasName;

public Object create(Object pk, IValue vo) throws PersistenceManagerException {
try {
this.log.info("Creating entity");
return this.pas.create(pk, vo);
} catch (CreateException e) {
this.log.warn("Unable to create entity");
throw new PersistenceManagerException(e);
}
}

public IValue read(Object pk) throws PersistenceManagerException {
try {
return this.pas.read(pk);
} catch (FinderException e) {
this.log.warn("Unable to read entity");
throw new PersistenceManagerException(e);
}
}

public void update(Object pk, IValue vo) throws PersistenceManagerException {
try {
this.pas.update(pk, vo);
} catch (FinderException e) {
this.log.warn("Unable to update entity");
throw new PersistenceManagerException(e);
}
}

public void delete(Object pk) throws PersistenceManagerException {
try {
this.pas.delete(pk);
} catch (RemoveException e) {
this.log.warn("Unable to delete entity");
throw new PersistenceManagerException(e);
}
}

public void ejbCreate(String pasName) throws CreateException {
try {
Class classDefinition = Class.forName(pasName);
this.pas = (IPersistenceAppService)classDefinition.newInstance();
this.pasName = pasName;
} catch (InstantiationException e) {
throw new CreateException();
} catch (IllegalAccessException e) {
throw new CreateException();
} catch (ClassNotFoundException e) {
throw new CreateException();
}
}

public void ejbActivate() throws EJBException {
try {
this.log = Logger.getLogger(PersistenceManagerBean.class);
Class classDefinition = Class.forName(this.pasName);
this.pas = (IPersistenceAppService)classDefinition.newInstance();
} catch (InstantiationException e) {
throw new EJBException(e);
} catch (IllegalAccessException e) {
throw new EJBException(e);
} catch (ClassNotFoundException e) {
throw new EJBException(e);
}
}

public void ejbPassivate() throws EJBException {
this.log = null;
this.pas = null;
}

public void ejbRemove() throws EJBException {
}

public void setSessionContext(SessionContext context) throws EJBException {
this.context = context;
}
}
Howard Kushner
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 361
Originally posted by James MacLean:
"How will this impact performance, and by how much?"

Use a profiling tool to measure performance rather than guessing.
That said, I prefer the stateless session bean facade, since they hold no conversational state and are not tied to a particular client.
I am not averse to the design patterns... there is a time and place for everything.
Of course YMMV.


Howard Kushner<br />IBM Certified Enterprise Developer - WebSphere Studio Application Developer V5.0<br />IBM Certified Advanced System Administrator - WebSphere Application Server V5.0<br />IBM Certified Solution Developer - Web Services with WebSphere Studio V5.1<br /><a href="http://www.amazon.com/exec/obidos/tg/detail/-/1931182108/" target="_blank" rel="nofollow">Developing J2EE Applications with WebSphere Studio</a> my Certification Study Guide for IBM Test 287
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Manipulating Entity Beans: Strategy vs. Facade
 
Similar Threads
ejbLoad is not getting called
runtime objects
runtime objects
Help !!!! StringIndexOut.....
Weblogic 6.0 EJBC and checked exceptions