Remove near From Query Builder DSL

I'd like to be a little bit more careful here and not add
a default method that throws an UnsupportedOperationException.

In the meantime, applications can use the filter method like
so:

LdapQueryBuilder.query().filter(new ProximityFilter("cn", "John Doe"))

PR gh-1052
This commit is contained in:
Josh Cummings
2025-04-17 10:34:23 -06:00
parent 058f529bb2
commit c98c0200f7
3 changed files with 3 additions and 21 deletions

View File

@@ -105,17 +105,4 @@ public interface ConditionCriteria {
*/
ConditionCriteria not();
/**
* Appends an {@link org.springframework.ldap.filter.ProximityFilter}.
* @param value the value to compare with.
* @return an ContainerCriteria instance that can be used to continue append more
* criteria or as the LdapQuery instance to be used as instance to e.g.
* {@link org.springframework.ldap.core.LdapOperations#search(LdapQuery, org.springframework.ldap.core.ContextMapper)}.
* @since 3.3
* @see org.springframework.ldap.filter.EqualsFilter
*/
default ContainerCriteria near(String value) {
throw new UnsupportedOperationException();
}
}

View File

@@ -23,7 +23,6 @@ import org.springframework.ldap.filter.LessThanOrEqualsFilter;
import org.springframework.ldap.filter.LikeFilter;
import org.springframework.ldap.filter.NotFilter;
import org.springframework.ldap.filter.PresentFilter;
import org.springframework.ldap.filter.ProximityFilter;
import org.springframework.ldap.filter.WhitespaceWildcardsFilter;
/**
@@ -73,11 +72,6 @@ class DefaultConditionCriteria implements ConditionCriteria {
return appendToParent(new PresentFilter(this.attribute));
}
@Override
public ContainerCriteria near(String value) {
return appendToParent(new ProximityFilter(this.attribute, value));
}
private ContainerCriteria appendToParent(Filter filter) {
return this.parent.append(negateIfApplicable(filter));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2023 the original author or authors.
* Copyright 2005-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package org.springframework.ldap.query;
import org.junit.Test;
import org.springframework.ldap.filter.ProximityFilter;
import org.springframework.ldap.support.LdapUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -75,7 +76,7 @@ public class LdapQueryBuilderTests {
@Test
public void buildProximity() {
LdapQuery result = LdapQueryBuilder.query().where("cn").near("John Doe");
LdapQuery result = LdapQueryBuilder.query().filter(new ProximityFilter("cn", "John Doe"));
assertThat(result.filter().encode()).isEqualTo("(cn~=John Doe)");
}