Solved

EJB: static references on a LocalHome

Posted on 2002-06-21
2
279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xampp tool 12 58
fibonacci ten numbers 4 54
Unhandled exception type Exception 18 52
jmeter usage 4 33
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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…

740 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