Solved

EJB: static references on a LocalHome

Posted on 2002-06-21
2
275 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 300 total points
Comment Utility
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
Comment Utility
90% of the answer is actually off topic, but since it's the only answer....
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

762 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now