Search in sources :

Example 1 with TableReferenceBuilder

use of org.sql.generation.api.grammar.builders.query.TableReferenceBuilder in project qi4j-sdk by Qi4j.

the class AbstractSQLQuerying method selectAllEntitiesOfCorrectType.

protected QuerySpecificationBuilder selectAllEntitiesOfCorrectType(SQLVendor vendor, org.sql.generation.api.grammar.booleans.BooleanExpression entityTypeCondition) {
    TableReferenceFactory t = vendor.getTableReferenceFactory();
    String tableAlias = TABLE_NAME_PREFIX + "0";
    TableReferenceBuilder from = t.tableBuilder(t.table(t.tableName(this._state.schemaName().get(), DBNames.ENTITY_TABLE_NAME), t.tableAlias(tableAlias)));
    this.addTypeJoin(vendor, from, 0);
    QuerySpecificationBuilder query = this.getBuilderForPredicate(vendor, tableAlias);
    query.getFrom().addTableReferences(from);
    query.getWhere().reset(entityTypeCondition);
    return query;
}
Also used : TableReferenceFactory(org.sql.generation.api.grammar.factories.TableReferenceFactory) QuerySpecificationBuilder(org.sql.generation.api.grammar.builders.query.QuerySpecificationBuilder) TableReferenceBuilder(org.sql.generation.api.grammar.builders.query.TableReferenceBuilder)

Example 2 with TableReferenceBuilder

use of org.sql.generation.api.grammar.builders.query.TableReferenceBuilder 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

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