Java源码示例:com.mysema.query.BooleanBuilder

示例1
/**
 * {@inheritDoc}
 */
@Override
public <T, E> BooleanBuilder createPredicateByIn(PathBuilder<T> entity,
        String fieldName, Set<E> values) {

    // Using BooleanBuilder, a cascading builder for
    // Predicate expressions
    BooleanBuilder predicate = new BooleanBuilder();
    if (StringUtils.isEmpty(fieldName) || values.isEmpty()) {
        return predicate;
    }

    // Build the predicate
    predicate.and(createCollectionExpression(entity, fieldName, values));

    return predicate;
}
 
示例2
/**
 * {@inheritDoc}
 */
@Override
public <T, E extends Comparable<?>> SearchResults<T> findByCriteria(
        Class<T> entityClass,
        Map<String, List<String>> filterByAssociations,
        Map<String, List<String>> orderByAssociations,
        DatatablesCriterias datatablesCriterias,
        BooleanBuilder basePredicate, boolean distinct)
        throws IllegalArgumentException {

    Assert.notNull(entityClass);

    // Query DSL builder
    PathBuilder<T> entity = new PathBuilder<T>(entityClass, "entity");

    return findByCriteria(entity, filterByAssociations,
            orderByAssociations, datatablesCriterias, basePredicate,
            distinct, null);
}
 
示例3
/**
 * {@inheritDoc}
 */
@Override
public <T, E extends Comparable<?>> SearchResults<T> findByCriteria(
        Class<T> entityClass,
        Map<String, List<String>> filterByAssociations,
        Map<String, List<String>> orderByAssociations,
        DatatablesCriterias datatablesCriterias,
        BooleanBuilder basePredicate, boolean distinct,
        Object[] rowsOnTopIds) throws IllegalArgumentException {

    Assert.notNull(entityClass);

    // Query DSL builder
    PathBuilder<T> entity = new PathBuilder<T>(entityClass, "entity");

    return findByCriteria(entity, filterByAssociations,
            orderByAssociations, datatablesCriterias, basePredicate,
            distinct, rowsOnTopIds);
}
 
示例4
default Iterable<CollectorItem> findAllByOptionMapAndCollectorIdsIn(Map<String, Object> options, List<ObjectId> collectorIds) {
    PathBuilder<CollectorItem> path = new PathBuilder<>(CollectorItem.class, "collectorItem");
    BooleanBuilder builder = new BooleanBuilder();
    builder.and(path.get("collectorId", ObjectId.class).in(collectorIds));
    options.forEach((key, value) -> builder.and(Objects.isNull(value)?path.get("options", Map.class).get(key, Object.class).isNull():path.get("options", Map.class).get(key, Object.class).eq(value)));
    return findAll(builder.getValue());
}
 
示例5
public JPAQuery createQuery(Predicate predicate) {
    QPermission permission = QPermission.permission;
    QRolePermission rolePermission = QRolePermission.rolePermission;
    QRole role = QRole.role;
    BooleanBuilder builder = new BooleanBuilder();
    builder.and(predicate);
    builder.and(permission.deletedAt.isNull());
    builder.and(rolePermission.deletedAt.isNull());
    builder.and(role.deletedAt.isNull());
    return new JPAQuery(em)
        .from(permission)
        .leftJoin(permission.rolePermission, rolePermission)
        .leftJoin(rolePermission.role, role)
        .where(builder);
}
 
示例6
/**
 * Creates a WHERE clause by the intersection of the given search-arguments
 * 
 * @param entity Entity {@link PathBuilder}. It represents the entity for
 *        class generation and alias-usage for path generation.
 *        <p/>
 *        Example: To retrieve a {@code Customer} with the first name 'Bob'
 *        entity must be a {@link PathBuilder} created for {@code Customer}
 *        class and searchArgs must contain the entry
 *        {@code 'firstName':'Bob'}
 * @param searchArgs Search arguments to be used to create the WHERE clause.
 *        It can contain {@code _operator_} entries for each field that want
 *        to use its own operator. By default {@code EQUALS} operator is
 *        used.
 *        <p/>
 *        Operator entry example: {@code _operator_weight = LT} the
 *        expression for {@code weight} field will do a less-than value
 *        comparison
 * @param conversionService required to transform values
 * @return the WHERE clause
 */
public static <T> BooleanBuilder createPredicateByAnd(
        PathBuilder<T> entity, Map<String, Object> searchArgs,
        ConversionService conversionService) {

    // Using BooleanBuilder, a cascading builder for
    // Predicate expressions
    BooleanBuilder predicate = new BooleanBuilder();
    if (searchArgs == null || searchArgs.isEmpty()) {
        return predicate;
    }

    // Build the predicate
    for (Entry<String, Object> entry : searchArgs.entrySet()) {
        String key = entry.getKey();
        // can
        // contain "_operator_"
        // entries for each
        // field
        Object valueToSearch = entry.getValue();
        String operator = (String) searchArgs.get(OPERATOR_PREFIX
                .concat(key));

        // If value to search is a collection, creates a predicate for
        // each object of the collection
        if (valueToSearch instanceof Collection) {
            @SuppressWarnings("unchecked")
            Collection<Object> valueColl = (Collection<Object>) valueToSearch;
            for (Object valueObj : valueColl) {
                predicate.and(createObjectExpression(entity, key, valueObj,
                        operator, conversionService));
            }
        }
        else {
            predicate.and(createObjectExpression(entity, key,
                    valueToSearch, operator, conversionService));
        }
    }
    return predicate;
}
 
