org.springframework.data.repository.query.parser.Part.Type Java Examples

The following examples show how to use org.springframework.data.repository.query.parser.Part.Type. 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: HazelcastQueryCreator.java    From spring-data-hazelcast with Apache License 2.0 6 votes vote down vote up
private Predicate<?, ?> fromLikeVariant(Type type, boolean ignoreCase, String property, Iterator<Comparable<?>> iterator) {
    String likeExpression = iterator.next().toString();
    switch (type) {
        case CONTAINING:
        case NOT_CONTAINING:
            likeExpression = String.join("", "%", likeExpression, "%");
            break;
        case STARTING_WITH:
            likeExpression = String.join("", likeExpression, "%");
            break;
        case ENDING_WITH:
            likeExpression = String.join("", "%", likeExpression);
            break;
        case LIKE:
        case NOT_LIKE:
            break;
        default:
            throw new InvalidDataAccessApiUsageException(String.format("'%s' is not supported for LIKE style query", type));
    }

    Predicate likePredicate = ignoreCase ? Predicates.ilike(property, likeExpression) : Predicates
            .like(property, likeExpression);
    return type.equals(NOT_LIKE) || type.equals(NOT_CONTAINING) ? Predicates.not(likePredicate) : likePredicate;
}
 
Example #2
Source File: HazelcastQueryCreator.java    From spring-data-hazelcast with Apache License 2.0 6 votes vote down vote up
private Predicate<?, ?> fromEqualityVariant(Type type, boolean ignoreCase, String property,
                                            Iterator<Comparable<?>> iterator) {
    switch (type) {
        case SIMPLE_PROPERTY:
            if (ignoreCase) {
                return Predicates.ilike(property, iterator.next().toString());
            } else {
                return Predicates.equal(property, iterator.next());
            }
        case NEGATING_SIMPLE_PROPERTY:
            if (ignoreCase) {
                return Predicates.not(Predicates.ilike(property, iterator.next().toString()));
            } else {
                return Predicates.notEqual(property, iterator.next());
            }
        default:
            throw new InvalidDataAccessApiUsageException(String.format("Logic error for '%s' in query", type));
    }
}
 
Example #3
Source File: StringQuery.java    From spring-data-ebean with Apache License 2.0 6 votes vote down vote up
/**
 * Extracts the like {@link Type} from the given JPA like expression.
 *
 * @param expression must not be {@literal null} or empty.
 * @return
 */
private static Type getLikeTypeFrom(String expression) {

    Assert.hasText(expression, "Expression must not be null or empty!");

    if (expression.matches("%.*%")) {
        return Type.CONTAINING;
    }

    if (expression.startsWith("%")) {
        return Type.ENDING_WITH;
    }

    if (expression.endsWith("%")) {
        return Type.STARTING_WITH;
    }

    return Type.LIKE;
}
 
Example #4
Source File: HazelcastQueryCreator.java    From spring-data-hazelcast with Apache License 2.0 6 votes vote down vote up
private Predicate<?, ?> fromInequalityVariant(Type type, String property, Iterator<Comparable<?>> iterator) {
    switch (type) {
        case AFTER:
        case GREATER_THAN:
            return Predicates.greaterThan(property, iterator.next());
        case GREATER_THAN_EQUAL:
            return Predicates.greaterEqual(property, iterator.next());
        case BEFORE:
        case LESS_THAN:
            return Predicates.lessThan(property, iterator.next());
        case LESS_THAN_EQUAL:
            return Predicates.lessEqual(property, iterator.next());
        case BETWEEN:
            Comparable<?> first = iterator.next();
            Comparable<?> second = iterator.next();
            return Predicates.between(property, first, second);
        default:
            throw new InvalidDataAccessApiUsageException(String.format("Logic error for '%s' in query", type));
    }
}
 
Example #5
Source File: StringQuery.java    From spring-data-mybatis with Apache License 2.0 6 votes vote down vote up
/**
 * Extracts the like {@link Type} from the given JPA like expression.
 * @param expression must not be {@literal null} or empty.
 */
