| Summary: | add convenience method on FormDataStatementBuilder for replacing tagged parts in a select statement | ||
|---|---|---|---|
| Product: | z_Archived | Reporter: | Andi Bur <andi.bur> |
| Component: | Scout | Assignee: | Project Inbox <scout.core-inbox> |
| Status: | CLOSED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | ||
| Version: | unspecified | ||
| Target Milestone: | --- | ||
| Hardware: | All | ||
| OS: | All | ||
| Whiteboard: | |||
Added new method and fixed replacement of <whereParts/> (tag content was missing). ticket closed. deliverd as part of eclipse scout 3.8.0 (juno release train) |
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());