示例7
/**
 * {@inheritDoc}
 */
@Override
public <T> BooleanBuilder createPredicateByAnd(PathBuilder<T> entity,
        Map<String, Object> searchArgs) {

    // Using BooleanBuilder, a cascading builder for
    // Predicate expressions
    BooleanBuilder predicate = new BooleanBuilder();
    if (searchArgs == null || searchArgs.isEmpty()) {
        return predicate;
    }

    // Build the predicate
    for (Entry<String, Object> entry : searchArgs.entrySet()) {
        String key = entry.getKey();
        // can
        // contain "_operator_"
        // entries for each
        // field
        Object valueToSearch = entry.getValue();
        String operator = (String) searchArgs.get(OPERATOR_PREFIX
                .concat(key));

        // If value to search is a collection, creates a predicate for
        // each object of the collection
        if (valueToSearch instanceof Collection) {
            @SuppressWarnings("unchecked")
            Collection<Object> valueColl = (Collection<Object>) valueToSearch;
            for (Object valueObj : valueColl) {
                predicate.and(createObjectExpression(entity, key, valueObj,
                        operator));
            }
        }
        else {
            predicate.and(createObjectExpression(entity, key,
                    valueToSearch, operator));
        }
    }
    return predicate;
}
 
示例8
/**
 * {@inheritDoc}
 */
@Override
public <T, E extends Comparable<?>> SearchResults<T> findByCriteria(
        PathBuilder<T> entity,
        Map<String, List<String>> filterByAssociations,
        Map<String, List<String>> orderByAssociations,
        DatatablesCriterias datatablesCriterias,
        BooleanBuilder basePredicate) throws IllegalArgumentException {
    return findByCriteria(entity, filterByAssociations,
            orderByAssociations, datatablesCriterias, basePredicate, false,
            null);
}
 
示例9
/**
 * {@inheritDoc}
 */
@Override
public <T, E extends Comparable<?>> SearchResults<T> findByCriteria(
        PathBuilder<T> entity, DatatablesCriterias datatablesCriterias,
        BooleanBuilder basePredicate) throws IllegalArgumentException {
    return findByCriteria(entity, null, null, datatablesCriterias,
            basePredicate, false, null);
}
 
示例10
/**
 * {@inheritDoc}
 */
@Override
public <T, E extends Comparable<?>> SearchResults<T> findByCriteria(
        PathBuilder<T> entity, DatatablesCriterias datatablesCriterias,
        BooleanBuilder basePredicate, Object[] rowsOnTopIds)
        throws IllegalArgumentException {
    return findByCriteria(entity, null, null, datatablesCriterias,
            basePredicate, false, rowsOnTopIds);
}
 
示例11
/**
 * {@inheritDoc}
 */
@Override
public <T, E extends Comparable<?>> SearchResults<T> findByCriteria(
        PathBuilder<T> entity,
        Map<String, List<String>> filterByAssociations,
        Map<String, List<String>> orderByAssociations,
        DatatablesCriterias datatablesCriterias,
        BooleanBuilder basePredicate, boolean distinct)
        throws IllegalArgumentException {

    return findByCriteria(entity, null, null, datatablesCriterias,
            basePredicate, false, null);
}
 
示例12
default List<Component> findByCollectorTypeAndItemIdIn(CollectorType collectorType, List<ObjectId> collectorItemIds) {
    BooleanBuilder builder = new BooleanBuilder();
    PathBuilder<Component> path = new PathBuilder<>(Component.class, "components");
    builder.and(path.get("collectorItems", Map.class).get(collectorType.toString(),List.class).get("id", ObjectId.class).in(collectorItemIds));
    return (List<Component>) findAll(builder.getValue());
}
 
示例13
default Iterable<CollectorItem> findAllByOptionNameValue(String optionName, String optionValue) {
    PathBuilder<CollectorItem> path = new PathBuilder<>(CollectorItem.class, "collectorItem");
    BooleanBuilder builder = new BooleanBuilder();
    builder.and(path.get("options", Map.class).get(optionName, String.class).eq(optionValue));
    return findAll(builder.getValue());
}
 
