Search in sources :

Example 1 with JoinType

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();
}
Also used : TableReferenceFactory(org.sql.generation.api.grammar.factories.TableReferenceFactory) BooleanBuilder(org.sql.generation.api.grammar.builders.booleans.BooleanBuilder) QuerySpecificationBuilder(org.sql.generation.api.grammar.builders.query.QuerySpecificationBuilder) JoinType(org.sql.generation.api.grammar.query.joins.JoinType) TableReferenceBuilder(org.sql.generation.api.grammar.builders.query.TableReferenceBuilder)

Aggregations

BooleanBuilder (org.sql.generation.api.grammar.builders.booleans.BooleanBuilder)1 QuerySpecificationBuilder (org.sql.generation.api.grammar.builders.query.QuerySpecificationBuilder)1 TableReferenceBuilder (org.sql.generation.api.grammar.builders.query.TableReferenceBuilder)1 TableReferenceFactory (org.sql.generation.api.grammar.factories.TableReferenceFactory)1 JoinType (org.sql.generation.api.grammar.query.joins.JoinType)1