advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement



Title: Professional EJB
ISBN: 1861005083
US Price: $ 59.99
Canadian Price:
C$ 89.95
UK Price: £ 47.99
© Wrox Press Limited, US and UK.

Reviews : Java Books :
Professional EJB : The EJB 2.0 Entity Model

Local Interfaces, Remote Interfaces, and the Client View

A local client is one that is located in the same Java Virtual Machine as its component and uses a local interface. A remote client uses the remote interface of the component. The two different types of clients have different privileges for accessing details of the object model.

A local interface may use other local interfaces as parameters and return values, and may also use the collection classes that represent multi-valued relationships as parameters and return values. A remote interface must not ever use a local interface or relationship collection as a parameter or a return value. The reason for this rule is easily understood: a remote client may not be using the same Java Virtual Machine, but these classes are dependent on a particular virtual machine for their correct execution.

The client view of an EJB component is defined by the methods in the EJB's home and remote interface. This view is independent of the EJB's implementation – and specifically, independent of the EJB's object model. From the point of view of a client, local interfaces and relationships are just an irrelevant implementation detail. All the client of an EJB cares about are the remote methods that it can invoke.

For instance, let's consider the example of an entity bean representing an order. This entity bean might have the following remote interface:

	import java.rmi.RemoteException;
	import javax.ejb.EJBObject;

	public interface Order extends EJBObject {

		public Long getOrderId() throws RemoteException;
		public String getCustomerName() throws RemoteException;
		public String getStreetAddress() throws RemoteException;
		public String getCity() throws RemoteException;
		public String getState() throws RemoteException;
		public String getZip() throws RemoteException;
	}

The implementation class for this EJB (perhaps named OrderEJB) might have state variables representing the customer's street address, city, state, and zip code. On the other hand, it might have a one-to-one relationship with a local address EJB. It might have a regular Java object that gets serialized into a database column. It might even have a one-to-many relationship with local address EJBs, and use an algorithm to select an appropriate shipping address for an order based on the order's manufacturing facility. From the client's point of view, it doesn't matter. The same street, city, state, and zip code strings are returned through the public interface.

In fact, it is illegal to return a local component interface or a relationship collection class from a remote interface method in an entity. You could not simply write the above interface as follows (assuming Address is a local component interface):

	import java.rmi.RemoteException;
	import javax.ejb.EJBObject;

	public interface Order extends EJBObject {

		public Long getOrderId() throws RemoteException;
		public Address getAddress() throws RemoteException;
	}

The local address remote interface cannot be the return value in a remote method invocation.

Transferring State to and from the Client

Even though it is illegal to return a local interface or a relationship collection to the client, it is still often necessary to transfer a view of the entity's state to the client, or to apply an update of the entity's state from the client. A common pattern is to use a Java class to represent the state or updates to be transferred. This class might be generic (a custom java.sql.ResultSet implementation) or specific to the state that needs to be transported (an AddressView or LineItemView class).

For instance, the interface for the order bean might be defined as follows:

	import java.rmi.RemoteException;
	import javax.ejb.EJBObject;
	import javax.ejb.CreateException;

	public interface Order extends EJBObject {

		public Long getOrderId() throws RemoteException;
		public LineItemView[] getLineItemViews() throws RemoteException;
		public void addLineItem(LineItemView liv)
			throws RemoteException, CreateException;
		public void updateLineItem(LineItemView liv) throws RemoteException;
		public void removeLineItem(long lineItemID) throws RemoteException;
	}

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Microsoft Visual Studio 2010 Showcase
 Avaya Developer Showcase
 MSDN Spotlight
 PHP for Windows Showcase
XML error: undefined entity at line 39
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Windows 7: From Beta to Final Code in One Year
Google Shows Off Chrome OS, Releases Source
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?
Fedora 12 Takes Aim at Linux Networking
Top Supercomputer Nearly Doubles in Speed
Fedora 12 Linux Tackles Virtualization
Apple Gives iPhone Developers App Status Tracker
Novell Sets OpenSUSE 11.2 Free

Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Exploring HTML 5's Audio/Video Multimedia Support
Overriding Virtual Functions? Use C++0x Attributes to Avoid Bugs.
Understanding the Cloud Computing Security Vulnerabilities
Cisco and IBM Target a Greener World
Upgrade to Visual Studio 2010 with the Ultimate Offer

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs