use of org.sql.generation.api.grammar.builders.query.QueryBuilder in project qi4j-sdk by Qi4j.
the class AbstractSQLQuerying method processBooleanExpression.
protected QueryBuilder processBooleanExpression(Specification<Composite> expression, Boolean negationActive, SQLVendor vendor, org.sql.generation.api.grammar.booleans.BooleanExpression entityTypeCondition, Map<String, Object> variables, List<Object> values, List<Integer> valueSQLTypes) {
QueryBuilder result = null;
if (expression == null) {
QueryFactory q = vendor.getQueryFactory();
result = q.queryBuilder(this.selectAllEntitiesOfCorrectType(vendor, entityTypeCondition).createExpression());
} else {
if (EXPRESSION_PROCESSORS.containsKey(expression.getClass())) {
result = EXPRESSION_PROCESSORS.get(expression.getClass()).processBooleanExpression(this, expression, negationActive, vendor, entityTypeCondition, variables, values, valueSQLTypes);
} else {
throw new UnsupportedOperationException("Expression " + expression + " of type " + expression.getClass() + " is not supported");
}
}
return result;
}
use of org.sql.generation.api.grammar.builders.query.QueryBuilder in project qi4j-sdk by Qi4j.
the class AbstractSQLQuerying method finalizeContainsQuery.
protected QueryBuilder finalizeContainsQuery(SQLVendor vendor, QuerySpecification contains, org.sql.generation.api.grammar.booleans.BooleanExpression entityTypeCondition, Boolean negationActive) {
QueryFactory q = vendor.getQueryFactory();
QueryBuilder result;
if (negationActive) {
result = q.queryBuilder(this.selectAllEntitiesOfCorrectType(vendor, entityTypeCondition).createExpression()).except(contains);
} else {
result = q.queryBuilder(contains);
}
return result;
}
use of org.sql.generation.api.grammar.builders.query.QueryBuilder in project qi4j-sdk by Qi4j.
the class AbstractSQLQuerying method constructQuery.
@Override
public //
String constructQuery(//
Class<?> resultType, //
Specification<Composite> whereClause, //
OrderBy[] orderBySegments, //
Integer firstResult, //
Integer maxResults, //
Map<String, Object> variables, //
List<Object> values, //
List<Integer> valueSQLTypes, //
Boolean countOnly) throws EntityFinderException {
SQLVendor vendor = this.descriptor.metaInfo(SQLVendor.class);
QueryFactory q = vendor.getQueryFactory();
TableReferenceFactory t = vendor.getTableReferenceFactory();
LiteralFactory l = vendor.getLiteralFactory();
ColumnsFactory c = vendor.getColumnsFactory();
ColumnReference mainColumn = c.colName(TABLE_NAME_PREFIX + "0", DBNames.ENTITY_TABLE_IDENTITY_COLUMN_NAME);
if (countOnly) {
mainColumn = c.colExp(l.func(SQLFunctions.COUNT, mainColumn));
}
QueryBuilder innerBuilder = this.processBooleanExpression(whereClause, false, vendor, this.createTypeCondition(resultType, vendor), variables, values, valueSQLTypes);
QuerySpecificationBuilder mainQuery = q.querySpecificationBuilder();
mainQuery.getSelect().addUnnamedColumns(mainColumn);
mainQuery.getFrom().addTableReferences(t.tableBuilder(t.table(q.createQuery(innerBuilder.createExpression()), t.tableAlias(TABLE_NAME_PREFIX + "0"))));
this.processOrderBySegments(orderBySegments, vendor, mainQuery);
QueryExpression finalMainQuery = this.finalizeQuery(vendor, mainQuery, resultType, whereClause, orderBySegments, firstResult, maxResults, variables, values, valueSQLTypes, countOnly);
String result = vendor.toString(finalMainQuery);
LOGGER.info("SQL query:\n" + result);
return result;
}
Aggregations