javax.persistence.criteria.From Java Examples

The following examples show how to use javax.persistence.criteria.From. 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: AbstractHerdDao.java    From herd with Apache License 2.0 7 votes vote down vote up
/**
 * Builds a query restriction predicate for the storage.
 *
 * @param builder the criteria builder
 * @param storageEntityFrom the storage entity that appears in the from clause
 * @param storageEntities the optional list of storage entities where business object data storage units should be looked for
 * @param storagePlatformEntity the optional storage platform entity, e.g. S3 for Hive DDL. It is ignored when the list of storage entities is not empty
 * @param excludedStoragePlatformEntity the optional storage platform entity to be excluded from search. It is ignored when the list of storage entities is
 * not empty or the storage platform entity is specified
 *
 * @return the query restriction predicate
 */
protected Predicate getQueryRestrictionOnStorage(CriteriaBuilder builder, From<?, StorageEntity> storageEntityFrom, List<StorageEntity> storageEntities,
    StoragePlatformEntity storagePlatformEntity, StoragePlatformEntity excludedStoragePlatformEntity)
{
    List<Predicate> predicates = new ArrayList<>();

    // If specified, add restriction on storage names.
    if (!CollectionUtils.isEmpty(storageEntities))
    {
        List<String> storageNames = storageEntities.stream().map(StorageEntity::getName).collect(Collectors.toList());
        predicates.add(storageEntityFrom.get(StorageEntity_.name).in(storageNames));
    }
    // Otherwise, add restriction on storage platform, if specified.
    else if (storagePlatformEntity != null)
    {
        predicates.add(builder.equal(storageEntityFrom.get(StorageEntity_.storagePlatformCode), storagePlatformEntity.getName()));
    }
    // Otherwise, add restriction per excluded storage platform, if specified.
    else if (excludedStoragePlatformEntity != null)
    {
        predicates.add(builder.notEqual(storageEntityFrom.get(StorageEntity_.storagePlatformCode), excludedStoragePlatformEntity.getName()));
    }

    return builder.and(predicates.toArray(new Predicate[predicates.size()]));
}
 
Example #2
Source File: JoinBuilder.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
@Override
public List<Predicate> build(CriteriaBuilder builder, Path<P> path)
{
    Join join = null;
    if (singular != null)
    {
        join = joinSingular((From) path);
    }
    else if (list != null)
    {
        join = joinList((From) path);
    }
    else if (collection != null)
    {
        join = joinCollection((From) path);
    }
    else if (set != null)
    {
        join = joinSet((From) path);
    }
    else
    {
        join = joinMap((From) path);
    }
    return criteria.predicates(builder, join);
}
 
Example #3
Source File: StaticEntityRepositoryImpl.java    From we-cmdb with Apache License 2.0 6 votes vote down vote up
private void queryJoin(CriteriaBuilder cb, CriteriaQuery query, From from, FilterPath path, EntityGraph<?> eg, Subgraph sg, List<Predicate> predicates) {
    String joinAttr = path.getJoinAttr();
    From joinPath = null;
    if (".".equals(joinAttr)) {
        joinPath = from;
    } else {
        if (sg == null) {
            sg = eg.addSubgraph(path.getJoinAttr());
        } else {
            sg = sg.addSubgraph(path.getJoinAttr());
        }
        joinPath = from.join(path.getJoinAttr());
    }
    applyFilter(cb, query, path.getFilters(), joinPath, predicates);
    if (path.getJoinChildren() != null && path.getJoinChildren().size() > 0) {
        for (FilterPath fp : path.getJoinChildren()) {
            queryJoin(cb, query, joinPath, fp, eg, sg, predicates);
        }
    }
}
 
