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

The following examples show how to use org.springframework.data.repository.query.parser.Part.IgnoreCaseType. 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: VaultQueryCreator.java    From spring-vault with Apache License 2.0 4 votes vote down vote up
private static boolean isIgnoreCase(Part part) {
	return part.shouldIgnoreCase() != IgnoreCaseType.NEVER;
}
 
Example #2
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 #3
Source File: MybatisMapperBuildAssistant.java    From spring-data-mybatis with Apache License 2.0 4 votes vote down vote up
protected String queryConditionLeft(String column, IgnoreCaseType ignoreCaseType) {
	if (ignoreCaseType == ALWAYS || ignoreCaseType == WHEN_POSSIBLE) {
		return dialect.getLowercaseFunction() + "(" + column + ")";
	}
	return column;
}
 
Example #4
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 #5
Source File: AbstractDynamoDBQueryCreator.java    From spring-data-dynamodb with Apache License 2.0 4 votes vote down vote up
protected DynamoDBQueryCriteria<T, ID> addCriteria(DynamoDBQueryCriteria<T, ID> criteria, Part part, Iterator<Object> iterator) {
	if (part.shouldIgnoreCase().equals(IgnoreCaseType.ALWAYS))
		throw new UnsupportedOperationException("Case insensitivity not supported");

	Class<?> leafNodePropertyType = part.getProperty().getLeafProperty().getType();
	
	PropertyPath leafNodePropertyPath = part.getProperty().getLeafProperty();
	String leafNodePropertyName = leafNodePropertyPath.toDotPath();
	if (leafNodePropertyName.indexOf(".") != -1)
	{
		int index = leafNodePropertyName.lastIndexOf(".");
		leafNodePropertyName = leafNodePropertyName.substring(index);
	}

	switch (part.getType()) {
	
	case IN:
		Object in = iterator.next();
		Assert.notNull(in, "Creating conditions on null parameters not supported: please specify a value for '"
				+ leafNodePropertyName + "'");
		boolean isIterable = ClassUtils.isAssignable(in.getClass(), Iterable.class);
		boolean isArray = ObjectUtils.isArray(in);
		Assert.isTrue(isIterable || isArray, "In criteria can only operate with Iterable or Array parameters");
		Iterable<?> iterable = isIterable ? ((Iterable<?>) in) : Arrays.asList(ObjectUtils.toObjectArray(in));
		return criteria.withPropertyIn(leafNodePropertyName, iterable, leafNodePropertyType);
	case CONTAINING:
		return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.CONTAINS,
				iterator.next(), leafNodePropertyType);
	case STARTING_WITH:
		return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.BEGINS_WITH,
				iterator.next(), leafNodePropertyType);
	case BETWEEN:
		Object first = iterator.next();
		Object second = iterator.next();
		return criteria.withPropertyBetween(leafNodePropertyName, first, second, leafNodePropertyType);
	case AFTER:
	case GREATER_THAN:
		return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.GT, iterator.next(),
				leafNodePropertyType);
	case BEFORE:
	case LESS_THAN:
		return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.LT, iterator.next(),
				leafNodePropertyType);
	case GREATER_THAN_EQUAL:
		return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.GE, iterator.next(),
				leafNodePropertyType);
	case LESS_THAN_EQUAL:
		return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.LE, iterator.next(),
				leafNodePropertyType);
	case IS_NULL:
		return criteria.withNoValuedCriteria(leafNodePropertyName, ComparisonOperator.NULL);
	case IS_NOT_NULL:
		return criteria.withNoValuedCriteria(leafNodePropertyName, ComparisonOperator.NOT_NULL);
	case TRUE:
		return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.EQ, Boolean.TRUE,
				leafNodePropertyType);
	case FALSE:
		return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.EQ, Boolean.FALSE,
				leafNodePropertyType);
	case SIMPLE_PROPERTY:
		return criteria.withPropertyEquals(leafNodePropertyName, iterator.next(), leafNodePropertyType);
	case NEGATING_SIMPLE_PROPERTY:
		return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.NE, iterator.next(),
				leafNodePropertyType);
	default:
		throw new IllegalArgumentException("Unsupported keyword " + part.getType());
	}

}