Java Code Examples for org.springframework.data.querydsl.binding.QuerydslBindings

The following examples show how to use org.springframework.data.querydsl.binding.QuerydslBindings. These examples are extracted from open source projects. 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
/**
 * Gets field values.
 *
 * @param instance the instance
 * @param fieldName the field name
 * @return the field values
 */
private Set<String> getFieldValues(QuerydslBindings instance, String fieldName) {
	try {
		Field field = FieldUtils.getDeclaredField(instance.getClass(),fieldName,true);
		return (Set<String>) field.get(instance);
	}
	catch (IllegalAccessException e) {
		LOGGER.warn(e.getMessage());
	}
	return Collections.emptySet();
}
 
Example 2
/**
 * Gets path spec.
 *
 * @param instance the instance
 * @param fieldName the field name
 * @return the path spec
 */
private Map<String, Object> getPathSpec(QuerydslBindings instance, String fieldName) {
	try {
		Field field = FieldUtils.getDeclaredField(instance.getClass(),fieldName,true);
		return (Map<String, Object>) field.get(instance);
	}
	catch (IllegalAccessException e) {
		LOGGER.warn(e.getMessage());
	}
	return Collections.emptyMap();
}
 
Example 3
Source Project: flair-engine   Source File: ConnectionRepository.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Customize the {@link QuerydslBindings} for the given root.
 *
 * @param bindings the {@link QuerydslBindings} to customize, will never be {@literal null}.
 * @param root     the entity root, will never be {@literal null}.
 */
@Override
default void customize(QuerydslBindings bindings, QConnection root) {
    bindings.bind(root.connectionType.id).first(SimpleExpression::eq);
    bindings.bind(root.name).first(SimpleExpression::eq);
    bindings.bind(root.linkId).first(SimpleExpression::eq);
}
 
Example 4
/**
 * Customize the {@link QuerydslBindings} for the given root.
 *
 * @param bindings the {@link QuerydslBindings} to customize, will never be {@literal null}.
 * @param root     the entity root, will never be {@literal null}.
 */
@Override
default void customize(QuerydslBindings bindings, QConnectionParameter root) {
    bindings.bind(root.value).first(SimpleExpression::eq);
    bindings.bind(root.name).first(SimpleExpression::eq);
    bindings.bind(root.linkId).first(SimpleExpression::eq);
}
 
Example 5
Source Project: SuperBoot   Source File: UserDAO.java    License: MIT License 5 votes vote down vote up
/**
 * 增加对查询条件的模糊搜索支持
 *
 * @param bindings
 * @param user
 */
@Override
default void customize(QuerydslBindings bindings, QSuperbootUser user) {
    bindings.bind(user.userCode).first(StringExpression::containsIgnoreCase);
    bindings.bind(user.userEmail).first(StringExpression::containsIgnoreCase);
    bindings.bind(user.userPhone).first(StringExpression::containsIgnoreCase);
}
 
Example 6
Source Project: java-platform   Source File: UserRepository.java    License: Apache License 2.0 5 votes vote down vote up
@Override
default void customize(QuerydslBindings bindings, QUser root) {
	bindings.bind(root.username).first((path, value) -> path.contains(value));
	bindings.bind(root.name).first((path, value) -> path.contains(value));
	bindings.bind(root.email).first((path, value) -> path.contains(value));
	bindings.bind(root.mobile).first((path, value) -> path.contains(value));

	bindings.excluding(root.password);
}
 
Example 7
@Override
public Operation customize(Operation operation, HandlerMethod handlerMethod) {
	if (operation.getParameters() == null) {
		return operation;
	}

	MethodParameter[] methodParameters = handlerMethod.getMethodParameters();

	int parametersLength = methodParameters.length;
	List<Parameter> parametersToAddToOperation = new ArrayList<>();
	for (int i = 0; i < parametersLength; i++) {
		MethodParameter parameter = methodParameters[i];
		QuerydslPredicate predicate = parameter.getParameterAnnotation(QuerydslPredicate.class);

		if (predicate == null) {
			continue;
		}

		QuerydslBindings bindings = extractQdslBindings(predicate);

		Set<String> fieldsToAdd = Arrays.stream(predicate.root().getDeclaredFields()).map(Field::getName).collect(Collectors.toSet());

		Map<String, Object> pathSpecMap = getPathSpec(bindings, "pathSpecs");
		//remove blacklisted fields
		Set<String> blacklist = getFieldValues(bindings, "blackList");
		fieldsToAdd.removeIf(blacklist::contains);

		Set<String> whiteList = getFieldValues(bindings, "whiteList");
		Set<String> aliases = getFieldValues(bindings, "aliases");

		fieldsToAdd.addAll(aliases);
		fieldsToAdd.addAll(whiteList);
		for (String fieldName : fieldsToAdd) {
			Type type = getFieldType(fieldName, pathSpecMap, predicate.root());
			io.swagger.v3.oas.models.parameters.Parameter newParameter = buildParam(type, fieldName);

			parametersToAddToOperation.add(newParameter);
		}
	}
	operation.getParameters().addAll(parametersToAddToOperation);
	return operation;
}
 
