Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 365913 - add convenience method on FormDataStatementBuilder for replacing tagged parts in a select statement
Summary: add convenience method on FormDataStatementBuilder for replacing tagged parts...
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Scout (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-07 10:28 EST by Andi Bur CLA
Modified: 2021-08-19 11:18 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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)