use of org.sql.generation.api.grammar.query.joins.JoinType in project qi4j-sdk by Qi4j.
the class AbstractSQLQuerying method constructQueryForPredicate.
protected //
QuerySpecification constructQueryForPredicate(//
Specification<Composite> predicate, //
PropertyFunction<?> propRef, //
TraversedAssoOrManyAssoRef assoRef, //
Boolean includeLastAssoPathTable, //
Boolean negationActive, //
SQLVendor vendor, //
org.sql.generation.api.grammar.booleans.BooleanExpression entityTypeCondition, //
WhereClauseProcessor whereClauseGenerator) {
Integer startingIndex = 0;
TableReferenceFactory t = vendor.getTableReferenceFactory();
QuerySpecificationBuilder builder = this.getBuilderForPredicate(vendor, TABLE_NAME_PREFIX + startingIndex);
TableReferenceBuilder from = t.tableBuilder(t.table(t.tableName(this._state.schemaName().get(), DBNames.ENTITY_TABLE_NAME), t.tableAlias(TABLE_NAME_PREFIX + startingIndex)));
this.addTypeJoin(vendor, from, startingIndex);
Integer lastTableIndex = null;
JoinType joinStyle = this.getTableJoinStyle(predicate, negationActive);
if (propRef == null && assoRef != null && assoRef._hasRefs) {
lastTableIndex = this.traverseAssociationPath(assoRef, startingIndex, startingIndex + 1, vendor, from, joinStyle, includeLastAssoPathTable);
} else if (assoRef == null || !assoRef._hasRefs) {
lastTableIndex = this.traversePropertyPath(propRef, startingIndex, startingIndex + 1, vendor, from, joinStyle);
} else {
throw new InternalError("Can not have both property reference and association reference (non-)nulls [propRef=" + propRef + ", assoRef=" + assoRef + ", predicate=" + predicate + "].");
}
builder.getFrom().addTableReferences(from);
BooleanBuilder afterWhere = vendor.getBooleanFactory().booleanBuilder();
whereClauseGenerator.processWhereClause(builder, afterWhere, joinStyle, startingIndex, lastTableIndex);
BooleanBuilder where = builder.getWhere();
if (negationActive) {
where.not();
}
where.and(afterWhere.createExpression());
where.and(entityTypeCondition);
builder.trimGroupBy();
return builder.createExpression();
}
Aggregations