Search in sources :

Example 11 with LiteralFactory

use of org.sql.generation.api.grammar.factories.LiteralFactory in project qi4j-sdk by Qi4j.

the class AbstractSQLQuerying method createTypeCondition.

protected org.sql.generation.api.grammar.booleans.BooleanExpression createTypeCondition(Class<?> resultType, SQLVendor vendor) {
    BooleanFactory b = vendor.getBooleanFactory();
    LiteralFactory l = vendor.getLiteralFactory();
    ColumnsFactory c = vendor.getColumnsFactory();
    List<Integer> typeIDs = this.getEntityTypeIDs(resultType);
    InBuilder in = b.inBuilder(c.colName(TABLE_NAME_PREFIX + TYPE_TABLE_SUFFIX, DBNames.ENTITY_TYPES_TABLE_PK_COLUMN_NAME));
    for (Integer i : typeIDs) {
        in.addValues(l.n(i));
    }
    return in.createExpression();
}
Also used : ColumnsFactory(org.sql.generation.api.grammar.factories.ColumnsFactory) InBuilder(org.sql.generation.api.grammar.builders.booleans.InBuilder) BooleanFactory(org.sql.generation.api.grammar.factories.BooleanFactory) LiteralFactory(org.sql.generation.api.grammar.factories.LiteralFactory)

Example 12 with LiteralFactory

use of org.sql.generation.api.grammar.factories.LiteralFactory 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;
}
Also used : TableReferenceFactory(org.sql.generation.api.grammar.factories.TableReferenceFactory) QueryFactory(org.sql.generation.api.grammar.factories.QueryFactory) ColumnsFactory(org.sql.generation.api.grammar.factories.ColumnsFactory) QuerySpecificationBuilder(org.sql.generation.api.grammar.builders.query.QuerySpecificationBuilder) SQLVendor(org.sql.generation.api.vendor.SQLVendor) QueryBuilder(org.sql.generation.api.grammar.builders.query.QueryBuilder) QueryExpression(org.sql.generation.api.grammar.query.QueryExpression) LiteralFactory(org.sql.generation.api.grammar.factories.LiteralFactory) ColumnReference(org.sql.generation.api.grammar.query.ColumnReference)

Aggregations

LiteralFactory (org.sql.generation.api.grammar.factories.LiteralFactory)12 TableReferenceFactory (org.sql.generation.api.grammar.factories.TableReferenceFactory)11 ColumnsFactory (org.sql.generation.api.grammar.factories.ColumnsFactory)8 ModificationFactory (org.sql.generation.api.grammar.factories.ModificationFactory)8 BooleanFactory (org.sql.generation.api.grammar.factories.BooleanFactory)6 QueryFactory (org.sql.generation.api.grammar.factories.QueryFactory)4 ColumnSourceByValuesBuilder (org.sql.generation.api.grammar.builders.modification.ColumnSourceByValuesBuilder)3 QuerySpecificationBuilder (org.sql.generation.api.grammar.builders.query.QuerySpecificationBuilder)3 QNameInfo (org.qi4j.index.sql.support.common.QNameInfo)2 SQLVendor (org.sql.generation.api.vendor.SQLVendor)2 AccessibleObject (java.lang.reflect.AccessibleObject)1 BigInteger (java.math.BigInteger)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 EntityDescriptor (org.qi4j.api.entity.EntityDescriptor)1 Property (org.qi4j.api.property.Property)1