Skip to content

Commit c179f37

Browse files
committed
Merge branch 'main' of github.com:spring-projects/spring-data-couchbase into datacouch_1057_illegal_reflective_access
2 parents 587be06 + 3e51707 commit c179f37

14 files changed

+97
-78
lines changed

pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,6 @@
273273
<groupId>org.asciidoctor</groupId>
274274
<artifactId>asciidoctor-maven-plugin</artifactId>
275275
</plugin>
276-
<plugin>
277-
<artifactId>maven-compiler-plugin</artifactId>
278-
<configuration>
279-
<source>16</source>
280-
<target>16</target>
281-
</configuration>
282-
</plugin>
283276
</plugins>
284277
</build>
285278
</project>

src/main/java/module-info.java

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/main/java/org/springframework/data/couchbase/core/index/CouchbasePersistentEntityIndexCreator.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors
2+
* Copyright 2012-2021 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,6 +34,10 @@
3434
import com.couchbase.client.core.error.IndexExistsException;
3535
import com.couchbase.client.java.Cluster;
3636

37+
/**
38+
* @author Michael Nitschinger
39+
* @author Michael Reiche
40+
*/
3741
public class CouchbasePersistentEntityIndexCreator implements ApplicationListener<MappingContextEvent<?, ?>> {
3842

3943
private static final Logger LOGGER = LoggerFactory.getLogger(CouchbasePersistentEntityIndexCreator.class);
@@ -95,7 +99,8 @@ private void checkForAndCreateIndexes(final CouchbasePersistentEntity<?> entity)
9599
private void createIndex(final IndexDefinitionHolder indexToCreate) {
96100
Cluster cluster = couchbaseOperations.getCouchbaseClientFactory().getCluster();
97101

98-
StringBuilder statement = new StringBuilder("CREATE INDEX ").append(indexToCreate.getIndexName()).append(" ON `")
102+
StringBuilder statement = new StringBuilder("CREATE INDEX `")
103+
.append(indexToCreate.getIndexName()).append("` ON `")
99104
.append(couchbaseOperations.getBucketName()).append("` (")
100105
.append(String.join(",", indexToCreate.getIndexFields())).append(")");
101106

src/main/java/org/springframework/data/couchbase/core/index/CouchbasePersistentEntityIndexResolver.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors
2+
* Copyright 2012-2021 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,6 +32,10 @@
3232
import org.springframework.util.Assert;
3333
import org.springframework.util.StringUtils;
3434

35+
/**
36+
* @author Michael Nitschinger
37+
* @author Michael Reiche
38+
*/
3539
public class CouchbasePersistentEntityIndexResolver implements QueryIndexResolver {
3640

3741
private final MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> mappingContext;
@@ -103,7 +107,8 @@ protected IndexDefinitionHolder createFieldQueryIndexDefinition(final CouchbaseP
103107
String fieldName = index.name().isEmpty() ? property.getFieldName() : index.name();
104108
fields.add(fieldName + (index.direction() == QueryIndexDirection.DESCENDING ? " DESC" : ""));
105109

106-
String indexName = "idx_" + StringUtils.uncapitalize(entity.getType().getSimpleName()) + "_" + fieldName;
110+
String indexName = "idx_" + StringUtils.uncapitalize(entity.getType().getSimpleName()) + "_"
111+
+ fieldName.replace(".", "_");
107112

108113
return new IndexDefinitionHolder(fields, indexName, getPredicate(entityInfo));
109114
}
@@ -126,8 +131,8 @@ protected List<IndexDefinitionHolder> createCompositeQueryIndexDefinitions(final
126131

127132
return indexAnnotations.stream().map(ann -> {
128133
List<String> fields = Arrays.asList(ann.fields());
129-
String fieldsIndexName = String.join("_", fields).toLowerCase().replace(" ", "").replace("asc", "")
130-
.replace("desc", "");
134+
String fieldsIndexName = String.join("_", fields).toLowerCase().replace(".", "_").replace(" ", "")
135+
.replace("asc", "").replace("desc", "");
131136

132137
String indexName = "idx_" + StringUtils.uncapitalize(entity.getType().getSimpleName()) + "_" + fieldsIndexName;
133138
return new IndexDefinitionHolder(fields, indexName, predicate);

src/main/java/org/springframework/data/couchbase/core/mapping/CouchbaseMappingContext.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.data.couchbase.core.mapping;
1818

19-
import java.lang.reflect.InaccessibleObjectException;
2019
import java.util.Optional;
2120

2221
import org.springframework.beans.BeansException;
@@ -141,8 +140,12 @@ protected Optional<BasicCouchbasePersistentEntity<?>> addPersistentEntity(TypeIn
141140
Optional<BasicCouchbasePersistentEntity<?>> entity = null;
142141
try {
143142
entity = super.addPersistentEntity(typeInformation);
144-
} catch (InaccessibleObjectException ioe) {
145-
throw new MappingException("due to InaccessibleObjectException", ioe);
143+
} catch (Exception ioe) {
144+
if(ioe.getClass().getName().equals("java.lang.reflect.InaccessibleObjectException")){
145+
throw new MappingException("due to InaccessibleObjectException", ioe);
146+
} else {
147+
throw ioe;
148+
}
146149
}
147150

148151
if (this.eventPublisher != null && entity.isPresent()) {

src/main/java/org/springframework/data/couchbase/repository/support/CrudMethodMetadataPostProcessor.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ public Object invoke(MethodInvocation invocation) throws Throwable {
145145
currentInvocation.set(invocation);
146146

147147
try {
148-
149148
CrudMethodMetadata metadata = (CrudMethodMetadata) TransactionSynchronizationManager.getResource(method);
150149

151150
if (metadata != null) {
@@ -156,7 +155,7 @@ public Object invoke(MethodInvocation invocation) throws Throwable {
156155

157156
if (methodMetadata == null) {
158157

159-
methodMetadata = new DefaultCrudMethodMetadata(method, repositoryInformation);
158+
methodMetadata = new DefaultCrudMethodMetadata(method);
160159
CrudMethodMetadata tmp = metadataCache.putIfAbsent(method, methodMetadata);
161160

162161
if (tmp != null) {
@@ -187,7 +186,6 @@ private static class DefaultCrudMethodMetadata implements CrudMethodMetadata {
187186

188187
private final Method method;
189188
private final ScanConsistency scanConsistency;
190-
private final RepositoryInformation repositoryInformation;
191189
private final String scope;
192190
private final String collection;
193191

@@ -198,10 +196,9 @@ private static class DefaultCrudMethodMetadata implements CrudMethodMetadata {
198196
*
199197
* @param method must not be {@literal null}.
200198
*/
201-
DefaultCrudMethodMetadata(Method method, RepositoryInformation repositoryInformation) {
199+
DefaultCrudMethodMetadata(Method method) {
202200
Assert.notNull(method, "Method must not be null!");
203201
this.method = method;
204-
this.repositoryInformation = repositoryInformation;
205202
String n = method.getName();
206203
// internal methods
207204
if (n.equals("getEntityInformation") || n.equals("getOperations") || n.equals("withOptions")
@@ -212,8 +209,7 @@ private static class DefaultCrudMethodMetadata implements CrudMethodMetadata {
212209
return;
213210
}
214211

215-
AnnotatedElement[] annotated = new AnnotatedElement[] { method, method.getDeclaringClass(),
216-
repositoryInformation.getRepositoryInterface(), repositoryInformation.getDomainType() };
212+
AnnotatedElement[] annotated = new AnnotatedElement[] { method, method.getDeclaringClass()};
217213
this.scanConsistency = OptionsBuilder.annotation(ScanConsistency.class, "query", QueryScanConsistency.NOT_BOUNDED,
218214
annotated);
219215
this.scope = OptionsBuilder.annotationString(Scope.class, CollectionIdentifier.DEFAULT_SCOPE, annotated);

src/main/resources/notice.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Spring Data Couchbase 4.3 M1 (2021.1.0)
1+
Spring Data Couchbase 4.3 M2 (2021.1.0)
22
Copyright (c) [2013-2019] Couchbase / Pivotal Software, Inc.
33

44
This product is licensed to you under the Apache License, Version 2.0 (the "License").
@@ -27,4 +27,5 @@ conditions of the subcomponent's license, as noted in the LICENSE file.
2727

2828

2929

30+
3031

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
@Document
2525
@CompositeQueryIndex(fields = { "id", "name desc" })
26+
@CompositeQueryIndex(fields = { "id.something", "name desc" })
2627
public class Airline extends ComparableEntity {
2728
@Id String id;
2829

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.springframework.data.annotation.LastModifiedBy;
2525
import org.springframework.data.annotation.LastModifiedDate;
2626
import org.springframework.data.annotation.PersistenceConstructor;
27+
import org.springframework.data.annotation.Transient;
2728
import org.springframework.data.annotation.Version;
2829
import org.springframework.data.couchbase.core.mapping.Document;
2930

@@ -41,6 +42,8 @@ public class User extends ComparableEntity {
4142
@Id private String id;
4243
private String firstname;
4344
private String lastname;
45+
@Transient
46+
private String transientInfo;
4447
@CreatedBy private String createdBy;
4548
@CreatedDate private long createdDate;
4649
@LastModifiedBy private String lastModifiedBy;
@@ -94,4 +97,10 @@ public int hashCode() {
9497
return Objects.hash(id, firstname, lastname);
9598
}
9699

100+
public String getTransientInfo(){
101+
return transientInfo;
102+
}
103+
public void setTransientInfo(String something) {
104+
transientInfo = something;
105+
}
97106
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
3939
public interface UserColRepository extends CouchbaseRepository<UserCol, String>, DynamicProxyable<UserColRepository> {
4040

41-
<S extends UserCol> S save(S var1);
41+
// CouchbaseRepositoryQueryCollectionIntegrationTests.testScopeCollectionAnnotationSwap() relies on this
42+
// being commented out.
43+
//<S extends UserCol> S save(S var1);
4244

4345
List<UserCol> findByFirstname(String firstname);
4446

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors
2+
* Copyright 2012-2021 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,15 +17,16 @@
1717
package org.springframework.data.couchbase.domain;
1818

1919
import java.util.List;
20+
import java.util.stream.Stream;
2021

22+
import com.couchbase.client.java.query.QueryScanConsistency;
2123
import org.springframework.data.couchbase.repository.CouchbaseRepository;
2224
import org.springframework.data.couchbase.repository.Query;
2325
import org.springframework.data.couchbase.repository.ScanConsistency;
2426
import org.springframework.data.repository.query.Param;
2527
import org.springframework.stereotype.Repository;
2628

2729
import com.couchbase.client.java.json.JsonArray;
28-
import com.couchbase.client.java.query.QueryScanConsistency;
2930

3031
/**
3132
* User Repository for tests
@@ -34,11 +35,13 @@
3435
* @author Michael Reiche
3536
*/
3637
@Repository
37-
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
38+
@ScanConsistency(query=QueryScanConsistency.REQUEST_PLUS)
3839
public interface UserRepository extends CouchbaseRepository<User, String> {
3940

4041
List<User> findByFirstname(String firstname);
4142

43+
Stream<User> findByLastname(String lastname);
44+
4245
List<User> findByFirstnameIn(String... firstnames);
4346

4447
List<User> findByFirstnameIn(JsonArray firstnames);
@@ -54,5 +57,4 @@ public interface UserRepository extends CouchbaseRepository<User, String> {
5457
List<User> findByIdIsNotNullAndFirstnameEquals(String firstname);
5558

5659
List<User> findByVersionEqualsAndFirstnameEquals(Long version, String firstname);
57-
5860
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ void createsCompositeIndex() {
6262
assertTrue(foundIndex.get().condition().get().contains("_class"));
6363
}
6464

65+
@Test
66+
void createsCompositeIndexWithPath() {
67+
Optional<QueryIndex> foundIndex = cluster.queryIndexes().getAllIndexes(bucketName()).stream()
68+
.filter(i -> i.name().equals("idx_airline_id_something_name")).findFirst();
69+
70+
assertTrue(foundIndex.isPresent());
71+
assertTrue(foundIndex.get().condition().get().contains("_class"));
72+
}
6573
@Configuration
6674
@EnableCouchbaseRepositories("org.springframework.data.couchbase")
6775
static class Config extends AbstractCouchbaseConfiguration {

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.concurrent.ExecutorService;
3636
import java.util.concurrent.Executors;
3737
import java.util.concurrent.Future;
38+
import java.util.Optional;
3839
import java.util.stream.Collectors;
3940

4041
import org.junit.jupiter.api.BeforeEach;
@@ -354,18 +355,42 @@ public void saveNotBounded() {
354355
assertNull(airport2, "airport2 should have likely been null at least once");
355356
}
356357

358+
@Test
359+
public void testTransient() {
360+
User user = new User("1", "Dave", "Wilson");
361+
user.setTransientInfo("something");
362+
userRepository.save(user);
363+
Optional<User> foundUser = userRepository.findById(user.getId());
364+
assertEquals(null, foundUser.get().getTransientInfo());
365+
userRepository.delete(user);
366+
}
367+
357368
@Test
358369
public void testCas() {
359370
User user = new User("1", "Dave", "Wilson");
360371
userRepository.save(user);
361-
userRepository.findByFirstname("Dave");
362372
user.setVersion(user.getVersion() - 1);
363373
assertThrows(DataIntegrityViolationException.class, () -> userRepository.save(user));
364374
user.setVersion(0);
365375
userRepository.save(user);
366376
userRepository.delete(user);
367377
}
368378

379+
@Test
380+
public void testStreamQuery() {
381+
User user1 = new User("1", "Dave", "Wilson");
382+
User user2 = new User("2", "Brian", "Wilson");
383+
384+
userRepository.save(user1);
385+
userRepository.save(user2);
386+
List<User> users = userRepository.findByLastname("Wilson").collect(Collectors.toList());
387+
assertEquals(2,users.size());
388+
assertTrue(users.contains(user1));
389+
assertTrue(users.contains(user2));
390+
userRepository.delete(user1);
391+
userRepository.delete(user2);
392+
}
393+
369394
@Test
370395
public void testExpiryAnnotation() {
371396
UserAnnotated user = new UserAnnotated("1", "Dave", "Wilson");

0 commit comments

Comments
 (0)