...
The SQLGeneration class combined with the PMSFormula class contain the code necessary for generating SQL based on the MQL model. First, an optimal join path is determined that contains all selected and referenced business tables. From there, the SQL is generated in seven generation steps. These generation steps include Select, From, Join, Where, Group By, Having, and Order By.
Join Path Algorithm
The getShortestPathBetween() method determines the shortest path between the list of included tables within the MQL Query.
The algorithm first determines if there is an existing path between all selected tables. If not, the algorithm continues to add new tables to the list until a path is discovered. If more than one path is available with a certain number of tables, the algorithm uses the relative size values if specified to determine which path to traverse in the SQL Join.
Select
The generateSelect() method traverses the set of selections and renders those selections to the SQL string buffer. This method determines the SQL column aliases. It also calls getBusinessColumnSQL() which renders each individual business column in three different ways. Either as an MQL Formula, an aggregate function, or as a standard SQL column.
From
The generateFrom() method traverses the set of included business tables and renders those tables to the SQL string buffer.
Joins
The generateJoins() method traverses the set of included RelationMetas and renders them to the SQL string buffer via the getJoin() method
Where
The generateWhere() method renders all WhereCondition's that are not part of an aggregate column.
Group By
The generateGroupBy() method renders the non aggregate columns in this section, creating the correct SQL for group by statements.
Having
The generateHaving() method renders all the Where Conditions of aggregate columns.
Order By
The generateOrderBy() method renders all the Order By business columns
...
The PMSFormula class is used in various contexts while generating SQL from MQL. These contexts include Business Column Exact Formula rendering, Relation Complex Join rendering, and Constraint rendering.
Business Column Exact Formula Rendering
Used within the SQLGeneration.getBusinessColumnSQL() method when a business column is configured as "exact", the formula specified as part of the business column is parsed as an open formula and then rendered as SQL.
Relation Complex Join Rendering
Used within the SQLGeneration.getJoin() method when a Relation is set to complex, the complex join string is parsed as open formula and rendered to SQL.
Constraint Rendering
Constraints are rendered using PMSFormula. Each WhereCondition class contains a PMSFormula object which manages the SQL rendering. Constraints are parsed and resolved before SQL generation, to determine which business tables are referenced. This is an important step so that the Join algorithm contains the correct set of tables.