private static Type getLikeTypeFrom(String expression) {

	Assert.hasText(expression, "Expression must not be null or empty!");

	if (expression.matches("%.*%")) {
		return Type.CONTAINING;
	}

	if (expression.startsWith("%")) {
		return Type.ENDING_WITH;
	}

	if (expression.endsWith("%")) {
		return Type.STARTING_WITH;
	}

	return Type.LIKE;
}
 
Example #6
Source File: HazelcastQueryCreator.java    From spring-data-hazelcast with Apache License 2.0 5 votes vote down vote up
private Predicate<?, ?> fromEmptyVariant(Type type, String property) {
    switch (type) {
        case IS_EMPTY:
            return Predicates.equal(property, "");
        case IS_NOT_EMPTY:
            return Predicates.notEqual(property, "");

        default:
            throw new InvalidDataAccessApiUsageException(String.format("Logic error for '%s' in query", type));
    }
}
 
Example #7
Source File: MybatisMapperBuildAssistant.java    From spring-data-mybatis with Apache License 2.0 5 votes vote down vote up
protected String calculateOperation(Type type) {

		switch (type) {

		case SIMPLE_PROPERTY:
			return "=";
		case NEGATING_SIMPLE_PROPERTY:
			return "<![CDATA[<>]]>";
		case LESS_THAN:
		case BEFORE:
			return "<![CDATA[<]]>";
		case LESS_THAN_EQUAL:
			return "<![CDATA[<=]]>";
		case GREATER_THAN:
		case AFTER:
			return "<![CDATA[>]]>";
		case GREATER_THAN_EQUAL:
			return ">=";
		case NOT_LIKE:
			return " not like ";
		case LIKE:
		case STARTING_WITH:
		case ENDING_WITH:
			return " like ";
		case CONTAINING:
			return " like ";
		case NOT_CONTAINING:
			return " not like ";
		case IN:
			return " in ";
		case NOT_IN:
			return " not in ";

		}

		return "";
	}
 
Example #8
Source File: HazelcastQueryCreator.java    From spring-data-hazelcast with Apache License 2.0 5 votes vote down vote up
private Predicate<?, ?> fromNullVariant(Type type, String property) {
    switch (type) {
        case IS_NULL:
            return Predicates.equal(property, null);
        case IS_NOT_NULL:
            return Predicates.notEqual(property, null);

        default:
            throw new InvalidDataAccessApiUsageException(String.format("Logic error for '%s' in query", type));
    }
}
 
Example #9
Source File: HazelcastQueryCreator.java    From spring-data-hazelcast with Apache License 2.0 5 votes vote down vote up
private Predicate<?, ?> fromCollectionVariant(Type type, String property, Iterator<Comparable<?>> iterator) {
    switch (type) {
        case IN:
            return Predicates.in(property, collectToArray(type, iterator));
        case NOT_IN:
            return Predicates.not(Predicates.in(property, collectToArray(type, iterator)));
        default:
            throw new InvalidDataAccessApiUsageException(String.format("Logic error for '%s' in query", type));
    }
}
 
Example #10
Source File: StringQuery.java    From spring-data-mybatis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link LikeParameterBinding} for the parameter with the given
 * name and {@link Type} and parameter binding input.
 * @param name must not be {@literal null} or empty.
 * @param type must not be {@literal null}.
 * @param expression may be {@literal null}.
 */
LikeParameterBinding(String name, Type type, @Nullable String expression) {

	super(name, null, expression);

	Assert.hasText(name, "Name must not be null or empty!");
	Assert.notNull(type, "Type must not be null!");

	Assert.isTrue(SUPPORTED_TYPES.contains(type), String.format(
			"Type must be one of %s!",
			StringUtils.collectionToCommaDelimitedString(SUPPORTED_TYPES)));

	this.type = type;
}
 
Example #11
Source File: HazelcastQueryCreator.java    From spring-data-hazelcast with Apache License 2.0 5 votes vote down vote up
private Predicate<?, ?> fromBooleanVariant(Type type, String property) {
    switch (type) {
        case TRUE:
            return Predicates.equal(property, true);
        case FALSE:
            return Predicates.equal(property, false);
        default:
            throw new InvalidDataAccessApiUsageException(String.format("Logic error for '%s' in query", type));
    }
}
 
