private Predicate buildPropertyRestriction( MapJoin<PersistentTemplate, String, String> propertiesMap, Map<String, String> someProperties) { Path<?> keyPath = propertiesMap.key(); Path<?> valuePath = propertiesMap.value(); List<Predicate> keyValuePairs = new LinkedList<Predicate>(); for (Map.Entry<String, String> entry : someProperties.entrySet()) { Predicate keyPredicate = criteriaBuilder.equal(keyPath, entry.getKey()); Predicate valuePredicate = criteriaBuilder.equal(valuePath, entry.getValue()); Predicate keyValuePair = criteriaBuilder.and(keyPredicate, valuePredicate); keyValuePairs.add(keyValuePair); } return criteriaBuilder.or(keyValuePairs .toArray(new Predicate[keyValuePairs.size()])); }
@SuppressWarnings("unchecked") private Predicate mapToMapPredicate(final ComparisonNode node, final Path<Object> fieldPath, final A enumField) { if (!enumField.isMap()) { return null; } final String[] graph = node.getSelector().split("\\" + FieldNameProvider.SUB_ATTRIBUTE_SEPERATOR); 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()); } return cb.equal(cb.upper(fieldPath.get(enumField.getKeyFieldName())), keyValue.toUpperCase()); }
@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; }
public List<Object> findMapJoin() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Object> c = cb.createQuery(); Root<Employee> emp = c.from(Employee.class); EntityType<Employee> emp_ = emp.getModel(); MapJoin<Employee, String, Phone> phone = emp.join(emp_.getMap("phones", String.class, Phone.class)); c.multiselect(emp.get(emp_.getSingularAttribute("name", String.class)), phone.key(), phone.value()); return em.createQuery(c).getResultList(); }
public WordTemplateQuery hasProperties(Map<String, String> someProperties) { Subquery<Long> subQuery = query.subquery(Long.class); Root<PersistentTemplate> fromSubQuery = subQuery .from(PersistentTemplate.class); Path<Long> id = fromSubQuery.get("id"); subQuery.select(id); MapJoin<PersistentTemplate, String, String> propertiesMap = fromSubQuery .joinMap("properties", JoinType.INNER); subQuery.where(buildPropertyRestriction(propertiesMap, someProperties)); subQuery.groupBy(id); subQuery.having(criteriaBuilder.equal(criteriaBuilder.count(id), someProperties.size())); restrictions.add(persistentTemplate.get("id").in(subQuery)); return this; }
@Override public <K, V> MapJoin<X, K, V> join(MapAttribute<? super X, K, V> map) { // TODO Auto-generated method stub return null; }
@Override public <K, V> MapJoin<X, K, V> join(MapAttribute<? super X, K, V> map, JoinType jt) { // TODO Auto-generated method stub return null; }
@Override public <X, K, V> MapJoin<X, K, V> joinMap(String attributeName) { // TODO Auto-generated method stub return null; }
@Override public <X, K, V> MapJoin<X, K, V> joinMap(String attributeName, JoinType jt) { // TODO Auto-generated method stub return null; }
@Override public <X, K, T, V extends T> MapJoin<X, K, V> treat(MapJoin<X, K, T> join, Class<V> type) { // TODO Auto-generated method stub return null; }
@Override @SuppressWarnings("unchecked") public <X, K, T, V extends T> MapJoin<X, K, V> treat(MapJoin<X, K, T> join, Class<V> type) { // return ( (MapJoinImplementor) join ).treatAs( type ); throw new NotYetImplementedException( ); }
@Override public <K, V> MapJoin<T, K, V> join( MapAttribute<? super T, K, V> arg0 ) { // TODO Auto-generated method stub return null; }
@Override public <K, V> MapJoin<T, K, V> join( MapAttribute<? super T, K, V> arg0, JoinType arg1 ) { // TODO Auto-generated method stub return null; }
@Override public <X, K, V> MapJoin<X, K, V> joinMap( String arg0 ) { // TODO Auto-generated method stub return null; }
@Override public <X, K, V> MapJoin<X, K, V> joinMap( String arg0, JoinType arg1 ) { // TODO Auto-generated method stub return null; }