• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Rules for home/component business method names

 
Colin Richardson
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anybody have a handy list of rules for home and component business method names?
From Head First EJB:
Page 279, entity bean home business methods cannot have the prefixes "create", "find" or "remove". Can they have the prefix "ejb"?
Page 272 says that entity bean component business methods can have arbitrary names, provided they don't begin with "ejb". Can they have the prefixes "create", "find" and "remove"? I can see that "create" and "find" have no special meaning for the component interface, but what about "remove" - there are remove methods in both home and component interfaces?
Page 133 gives a list of rules for the component interface for session beans, similar to the rules for entity beans on pages 272, 279, but it does not specify restrictions on business method names. What are the rules?
Thanks for any help!
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[BOLD]Does anybody have a handy list of rules for home and component business method names?
Page 279, entity bean home business methods cannot have the prefixes "create", "find" or "remove". Can they have the prefix "ejb"?
[/BOLD]
Sure. (although you wouldn't want to do that, but I realize this question is about whether you CAN... for the purposes of the spec/exam.) It will just *look* awkward inside the bean class because of the naming rules:
HOME interface: ejbDoSomething()
BEAN CLASS: ejbHomeEjbDoSomething()

[BOLD]
Page 272 says that entity bean component business methods can have arbitrary names, provided they don't begin with "ejb". Can they have the prefixes "create", "find" and "remove"? I can see that "create" and "find" have no special meaning for the component interface, but what about "remove" - there are remove methods in both home and component interfaces?
[/BOLD]
Yes, you can have all of those prefixes. The reason why the rules are different for home and component interfaces is that remember -- business methods are matched EXACTLY as you write them in the interface. So there is no conflict with the methods inside the bean class as long as you don't start with "ejb".
Example:
Component interface: createAccount()
Inside Bean class: createAccount() // so it doesn't conflict with ejbCreate methods, because business methods in the bean class match the name of the method in the component interface *exactly*.
Component interface: removeAccount()
Inside Bean class: removeAccount(), so it doesn't conflict with the "ejbRemove"
If a client calls remove() on a bean's component interface, the Container will *always* invoke the ejbRemove() method in the bean class. So even if you had your own remove() method in the Bean class, it couldn't be called. (unless YOU call it from within some other method in the bean class). The Container will always implement the remove() in the implementation of the component interface, and that always results in a call to the ejbRemove() method in the bean. But I can't say that I've actually tried putting in a remove() method of my own.
[BOLD]Page 133 gives a list of rules for the component interface for session beans, similar to the rules for entity beans on pages 272, 279, but it does not specify restrictions on business method names. What are the rules?[/BOLD]
It's the same rule as for entity beans... you can't start with "ejb". I've listed that on page 234... rules for the bean *class*. I didn't put this rule on page 133, although I should have, but if you get to page 234 -- if you can't have a business method in the bean class that starts with "ejb", then you definitely can't have one in the component interface either, since they must match. It's a weird kind of reverse engineering where you can go in either direction... to work out the rules.
But I really should have said it also on page 133... or else you could write one in the interface, then get to the bean class and realize, "Uh oh... I'm not allowed to do that..."
So, the rules really are *exactly* as I listed them in the book, except for page 133.
To summarize in one place (here ):

* ENTITY BEANS AND SESSION BEANS:
- Business methods must NOT start with "ejb". That is the only rule for business methods, and applies both to the interface and bean class, since business method names must match EXACTLY.
* ENTITY BEAN HOME INTERFACE:
You can use any name except they can't start with "create", "remove", or "find". You CAN start with "ejb".

* SESSION BEAN HOME INTERFACE:
You can have ONLY methods that start with "create". StateFUL beans can have as many as you want, both overloaded or other names (providing they start with "create"), but stateLESS beans can have only one, no-arg create().
Good questions
I think in a future version of the book we should put that all in one summary page instead of spread out. That's one of the things that drives me crazy about the spec... you have to hunt in so many different locations to get the full story...
cheers,
Kathy
 
Colin Richardson
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kathy,
Thanks for another comprehensive answer! I did read page 234, honest, but it's just so difficult to remember if or where you might have read something before. Learning EJB, I'm reminded of a Far Side cartoon where a boy in class puts his hand up and says "Please sir, my brain is full".
I certainly like the idea of adding a summary of naming requirements to a future version of the book.
Thanks again.
Colin
 
Keith Rosenfield
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Kathy,
Just a quick clarification. When you say
* ENTITY BEAN HOME INTERFACE:
You can use any name except they can't start with "create", "remove", or "find". You CAN start with "ejb".

Are the 'they' that you are referring to the home business methods?
Thanks.
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes!! I mean *only* the home business methods
thanks...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic