permaculture playing cards*
The moose likes EJB and other Java EE Technologies and the fly likes EJB-QL and operators Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB-QL and operators" Watch "EJB-QL and operators" New topic
Author

EJB-QL and operators

HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Have the operators UNION and NOT been adopted yet in EJB-QL ?
regards
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
NOT is already part of EJB-QL, but UNION isn't (at least in 2.0) and I doubt it will because UNION is not that helpful with objects, I think.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
EJB-QL is used to handle Business Rules.
How would you code up the following in EJB-QL.
1% Discounts apply to Customers who have bought Books in the any quarter
(Qx), 10% discounts apply to customers who have bought Books in quarters (Q1, Q2 ,Q3) and the total value exceeds 50$.
Customers may only be applicable to 1 discount.

With SQL it would be quite easy to exclude groups by NOT EXISTS and include Groups by the UNION operator.
How would you code these sets of rules in EJB-QL ?
regards
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
First of all, I don't think I'll be that active today...
Anyway, I'll have to say that you encode all of those rules in EJB-QL, yet. For example, the SUM() function will be introduced in EJB 2.1 (still a public draft).
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Anyway, I'll have to say that you encode all of those rules in EJB-QL, yet.

Did you mean ...
"Anyway, I'll have to say that you CAN'T encode all of those rules in EJB-QL, yet."

First of all, I don't think I'll be that active today...

What!Taking a break ? Well deserved!
regards
[ September 20, 2003: Message edited by: HS Thomas ]
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Yep, that's what I meant to say. See why I need(ed) the break...
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
"Anyway, I'll have to say that you CAN'T encode all of those rules in EJB-QL, yet."

And no SUM function or UNION.
This is either a glaring or deliberate ommission ! Which?
regards
[ September 21, 2003: Message edited by: HS Thomas ]
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
SUM (and AVG etc) is coming in the 2.1 version of the specification, but UNION is not as far as I know.
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
I believe that's too far down the line.
What options do you have if you were implementing the above rules with EJB ?
I suppose you'd derive that information from two simpler Entity beans.
There must be a finder (?) method that is the equivalent of UNION.
Creating and developing related CMP entity beans. Related entity beans are sets of EJB components that represent complex data from multiple database tables that have primary/foreign key relationships. There is a new wizard that enables you to select a database connection or schema and generate related CMP entity beans that model the relationships among the tables of the database. The Related CMP Entity Bean wizard generates all the beans and relationships and groups them in an EJB module. The IDE provides editors that enable you to edit and add relationships. The IDE also displays custom, modal property sheets on which you can edit the properties of the beans and the EJB module, and it generates a deployment descriptor from your property settings.

New J2EE CMP Entity EJB Wizard Options. The J2EE CMP Entity EJB wizard has been updated to include two new options. On the first wizard panel, the section Source for Entities and Fields now contains the choices: CMP 2.x Bean Class and CMP 1.x Bean Class. This option allows a user to select the bean class for an existing EJB and the wizard will obtain the CMP field information from the class. Using these new options requires that the user understands several potential issues: 1.) This feature was not created as a robust feature with error checks for incorrect class files, 2) when generating a 2.x CMP EJB with additional finder and ejbSelect methods, the EJBQL will not be generated: you must manually add back all EJBQL statements since these statements are stored with the bean's deployment descriptor rather than in the class files, and 3) Although the Finish button is enabled, the user must continue through all the wizard screens and add the class files for all of the bean's classes (home, remote, localHome, local). If Finish is pressed before this last step is taken, the results will be inconsistent. An exception may appear or the EJB's finder and ejbSelect (for a 2.x bean) may not be generated as expected.

Is it best to use EJB-QL with an IDE rather than writing it out free-hand ?
regards
[ September 21, 2003: Message edited by: HS Thomas ]
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
It depends on whether using the IDE improves your productivity. I haven't used an IDE with this kind of EJB-QL Wizard (if there was such a widget, I wasn't aware of it) so I can't retrospect on my own experiences.
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Thanks Lasse.
This was an article on SUN ONE Forte !I'll see if I can find the link again.
regards
 
GeeCON Prague 2014
 
subject: EJB-QL and operators