Feeds

Migrating EJB 2.1 Entity and Session Beans to EJB 3.0

The nuts and bolts

Providing a secure and efficient Helpdesk

Listing 2. CatalogBean.java EJB 3.0 Session Bean

@Stateless
@Local ({CatalogLocal.java})

public class CatalogBean implements CatalogLocal {
    public String getJournal(String publisher) {
        if (publisher.equals("Oracle Publisher"))
            return new String("Oracle Magazine");
        if (journal.equals("OReilly"))
            return new String("dev2dev");
    }
}

In EJB 3.0, the component and home interfaces of EJB 2.1 are replaced with a business interface. The business interfaces for the session bean are POJIs, and do not extend the EJBLocalObject or the EJBObject. A local business interface is denoted with the annotation @Local. A remote business interface is denoted with the annotation @Remote. A remote business interface does not throw the RemoteException. The local business interface corresponding to the session bean class is listed in Listing 3.

Listing 3. CatalogLocal.java. Local Interface of Session Bean

@Local

public interface CatalogLocal{
    public String getJournal(String publisher);
}

A client for an EJB 2.1 session bean gets a reference to the session bean with JNDI. The JNDI name for the CatalogBean session bean is CatalogLocalHome. The local/remote object is obtained with the create() method. The client class for the EJB 2.1 session bean is listed in Listing 4.

Listing 4. EJB 2.1 Session Bean Client Class

import javax.naming.InitialContext;

public class CatalogClient {

    public static void main(String[] argv) {
        try {
            InitialContext ctx=new InitialContext();
            Object objref=ctx.lookup("CatalogLocalHome");
            CatalogLocalHome catalogLocalHome=(CatalogLocalHome)objref;
            CatalogLocal catalogLocal=(CatalogLocal)catalogLocalHome.create();
            String publisher="OReilly";
            String journal=catalogLocal.getJournal(publisher);
            System.out.println("Journal for Publisher: "+publisher +" "+journal);
        }
        catch (Exception e) {}
    }
}

In EJB 3.0 a reference to a resource is obtained with dependency injection with the @Inject annotation or the @Resource annotation. JNDI lookup and create() method invocation is not required in EJB 3.0. The client class for the EJB 3.0 session bean is listed in Listing 5.

Secure remote control for conventional and virtual desktops

More from The Register

next story
'Windows 9' LEAK: Microsoft's playing catchup with Linux
Multiple desktops and live tiles in restored Start button star in new vids
Not appy with your Chromebook? Well now it can run Android apps
Google offers beta of tricky OS-inside-OS tech
New 'Cosmos' browser surfs the net by TXT alone
No data plan? No WiFi? No worries ... except sluggish download speed
Greater dev access to iOS 8 will put us AT RISK from HACKERS
Knocking holes in Apple's walled garden could backfire, says securo-chap
NHS grows a NoSQL backbone and rips out its Oracle Spine
Open source? In the government? Ha ha! What, wait ...?
Google extends app refund window to two hours
You now have 120 minutes to finish that game instead of 15
Intel: Hey, enterprises, drop everything and DO HADOOP
Big Data analytics projected to run on more servers than any other app
prev story

Whitepapers

Secure remote control for conventional and virtual desktops
Balancing user privacy and privileged access, in accordance with compliance frameworks and legislation. Evaluating any potential remote control choice.
Saudi Petroleum chooses Tegile storage solution
A storage solution that addresses company growth and performance for business-critical applications of caseware archive and search along with other key operational systems.
High Performance for All
While HPC is not new, it has traditionally been seen as a specialist area – is it now geared up to meet more mainstream requirements?
Security for virtualized datacentres
Legacy security solutions are inefficient due to the architectural differences between physical and virtual environments.
Providing a secure and efficient Helpdesk
A single remote control platform for user support is be key to providing an efficient helpdesk. Retain full control over the way in which screen and keystroke data is transmitted.