Example #4
Source File: ComputedAttributeCriteriaTest.java    From crnk-framework with Apache License 2.0 6 votes vote down vote up
@Override
protected JpaQueryFactory createQueryFactory(final EntityManager em) {
	JpaCriteriaQueryFactory factory = JpaCriteriaQueryFactory.newInstance();

	factory.registerComputedAttribute(TestEntity.class, ATTR_VIRTUAL_VALUE, String.class,
			new JpaCriteriaExpressionFactory<From<?, TestEntity>>() {

				@Override
				public Expression<String> getExpression(From<?, TestEntity> parent, CriteriaQuery<?> query) {
					CriteriaBuilder builder = em.getCriteriaBuilder();
					Path<String> stringValue = parent.get(TestEntity.ATTR_stringValue);
					return builder.upper(stringValue);
				}
			});

	return factory;
}
 
Example #5
Source File: ComputedAttributeCriteriaTest.java    From katharsis-framework with Apache License 2.0 6 votes vote down vote up
@Override
protected JpaQueryFactory createQueryFactory(final EntityManager em) {
	JpaCriteriaQueryFactory factory = JpaCriteriaQueryFactory.newInstance();

	factory.registerComputedAttribute(TestEntity.class, ATTR_VIRTUAL_VALUE, String.class,
			new JpaCriteriaExpressionFactory<From<?, TestEntity>>() {

				@Override
				public Expression<String> getExpression(From<?, TestEntity> parent, CriteriaQuery<?> query) {
					CriteriaBuilder builder = em.getCriteriaBuilder();
					Path<String> stringValue = parent.get(TestEntity.ATTR_stringValue);
					return builder.upper(stringValue);
				}
			});

	return factory;
}
 
Example #6
Source File: CiServiceImpl.java    From we-cmdb with Apache License 2.0 6 votes vote down vote up
private void attachAdditionalAttr(Map<String, FieldInfo> attrExprMap, Stack<String> path, int curCiTypeId, From curFrom, String propertyName,String curQueryKeyName) {
    AdmCiTypeAttr attr = ciTypeAttrRepository.findFirstByCiTypeIdAndPropertyName(curCiTypeId, propertyName);
    validateStatusOfCiTypeAttr(attr);
    if (attr == null) {
        throw new ServiceException(String.format("Can not find out [%s] for CI Type [%d].", propertyName, curCiTypeId));
    }

    String alias = null;
    if(Strings.isNullOrEmpty(curQueryKeyName)) {
        alias = getTemplAlias(path) + "." + propertyName;
    }else{
        alias = curQueryKeyName + "." + propertyName;
    }

    Expression expression = curFrom.get(attr.getPropertyName());
    if (expression.getAlias() == null) {
        expression.alias(alias);
    }
    attrExprMap.put(alias, new FieldInfo(expression, FieldType.getTypeFromCode(attr.getPropertyType()), attr.getCiTypeId(), attr.getInputType(), attr.getName(), null,alias));
}
 
Example #7
Source File: EqualSpecification.java    From jpa-spec with MIT License 6 votes vote down vote up
@Override
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
    From from = getRoot(property, root);
    String field = getProperty(property);
    if (values == null) {
        return cb.isNull(from.get(field));
    }
    if (values.length == 1) {
        return getPredicate(from, cb, values[0], field);
    }

    Predicate[] predicates = new Predicate[values.length];
    for (int i = 0; i < values.length; i++) {
        predicates[i] = getPredicate(root, cb, values[i], field);
    }
    return cb.or(predicates);
}
 
Example #8
Source File: NotEqualSpecification.java    From jpa-spec with MIT License 6 votes vote down vote up
@Override
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
    From from = getRoot(property, root);
    String field = getProperty(property);
    if (values == null) {
        return cb.isNotNull(from.get(field));
    }
    if (values.length == 1) {
        return getPredicate(from, cb, values[0], field);
    }
    Predicate[] predicates = new Predicate[values.length];
    for (int i = 0; i < values.length; i++) {
        predicates[i] = getPredicate(root, cb, values[i], field);
    }
    return cb.or(predicates);
}
 
Example #9
Source File: AbstractHerdDao.java    From herd with Apache License 2.0 6 votes vote down vote up
/**
 * TODO This method may be bdata specific. Consider creating new abstract class to group all bdata related DAO. Builds a query restriction predicate for the
 * specified entities as per business object data key values.
 *
 * @param builder the criteria builder
 * @param businessObjectDataEntity the business object data entity that appears in the from clause
 * @param businessObjectFormatEntity the business object format entity that appears in the from clause
 * @param fileTypeEntity the file type entity that appears in the from clause
 * @param businessObjectDefinitionEntity the business object definition entity that appears in the from clause
 * @param businessObjectDataKey the business object data key
 *
 * @return the query restriction predicate
 */
protected Predicate getQueryRestriction(CriteriaBuilder builder, From<?, BusinessObjectDataEntity> businessObjectDataEntity,
    From<?, BusinessObjectFormatEntity> businessObjectFormatEntity, From<?, FileTypeEntity> fileTypeEntity,
    From<?, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity, BusinessObjectDataKey businessObjectDataKey)
{
    // Create the standard restrictions based on the business object format key values that are part of the business object data key.
    // Please note that we specify not to ignore the business object format version.
    Predicate predicate = getQueryRestriction(builder, businessObjectFormatEntity, fileTypeEntity, businessObjectDefinitionEntity,
        getBusinessObjectFormatKey(businessObjectDataKey), false);

    // Create and append a restriction on partition values.
    predicate = builder.and(predicate, getQueryRestrictionOnPartitionValues(builder, businessObjectDataEntity, businessObjectDataKey));

    // If it is specified, create and append a restriction on business object data version.
    if (businessObjectDataKey.getBusinessObjectDataVersion() != null)
    {
        predicate = builder.and(predicate,
            builder.equal(businessObjectDataEntity.get(BusinessObjectDataEntity_.version), businessObjectDataKey.getBusinessObjectDataVersion()));
    }

    return predicate;
}
 
Example #10
Source File: AbstractHerdDao.java    From herd with Apache License 2.0 6 votes vote down vote up
/**
 * TODO This method may be bdata specific. Consider creating new abstract class to group all bdata related DAO. Builds a query restriction predicate for the
 * specified business object data entity as per primary and sub-partition values in the business object data key.
 *
 * @param builder the criteria builder
 * @param businessObjectDataEntity the business object data entity that appears in the from clause
 * @param primaryPartitionValue the primary partition value of the business object data
 * @param subPartitionValues the list of sub-partition values for the business object data
 *
 * @return the query restriction predicate
 */
protected Predicate getQueryRestrictionOnPartitionValues(CriteriaBuilder builder, From<?, BusinessObjectDataEntity> businessObjectDataEntity,
    String primaryPartitionValue, List<String> subPartitionValues)
{
    // Create a standard restriction on primary partition value.
    Predicate predicate = builder.equal(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue), primaryPartitionValue);

    // Create and add standard restrictions on sub-partition values. Please note that the subpartition value columns are nullable.
    int subPartitionValuesCount = CollectionUtils.size(subPartitionValues);
    for (int i = 0; i < BusinessObjectDataEntity.MAX_SUBPARTITIONS; i++)
    {
        predicate = builder.and(predicate, i < subPartitionValuesCount ?
            builder.equal(businessObjectDataEntity.get(BUSINESS_OBJECT_DATA_SUBPARTITIONS.get(i)), subPartitionValues.get(i)) :
            builder.isNull(businessObjectDataEntity.get(BUSINESS_OBJECT_DATA_SUBPARTITIONS.get(i))));
    }

    return predicate;
}
 
Example #11
Source File: AbstractHerdDao.java    From herd with Apache License 2.0 6 votes vote down vote up
/**
 * Builds a query restriction predicate for the specified business object format entity as per business object format alternate key values.
 *
 * @param builder the criteria builder
 * @param businessObjectFormatEntityFrom the business object format entity that appears in the from clause of the main query
 * @param businessObjectDefinitionEntity the business object definition entity
 * @param businessObjectFormatUsage the business object format usage (case-insensitive)
 * @param fileTypeEntity the file type entity
 * @param businessObjectFormatVersion the optional business object format version
 *
 * @return the query restriction predicate
 */
protected Predicate getQueryRestriction(CriteriaBuilder builder, From<?, BusinessObjectFormatEntity> businessObjectFormatEntityFrom,
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity, String businessObjectFormatUsage, FileTypeEntity fileTypeEntity,
    Integer businessObjectFormatVersion)
{
    // Create restriction on business object definition.
    Predicate predicate =
        builder.equal(businessObjectFormatEntityFrom.get(BusinessObjectFormatEntity_.businessObjectDefinitionId), businessObjectDefinitionEntity.getId());

    // Create and append restriction on business object format usage.
    predicate = builder.and(predicate,
        builder.equal(builder.upper(businessObjectFormatEntityFrom.get(BusinessObjectFormatEntity_.usage)), businessObjectFormatUsage.toUpperCase()));

    // Create and append restriction on business object format file type.
    predicate =
        builder.and(predicate, builder.equal(businessObjectFormatEntityFrom.get(BusinessObjectFormatEntity_.fileTypeCode), fileTypeEntity.getCode()));

    // If specified, create and append restriction on business object format version.
    if (businessObjectFormatVersion != null)
    {
        predicate = builder.and(predicate,
            builder.equal(businessObjectFormatEntityFrom.get(BusinessObjectFormatEntity_.businessObjectFormatVersion), businessObjectFormatVersion));
    }

    return predicate;
}
 
Example #12
Source File: AbstractHerdDao.java    From herd with Apache License 2.0 6 votes vote down vote up
/**
 * TODO This method may be bdata specific. Consider creating new abstract class to group all bdata related DAO. Builds a query restriction predicate for the
 * sub-query business object data entity as per partition values from the specified main query business object data entity.
 *
 * @param builder the criteria builder
 * @param businessObjectDataEntity the business object data entity that appears in the from clause
 * @param partitionFilters the list of partition filter to be used to select business object data instances. Each partition filter contains a list of
 * primary and sub-partition values in the right order up to the maximum partition levels allowed by business object data registration - with partition
 * values for the relative partitions not to be used for selection passed as nulls.
 *
 * @return the query restriction predicate
 */
protected Predicate getQueryRestrictionOnPartitionValues(CriteriaBuilder builder, From<?, BusinessObjectDataEntity> businessObjectDataEntity,
    List<List<String>> partitionFilters)
{
    // Create a query restriction as per specified primary and/or sub-partition values.
    Predicate predicate = null;
    for (List<String> partitionFilter : partitionFilters)
    {
        // Add restriction for each partition level if the relative partition value is specified in the partition filter.
        Predicate partitionRestriction = null;
        for (int partitionLevel = 0; partitionLevel < BusinessObjectDataEntity.MAX_SUBPARTITIONS + 1; partitionLevel++)
        {
            String partitionValue = partitionFilter.get(partitionLevel);
            if (StringUtils.isNotBlank(partitionValue))
            {
                Predicate partitionValueRestriction =
                    builder.equal(businessObjectDataEntity.get(BUSINESS_OBJECT_DATA_PARTITIONS.get(partitionLevel)), partitionValue);
                partitionRestriction =
                    (partitionRestriction == null ? partitionValueRestriction : builder.and(partitionRestriction, partitionValueRestriction));
            }
        }
        predicate = (predicate == null ? partitionRestriction : builder.or(predicate, partitionRestriction));
    }

    return predicate;
}
 
