com.mysema.query.BooleanBuilder Java Examples
The following examples show how to use
com.mysema.query.BooleanBuilder.
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: DatatablesUtilsBeanImpl.java From gvnix with GNU General Public License v3.0 | 6 votes |
/** * {@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); }
Example #2
Source File: DatatablesUtilsBeanImpl.java From gvnix with GNU General Public License v3.0 | 6 votes |
/** * {@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); }
Example #3
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 #4
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 #5
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 #6
Source File: DatatablesUtilsBeanImpl.java From gvnix with GNU General Public License v3.0 | 5 votes |
/** * {@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); }
Example #7
Source File: DatatablesUtilsBeanImpl.java From gvnix with GNU General Public License v3.0 | 5 votes |
/** * {@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); }
Example #8
Source File: DatatablesUtilsBeanImpl.java From gvnix with GNU General Public License v3.0 | 5 votes |
/** * {@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); }
Example #9
Source File: DatatablesUtilsBeanImpl.java From gvnix with GNU General Public License v3.0 | 5 votes |
/** * {@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); }
Example #10
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 #11
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 #12
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 #13
Source File: QuerydslUtilsBeanGeoImpl.java From gvnix with GNU General Public License v3.0 | 4 votes |
@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; }
Example #14
Source File: DatatablesUtilsBeanImpl.java From gvnix with GNU General Public License v3.0 | 4 votes |
/** * 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; }
Example #15
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; }
Example #16
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 #17
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 #18
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 #19
Source File: DatatablesUtils.java From gvnix with GNU General Public License v3.0 | 4 votes |
/** * 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); }
Example #20
Source File: DatatablesUtils.java From gvnix with GNU General Public License v3.0 | 4 votes |
/** * 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); }
Example #21
Source File: DatatablesUtils.java From gvnix with GNU General Public License v3.0 | 4 votes |
/** * 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; }
Example #22
Source File: DatatablesUtils.java From gvnix with GNU General Public License v3.0 | 3 votes |
/** * 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); }
Example #23
Source File: DatatablesUtils.java From gvnix with GNU General Public License v3.0 | 3 votes |
/** * 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); }
Example #24
Source File: DatatablesUtils.java From gvnix with GNU General Public License v3.0 | 3 votes |
/** * 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); }
Example #25
Source File: DatatablesUtils.java From gvnix with GNU General Public License v3.0 | 3 votes |
/** * 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); }
Example #26
Source File: DatatablesUtils.java From gvnix with GNU General Public License v3.0 | 3 votes |
/** * 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); }
Example #27
Source File: DatatablesUtilsBean.java From gvnix with GNU General Public License v3.0 | 3 votes |
/** * 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 datatablesCriterias datatables parameters for query * @param basePredicate (optional) base filter conditions * @param distinct use distinct query * @return */ 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);
Example #28
Source File: DatatablesUtils.java From gvnix with GNU General Public License v3.0 | 3 votes |
/** * 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); }
Example #29
Source File: DatatablesUtilsBean.java From gvnix with GNU General Public License v3.0 | 3 votes |
/** * 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 datatablesCriterias datatables parameters for query * @param basePredicate (optional) base filter * @param distinct use distinct query * @param rowsOnTopIds (optional) array with id of rows to show on top of * result list * @return * @throws IllegalArgumentException */ 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);
Example #30
Source File: DatatablesUtils.java From gvnix with GNU General Public License v3.0 | 3 votes |
/** * 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); }