示例14
/**
 * Execute a select query on entityClass using <a
 * href="http://www.querydsl.com/">Querydsl</a> which enables the
 * construction of type-safe SQL-like queries.
 * 
 * @param entityClass entity to use in search
 * @param filterByAssociations (optional) for each related entity to join
 *        contain as key the name of the association and as value the List
 *        of related entity fields to filter by
 * @param orderByAssociations (optional) for each related entity to order
 *        contain as key the name of the association and as value the List
 *        of related entity fields to order by
 * @param entityManager {@code entityClass} {@link EntityManager}
 * @param datatablesCriterias datatables parameters for query
 * @param basePredicate (optional) base filter conditions
 * @param distinct use distinct query
 * @return
 * @deprecated see
 *             {@link #findByCriteria(Class, Map, Map, EntityManager, DatatablesCriterias, BooleanBuilder, boolean, ConversionService, MessageSource, Object[])}
 */
public static <T, E extends Comparable<?>> SearchResults<T> findByCriteria(
        Class<T> entityClass,
        Map<String, List<String>> filterByAssociations,
        Map<String, List<String>> orderByAssociations,
        EntityManager entityManager,
        DatatablesCriterias datatablesCriterias,
        BooleanBuilder basePredicate, boolean distinct,
        ConversionService conversionService, MessageSource messageSource)
        throws IllegalArgumentException {

    Assert.notNull(entityClass);

    // Query DSL builder
    PathBuilder<T> entity = new PathBuilder<T>(entityClass, "entity");

    return findByCriteria(entity, filterByAssociations,
            orderByAssociations, entityManager, datatablesCriterias,
            basePredicate, distinct, conversionService, messageSource, null);
}
 
示例15
/**
 * Execute a select query on entityClass using {@code DatatablesCriterias}
 * information for filter, sort and paginate result.
 * <p/>
 * This method can receive rows-on-top as parameter on
 * <code>baseSearchValueMap</code> using {@link #ROWS_ON_TOP_IDS_PARAM}
 * name.
 * 
 * @param entityClass entity to use in search
 * @param filterByAssociations (optional) for each related entity to join
 *        contain as key the name of the association and as value the List
 *        of related entity fields to filter by
 * @param orderByAssociations (optional) for each related entity to order
 *        contain as key the name of the association and as value the List
 *        of related entity fields to order by
 * @param entityManager {@code entityClass} {@link EntityManager}
 * @param datatablesCriterias datatables parameters for query
 * @param basePredicate (optional) base filter
 * @param conversionService required by filter-by-expression and rows-on-top
 *        (otherwise optional)
 * @param messageSource required by filter-by-expression (otherwise
 *        optional)
 * @param rowsOnTopIds (optional) array with id of rows to show on top of
 *        result list
 * @return
 * @throws IllegalArgumentException
 */
public static <T, E extends Comparable<?>> SearchResults<T> findByCriteria(
        Class<T> entityClass,
        Map<String, List<String>> filterByAssociations,
        Map<String, List<String>> orderByAssociations,
        EntityManager entityManager,
        DatatablesCriterias datatablesCriterias,
        BooleanBuilder basePredicate, boolean distinct,
        ConversionService conversionService, MessageSource messageSource,
        Object[] rowsOnTopIds) throws IllegalArgumentException {

    Assert.notNull(entityClass);

    // Query DSL builder
    PathBuilder<T> entity = new PathBuilder<T>(entityClass, "entity");

    return findByCriteria(entity, filterByAssociations,
            orderByAssociations, entityManager, datatablesCriterias,
            basePredicate, distinct, conversionService, messageSource,
            rowsOnTopIds);
}
 
示例16
/**
 * Prepares filter part for a query of findByCriteria
 * 
 * @param entity
 * @param filterByAssociations
 * @param datatablesCriterias
 * @param associationMap
 * @param filtersByColumnPredicate
 * @return
 */
