• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Concept understanding on Remote and Local views

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,
I would just like some guidance on remote and local views for entity beans. I have been toying with the Movie-Director code from Head First EJB and have some modified it to test out my understanding on the remote and local view concepts but however, there were problems when I tried used the Tool Verifier in sun deploytool
ok here's the gist of what I am trying to do. I understand that in most cases, there would be either a remote view or a local view of an entity bean although both views would still be achievable. What I am trying to do is to implement both views to see how it would be done in the code. To my knowlege, the book only gives the code for the Movie part of the entity relationship but not the Director so I decided to get some hands on exp to implement the Director code. I hope a kind soul would be able to help to take a look at the code, the source code is very simple , its just that I have difficulty getting it verified. I believe the problem is very simple to solve but the thing is I don't know where or what the problem is. The code and ear file can be downloaded at http://f2.pg.briefcase.yahoo.com/bc/happygamer1978/lst?.dir=/headfirst&.view=l.
Basically what I want to do is to get both the Movie and Director to have remote and local views, local is because they have a 1:* relationship, remote is because I want the remote client to access the entity beans directly. I understand that a localhome is to return a local component interface and same thing with remote but what about the return values of the methods in the local component interface? are they to be local as well(I am not refering to standard return values like String or int but other entity beans)? I do believe that they have to be local as well. In the case of the MovieBean, because it has a relationship with the DirectorBean, I understand that the setter and getters type of the Director in the MovieBean is the local comp interface but what if I want the getter and setters to be remote so that they can be accessed by remote clients directly? How would I write that?
And another thing about relationships. I specified in the deploytool the 1:* many Movie and Director relationship, but when the tool verified failed, I looked at the Results.txt file and saw this entry:
***********************************************************
Test Name: tests.ejb.entity.cmp2.CmrFieldsAccessorExposition
Test Assertion: EJB 2.0 Spec 9.4.11 CMR accessor methods for other than one-to-one or many-to-one relationships between entity beans should not be exposed in the remote interface
Detailed Messages:
Error : CMR field get accessor method [ movies ] is exposed through the remote interface [ headfirst.Director ]
Error : CMR field set accessor method [ movies ] is exposed through the remote interface [ headfirst.Director ]
***********************************************************
so what gives? What I wanted to achieve was to enable someone with a MovieBean to get its director and someone with a DirectorBean to get its movies. If this is any useful, there is only one entry in the Relationships tab in the deploytool which specifies a 1:* relationship.
The other 2 entries in the Results.txt are:
***********************************************************
Test Name: tests.ejb.intf.localintf.LocalInterfaceMatchMethodReturn
Test Assertion: Remote interface business methods have matching method return type test
Detailed Messages:
For Local Interface [ headfirst.MovieLocal ] method [ getDirector ]
Error: No corresponding business method with matching return type was found for method [ getDirector ].
==============================
***********************************************************
***********************************************************
Test Name: tests.ejb.intf.localintf.LocalInterfaceMatchMethodArgs
Test Assertion: Local interface business methods have matching method arguments test
Detailed Messages:
For Local Interface [ headfirst.MovieLocal ] method [ setDirector ]
Error: No corresponding business method with matching arguments was found for method [ setDirector ].
==============================
***********************************************************

Thirdly, would the bean need to be aware that a call made to it is local or remote?if a remote call to a SessionBean to get an EntityBean is made and as far as the Entity Bean is concerned, the SessionBean is a local client, but the SessionBean need to return a remote comp interface to the remote client, so how does the code work out?
I have been stuck on this problem for some time already trying to figure out the concepts or remote and local views and how to write them correctly. I would appreciate if anyone could give me some enlightenment on this isssue. Thanks in advance!!
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remember, to do CMR we use only the local component interfaces, regardless of whether there is also a remote component interface. Local interfaces can only be used locally of course, and remote interfaces likewise can be used either locally or remotely (but both act as a truly-remoted client).
Now, if CMR uses only local component interfaces, which MUST be used locally, does it make any sense to see a local component interface anywhere in the remote component interfaces? It definitely does not.
The pattern-du-jour is to create what we call "value objects" which wrap up relationship-members into JavaBeans which we then return to remote clients instead of (the undeployable) CMR local component interfaces.
The rest of your questions are magically answered by the understanding of this simple rule. I hope this helps a bit.
 
steward frank
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Nathaniel,
thank you for your prmpt reply but however, I am not so concerned about creating value objects to return the relationship members to the remote client, what I am looking at is how to enable the remote client to get the relationship member by it self directly, how can I achieve that in the code?
I know that creating value objects is the way to go, but I really wanted to understand how do I go about writing my local, remote and bean code to to that?
 
steward frank
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An example
public interface MovieLocal extends EJBLocalObject
{
public DirectorLocal getDirector() ;
public void setDirector(DirectorLocal dir) ;
}
public interface MovieRemote extends EJBObject
{
public Director getDirector() throws RemoteException;
public void setDirector(Director dir) throws RemoteException;

}
public abstract class MovieBean implements EntityBean
{
....
public abstract DirectorLocal getDirector();
public abstract void setDirector(DirectorLocal dir);
....
}
ok, what we have above are watered down code of local and remote views of the moviebean and the movie bean itself. Is there anything lacking or missing in the code above? so far , the MovieLocal returns back a local Director interface and MovieRemotes returns back a remote Director interface, no issues about that. now lets take a look at the movie bean code, the cmr field deals only in local Director comp interfaces which is also correct. now, what do I add to the code above to enable a working remote view of the cmr? I know I already have a getter and setter in MovieRemote which returns a remote comp interface of Director but there got to be something else to make that remote interface work rite? if so what is it? do i need to add
public abstract Director getDirector();
public abstract void setDirector(Director dir);
to moviebean? but that would also be erroneous cos it would seem like there are now 2 CMR fields instead of just one director field in movie bean.
 
steward frank
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hullo?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic