javax.persistence.criteria.MapJoin Java Examples

The following examples show how to use javax.persistence.criteria.MapJoin. 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: MCRJobQueue.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param action
 * @param params
 *
 * @return the query for the given parameters
 * */
private <T> T buildQuery(Class<? extends MCRJobAction> action, Map<String, String> params,
    Function<TypedQuery<MCRJob>, T> consumer) {
    EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
    CriteriaBuilder cb = em.getCriteriaBuilder();

    CriteriaQuery<MCRJob> query = cb.createQuery(MCRJob.class);
    Root<MCRJob> jobRoot = query.from(MCRJob.class);
    query.select(jobRoot);

    params.keySet().forEach(key -> {
        MapJoin<MCRJob, String, String> parameterJoin = jobRoot.join(MCRJob_.parameters, JoinType.INNER);
        Path<String> keyPath = parameterJoin.key();
        Path<String> valuePath = parameterJoin.value();
        parameterJoin.on(cb.equal(keyPath, key), cb.equal(valuePath, params.get(key)));
    });

    query.where(cb.equal(jobRoot.get(MCRJob_.action), action));
    T result = consumer.apply(em.createQuery(query));
    clearPreFetch();
    return result;
}
 
Example #2
Source File: RSQLUtility.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private Predicate mapToMapPredicate(final ComparisonNode node, final Path<Object> fieldPath,
        final A enumField) {
    if (!enumField.isMap()) {
        return null;
    }

    final String[] graph = getSubAttributesFrom(node.getSelector());

    final String keyValue = graph[graph.length - 1];
    if (fieldPath instanceof MapJoin) {
        // Currently we support only string key .So below cast is safe.
        return cb.equal(cb.upper((Expression<String>) (((MapJoin<?, ?, ?>) fieldPath).key())),
                keyValue.toUpperCase());
    }

    final String keyFieldName = enumField.getSubEntityMapTuple().map(Entry::getKey)
            .orElseThrow(() -> new UnsupportedOperationException(
                    "For the fields, defined as Map, only Map java type or tuple in the form of SimpleImmutableEntry are allowed. Neither of those could be found!"));

    return cb.equal(cb.upper(fieldPath.get(keyFieldName)), keyValue.toUpperCase());
}
 
Example #3
Source File: JpaCriteriaQueryBackend.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
@Override
public Expression<?> joinMapValue(Expression<?> currentCriteriaPath, MetaAttribute pathElement, Object key) {
    MapJoin<Object, Object, Object> mapJoin = ((From<?, ?>) currentCriteriaPath).joinMap(pathElement.getName(),
            JoinType.LEFT);
    Predicate mapJoinCondition = cb.equal(mapJoin.key(), key);
    Predicate nullCondition = cb.isNull(mapJoin.key());
    addPredicate(cb.or(mapJoinCondition, nullCondition));
    return mapJoin;
}
 
Example #4
Source File: AbstractFromImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
@SuppressWarnings({"unchecked"})
public <X, K, V> MapJoin<X, K, V> joinMap(String attributeName, JoinType jt) {
	final Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute( attributeName );
	if ( !attribute.isCollection() ) {
		throw new IllegalArgumentException( "Requested attribute was not a map" );
	}

	final PluralAttribute pluralAttribute = (PluralAttribute) attribute;
	if ( !PluralAttribute.CollectionType.MAP.equals( pluralAttribute.getCollectionType() ) ) {
		throw new IllegalArgumentException( "Requested attribute was not a map" );
	}

	return (MapJoin<X, K, V>) join( (MapAttribute) attribute, jt );
}
 
Example #5
Source File: JpaCriteriaQueryBackend.java    From katharsis-framework with Apache License 2.0 5 votes vote down vote up
@Override
public Expression<?> joinMapValue(Expression<?> currentCriteriaPath, MetaAttribute pathElement, Object key) {
	MapJoin<Object, Object, Object> mapJoin = ((From<?, ?>) currentCriteriaPath).joinMap(pathElement.getName(),
			JoinType.LEFT);
	Predicate mapJoinCondition = cb.equal(mapJoin.key(), key);
	Predicate nullCondition = cb.isNull(mapJoin.key());
	addPredicate(cb.or(mapJoinCondition, nullCondition));
	return mapJoin;
}
 
Example #6
Source File: TargetSpecifications.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@link Specification} for retrieving {@link Target}s by "like attribute
 * value".
 *
 * @param searchText
 *            to be filtered on
 * @return the {@link Target} {@link Specification}
 */
public static Specification<JpaTarget> likeAttributeValue(final String searchText) {
    return (targetRoot, query, cb) -> {
        final String searchTextToLower = searchText.toLowerCase();
        final MapJoin<JpaTarget, String, String> attributeMap = targetRoot.join(JpaTarget_.controllerAttributes,
                JoinType.LEFT);
        query.distinct(true);
        return cb.like(cb.lower(attributeMap.value()), searchTextToLower);
    };
}
 
Example #7
Source File: RSQLUtility.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
private Expression<String> getExpressionToCompare(final Path innerFieldPath, final A enumField) {
    if (!enumField.isMap()) {
        return pathOfString(innerFieldPath);
    }
    if (innerFieldPath instanceof MapJoin) {
        // Currently we support only string key .So below cast
        // is safe.
        return (Expression<String>) (((MapJoin<?, ?, ?>) pathOfString(innerFieldPath)).value());
    }
    final String valueFieldName = enumField.getSubEntityMapTuple().map(Entry::getValue)
            .orElseThrow(() -> new UnsupportedOperationException(
                    "For the fields, defined as Map, only Map java type or tuple in the form of SimpleImmutableEntry are allowed. Neither of those could be found!"));
    return pathOfString(innerFieldPath).get(valueFieldName);
}
 
Example #8
Source File: CriteriaBuilderImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <X, K, T, V extends T> MapJoin<X, K, V> treat(MapJoin<X, K, T> join, Class<V> type) {
	return treat( join, type, (j, t) -> ((MapJoinImplementor) join).treatAs( type ) );
}
 
Example #9
Source File: CriteriaSubqueryImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public <X, K, V> MapJoin<X, K, V> correlate(MapJoin<X, K, V> source) {
	final MapJoinImplementor<X, K, V> correlation = ( (MapJoinImplementor<X, K, V>) source ).correlateTo( this );
	queryStructure.addCorrelationRoot( correlation );
	return correlation;
}
 
Example #10
Source File: AbstractFromImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public <K, V> MapJoin<X, K, V> join(MapAttribute<? super X, K, V> map) {
	return join( map, DEFAULT_JOIN_TYPE );
}
 
Example #11
Source File: AbstractFromImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public <X, K, V> MapJoin<X, K, V> joinMap(String attributeName) {
	return joinMap( attributeName, DEFAULT_JOIN_TYPE );
}