private static <T> BooleanBuilder prepareQueryFilterPart(
        PathBuilder<T> entity,
        Map<String, List<String>> filterByAssociations,
        DatatablesCriterias datatablesCriterias,
        Map<String, PathBuilder<?>> associationMap,
        BooleanBuilder filtersByColumnPredicate,
        ConversionService conversionService, MessageSource messageSource) {
    // Add filterable columns only

    LOGGER.debug("Preparing filter-column expression for entity {}...",
            entity.getType());

    Predicate filterExpression;

    for (ColumnDef column : datatablesCriterias.getColumnDefs()) {

        // Each column has its own search by value
        String searchStr = column.getSearch();

        // true if the search must include this column
        boolean findInColumn = column.isFilterable()
                && StringUtils.isNotEmpty(searchStr);

        if (findInColumn) {

            // Entity field name and type
            String fieldName = unescapeDot(column.getName());

            LOGGER.trace("Preparing filter for '{}' by '{}'...", fieldName,
                    searchStr);

            // On column search, connect where clauses together by
            // AND
            // because we want found the records which columns
            // match with column filters
            filterExpression = QuerydslUtils.createExpression(entity,
                    fieldName, searchStr, conversionService, messageSource);

            filtersByColumnPredicate = filtersByColumnPredicate
                    .and(filterExpression);

            LOGGER.trace("filtersByColumnPredicate AND '{}'",
                    filterExpression);

            // TODO: Este codigo se puede pasar a QuerydslUtils ?

            // If column is an association and there are given
            // join attributes, add those attributes to WHERE
            // predicates
            List<String> attributes = filterByAssociations.get(fieldName);
            if (attributes != null && attributes.size() > 0) {

                // Filters of associated entity properties
                BooleanBuilder filtersByAssociationPredicate = new BooleanBuilder();

                PathBuilder<?> associationPath = associationMap
                        .get(fieldName);
                List<String> associationFields = filterByAssociations
                        .get(fieldName);

                for (String associationFieldName : associationFields) {

                    // On association search, connect
                    // associated entity where clauses by OR
                    // because all assoc entity properties are
                    // inside the same column and any of its
                    // property value can match with given search
                    // value
                    filterExpression = QuerydslUtils.createExpression(
                            associationPath, associationFieldName,
                            searchStr, conversionService);
                    filtersByAssociationPredicate = filtersByAssociationPredicate
                            .or(filterExpression);

                    LOGGER.trace("filtersByAssociationPredicate OR '{}'",
                            filterExpression);
                }

                filtersByColumnPredicate = filtersByColumnPredicate
                        .and(filtersByAssociationPredicate.getValue());

                LOGGER.trace("filtersByColumnPredicate AND '{}'",
                        filtersByAssociationPredicate.getValue());
            }
        }
    }

    LOGGER.debug("Final filtersByColumnPredicate  =  '{}'",
            filtersByColumnPredicate);
    return filtersByColumnPredicate;
}
 
示例17
/**
 * Prepare search part for a query of findByCriteria
 * 
 * @param entity
 * @param filterByAssociations
 * @param datatablesCriterias
 * @param findInAllColumns
 * @param associationMap
 * @param filtersByTablePredicate
 * @return
 */
private static <T> BooleanBuilder prepareQuerySearchPart(
        PathBuilder<T> entity,
        Map<String, List<String>> filterByAssociations,
        DatatablesCriterias datatablesCriterias, boolean findInAllColumns,
        Map<String, PathBuilder<?>> associationMap,
        BooleanBuilder filtersByTablePredicate,
        ConversionService conversionService) {
    String searchStr = datatablesCriterias.getSearch();
    if (StringUtils.isEmpty(searchStr)) {
        // Nothing to do
        return filtersByTablePredicate;
    }
    LOGGER.debug(
            "Preparing search expression for '{}' string on entity {}...",
            searchStr, entity.getType());
    if (findInAllColumns) {
        boolean expressionExists = false;
        // Add filterable columns only
        for (ColumnDef column : datatablesCriterias.getColumnDefs()) {
            if (column.isFilterable()) {

                // Entity field name and type
                String fieldName = unescapeDot(column.getName());
                LOGGER.trace("Check expression column {}...", fieldName);

                // Find in all columns means we want to find given
                // value in at least one entity property, so we must
                // join the where clauses by OR
                Predicate expression = QuerydslUtils.createExpression(
                        entity, fieldName, searchStr, conversionService);
                if (expression != null) {
                    filtersByTablePredicate = filtersByTablePredicate
                            .or(expression);
                    LOGGER.trace("Added expression {}", expression);
                    expressionExists = true;
                }

                // If column is an association and there are given
                // join attributes, add those attributes to WHERE
                // predicates
                List<String> attributes = filterByAssociations
                        .get(fieldName);
                if (attributes != null && attributes.size() > 0) {
                    PathBuilder<?> associationPath = associationMap
                            .get(fieldName);
                    List<String> associationFields = filterByAssociations
                            .get(fieldName);

                    for (String associationFieldName : associationFields) {

                        expression = QuerydslUtils.createExpression(
                                associationPath, associationFieldName,
                                searchStr, conversionService);
                        filtersByTablePredicate = filtersByTablePredicate
                                .or(expression);

                        LOGGER.trace(
                                "Added expression (by association) {}",
                                expression);
                    }
                }
            }
        }
        // If expression is null returns error to returns an empty
        // DataSource
        if (!expressionExists) {
            throw new RuntimeException("Expression cannot be null");
        }
    }
    LOGGER.debug("Search expression: {}", filtersByTablePredicate);
    return filtersByTablePredicate;
}
 
示例18
/**
 * Creates a WHERE clause to specify given {@code fieldName} must be equal
 * to one element of the provided Collection.
 * 
 * @param entity Entity {@link PathBuilder}. It represents the entity for
 *        class generation and alias-usage for path generation.
 *        <p/>
 *        Example: To retrieve a {@code Customer} with the first name 'Bob'
 *        entity must be a {@link PathBuilder} created for {@code Customer}
 *        class and searchArgs must contain the entry
 *        {@code 'firstName':'Bob'}
 * @param fieldName Property name in the given entity path. For example:
 *        {@code name} in {@code Pet} entity, {@code firstName} in
 *        {@code Pet.owner} entity.
 * @param values the Set of values to find the given field name, may be null
 * @return the WHERE clause
 */