Example 8
/**
 * Extract qdsl bindings querydsl bindings.
 *
 * @param predicate the predicate
 * @return the querydsl bindings
 */
private QuerydslBindings extractQdslBindings(QuerydslPredicate predicate) {
	ClassTypeInformation<?> classTypeInformation = ClassTypeInformation.from(predicate.root());
	TypeInformation<?> domainType = classTypeInformation.getRequiredActualType();

	Optional<Class<? extends QuerydslBinderCustomizer<?>>> bindingsAnnotation = Optional.of(predicate)
			.map(QuerydslPredicate::bindings)
			.map(CastUtils::cast);

	return bindingsAnnotation
			.map(it -> querydslBindingsFactory.createBindingsFor(domainType, it))
			.orElseGet(() -> querydslBindingsFactory.createBindingsFor(domainType));
}
 
Example 9
Source Project: springdoc-openapi   Source File: CountryPredicate.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void customize(QuerydslBindings querydslBindings, QCountry qCountry) {
	querydslBindings.bind(qCountry.codeISO3166).as("code").first((path, value) -> path.containsIgnoreCase(value));
	querydslBindings.bind(qCountry.dialingCode).as("postCode").first((path, value) -> path.containsIgnoreCase(value));
}
 
Example 10
Source Project: SuperBoot   Source File: RoleDAO.java    License: MIT License 4 votes vote down vote up
/**
 * 增加对查询条件的模糊搜索支持
 * @param bindings
 * @param role
 */
@Override
default void customize(QuerydslBindings bindings, QSuperbootRole role) {
    bindings.bind(role.roleCode).first(StringExpression::containsIgnoreCase);
    bindings.bind(role.roleName).first(StringExpression::containsIgnoreCase);
}
 
Example 11
Source Project: SMSC   Source File: CustomerRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Override
default public void customize(QuerydslBindings bindings, QCustomer root) {
    bindings.bind(String.class).first((SingleValueBinding<StringPath, String>) StringExpression::startsWithIgnoreCase);
    bindings.bind(Long.class).first((SingleValueBinding<NumberPath<Long>, Long>) NumberExpression::in);
}
 
Example 12
Source Project: SMSC   Source File: ContactRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Override
default public void customize(QuerydslBindings bindings, QContact root) {
    bindings.bind(String.class).first((SingleValueBinding<StringPath, String>) StringExpression::containsIgnoreCase);
}
 
Example 13
Source Project: SMSC   Source File: UserRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Override
default public void customize(QuerydslBindings bindings, QUser root) {
    bindings.bind(String.class).first((SingleValueBinding<StringPath, String>) StringExpression::containsIgnoreCase);
    bindings.excluding(root.password);
}
 
Example 14
Source Project: SMSC   Source File: GroupRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Override
default public void customize(QuerydslBindings bindings, QGroup root) {
    bindings.bind(String.class).first((SingleValueBinding<StringPath, String>) StringExpression::containsIgnoreCase);
}
 
Example 15
Source Project: SMSC   Source File: RoleRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Override
default public void customize(QuerydslBindings bindings, QRole root) {
    bindings.bind(String.class).first((SingleValueBinding<StringPath, String>) StringExpression::containsIgnoreCase);
}
 
Example 16
Source Project: SMSC   Source File: AuthorityRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Override
default public void customize(QuerydslBindings bindings, QAuthority root) {
    bindings.bind(String.class).first((SingleValueBinding<StringPath, String>) StringExpression::containsIgnoreCase);
}
 
Example 17
Source Project: SMSC   Source File: UserRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Override
default public void customize(QuerydslBindings bindings, QUser root) {
    bindings.bind(String.class).first((SingleValueBinding<StringPath, String>) StringExpression::containsIgnoreCase);
    bindings.excluding(root.password);
}
 
Example 18
Source Project: SMSC   Source File: DashboardBoxRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Override
default public void customize(QuerydslBindings bindings, QDashboardBox root) {
    bindings.bind(String.class).first((SingleValueBinding<StringPath, String>) StringExpression::containsIgnoreCase);
}
 