Example #12
Source File: StringQuery.java    From spring-data-mybatis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link LikeParameterBinding} for the parameter with the given
 * position and {@link Type}.
 * @param position position of the parameter in the query.
 * @param type must not be {@literal null}.
 * @param expression may be {@literal null}.
 */
LikeParameterBinding(int position, Type type, @Nullable String expression) {

	super(null, position, expression);

	Assert.isTrue(position > 0, "Position must be greater than zero!");
	Assert.notNull(type, "Type must not be null!");

	Assert.isTrue(SUPPORTED_TYPES.contains(type), String.format(
			"Type must be one of %s!",
			StringUtils.collectionToCommaDelimitedString(SUPPORTED_TYPES)));

	this.type = type;
}
 
Example #13
Source File: StringQuery.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Extracts the like {@link Type} from the given JPA like expression.
 *
 * @param expression must not be {@literal null} or empty.
 */
private static Type getLikeTypeFrom(String expression) {

    Assert.hasText(expression, "Expression must not be null or empty!");

    if (expression.matches("%.*%"))
        return Type.CONTAINING;

    if (expression.startsWith("%"))
        return Type.ENDING_WITH;

    if (expression.endsWith("%"))
        return Type.STARTING_WITH;

    return Type.LIKE;
}
 
Example #14
Source File: SolrQueryCreator.java    From dubbox with Apache License 2.0 4 votes vote down vote up
private Criteria from(Type type, Criteria instance, Iterator<?> parameters) {
	Criteria criteria = instance;
	if (criteria == null) {
		criteria = new Criteria();
	}

	switch (type) {
	case TRUE:
		return criteria.is(true);
	case FALSE:
		return criteria.is(false);
	case SIMPLE_PROPERTY:
		return criteria.is(appendBoostAndGetParameterValue(criteria, parameters));
	case NEGATING_SIMPLE_PROPERTY:
		return criteria.is(appendBoostAndGetParameterValue(criteria, parameters)).not();
	case IS_NULL:
		return criteria.isNull();
	case IS_NOT_NULL:
		return criteria.isNotNull();
	case REGEX:
		return criteria.expression(appendBoostAndGetParameterValue(criteria, parameters).toString());
	case LIKE:
	case STARTING_WITH:
		return criteria.startsWith(asStringArray(appendBoostAndGetParameterValue(criteria, parameters)));
	case NOT_LIKE:
		return criteria.startsWith(asStringArray(appendBoostAndGetParameterValue(criteria, parameters))).not();
	case ENDING_WITH:
		return criteria.endsWith(asStringArray(appendBoostAndGetParameterValue(criteria, parameters)));
	case CONTAINING:
		return criteria.contains(asStringArray(appendBoostAndGetParameterValue(criteria, parameters)));
	case AFTER:
	case GREATER_THAN:
		return criteria.greaterThan(appendBoostAndGetParameterValue(criteria, parameters));
	case GREATER_THAN_EQUAL:
		return criteria.greaterThanEqual(appendBoostAndGetParameterValue(criteria, parameters));
	case BEFORE:
	case LESS_THAN:
		return criteria.lessThan(appendBoostAndGetParameterValue(criteria, parameters));
	case LESS_THAN_EQUAL:
		return criteria.lessThanEqual(appendBoostAndGetParameterValue(criteria, parameters));
	case BETWEEN:
		return criteria.between(appendBoostAndGetParameterValue(criteria, parameters),
				appendBoostAndGetParameterValue(criteria, parameters));
	case IN:
		return criteria.in(asArray(appendBoostAndGetParameterValue(criteria, parameters)));
	case NOT_IN:
		return criteria.in(asArray(appendBoostAndGetParameterValue(criteria, parameters))).not();
	case NEAR:
		return createNearCriteria(parameters, criteria);
	case WITHIN:
		return criteria.within((Point) getBindableValue((BindableSolrParameter) parameters.next()),
				(Distance) getBindableValue((BindableSolrParameter) parameters.next()));
	default:
		throw new InvalidDataAccessApiUsageException("Illegal criteria found '" + type + "'.");
	}
}
 
Example #15
Source File: StringQuery.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Extracts the like {@link Type} from the given JPA like expression.
 *
 * @param expression must not be {@literal null} or empty.
 */