public static <T, E> BooleanBuilder createPredicateByIn(
        PathBuilder<T> entity, String fieldName, Set<E> values) {

    // Using BooleanBuilder, a cascading builder for
    // Predicate expressions
    BooleanBuilder predicate = new BooleanBuilder();
    if (StringUtils.isEmpty(fieldName) || values.isEmpty()) {
        return predicate;
    }

    // Build the predicate
    predicate.and(createCollectionExpression(entity, fieldName, values));

    return predicate;
}
 
示例19
/**
 * Prepares filter part for a query of findByCriteria
 * 
 * @param entity
 * @param filterByAssociations
 * @param datatablesCriterias
 * @param associationMap
 * @param filtersByColumnPredicate
 * @return
 */
private <T> BooleanBuilder prepareQueryFilterPart(PathBuilder<T> entity,
        Map<String, List<String>> filterByAssociations,
        DatatablesCriterias datatablesCriterias,
        Map<String, PathBuilder<?>> associationMap,
        BooleanBuilder filtersByColumnPredicate) {
    // Add filterable columns only

    LOGGER.debug("Preparing filter-column expression for entity {}...",
            entity.getType());

    Predicate filterExpression;

    for (ColumnDef column : datatablesCriterias.getColumnDefs()) {

        // Each column has its own search by value
        String searchStr = column.getSearch();

        // true if the search must include this column
        boolean findInColumn = column.isFilterable()
                && StringUtils.isNotEmpty(searchStr);

        if (findInColumn) {

            // Entity field name and type
            String fieldName = unescapeDot(column.getName());

            LOGGER.trace("Preparing filter for '{}' by '{}'...", fieldName,
                    searchStr);

            // On column search, connect where clauses together by
            // AND
            // because we want found the records which columns
            // match with column filters
            filterExpression = querydslUtilsBean.createFilterExpression(
                    entity, fieldName, searchStr);

            filtersByColumnPredicate = filtersByColumnPredicate
                    .and(filterExpression);

            LOGGER.trace("filtersByColumnPredicate AND '{}'",
                    filterExpression);

            // TODO: Este codigo se puede pasar a QuerydslUtils ?

            // If column is an association and there are given
            // join attributes, add those attributes to WHERE
            // predicates
            List<String> attributes = filterByAssociations.get(fieldName);
            if (attributes != null && attributes.size() > 0) {

                // Filters of associated entity properties
                BooleanBuilder filtersByAssociationPredicate = new BooleanBuilder();

                PathBuilder<?> associationPath = associationMap
                        .get(fieldName);
                List<String> associationFields = filterByAssociations
                        .get(fieldName);

                for (String associationFieldName : associationFields) {

                    // On association search, connect
                    // associated entity where clauses by OR
                    // because all assoc entity properties are
                    // inside the same column and any of its
                    // property value can match with given search
                    // value
                    filterExpression = querydslUtilsBean
                            .createFilterExpression(associationPath,
                                    associationFieldName, searchStr);
                    filtersByAssociationPredicate = filtersByAssociationPredicate
                            .or(filterExpression);

                    LOGGER.trace("filtersByAssociationPredicate OR '{}'",
                            filterExpression);
                }

                filtersByColumnPredicate = filtersByColumnPredicate
                        .and(filtersByAssociationPredicate.getValue());

                LOGGER.trace("filtersByColumnPredicate AND '{}'",
                        filtersByAssociationPredicate.getValue());
            }
        }
    }

    LOGGER.debug("Final filtersByColumnPredicate  =  '{}'",
            filtersByColumnPredicate);
    return filtersByColumnPredicate;
}
 
示例20
/**
 * Prepare search part for a query of findByCriteria
 * 
 * @param entity
 * @param filterByAssociations
 * @param datatablesCriterias
 * @param findInAllColumns
 * @param associationMap
 * @param filtersByTablePredicate
 * @return
 */
