Skip to content

Commit c008466

Browse files
committed
DATACOUCH-1055 - Queries on field annotated properties have original name.
Queries on field annotated properties have original name. They should use getFieldName() which will use the annotated if it exists.
1 parent 29766bf commit c008466

File tree

5 files changed

+69
-19
lines changed

5 files changed

+69
-19
lines changed

pom.xml

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525
</properties>
2626

2727
<dependencyManagement>
28-
<dependencies>
29-
<dependency>
30-
<groupId>org.testcontainers</groupId>
31-
<artifactId>testcontainers-bom</artifactId>
32-
<version>${testcontainers}</version>
33-
<type>pom</type>
34-
<scope>import</scope>
35-
</dependency>
36-
</dependencies>
37-
</dependencyManagement>
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.testcontainers</groupId>
31+
<artifactId>testcontainers-bom</artifactId>
32+
<version>${testcontainers}</version>
33+
<type>pom</type>
34+
<scope>import</scope>
35+
</dependency>
36+
</dependencies>
37+
</dependencyManagement>
3838

3939
<dependencies>
4040
<dependency>
@@ -173,6 +173,7 @@
173173
<dependency>
174174
<groupId>io.projectreactor</groupId>
175175
<artifactId>reactor-test</artifactId>
176+
<version>3.1.0.RELEASE</version>
176177
<scope>test</scope>
177178
</dependency>
178179

@@ -279,6 +280,14 @@
279280
<groupId>org.asciidoctor</groupId>
280281
<artifactId>asciidoctor-maven-plugin</artifactId>
281282
</plugin>
283+
<plugin>
284+
<groupId>org.apache.maven.plugins</groupId>
285+
<artifactId>maven-compiler-plugin</artifactId>
286+
<configuration>
287+
<source>8</source>
288+
<target>8</target>
289+
</configuration>
290+
</plugin>
282291
</plugins>
283292
</build>
284293
</project>

src/test/java/org/springframework/data/couchbase/domain/Person.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.util.Optional;
1919
import java.util.UUID;
2020

21-
import com.couchbase.client.core.deps.com.fasterxml.jackson.annotation.JsonProperty;
2221
import org.springframework.data.annotation.CreatedBy;
2322
import org.springframework.data.annotation.CreatedDate;
2423
import org.springframework.data.annotation.LastModifiedBy;
@@ -53,6 +52,7 @@ public Person(String firstname, String lastname) {
5352
this();
5453
setFirstname(firstname);
5554
setLastname(lastname);
55+
setMiddlename("Nick");
5656
}
5757