private static Type getLikeTypeFrom(String expression) {

    Assert.hasText(expression, "Expression must not be null or empty!");

    if (expression.matches("%.*%"))
        return Type.CONTAINING;

    if (expression.startsWith("%"))
        return Type.ENDING_WITH;

    if (expression.endsWith("%"))
        return Type.STARTING_WITH;

    return Type.LIKE;
}
 
Example #16
Source File: MybatisMapperBuildAssistant.java    From spring-data-mybatis with Apache License 2.0 4 votes vote down vote up
protected String queryConditionRight(Type type, IgnoreCaseType ignoreCaseType,
		String[] properties) {
	StringBuilder builder = new StringBuilder();
	switch (type) {
	case BETWEEN:
		return String.format(" between #{%s} and #{%s}", properties[0],
				properties[1]);
	case CONTAINING:
	case NOT_CONTAINING:
		String bind = "__bind_" + properties[0];
		builder.append("<bind name=\"").append(bind)
				.append("\" value=\"'%' + " + properties[0] + " + '%'\" />");
		if (ignoreCaseType == ALWAYS || ignoreCaseType == WHEN_POSSIBLE) {
			builder.append(dialect.getLowercaseFunction()).append("(#{").append(bind)
					.append("})");
		}
		else {
			builder.append("#{").append(bind).append("}");
		}
		return builder.toString();
	case STARTING_WITH:
		bind = "__bind_" + properties[0];
		builder.append("<bind name=\"").append(bind)
				.append("\" value=\"" + properties[0] + " + '%'\" />");
		if (ignoreCaseType == ALWAYS || ignoreCaseType == WHEN_POSSIBLE) {
			builder.append(dialect.getLowercaseFunction()).append("(#{").append(bind)
					.append("})");
		}
		else {
			builder.append("#{").append(bind).append("}");
		}
		return builder.toString();
	case ENDING_WITH:
		bind = "__bind_" + properties[0];
		builder.append("<bind name=\"").append(bind)
				.append("\" value=\"'%' + " + properties[0] + "\" />");
		if (ignoreCaseType == ALWAYS || ignoreCaseType == WHEN_POSSIBLE) {
			builder.append(dialect.getLowercaseFunction()).append("(#{").append(bind)
					.append("})");
		}
		else {
			builder.append("#{").append(bind).append("}");
		}
		return builder.toString();
	case IN:
	case NOT_IN:
		builder.append("<foreach item=\"__item\" index=\"__index\" collection=\"")
				.append(properties[0])
				.append("\" open=\"(\" separator=\",\" close=\")\">#{__item}</foreach>");
		return builder.toString();
	case IS_NOT_NULL:
		return " is not null";
	case IS_NULL:
		return " is null";
	case TRUE:
		return " = true";
	case FALSE:
		return " = false";
	default:
		if (ignoreCaseType == ALWAYS || ignoreCaseType == WHEN_POSSIBLE) {
			builder.append(dialect.getLowercaseFunction()).append("(#{")
					.append(properties[0]).append("})");
		}
		else {
			builder.append("#{").append(properties[0]).append("}");
		}
		return builder.toString();
	}
}
 
