Search in sources :

Example 46 with Condition

use of org.jooq.Condition in project waltz by khartec.

the class SqlServerOrganisationalUnitSearch method search.

@Override
public List<OrganisationalUnit> search(DSLContext dsl, String query, EntitySearchOptions options) {
    List<String> terms = mkTerms(query);
    if (terms.isEmpty()) {
        return Collections.emptyList();
    }
    Condition nameCondition = terms.stream().map(term -> ORGANISATIONAL_UNIT.NAME.like("%" + term + "%")).collect(Collectors.reducing(DSL.trueCondition(), (acc, frag) -> acc.and(frag)));
    List<OrganisationalUnit> orgUnitsViaName = dsl.selectDistinct(ORGANISATIONAL_UNIT.fields()).from(ORGANISATIONAL_UNIT).where(nameCondition).orderBy(ORGANISATIONAL_UNIT.NAME).limit(options.limit()).fetch(OrganisationalUnitDao.TO_DOMAIN_MAPPER);
    List<OrganisationalUnit> orgUnitsViaFullText = dsl.select(ORGANISATIONAL_UNIT.fields()).from(ORGANISATIONAL_UNIT).where(JooqUtilities.MSSQL.mkContainsPrefix(terms)).limit(options.limit()).fetch(OrganisationalUnitDao.TO_DOMAIN_MAPPER);
    return new ArrayList<>(orderedUnion(orgUnitsViaName, orgUnitsViaFullText));
}
Also used : Condition(org.jooq.Condition) DSL(org.jooq.impl.DSL) OrganisationalUnit(com.khartec.waltz.model.orgunit.OrganisationalUnit) OrganisationalUnitDao(com.khartec.waltz.data.orgunit.OrganisationalUnitDao) Collectors(java.util.stream.Collectors) Condition(org.jooq.Condition) ArrayList(java.util.ArrayList) List(java.util.List) ORGANISATIONAL_UNIT(com.khartec.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT) DSLContext(org.jooq.DSLContext) EntitySearchOptions(com.khartec.waltz.model.entity_search.EntitySearchOptions) SearchUtilities.mkTerms(com.khartec.waltz.data.SearchUtilities.mkTerms) JooqUtilities(com.khartec.waltz.data.JooqUtilities) DatabaseVendorSpecific(com.khartec.waltz.data.DatabaseVendorSpecific) Collections(java.util.Collections) SetUtilities.orderedUnion(com.khartec.waltz.common.SetUtilities.orderedUnion) FullTextSearch(com.khartec.waltz.data.FullTextSearch) ArrayList(java.util.ArrayList) OrganisationalUnit(com.khartec.waltz.model.orgunit.OrganisationalUnit)

Example 47 with Condition

use of org.jooq.Condition in project apex-malhar by apache.

the class AbstractJdbcPollInputOperator method getRecordsCount.

/**
 * Finds the total number of rows in the table
 *
 * @return number of records in table
 */
private int getRecordsCount(Object lowerBoundKey) throws SQLException {
    Condition condition = DSL.trueCondition();
    if (getWhereCondition() != null) {
        condition = condition.and(getWhereCondition());
    }
    if (isPollerPartition && lowerBoundKey != null) {
        condition = andLowerBoundKeyCondition(condition, lowerBoundKey);
    }
    int recordsCount = dslContext.select(DSL.count()).from(getTableName()).where(condition).fetchOne(0, int.class);
    return recordsCount;
}
Also used : Condition(org.jooq.Condition)

Aggregations

Condition (org.jooq.Condition)47 Field (org.jooq.Field)17 ArrayList (java.util.ArrayList)14 List (java.util.List)11 GroupField (org.jooq.GroupField)11 SortField (org.jooq.SortField)11 TableField (org.jooq.TableField)11 DSLContext (org.jooq.DSLContext)7 Record1 (org.jooq.Record1)7 SearchUtilities.mkTerms (com.khartec.waltz.data.SearchUtilities.mkTerms)6 Collectors (java.util.stream.Collectors)6 DSL (org.jooq.impl.DSL)6 EntitySearchOptions (com.khartec.waltz.model.entity_search.EntitySearchOptions)5 SetUtilities.orderedUnion (com.khartec.waltz.common.SetUtilities.orderedUnion)4 DatabaseVendorSpecific (com.khartec.waltz.data.DatabaseVendorSpecific)4 FullTextSearch (com.khartec.waltz.data.FullTextSearch)4 JooqUtilities (com.khartec.waltz.data.JooqUtilities)4 Collections.emptyList (java.util.Collections.emptyList)4 Record (org.jooq.Record)4 EntityKind (com.khartec.waltz.model.EntityKind)3