Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 365913

Summary: add convenience method on FormDataStatementBuilder for replacing tagged parts in a select statement
Product: z_Archived Reporter: Andi Bur <andi.bur>
Component: ScoutAssignee: Project Inbox <scout.core-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Andi Bur CLA 2011-12-07 10:28:24 EST
Add a convenience method on the FormDataStatementBuilder that replaces tags in an SQL statement by an EntityContribution.

Example: Dynamic SQL statements are often written in the following way

FormDataStatementBuilder builder = ....;
String attributes = ", PA.STREET, PA.CITY ";
String tables = ", PERSON_ADDRESS PA ";
String constraints = "AND PA.PERSON_ID = P.PERSON_ID AND PA.TYPE = 'MAIN_ADDRESS'";

String sql = "SELECT P.NAME, " + 
             "       P.FIRST_NAME " + 
             attributes +
             "FROM   PERSON P " +
             tables + 
             "WHERE  P.PERSON_ID = 'bob' " +
             constraints + " " +
             bulder.getWhereConstraints();


Scout however already provides a superior way:

String sql = "SELECT <selectParts>P.NAME, P.FIRST_NAME</selectParts> " + 
             "FROM   <fromParts>PERSON P</fromParts " +
             "WHERE  <whereParts>P.PERSON_ID = 'bob'</whereParts> ";

EntityContribution c = new EntityContribution();
c.getSelectParts().add("PA.STREET");
c.getSelectParts().add("PA.CITY");
c.getFromParts().add("PERSON_ADDRESS PA");
c.getWhereParts().add("PA.PERSON_ID = P.PERSON_ID AND PA.TYPE = 'MAIN_ADDRESS'");

The actual SQL statement can be built and used later on by calling
String replacedSql = builder.createEntityPart(sql, false, c);
Object[][] data = SQL.select(replacedSql + builder.getWhereConstraints(), builder.getBindMap());

The new method should wrap the invocation of createEntityPart and the EntityContribution's whereParts should be extended by the builder's getWhereConstraints().

String replacedSql = builder.createSelectStatement(sql, c);
Object[][] data = SQL.select(replacedSql, builder.getBindMap());
Comment 1 Andi Bur CLA 2011-12-07 11:23:38 EST
Added new method and fixed replacement of <whereParts/> (tag content was missing).
Comment 2 Matthias Zimmermann CLA 2012-07-09 06:50:56 EDT
ticket closed.
deliverd as part of eclipse scout 3.8.0 (juno release train)