Example #17
Source File: MybatisBasicMapperBuilder.java    From spring-data-mybatis with Apache License 2.0 4 votes vote down vote up
private String buildCondition() {

		final StringBuilder builder = new StringBuilder();

		entity.doWithProperties((PropertyHandler<MybatisPersistentProperty>) p -> {

			Set<Condition> set = new HashSet<>();

			Conditions conditions = p.findAnnotation(Conditions.class);
			if (null != conditions && conditions.value().length > 0) {
				set.addAll(Stream.of(conditions.value()).collect(Collectors.toSet()));
			}
			Condition condition = p.findAnnotation(Condition.class);
			if (null != condition) {
				set.add(condition);
			}

			builder.append(set.stream().map(c -> {

				String[] properties = c.properties();
				if (null == properties || properties.length == 0) {
					properties = new String[] { p.getName() };
				}
				Type type = Type.valueOf(c.type().name());
				if (type.getNumberOfArguments() > 0
						&& type.getNumberOfArguments() != properties.length) {
					throw new MappingException("@Condition with type " + type + " needs "
							+ type.getNumberOfArguments() + " arguments, but only find "
							+ properties.length + " properties in this @Condition.");
				}

				StringBuilder sb = new StringBuilder();
				sb.append("<if test=\"");
				sb.append(Stream.of(properties).map(
						property -> String.format("__condition.%s != null", property))
						.collect(Collectors.joining(" and ")));

				sb.append("\">");

				sb.append(" and ")
						.append(queryConditionLeft(
								StringUtils.hasText(c.column()) ? c.column()
										: p.getColumnName(),
								IgnoreCaseType.valueOf(c.ignoreCaseType().name())))
						.append(calculateOperation(type));

				sb.append(queryConditionRight(type,
						IgnoreCaseType.valueOf(c.ignoreCaseType().name()),
						Stream.of(properties).map(p1 -> "__condition." + p1)
								.toArray(String[]::new)));

				sb.append("</if>");
				return sb;
			}).collect(Collectors.joining(" ")));

		});

		return builder.toString();
	}
 
Example #18
Source File: HazelcastQueryCreator.java    From spring-data-hazelcast with Apache License 2.0 4 votes vote down vote up
private Predicate<?, ?> from(Part part, Iterator<Comparable<?>> iterator) {
    String property = part.getProperty().toDotPath();
    Type type = part.getType();
    boolean ignoreCase = ifIgnoreCase(part);

    switch (type) {
        case AFTER:
        case GREATER_THAN:
        case GREATER_THAN_EQUAL:
        case BEFORE:
        case LESS_THAN:
        case LESS_THAN_EQUAL:
        case BETWEEN:
            return fromInequalityVariant(type, property, iterator);
        case IS_NULL:
        case IS_NOT_NULL:
            return fromNullVariant(type, property);
        case IN:
        case NOT_IN:
            return fromCollectionVariant(type, property, iterator);
        case CONTAINING:
        case NOT_CONTAINING:
        case STARTING_WITH:
        case ENDING_WITH:
        case LIKE:
        case NOT_LIKE:
            return fromLikeVariant(type, ignoreCase, property, iterator);
        case TRUE:
        case FALSE:
            return fromBooleanVariant(type, property);
        case SIMPLE_PROPERTY:
        case NEGATING_SIMPLE_PROPERTY:
            return fromEqualityVariant(type, ignoreCase, property, iterator);
        case REGEX:
            return Predicates.regex(property, iterator.next().toString());
        case IS_EMPTY:
        case IS_NOT_EMPTY:
            return fromEmptyVariant(type, property);
        /* case EXISTS:*/
        case NEAR:
        case WITHIN:
            return fromGeoVariant(type, property, iterator);

        default:
            throw new InvalidDataAccessApiUsageException(String.format("Unsupported type '%s'", type));
    }
}
 
Example #19
Source File: HazelcastQueryCreator.java    From spring-data-hazelcast with Apache License 2.0 4 votes vote down vote up
private Comparable<?>[] collectToArray(Type type, Iterator<Comparable<?>> iterator) {
    Object item = iterator.next();
    Assert.state(isCollection(item), String.format("%s requires collection of values", type));
    Collection<Comparable<?>> itemcol = (Collection<Comparable<?>>) item;
    return itemcol.toArray(new Comparable<?>[0]);
}
 
