Java Code Examples for com.mysema.query.BooleanBuilder#and()
The following examples show how to use
com.mysema.query.BooleanBuilder#and() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QuerydslUtilsBeanImpl.java From gvnix with GNU General Public License v3.0 | 6 votes |
/** * {@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; }
Example 2
Source File: CollectorItemRepository.java From hygieia-core with Apache License 2.0 | 5 votes |
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()); }
Example 3
Source File: PermissionService.java From spring-boot-practice with Apache License 2.0 | 5 votes |
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); }
Example 4
Source File: QuerydslUtils.java From gvnix with GNU General Public License v3.0 | 5 votes |
/** * 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; }
Example 5
Source File: QuerydslUtilsBeanImpl.java From gvnix with GNU General Public License v3.0 | 5 votes |
/** * {@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; }
Example 6
Source File: ComponentRepository.java From hygieia-core with Apache License 2.0 | 4 votes |
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()); }
Example 7
Source File: CollectorItemRepository.java From hygieia-core with Apache License 2.0 | 4 votes |
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()); }
Example 8
Source File: DatatablesUtils.java From gvnix with GNU General Public License v3.0 | 4 votes |
/** * 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; }
Example 9
Source File: QuerydslUtils.java From gvnix with GNU General Public License v3.0 | 4 votes |
/** * 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; }
Example 10
Source File: DatatablesUtilsBeanImpl.java From gvnix with GNU General Public License v3.0 | 4 votes |
/** * 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; }