Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

EJB: static references on a LocalHome

Posted on 2002-06-21
2
Medium Priority
?
286 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 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

Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This video teaches viewers about errors in exception handling.
Suggested Courses

704 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