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
posted 16 years ago
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).
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 ]
posted 16 years ago
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.