// Create the container table if not yet present in the statement
stmt.newTableExpression(containerTable, containerRangeVar);
}
// Reverse collection contains query so join back to the owner
ScalarExpression ownerExpr = ownerMapping.newScalarExpression(stmt, ownerTe);
ScalarExpression ownerSetExpr = this.ownerMapping.newScalarExpression(stmt,
stmt.getTableExpression(containerRangeVar));
stmt.andCondition(ownerExpr.eq(ownerSetExpr), true);
}
else
{
if (elementExpr.getLogicSetExpression().getMainTable() == filteredElementTable)
{
// Element expression is of the container table
// Simple example is "SELECT FROM MyType WHERE field1.contains(this)"
// so candidate is MyType, element type is MyType and the element we are checking
// is MyType.
if (stmt.getTableExpression(containerRangeVar) == null)
{
// Why???????????????
containerRangeVar = elementTableAlias;
}
if (stmt.getTableExpression(containerRangeVar) == null)
{
// Create the container table if not yet present in the statement
stmt.newTableExpression(containerTable, containerRangeVar);
}
ScalarExpression ownerExpr = ownerMapping.newScalarExpression(stmt, ownerTe);
ScalarExpression ownerSetExpr = this.ownerMapping.newScalarExpression(stmt,
stmt.getTableExpression(containerRangeVar));
stmt.andCondition(ownerExpr.eq(ownerSetExpr), true);
}
else
{
// Element is of a different table
// Simple example is "SELECT FROM MyType WHERE field1.contains(field2)"
// so candidate is MyType, element type is MyElement, and the element we are checking
// is MyType.field2. This creates an INNER JOIN MYTYPES.ID -> MYELEMENT.FK
if (stmt.getTableExpression(containerRangeVar) == null)
{
// Create the container table if not yet present in the statement
stmt.newTableExpression(containerTable, containerRangeVar);
}
// Add a join from the owner table to the container table
ScalarExpression ownerExpr = ownerMapping.newScalarExpression(stmt, ownerTe);
ScalarExpression ownerSetExpr = this.ownerMapping.newScalarExpression(stmt,
stmt.getTableExpression(containerRangeVar));
stmt.innerJoin(ownerExpr, ownerSetExpr, stmt.getTableExpression(containerRangeVar), true, true);
}
}
}