Example #13
Source File: AbstractHerdDao.java    From herd with Apache License 2.0 6 votes vote down vote up
/**
 * TODO This method may be bdata specific. Consider creating new abstract class to group all bdata related DAO. Builds a query restriction predicate for the
 * sub-query business object data entity as per partition values from the specified main query business object data entity.
 *
 * @param builder the criteria builder
 * @param subBusinessObjectDataEntity the sub-query business object data entity that appears in the from clause
 * @param mainBusinessObjectDataEntity the main query business object data entity that appears in the from clause
 *
 * @return the query restriction predicate
 */
protected Predicate getQueryRestrictionOnPartitionValues(CriteriaBuilder builder, From<?, BusinessObjectDataEntity> subBusinessObjectDataEntity,
    From<?, BusinessObjectDataEntity> mainBusinessObjectDataEntity)
{
    // Create a standard restriction on primary partition value.
    Predicate predicate = builder.equal(subBusinessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue),
        mainBusinessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue));

    // Create and add standard restrictions on sub-partition values. Please note that the subpartition value columns are nullable.
    for (SingularAttribute<BusinessObjectDataEntity, String> businessObjectDataPartitionValueSingularAttribute : BUSINESS_OBJECT_DATA_SUBPARTITIONS)
    {
        predicate = builder.and(predicate, builder.or(builder
            .and(builder.isNull(subBusinessObjectDataEntity.get(businessObjectDataPartitionValueSingularAttribute)),
                builder.isNull(mainBusinessObjectDataEntity.get(businessObjectDataPartitionValueSingularAttribute))), builder
            .equal(subBusinessObjectDataEntity.get(businessObjectDataPartitionValueSingularAttribute),
                mainBusinessObjectDataEntity.get(businessObjectDataPartitionValueSingularAttribute))));
    }

    return predicate;
}
 
Example #14
Source File: AbstractHerdDao.java    From herd with Apache License 2.0 6 votes vote down vote up
/**
 * TODO This method may be bdata specific. Consider creating new abstract class to group all bdata related DAO. Builds query restriction predicates and adds
 * them to the query restriction as per specified business object data version and status. If a business object data version is specified, the business
 * object data status is ignored. When both business object data version and business object data status are not specified, the sub-query restriction is not
 * getting updated.
 *
 * @param builder the criteria builder
 * @param businessObjectDataEntity the business object data entity that appears in the from clause
 * @param businessObjectDataVersion the business object data version
 * @param businessObjectDataStatusEntity the optional business object data status entity. This parameter is ignored when the business object data version is
 * specified
 *
 * @return the query restriction predicate or null if both business object data version and business object data status are not specified
 */
protected Predicate getQueryRestrictionOnBusinessObjectDataVersionAndStatus(CriteriaBuilder builder,
    From<?, BusinessObjectDataEntity> businessObjectDataEntity, Integer businessObjectDataVersion,
    BusinessObjectDataStatusEntity businessObjectDataStatusEntity)
{
    Predicate predicate = null;

    // If specified, create a standard restriction on the business object data version.
    if (businessObjectDataVersion != null)
    {
        predicate = builder.equal(businessObjectDataEntity.get(BusinessObjectDataEntity_.version), businessObjectDataVersion);
    }
    // Only if a business object data version is not specified, check if we need to add a restriction on the business object data status.
    else if (businessObjectDataStatusEntity != null)
    {
        predicate = builder.equal(businessObjectDataEntity.get(BusinessObjectDataEntity_.statusCode), businessObjectDataStatusEntity.getCode());
    }

    return predicate;
}
 
Example #15
Source File: RSQLUtility.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
private Path<?> getJoinFieldPath(final Path<?> fieldPath, final String fieldNameSplit) {
    if (fieldPath instanceof PluralJoin) {
        final Join<Object, ?> join = (Join<Object, ?>) fieldPath;
        final From<?, Object> joinParent = join.getParent();
        final Optional<Join<Object, Object>> currentJoinOfType = findCurrentJoinOfType(join.getJavaType());
        if (currentJoinOfType.isPresent() && isOrLevel) {
            // remove the additional join and use the existing one
            joinParent.getJoins().remove(join);
            return currentJoinOfType.get();
        } else {
            final Join<Object, Object> newJoin = joinParent.join(fieldNameSplit, JoinType.LEFT);
            addCurrentJoin(newJoin);
            return newJoin;
        }
    }
    return fieldPath;
}
 
