Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

EJB: static references on a LocalHome

Posted on 2002-06-21
2
Medium Priority
?
292 Views
Last Modified: 2013-11-24
Hi,

we are in need of some sort of utility class that resolves finder functionality for us. This should provide methods in the form of findXXXByPK(String) or findYYYByName(String), returning a local reference.
We have some different opinions on how to code this best, considering performance and "political correctness" of the code and code placement.

The first version would be a stateless session bean that instantiates all necessary home interfaces in the ejbCreate() method to use them later. Advantage: clean, nice code. Disadvantage: Every SessionBean using this SessionBean needs to make a new JNDI lookup to get this utility class.

Second version is a regular class (not an EJB) that can be accessed statically to provide these methods. This class would instantiate the relevant home interfaces in a static context and call find methods on these home interfaces from its static methods. Advantage: probably better performance than first version and easier access without JNDI lookup. Disadvantage: I am not sure if those static home interfaces are evil.

I know this might be an ethical question about code beauty, but I would like to hear some input on this.

thanks,
  exorcist.

0
Comment
Question by:exorcist
2 Comments
 

Accepted Solution

by:
fi76631 earned 600 total points
ID: 7101160
Hmmm...

Best solution for what you propose is similar to option two above. You should use the singleton pattern.

Static home interfaces work just fine. I use this approach a lot and it makes my code run a lot faster.

Specifically, what I do is have a client wrapper for each EJB. This abstracts the fact from the caller of the bean that they are interacting with a bean. The client is a singleton that loads the specific home interfaces on creation.

Calls to the bean are very simple:

Result = myBeanClient.sInstance().beanMethod(...);

Obviously, the beanClient is derived from a baseBeanClient class that does all of the work. Each bean client has only a hand full of lines of code...so each client can be written in about 10 seconds!

Its quick, simple, controllable and it works!
0
 
LVL 3

Author Comment

by:exorcist
ID: 7121473
90% of the answer is actually off topic, but since it's the only answer....
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question