Skip to content

reproducing 1628- Do not merge #1629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/test/java/org/springframework/data/couchbase/domain/Asset.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.springframework.data.couchbase.domain;

import lombok.Data;
import org.springframework.data.couchbase.core.mapping.Field;

@Data
public class Asset {
@Field
private String id;
@Field
private String desc;
}

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.springframework.data.annotation.TypeAlias;
import org.springframework.data.annotation.Version;
import org.springframework.data.couchbase.core.mapping.Document;
import org.springframework.data.couchbase.core.mapping.Field;

/**
* User entity for tests
Expand Down Expand Up @@ -55,6 +56,9 @@ public User(final String id, final String firstname, final String lastname) {
@LastModifiedBy protected String lastModifiedBy;
@LastModifiedDate protected long lastModifiedDate;

@Field
protected Asset asset;

public String getLastname() {
return lastname;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public interface UserRepository extends CouchbaseRepository<User, String> {

List<User> findByVersionEqualsAndFirstnameEquals(Long version, String firstname);

List<User> findByAsset_IdAndAsset_Desc(String id, String desc);

@Query("#{#n1ql.selectEntity}|#{#n1ql.filter}|#{#n1ql.bucket}|#{#n1ql.scope}|#{#n1ql.collection}")
@Scope("thisScope")
@Collection("thisCollection")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,40 @@ void createsQueryFindByVersionEqualsAndAndFirstname() throws Exception {
query.export());
}

@Test
void findByAssetId() throws Exception {
String input = "findByAsset_IdAndAsset_Desc";
PartTree tree = new PartTree(input, User.class);
Method method = UserRepository.class.getMethod(input, String.class, String.class);
QueryMethod queryMethod = new QueryMethod(method, new DefaultRepositoryMetadata(UserRepository.class),
new SpelAwareProxyProjectionFactory());
N1qlQueryCreator creator = new N1qlQueryCreator(tree,
getAccessor(getParameters(method), "test", "Home in Brooklyn"), queryMethod, converter, bucketName);
Query query = creator.createQuery();
//We expect query to be
//WHERE `asset`.`id` = "test" and `asset`.`desc` = "Home in Brooklyn"
//But it was generated on version 4.2.11
//WHERE META(bucketName).`id` = "test" and `asset`.`desc` = "Home in Brooklyn"
assertEquals(query.export(), " WHERE " + where(x("`asset`.`id`")).is("test")
.and("`asset`.`desc`").is("Home in Brooklyn").export());

//version 4.2.11
/*
String input = "findByAsset_IdAndAsset_Desc";
PartTree tree = new PartTree(input, User.class);
Method method = UserRepository.class.getMethod(input, String.class, String.class);
N1qlQueryCreator creator = new N1qlQueryCreator(tree,
getAccessor(getParameters(method), "test", "Home in Brooklyn"), null, converter, bucketName);
Query query = creator.createQuery();
//We expect query to be
//WHERE `asset`.`id` = "test" and `asset`.`desc` = "Home in Brooklyn"
//But it was generated on version 4.2.11
//WHERE META(bucketName).`id` = "test" and `asset`.`desc` = "Home in Brooklyn"
assertEquals(query.export(), " WHERE " + where(x("META(`" + bucketName + "`).`id`")).is("test")
.and("`asset`.`desc`").is("Home in Brooklyn").export());
*/
}

private ParameterAccessor getAccessor(Parameters<?, ?> params, Object... values) {
return new ParametersParameterAccessor(params, values);
}
Expand Down