Example #16
Source File: ColumnFilter.java    From spring-data-jpa-datatables with Apache License 2.0 6 votes vote down vote up
@Override
public javax.persistence.criteria.Predicate createPredicate(From<?, ?> from, CriteriaBuilder criteriaBuilder, String attributeName) {
    Expression<?> expression = from.get(attributeName);

    if (values.isEmpty()) {
        return addNullCase ? expression.isNull() : criteriaBuilder.conjunction();
    } else if (isBasicFilter()) {
        return super.createPredicate(from, criteriaBuilder, attributeName);
    }

    javax.persistence.criteria.Predicate predicate;
    if (isBooleanComparison) {
        predicate = expression.in(booleanValues);
    } else {
        predicate = expression.as(String.class).in(values);
    }
    if (addNullCase) predicate = criteriaBuilder.or(predicate, expression.isNull());

    return predicate;
}
 
Example #17
Source File: JoinBuilder.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
private Join joinSingular(From path)
{
    if (joinType == null)
    {
        return path.join(singular);
    }
    return path.join(singular, joinType);
}
 
Example #18
Source File: JoinBuilder.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
private Join joinCollection(From path)
{
    if (joinType == null)
    {
        return path.join(collection);
    }
    return path.join(collection, joinType);
}
 
Example #19
Source File: AbstractConstruct.java    From activejpa with Apache License 2.0 5 votes vote down vote up
protected <T, S> Path<?> getPath(From<T, S> root, String name) {
	int index = name.indexOf(".");
	if (index > 0 ) {
		String attribute = name.substring(0, index);
		From<S, ?> join = getJoin(attribute, root.getJoins());
		if (join == null) {
			join = root.join(attribute);
		}
		return getPath(join, name.substring(index + 1));
	} else {
		return root.get(name);
	}
}
 
Example #20
Source File: AbstractJPATypedQueryVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Path<?> getExistingJoinProperty(From<?, ?> element, String prop) {
    final Set<?> joins = element.getJoins();
    for (Object object : joins) {
        Join<?, ?> join = (Join<?, ?>) object;
        if (join.getAttribute().getName().equals(prop)) {
            return join;
        }
    }
    return null;
}
 
Example #21
Source File: JoinBuilder.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
private Join joinList(From path)
{
    if (joinType == null)
    {
        return path.join(list);
    }
    return path.join(list, joinType);
}
 
Example #22
Source File: AbstractJPATypedQueryVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Path<?> getNextPath(Path<?> element, String name, String postName,
    ClassValue cv, CollectionCheckInfo collSize) {
    final boolean isCollectionOrJoin = collSize == null
        && (cv.isCollection(name) || isJoinProperty(name) || existingCollectionInPostName(cv, postName))
        && (element == root || element instanceof Join);
    if (isCollectionOrJoin) {
        final Path<?> path = getExistingJoinProperty((From<?, ?>)element, name);
        if (path != null) {
            return path;
        }
        return element == root ? root.join(name) : ((Join<?, ?>)element).join(name);
    }
    return element.get(name);
}
 
Example #23
Source File: RSQLPredicateProducerTest.java    From pnc with Apache License 2.0 5 votes vote down vote up
private Path<?> toPathEnvironment(From<?, BuildEnvironment> from, RSQLSelectorPath selector) {
    switch (selector.getElement()) {
        case "name":
            return from.get(BuildEnvironment_.name);
        default:
            throw new IllegalArgumentException("Unknown RSQL selector " + selector.getElement());
    }
}
 