5858
public Person(int id, String firstname, String lastname) {

src/test/java/org/springframework/data/couchbase/domain/PersonRepository.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515
*/
1616
package org.springframework.data.couchbase.domain;
1717

18-
import com.couchbase.client.java.query.QueryScanConsistency;
18+
import java.util.List;
19+
import java.util.Optional;
20+
import java.util.UUID;
21+
1922
import org.springframework.data.couchbase.repository.Query;
2023
import org.springframework.data.couchbase.repository.ScanConsistency;
2124
import org.springframework.data.repository.CrudRepository;
2225
import org.springframework.data.repository.query.Param;
2326

24-
import java.util.List;
25-
import java.util.Optional;
26-
import java.util.UUID;
27+
import com.couchbase.client.java.query.QueryScanConsistency;
2728

2829
/**
2930
* @author Michael Reiche
@@ -107,6 +108,9 @@ public interface PersonRepository extends CrudRepository<Person, String> {
107108

108109
void deleteAll();
109110

110-
@ScanConsistency(query=QueryScanConsistency.REQUEST_PLUS)
111+
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
111112
List<Person> findByAddressStreet(String street);
113+
114+
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
115+
List<Person> findByMiddlename(String nickName);
112116
}

src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryQueryIntegrationTests.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
import com.couchbase.client.core.error.CouchbaseException;
7777
import com.couchbase.client.core.error.IndexExistsException;
7878
import com.couchbase.client.java.query.QueryScanConsistency;
79+
import com.couchbase.client.java.query.QueryOptions;
80+
import com.couchbase.client.java.query.QueryScanConsistency;
7981

8082
/**
8183
* Repository tests
@@ -133,6 +135,22 @@ void nestedFind() {
133135
personRepository.save(person);
134136
List<Person> persons = personRepository.findByAddressStreet("Maple");
135137
assertEquals(1, persons.size());
138+
List<Person> persons2 = personRepository.findByMiddlename("Nick");
139+
assertEquals(1, persons2.size());
140+
} finally {
141+
personRepository.deleteById(person.getId().toString());
142+
}
143+
}
144+
145+
@Test
146+
void annotatedFieldFind() {
147+
Person person = null;
148+
try {
149+
person = new Person(1, "first", "last");
150+
person.setMiddlename("Nick"); // middlename is stored as nickname
151+
personRepository.save(person);
152+
List<Person> persons2 = personRepository.findByMiddlename("Nick");
153+
assertEquals(1, persons2.size());
136154
} finally {
137155
personRepository.deleteById(person.getId().toString());
138156
}
@@ -166,12 +184,14 @@ void findBySimpleProperty() {
166184
try {
167185
vie = new Airport("airports::vie", "vie", "loww");
168186
vie = airportRepository.save(vie);
187+
Airport airport2 = airportRepository.withOptions(QueryOptions.queryOptions().scanConsistency(QueryScanConsistency.NOT_BOUNDED)).findByIata(vie.getIata());
188+
assertEquals(airport2.getId(), vie.getId());
189+
169190
List<Airport> airports = airportRepository.findAllByIata("vie");
170191
assertEquals(1, airports.size());
171192
Airport airport1 = airportRepository.findById(airports.get(0).getId()).get();
172193
assertEquals(airport1.getIata(), vie.getIata());
173-
Airport airport2 = airportRepository.findByIata(airports.get(0).getIata());
174-
assertEquals(airport1.getId(), vie.getId());
194+
175195
} finally {
176196
airportRepository.delete(vie);
177197
}
@@ -401,7 +421,9 @@ void findBySimplePropertyAudited() {
401421
private void sleep(int millis) {
402422
try {
403423
Thread.sleep(millis); // so they are executed out-of-order
404-
} catch (InterruptedException ie) {}
424+
} catch (InterruptedException ie) {
425+
;
426+
}
405427
}
406428

407429
@Configuration

src/test/java/org/springframework/data/couchbase/repository/query/N1qlQueryCreatorTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity;
3333
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty;
3434
import org.springframework.data.couchbase.core.query.Query;
35+
import org.springframework.data.couchbase.domain.Person;
36+
import org.springframework.data.couchbase.domain.PersonRepository;
3537
import org.springframework.data.couchbase.domain.User;
3638
import org.springframework.data.couchbase.domain.UserRepository;
3739
import org.springframework.data.mapping.context.MappingContext;
@@ -75,6 +77,19 @@ void createsQueryCorrectly() throws Exception {
7577
assertEquals(query.export(), " WHERE " + where(i("firstname")).is("Oliver").export());
7678
}
7779

80+
@Test
81+
void createsQueryFieldAnnotationCorrectly() throws Exception {
82+
String input = "findByMiddlename";
83+
PartTree tree = new PartTree(input, Person.class);
84+
Method method = PersonRepository.class.getMethod(input, String.class);
85+
86+
N1qlQueryCreator creator = new N1qlQueryCreator(tree, getAccessor(getParameters(method), "Oliver"), null,
87+
converter, bucketName);
88+
Query query = creator.createQuery();
89+
90+
assertEquals(query.export(), " WHERE " + where("nickname").is("Oliver").export());
91+
}
92+
7893
@Test
7994
void queryParametersArray() throws Exception {
8095
String input = "findByFirstnameIn";

0 commit comments

Comments
 (0)