Example #20
Source File: StringQuery.java    From spring-data-ebean with Apache License 2.0 4 votes vote down vote up
/**
      * Parses {@link ParameterBinding} instances from the given query and adds them to the registered bindings. Returns
      * the cleaned up query.
      *
      * @param query
      * @return
      */
     private final String parseParameterBindingsOfQueryIntoBindingsAndReturnCleanedQuery(String query,
                                                                                         List<ParameterBinding> bindings) {

         String result = query;
         Matcher matcher = PARAMETER_BINDING_PATTERN.matcher(query);

         int greatestParameterIndex = tryFindGreatestParameterIndexIn(query);

         boolean parametersShouldBeAccessedByIndex = greatestParameterIndex != -1;

/*
          * Prefer indexed access over named parameters if only SpEL Expression parameters are present.
 */
         if (!parametersShouldBeAccessedByIndex && query.contains("?#{")) {
             parametersShouldBeAccessedByIndex = true;
             greatestParameterIndex = 0;
         }

/*
          * If parameters need to be bound by index, we bind the synthetic expression parameters starting from position of the greatest discovered index parameter in order to
 * not mix-up with the actual parameter indices.
 */
         int expressionParameterIndex = parametersShouldBeAccessedByIndex ? greatestParameterIndex : 0;

         while (matcher.find()) {

             String parameterIndexString = matcher.group(4);
             String parameterName = parameterIndexString != null ? null : matcher.group(6);
             Integer parameterIndex = parameterIndexString == null ? null : Integer.valueOf(parameterIndexString);
             String typeSource = matcher.group(1);
             String expression = null;
             String replacement = null;

             if (parameterName == null && parameterIndex == null) {
                 expressionParameterIndex++;

                 if (parametersShouldBeAccessedByIndex) {
                     parameterIndex = expressionParameterIndex;
                     replacement = "?" + parameterIndex;
                 } else {
                     parameterName = EXPRESSION_PARAMETER_PREFIX + expressionParameterIndex;
                     replacement = ":" + parameterName;
                 }

                 expression = matcher.group(9);
             }

             switch (ParameterBindingType.of(typeSource)) {

                 case LIKE:

                     Type likeType = LikeParameterBinding.getLikeTypeFrom(matcher.group(2));
                     replacement = replacement != null ? replacement : matcher.group(3);

                     if (parameterIndex != null) {
                         checkAndRegister(new LikeParameterBinding(parameterIndex, likeType, expression), bindings);
                     } else {
                         checkAndRegister(new LikeParameterBinding(parameterName, likeType, expression), bindings);

                         replacement = expression != null ? ":" + parameterName : matcher.group(5);
                     }

                     break;

                 case IN:

                     if (parameterIndex != null) {
                         checkAndRegister(new InParameterBinding(parameterIndex, expression), bindings);
                     } else {
                         checkAndRegister(new InParameterBinding(parameterName, expression), bindings);
                     }

                     break;

                 case AS_IS: // fall-through we don't need a special parameter binding for the given parameter.
                 default:

                     bindings.add(parameterIndex != null ? new ParameterBinding(null, parameterIndex, expression)
                             : new ParameterBinding(parameterName, null, expression));
             }

             if (replacement != null) {
                 result = StringUtils.replace(result, matcher.group(2), replacement);
             }

         }

         return result;
     }
 
Example #21
Source File: SpelQueryCreator.java    From spring-data-keyvalue with Apache License 2.0 4 votes vote down vote up
private static boolean requiresInverseLookup(Part part) {
	return part.getType() == Type.IN;
}
 
Example #22
Source File: StringQuery.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new {@link LikeParameterBinding} for the parameter with the given position and {@link Type}.
 *
 * @param position   position of the parameter in the query.
 * @param type       must not be {@literal null}.
 * @param expression may be {@literal null}.
 */
LikeParameterBinding(int position, Type type, @Nullable String expression) {

    super(null, position, expression);

    Assert.isTrue(position > 0, "Position must be greater than zero!");
    Assert.notNull(type, "Type must not be null!");

    Assert.isTrue(SUPPORTED_TYPES.contains(type), String.format("Type must be one of %s!",
        StringUtils.collectionToCommaDelimitedString(SUPPORTED_TYPES)));

    this.type = type;
}
 
Example #23
Source File: StringQuery.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new {@link LikeParameterBinding} for the parameter with the given name and {@link Type} and
 * parameter binding input.
 *
 * @param name       must not be {@literal null} or empty.
 * @param type       must not be {@literal null}.
 * @param expression may be {@literal null}.
 */
LikeParameterBinding(String name, Type type, @Nullable String expression) {

    super(name, null, expression);

    Assert.hasText(name, "Name must not be null or empty!");
    Assert.notNull(type, "Type must not be null!");

    Assert.isTrue(SUPPORTED_TYPES.contains(type), String.format("Type must be one of %s!",
        StringUtils.collectionToCommaDelimitedString(SUPPORTED_TYPES)));

    this.type = type;
}
 
