Ejemplo n.º 1
0
  public Predicate addFilter(
      Root<UserEntity> root, FilterConstraint constraint, String value, CriteriaBuilder cb) {

    if (constraint != FilterConstraint.PRESENT
        && (field.getType() == ExtensionFieldType.INTEGER
            || field.getType() == ExtensionFieldType.DECIMAL)) {

      value = numberPadder.pad(value);
    }

    final SetJoin<UserEntity, ExtensionFieldValueEntity> join =
        createOrGetJoin(
            generateAlias(urn + "." + field.getName()), root, UserEntity_.extensionFieldValues);

    Predicate filterPredicate =
        constraint.createPredicateForExtensionField(
            join.get(ExtensionFieldValueEntity_.value), value, field, cb);

    Predicate valueBelongsToField =
        cb.equal(
            join.get(ExtensionFieldValueEntity_.extensionField)
                .get(ExtensionFieldEntity_.internalId),
            field.getInternalId());

    join.on(valueBelongsToField);

    return filterPredicate;
  }
Ejemplo n.º 2
0
  @SuppressWarnings("unchecked")
  protected SetJoin<UserEntity, ExtensionFieldValueEntity> createOrGetJoin(
      String alias,
      Root<UserEntity> root,
      SetAttribute<UserEntity, ExtensionFieldValueEntity> attribute) {

    for (Join<UserEntity, ?> currentJoin : root.getJoins()) {
      if (currentJoin.getAlias() == null) {
        // if alias is null, it is not an alias for an extension join, so we ignore it
        continue;
      }

      if (currentJoin.getAlias().equals(alias)) {
        return (SetJoin<UserEntity, ExtensionFieldValueEntity>) currentJoin;
      }
    }

    final SetJoin<UserEntity, ExtensionFieldValueEntity> join = root.join(attribute, JoinType.LEFT);

    join.alias(alias);

    return join;
  }