private <T> BooleanBuilder prepareQuerySearchPart(PathBuilder<T> entity,
        Map<String, List<String>> filterByAssociations,
        DatatablesCriterias datatablesCriterias, boolean findInAllColumns,
        Map<String, PathBuilder<?>> associationMap,
        BooleanBuilder filtersByTablePredicate) {
    String searchStr = datatablesCriterias.getSearch();
    if (StringUtils.isEmpty(searchStr)) {
        // Nothing to do
        return filtersByTablePredicate;
    }
    LOGGER.debug(
            "Preparing search expression for '{}' string on entity {}...",
            searchStr, entity.getType());
    if (findInAllColumns) {
        boolean expressionExists = false;
        // Add filterable columns only
        for (ColumnDef column : datatablesCriterias.getColumnDefs()) {
            if (column.isFilterable()) {

                // Entity field name and type
                String fieldName = unescapeDot(column.getName());
                LOGGER.trace("Check expression column {}...", fieldName);

                // Find in all columns means we want to find given
                // value in at least one entity property, so we must
                // join the where clauses by OR
                Predicate expression = querydslUtilsBean
                        .createSearchExpression(entity, fieldName,
                                searchStr);
                if (expression != null) {
                    filtersByTablePredicate = filtersByTablePredicate
                            .or(expression);
                    LOGGER.trace("Added expression {}", expression);
                    expressionExists = true;
                }

                // If column is an association and there are given
                // join attributes, add those attributes to WHERE
                // predicates
                List<String> attributes = filterByAssociations
                        .get(fieldName);
                if (attributes != null && attributes.size() > 0) {
                    PathBuilder<?> associationPath = associationMap
                            .get(fieldName);
                    List<String> associationFields = filterByAssociations
                            .get(fieldName);

                    for (String associationFieldName : associationFields) {

                        expression = querydslUtilsBean
                                .createSearchExpression(associationPath,
                                        associationFieldName, searchStr);
                        filtersByTablePredicate = filtersByTablePredicate
                                .or(expression);

                        LOGGER.trace(
                                "Added expression (by association) {}",
                                expression);
                    }
                }
            }
        }
        // If expression is null returns error to returns an empty
        // DataSource
        if (!expressionExists) {
            throw new RuntimeException("Expression cannot be null");
        }
    }
    LOGGER.debug("Search expression: {}", filtersByTablePredicate);
    return filtersByTablePredicate;
}
 
示例21
@Override
public <T> BooleanBuilder createPredicateByAnd(PathBuilder<T> entity,
        Map<String, Object> searchArgs) {
    BooleanBuilder predicate = super.createPredicateByAnd(entity,
            searchArgs);
    if (searchArgs == null || searchArgs.isEmpty()) {
        return predicate;
    }

    // Build the predicate
    for (Entry<String, Object> entry : searchArgs.entrySet()) {
        String key = entry.getKey();

        // searchArgs can contain dtt_bbox attribute
        if (key.equals(DatatablesUtilsBeanGeoImpl.BOUNDING_BOX_PARAM)) {
            // Getting bbox to Search
            String bBoxToSearch = ((String[]) entry.getValue())[0];
            Geometry bBoxGeometry = null;
            try {
                bBoxGeometry = getConversionService().convert(bBoxToSearch,
                        Geometry.class);
            }
            catch (Exception e) {
                try {
                    // Legacy bbox parameter support (no WKT string)
                    bBoxGeometry = getConversionService().convert(
                            String.format("POLYGON((%s))", bBoxToSearch),
                            Geometry.class);
                }
                catch (Exception e1) {
                    throw new RuntimeException(
                            String.format(
                                    "Error getting map Bounding Box on QuerydslUtils from string: '%s'",
                                    bBoxToSearch), e);
                }
            }
            // Getting fields to filter using bbox
            if (searchArgs
                    .get(DatatablesUtilsBeanGeoImpl.BOUNDING_BOX_FIELDS_PARAM) != null
                    && bBoxGeometry != null) {
                String bBoxFields = ((String[]) searchArgs
                        .get(DatatablesUtilsBeanGeoImpl.BOUNDING_BOX_FIELDS_PARAM))[0];
                String[] separatedFields = StringUtils.split(bBoxFields,
                        ",");
                for (String field : separatedFields) {
                    predicate.or(createIntersectsExpression(entity, field,
                            bBoxGeometry));
                }
            }
        }
    }
    return predicate;
}
 
示例22
/**
 * Execute a select query on entityClass using {@code DatatablesCriterias}
 * information for filter, sort and paginate result.
 * 
 * @param entityClass entity to use in search
 * @param entityManager {@code entityClass} {@link EntityManager}
 * @param datatablesCriterias datatables parameters for query
 * @return
 * @deprecated see
 *             {@link #findByCriteria(Class, Map, Map, EntityManager, DatatablesCriterias, BooleanBuilder, boolean, ConversionService, MessageSource, Object[])}
 */
public static <T> SearchResults<T> findByCriteria(Class<T> entityClass,
        EntityManager entityManager,
        DatatablesCriterias datatablesCriterias,
        ConversionService conversionService, MessageSource messageSource) {
    return findByCriteria(entityClass, null, null, entityManager,
            datatablesCriterias, (BooleanBuilder) null, false,
            conversionService, messageSource, null);
}
 
示例23
/**
 * Execute a select query on entityClass using {@code DatatablesCriterias}
 * information for filter, sort and paginate result.
 * 
 * @param entityClass entity to use in search
 * @param entityManager {@code entityClass} {@link EntityManager}
 * @param datatablesCriterias datatables parameters for query
 * @return
 * @deprecated see
 *             {@link #findByCriteria(Class, Map, Map, EntityManager, DatatablesCriterias, BooleanBuilder, boolean, ConversionService, MessageSource, Object[])}
 */
public static <T> SearchResults<T> findByCriteria(Class<T> entityClass,
        EntityManager entityManager, DatatablesCriterias datatablesCriterias) {
    return findByCriteria(entityClass, null, null, entityManager,
            datatablesCriterias, (BooleanBuilder) null, false, null, null,
            null);
}
 
