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

The following examples show how to use org.springframework.data.querydsl.binding.QuerydslBindings. 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: QuerydslPredicateOperationCustomizer.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
/**
 * 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
Source File: QuerydslPredicateOperationCustomizer.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
/**
 * 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 File: ConnectionRepository.java    From flair-engine with 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
Source File: ConnectionParameterRepository.java    From flair-engine with 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, 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 File: UserDAO.java    From SuperBoot with 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 File: UserRepository.java    From java-platform with 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
Source File: UserRepository.java    From spring-data-examples with 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 #8
Source File: GroupRepository.java    From SMSC with 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 #9
Source File: RoleRepository.java    From SMSC with 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 #10
Source File: AuthorityRepository.java    From SMSC with 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 #11
Source File: UserRepository.java    From SMSC with 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 #12
Source File: DashboardBoxRepository.java    From SMSC with 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 #13
Source File: DashboardBoxTypeRepository.java    From SMSC with 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 #14
Source File: DashboardRepository.java    From SMSC with 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 #15
Source File: ProductRepository.java    From java-platform with 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 #16
Source File: CustomerRepository.java    From SMSC with 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 #17
Source File: AddressRepository.java    From tutorials with 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 #18
Source File: UserRepository.java    From tutorials with 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 #19
Source File: MyUserRepository.java    From tutorials with 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 #20
Source File: UserRepository.java    From SMSC with 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 #21
Source File: ContactRepository.java    From SMSC with 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 #22
Source File: QuerydslPredicateOperationCustomizer.java    From springdoc-openapi with Apache License 2.0 4 votes vote down vote up
@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 #23
Source File: RoleDAO.java    From SuperBoot with 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 #24
Source File: CountryPredicate.java    From springdoc-openapi with 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 #25
Source File: QuerydslPredicateOperationCustomizer.java    From springdoc-openapi with Apache License 2.0 4 votes vote down vote up
/**
 * 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 #26
Source File: MedicationRepository.java    From spring-boot-jpa with 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 #27
Source File: PatientRepository.java    From spring-boot-jpa with 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 #28
Source File: DutiesDAO.java    From SuperBoot with MIT License 2 votes vote down vote up
/**
 * 增加对查询条件的模糊搜索支持
 *
 * @param bindings
 * @param duties
 */
@Override
default void customize(QuerydslBindings bindings, QSuperbootDuties duties) {
    bindings.bind(duties.dutiesCode).first(StringExpression::containsIgnoreCase);
    bindings.bind(duties.dutiesName).first(StringExpression::containsIgnoreCase);
}
 
Example #29
Source File: EmployeesDAO.java    From SuperBoot with MIT License 2 votes vote down vote up
/**
 * 增加对查询条件的模糊搜索支持
 *
 * @param bindings
 * @param emp
 */
@Override
default void customize(QuerydslBindings bindings, QSuperbootEmployees emp) {
    bindings.bind(emp.employeesCode).first(StringExpression::containsIgnoreCase);
    bindings.bind(emp.employeesName).first(StringExpression::containsIgnoreCase);
}
 
Example #30
Source File: OrgDAO.java    From SuperBoot with 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);
}