Example #24
Source File: StringQuery.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new {@link LikeParameterBinding} for the parameter with the given name and {@link Type} and
 * parameter binding input.
 *
 * @param name       must not be {@literal null} or empty.
 * @param type       must not be {@literal null}.
 * @param expression may be {@literal null}.
 */
LikeParameterBinding(String name, Type type, @Nullable String expression) {

    super(name, null, expression);

    Assert.hasText(name, "Name must not be null or empty!");
    Assert.notNull(type, "Type must not be null!");

    Assert.isTrue(SUPPORTED_TYPES.contains(type), String.format("Type must be one of %s!",
        StringUtils.collectionToCommaDelimitedString(SUPPORTED_TYPES)));

    this.type = type;
}
 
Example #25
Source File: ParameterMetadataProvider.java    From spring-data-ebean with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new {@link ParameterMetadata}.
 *
 * @param parameterType
 * @param parameterName
 * @param type
 * @param value
 */
public ParameterMetadata(Class<T> parameterType, String parameterName, Type type, Object value) {
    this.parameterType = parameterType;
    this.parameterName = parameterName;
    this.parameterValue = value;
    this.type = (value == null && Type.SIMPLE_PROPERTY.equals(type) ? Type.IS_NULL : type);
}
 
Example #26
Source File: StringQuery.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new {@link LikeParameterBinding} for the parameter with the given position and {@link Type}.
 *
 * @param position   position of the parameter in the query.
 * @param type       must not be {@literal null}.
 * @param expression may be {@literal null}.
 */
LikeParameterBinding(int position, Type type, @Nullable String expression) {

    super(null, position, expression);

    Assert.isTrue(position > 0, "Position must be greater than zero!");
    Assert.notNull(type, "Type must not be null!");

    Assert.isTrue(SUPPORTED_TYPES.contains(type), String.format("Type must be one of %s!",
        StringUtils.collectionToCommaDelimitedString(SUPPORTED_TYPES)));

    this.type = type;
}
 
Example #27
Source File: StringQuery.java    From spring-data-ebean with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new {@link LikeParameterBinding} for the parameter with the given name and {@link Type} and parameter
 * binding input.
 *
 * @param name       must not be {@literal null} or empty.
 * @param type       must not be {@literal null}.
 * @param expression may be {@literal null}.
 */
public LikeParameterBinding(String name, Type type, String expression) {

    super(name, null, expression);

    Assert.hasText(name, "Name must not be null or empty!");
    Assert.notNull(type, "Type must not be null!");

    Assert.isTrue(SUPPORTED_TYPES.contains(type),
            String.format("Type must be one of %s!", StringUtils.collectionToCommaDelimitedString(SUPPORTED_TYPES)));

    this.type = type;
}
 
Example #28
Source File: StringQuery.java    From spring-data-ebean with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new {@link LikeParameterBinding} for the parameter with the given position and {@link Type}.
 *
 * @param position
 * @param type       must not be {@literal null}.
 * @param expression may be {@literal null}.
 */
public LikeParameterBinding(int position, Type type, String expression) {

    super(null, position, expression);

    Assert.isTrue(position > 0, "Position must be greater than zero!");
    Assert.notNull(type, "Type must not be null!");

    Assert.isTrue(SUPPORTED_TYPES.contains(type),
            String.format("Type must be one of %s!", StringUtils.collectionToCommaDelimitedString(SUPPORTED_TYPES)));

    this.type = type;
}
 
Example #29
Source File: StringQuery.java    From spring-data-mybatis with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new {@link LikeParameterBinding} for the parameter with the given
 * position and {@link Type}.
 * @param position position of the parameter in the query.
 * @param type must not be {@literal null}.
 */
LikeParameterBinding(int position, Type type) {
	this(position, type, null);
}
 
Example #30
Source File: ParameterMetadataProvider.java    From spring-data-ebean with Apache License 2.0 2 votes vote down vote up
/**
 * Returns whether the parameter shall be considered an {@literal IS NULL} parameter.
 *
 * @return
 */
public boolean isIsNullParameter() {
    return Type.IS_NULL.equals(type);
}