Example 19
Source Project: SMSC   Source File: DashboardBoxTypeRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Override
default public void customize(QuerydslBindings bindings, QDashboardBoxType root) {
    bindings.bind(String.class).first((SingleValueBinding<StringPath, String>) StringExpression::containsIgnoreCase);
}
 
Example 20
Source Project: SMSC   Source File: DashboardRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Override
default public void customize(QuerydslBindings bindings, QDashboard root) {
    bindings.bind(String.class).first((SingleValueBinding<StringPath, String>) StringExpression::containsIgnoreCase);
}
 
Example 21
Source Project: java-platform   Source File: ProductRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Override
default void customize(QuerydslBindings bindings, QProduct root) {
	bindings.bind(root.name).first((path, value) -> path.contains(value));
}
 
Example 22
Source Project: spring-data-examples   Source File: UserRepository.java    License: Apache License 2.0 4 votes vote down vote up
@Override
default public void customize(QuerydslBindings bindings, QUser root) {

	bindings.bind(String.class).first((StringPath path, String value) -> path.containsIgnoreCase(value));
	bindings.excluding(root.password);
}
 
Example 23
Source Project: tutorials   Source File: AddressRepository.java    License: MIT License 4 votes vote down vote up
@Override
default void customize(final QuerydslBindings bindings, final QAddress root) {
    bindings.bind(String.class).first((SingleValueBinding<StringPath, String>) StringExpression::eq);
}
 
Example 24
Source Project: tutorials   Source File: UserRepository.java    License: MIT License 4 votes vote down vote up
@Override
default void customize(final QuerydslBindings bindings, final QUser root) {
    bindings.bind(String.class).first((SingleValueBinding<StringPath, String>) StringExpression::eq);
}
 
Example 25
Source Project: tutorials   Source File: MyUserRepository.java    License: MIT License 4 votes vote down vote up
@Override
default public void customize(final QuerydslBindings bindings, final QMyUser root) {
    bindings.bind(String.class)
      .first((SingleValueBinding<StringPath, String>) StringExpression::containsIgnoreCase);
    bindings.excluding(root.email);
}
 
Example 26
Source Project: spring-boot-jpa   Source File: PatientRepository.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Override default QueryDsl bindings.
 * TODO explain what and why?
 * This customizes QueryDsl to ignore case on queries involving String values
 *
 * @param bindings a QueryDslBindings to use
 * @param root     the QPatient root
 */
@Override
default void customize(QuerydslBindings bindings, QPatient root) {
    bindings.excluding(root.id);
    //bindings.excluding(root.patientId);
    bindings.bind(String.class)
            .first((SingleValueBinding<StringPath, String>) StringExpression::containsIgnoreCase);
}
 
Example 27
Source Project: spring-boot-jpa   Source File: MedicationRepository.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Override default QueryDsl bindings.
 * TODO explain what and why?
 *
 * @param bindings a QueryDslBindings to use
 * @param root     the QPatient root
 */
@Override
default void customize(QuerydslBindings bindings, QMedication root) {
	bindings.excluding(root.id);
	bindings.bind(String.class)
			.first((SingleValueBinding<StringPath, String>) StringExpression::containsIgnoreCase);
}
 
Example 28
Source Project: SuperBoot   Source File: GroupDAO.java    License: MIT License 2 votes vote down vote up
/**
 * 增加对查询条件的模糊搜索支持
 *
 * @param bindings
 * @param group
 */
@Override
default void customize(QuerydslBindings bindings, QSuperbootGroup group) {
    bindings.bind(group.groupCode).first(StringExpression::containsIgnoreCase);
    bindings.bind(group.groupName).first(StringExpression::containsIgnoreCase);
}
 
Example 29
Source Project: SuperBoot   Source File: MenuDAO.java    License: MIT License 2 votes vote down vote up
/**
 * 增加对查询条件的模糊搜索支持
 *
 * @param bindings
 * @param menu
 */
@Override
default void customize(QuerydslBindings bindings, QSuperbootMenu menu) {
    bindings.bind(menu.menuCode).first(StringExpression::containsIgnoreCase);
    bindings.bind(menu.menuName).first(StringExpression::containsIgnoreCase);
}
 
Example 30
Source Project: SuperBoot   Source File: OrgDAO.java    License: MIT License 2 votes vote down vote up
/**
 * 增加对查询条件的模糊搜索支持
 *
 * @param bindings
 * @param org
 */
@Override
default void customize(QuerydslBindings bindings, QSuperbootOrg org) {
    bindings.bind(org.orgName).first(StringExpression::containsIgnoreCase);
}