示例24
/**
 * Execute a select query on entityClass using <a
 * href="http://www.querydsl.com/">Querydsl</a> which enables the
 * construction of type-safe SQL-like queries.
 * 
 * @param entityClass entity to use in search
 * @param filterByAssociations (optional) for each related entity to join
 *        contain as key the name of the association and as value the List
 *        of related entity fields to filter by
 * @param orderByAssociations (optional) for each related entity to order
 *        contain as key the name of the association and as value the List
 *        of related entity fields to order by
 * @param entityManager {@code entityClass} {@link EntityManager}
 * @param datatablesCriterias datatables parameters for query
 * @param basePredicate (optional) base filter conditions
 * @param distinct use distinct query
 * @return
 * @deprecated {@link #findByCriteria(Class, Map, Map, EntityManager, DatatablesCriterias, BooleanBuilder, boolean, ConversionService, MessageSource, Object[])}
 */
public static <T, E extends Comparable<?>> SearchResults<T> findByCriteria(
        Class<T> entityClass,
        Map<String, List<String>> filterByAssociations,
        Map<String, List<String>> orderByAssociations,
        EntityManager entityManager,
        DatatablesCriterias datatablesCriterias,
        BooleanBuilder basePredicate, boolean distinct)
        throws IllegalArgumentException {

    return findByCriteria(entityClass, filterByAssociations,
            orderByAssociations, entityManager, datatablesCriterias,
            basePredicate, distinct, null, null, null);
}
 
示例25
/**
 * Execute a select query on entityClass using <a
 * href="http://www.querydsl.com/">Querydsl</a> which enables the
 * construction of type-safe SQL-like queries.
 * 
 * @param entity builder for entity to use in search. Represents the entity
 *        and gives access to its properties for query purposes
 * @param filterByAssociations (optional) for each related entity to join
 *        contain as key the name of the association and as value the List
 *        of related entity fields to filter by
 * @param orderByAssociations (optional) for each related entity to order
 *        contain as key the name of the association and as value the List
 *        of related entity fields to order by
 * @param entityManager {@code entityClass} {@link EntityManager}
 * @param datatablesCriterias datatables parameters for query
 * @param basePredicate (optional) base filter conditions
 * @param conversionService required by filter-by-expression and rows-on-top
 *        (otherwise optional)
 * @param distinct use distinct query
 * @return
 * @deprecated see
 *             {@link #findByCriteria(Class, EntityManager, DatatablesCriterias, Map, ConversionService, MessageSource)}
 */
public static <T, E extends Comparable<?>> SearchResults<T> findByCriteria(
        PathBuilder<T> entity,
        Map<String, List<String>> filterByAssociations,
        Map<String, List<String>> orderByAssociations,
        EntityManager entityManager,
        DatatablesCriterias datatablesCriterias,
        BooleanBuilder basePredicate, ConversionService conversionService,
        MessageSource messageSource) throws IllegalArgumentException {
    return findByCriteria(entity, filterByAssociations,
            orderByAssociations, entityManager, datatablesCriterias,
            basePredicate, false, conversionService, messageSource, null);
}
 
示例26
/**
 * Execute a select query on entityClass using <a
 * href="http://www.querydsl.com/">Querydsl</a> which enables the
 * construction of type-safe SQL-like queries.
 * 
 * @param entity builder for entity to use in search. Represents the entity
 *        and gives access to its properties for query purposes
 * @param filterByAssociations (optional) for each related entity to join
 *        contain as key the name of the association and as value the List
 *        of related entity fields to filter by
 * @param orderByAssociations (optional) for each related entity to order
 *        contain as key the name of the association and as value the List
 *        of related entity fields to order by
 * @param entityManager {@code entityClass} {@link EntityManager}
 * @param datatablesCriterias datatables parameters for query
 * @param basePredicate (optional) base filter conditions
 * @return
 * @deprecated see
 *             {@link #findByCriteria(PathBuilder, Map, Map, EntityManager, DatatablesCriterias, BooleanBuilder, boolean, ConversionService, MessageSource, Object[])}
 */
public static <T, E extends Comparable<?>> SearchResults<T> findByCriteria(
        PathBuilder<T> entity,
        Map<String, List<String>> filterByAssociations,
        Map<String, List<String>> orderByAssociations,
        EntityManager entityManager,
        DatatablesCriterias datatablesCriterias,
        BooleanBuilder basePredicate) throws IllegalArgumentException {
    return findByCriteria(entity, filterByAssociations,
            orderByAssociations, entityManager, datatablesCriterias,
            basePredicate, false, null, null, null);
}
 