Example #24
Source File: RSQLPredicateProducerTest.java    From pnc with Apache License 2.0 5 votes vote down vote up
private Path<?> toPath(From<?, BuildRecord> from, RSQLSelectorPath selector) {
    switch (selector.getElement()) {
        case "id":
            return from.get(BuildRecord_.id);
        case "environment":
            return toPathEnvironment(from.join(BuildRecord_.buildEnvironment), selector.next());
        default:
            throw new IllegalArgumentException("Unknown RSQL selector " + selector.getElement());
    }
}
 
Example #25
Source File: ProductReleaseRSQLMapper.java    From pnc with Apache License 2.0 5 votes vote down vote up
@Override
public Path<?> toPath(From<?, ProductRelease> from, RSQLSelectorPath selector) {
    switch (selector.getElement()) {
        case "productVersion":
            return pvm.toPath(
                    from.join(ProductRelease_.productMilestone).join(ProductMilestone_.productVersion),
                    selector.next());
        default:
            return super.toPath(from, selector);
    }
}
 
Example #26
Source File: AbstractRSQLMapper.java    From pnc with Apache License 2.0 5 votes vote down vote up
protected <X extends GenericEntity<?>> Path<?> mapEntity(
        From<?, DB> from,
        SingularAttribute<DB, X> entity,
        RSQLSelectorPath selector) {
    Class<X> bindableJavaType = entity.getBindableJavaType();
    From<DB, X> join = from.join(entity);
    return mapper.toPath(bindableJavaType, join, selector);
}
 
Example #27
Source File: AbstractRSQLMapper.java    From pnc with Apache License 2.0 5 votes vote down vote up
@Override
public Path<?> toPath(From<?, DB> from, RSQLSelectorPath selector) {
    String name = selector.getElement();
    if (toAttribute(name) != null) {
        return from.get(toAttribute(name));
    }
    if (toEntity(name) != null) {
        if (selector.isFinal()) {
            return from.get(toEntity(name));
        } else {
            return mapEntity(from, toEntity(name), selector.next());
        }
    }
    throw new RSQLException("Unknown RSQL selector " + name + " for type " + type);
}
 
Example #28
Source File: EntityRSQLNodeTraveller.java    From pnc with Apache License 2.0 5 votes vote down vote up
public EntityRSQLNodeTraveller(
        Root<DB> root,
        CriteriaBuilder cb,
        BiFunction<From<?, DB>, RSQLSelectorPath, Path> toPath) {
    this.root = root;
    this.cb = cb;
    this.toPath = toPath;
}
 
Example #29
Source File: JpaCriteriaQueryBackend.java    From katharsis-framework with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public From<?, ?> doJoin(MetaAttribute targetAttr, JoinType joinType, From<?, ?> parent) {
	if (targetAttr instanceof MetaComputedAttribute) {
		MetaComputedAttribute projAttr = (MetaComputedAttribute) targetAttr;
		@SuppressWarnings("rawtypes")
		JpaCriteriaExpressionFactory expressionFactory = (JpaCriteriaExpressionFactory<?>) queryImpl.getComputedAttrs()
				.get(projAttr);

		return (From<?, ?>) expressionFactory.getExpression(parent, getCriteriaQuery());
	}
	else {
		return parent.join(targetAttr.getName(), joinType);
	}
}
 
Example #30
Source File: RSQLProducerImpl.java    From pnc with Apache License 2.0 5 votes vote down vote up
private <DB extends GenericEntity<?>> Predicate<DB> getEntityPredicate(Node rootNode, Class<DB> type) {
    return (root, query, cb) -> {
        RSQLNodeTraveller<javax.persistence.criteria.Predicate> visitor = new EntityRSQLNodeTraveller(
                root,
                cb,
                new BiFunction<From<?, DB>, RSQLSelectorPath, Path>() {
                    @Override
                    public Path apply(From<?, DB> from, RSQLSelectorPath selector) {
                        return mapper.toPath(type, from, selector);
                    }
                });
        return rootNode.accept(visitor);
    };
}