Solved

EJB: static references on a LocalHome

Posted on 2002-06-21
2
276 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

863 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

20 Experts available now in Live!

Get 1:1 Help Now