示例27
/**
 * Execute a select query on entityClass using <a
 * href="http://www.querydsl.com/">Querydsl</a> which enables the
 * construction of type-safe SQL-like queries.
 * 
 * @param entity builder for entity to use in search. Represents the entity
 *        and gives access to its properties for query purposes
 * @param entityManager {@code entityClass} {@link EntityManager}
 * @param datatablesCriterias datatables parameters for query
 * @param basePredicate (optional) base filter conditions
 * @param conversionService required by filter-by-expression and rows-on-top
 *        (otherwise optional)
 * @param messageSource required by filter-by-expression (otherwise
 *        optional)
 * @return
 * @deprecated see
 *             {@link #findByCriteria(PathBuilder, Map, Map, EntityManager, DatatablesCriterias, BooleanBuilder, boolean, ConversionService, MessageSource, Object[])}
 */
public static <T, E extends Comparable<?>> SearchResults<T> findByCriteria(
        PathBuilder<T> entity, EntityManager entityManager,
        DatatablesCriterias datatablesCriterias,
        BooleanBuilder basePredicate, ConversionService conversionService,
        MessageSource messageSource) throws IllegalArgumentException {
    return findByCriteria(entity, null, null, entityManager,
            datatablesCriterias, basePredicate, false, conversionService,
            messageSource, null);
}
 
示例28
/**
 * Execute a select query on entityClass using <a
 * href="http://www.querydsl.com/">Querydsl</a> which enables the
 * construction of type-safe SQL-like queries.
 * 
 * @param entity builder for entity to use in search. Represents the entity
 *        and gives access to its properties for query purposes
 * @param entityManager {@code entityClass} {@link EntityManager}
 * @param datatablesCriterias datatables parameters for query
 * @param basePredicate (optional) base filter conditions
 * @param conversionService required by filter-by-expression and rows-on-top
 *        (otherwise optional)
 * @param messageSource required by filter-by-expression (otherwise
 *        optional)
 * @param rowsOnTopIds (optional) array with id of rows to show on top of
 *        result list
 * @return
 * @throws IllegalArgumentException
 */
public static <T, E extends Comparable<?>> SearchResults<T> findByCriteria(
        PathBuilder<T> entity, EntityManager entityManager,
        DatatablesCriterias datatablesCriterias,
        BooleanBuilder basePredicate, ConversionService conversionService,
        MessageSource messageSource, Object[] rowsOnTopIds)
        throws IllegalArgumentException {
    return findByCriteria(entity, null, null, entityManager,
            datatablesCriterias, basePredicate, false, conversionService,
            messageSource, rowsOnTopIds);
}
 
示例29
/**
 * Execute a select query on entityClass using <a
 * href="http://www.querydsl.com/">Querydsl</a> which enables the
 * construction of type-safe SQL-like queries.
 * 
 * @param entity builder for entity to use in search. Represents the entity
 *        and gives access to its properties for query purposes
 * @param entityManager {@code entityClass} {@link EntityManager}
 * @param datatablesCriterias datatables parameters for query
 * @param basePredicate (optional) base filter conditions
 * @return
 * @deprecated see
 *             {@link #findByCriteria(PathBuilder, Map, Map, EntityManager, DatatablesCriterias, BooleanBuilder, boolean, ConversionService, MessageSource, Object[])}
 */
public static <T, E extends Comparable<?>> SearchResults<T> findByCriteria(
        PathBuilder<T> entity, EntityManager entityManager,
        DatatablesCriterias datatablesCriterias,
        BooleanBuilder basePredicate) throws IllegalArgumentException {
    return findByCriteria(entity, null, null, entityManager,
            datatablesCriterias, basePredicate, false, null, null, null);
}
 
示例30
/**
 * Execute a select query on entityClass using <a
 * href="http://www.querydsl.com/">Querydsl</a> which enables the
 * construction of type-safe SQL-like queries.
 * 
 * @param entity builder for entity to use in search. Represents the entity
 *        and gives access to its properties for query purposes
 * @param filterByAssociations (optional) for each related entity to join
 *        contain as key the name of the association and as value the List
 *        of related entity fields to filter by
 * @param orderByAssociations (optional) for each related entity to order
 *        contain as key the name of the association and as value the List
 *        of related entity fields to order by
 * @param entityManager {@code entityClass} {@link EntityManager}
 * @param datatablesCriterias datatables parameters for query
 * @param basePredicate (optional) base filter conditions
 * @param distinct use distinct query
 * @param conversionService required by filter-by-expression and rows-on-top
 *        (otherwise optional)
 * @param messageSource required by filter-by-expression (otherwise
 *        optional)
 * @return
 * @deprecated see
 *             {@link #findByCriteria(PathBuilder, Map, Map, EntityManager, DatatablesCriterias, BooleanBuilder, boolean, ConversionService, MessageSource, Object[])}
 */
public static <T, E extends Comparable<?>> SearchResults<T> findByCriteria(
        PathBuilder<T> entity,
        Map<String, List<String>> filterByAssociations,
        Map<String, List<String>> orderByAssociations,
        EntityManager entityManager,
        DatatablesCriterias datatablesCriterias,
        BooleanBuilder basePredicate, boolean distinct,
        ConversionService conversionService, MessageSource messageSource)
        throws IllegalArgumentException {

    return findByCriteria(entity, null, null, entityManager,
            datatablesCriterias, basePredicate, false, null, null, null);
}