Skip to content

Commit 09b1503

Browse files
committed
DATACOUCH-955 - Add support for reactive auditing and ReactiveEntityCallbacks. Also, adapt CouchbaseAuditingRegistrar for support AuditingEntityCallback.
Co-authored-by: Carlos Espinado <carlosemart>
1 parent cbcd048 commit 09b1503

31 files changed

+926
-98
lines changed

src/main/java/org/springframework/data/couchbase/config/BeanNames.java

Lines changed: 7 additions & 1 deletion
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.
@@ -24,6 +24,7 @@
2424
* @author Michael Nitschinger
2525
* @author Simon Baslé
2626
* @author Michael Reiche
27+
* @author Jorge Rodríguez Martín
2728
*/
2829
public class BeanNames {
2930

@@ -53,4 +54,9 @@ public class BeanNames {
5354
* The name for the bean that will handle audit trail marking of entities.
5455
*/
5556
public static final String COUCHBASE_AUDITING_HANDLER = "couchbaseAuditingHandler";
57+
58+
/**
59+
* The name for the bean that will handle reactive audit trail marking of entities.
60+
*/
61+
public static final String REACTIVE_COUCHBASE_AUDITING_HANDLER = "reactiveCouchbaseAuditingHandler";
5662
}

src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java

Lines changed: 5 additions & 1 deletion
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.
@@ -180,4 +180,8 @@ private void prepareIndexCreator(final ApplicationContext context) {
180180
}
181181
}
182182
}
183+
184+
TemplateSupport support() {
185+
return templateSupport;
186+
}
183187
}

src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplateSupport.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors
2+
/*
3+
* Copyright 2012-2021 the original author or authors
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
56
* you may not use this file except in compliance with the License.
@@ -45,9 +46,10 @@
4546
* @author Michael Nitschinger
4647
* @author Michael Reiche
4748
* @author Jorge Rodriguez Martin
49+
* @author Carlos Espinaco
4850
* @since 3.0
4951
*/
50-
class CouchbaseTemplateSupport implements ApplicationContextAware {
52+
class CouchbaseTemplateSupport implements ApplicationContextAware, TemplateSupport {
5153

5254
private static final Logger LOG = LoggerFactory.getLogger(CouchbaseTemplateSupport.class);
5355

@@ -63,6 +65,7 @@ public CouchbaseTemplateSupport(final CouchbaseConverter converter, final Transl
6365
this.translationService = translationService;
6466
}
6567

68+
@Override
6669
public CouchbaseDocument encodeEntity(final Object entityToEncode) {
6770
maybeEmitEvent(new BeforeConvertEvent<>(entityToEncode));
6871
Object maybeNewEntity = maybeCallBeforeConvert(entityToEncode, "");
@@ -73,6 +76,7 @@ public CouchbaseDocument encodeEntity(final Object entityToEncode) {
7376
return converted;
7477
}
7578

79+
@Override
7680
public <T> T decodeEntity(String id, String source, long cas, Class<T> entityClass) {
7781
final CouchbaseDocument converted = new CouchbaseDocument(id);
7882
converted.setId(id);
@@ -90,6 +94,7 @@ public <T> T decodeEntity(String id, String source, long cas, Class<T> entityCla
9094
return accessor.getBean();
9195
}
9296

97+
@Override
9398
public Object applyUpdatedCas(final Object entity, final long cas) {
9499
final ConvertingPropertyAccessor<Object> accessor = getPropertyAccessor(entity);
95100
final CouchbasePersistentEntity<?> persistentEntity = mappingContext.getRequiredPersistentEntity(entity.getClass());
@@ -102,6 +107,7 @@ public Object applyUpdatedCas(final Object entity, final long cas) {
102107
return entity;
103108
}
104109

110+
@Override
105111
public Object applyUpdatedId(final Object entity, Object id) {
106112
final ConvertingPropertyAccessor<Object> accessor = getPropertyAccessor(entity);
107113
final CouchbasePersistentEntity<?> persistentEntity = mappingContext.getRequiredPersistentEntity(entity.getClass());
@@ -114,6 +120,7 @@ public Object applyUpdatedId(final Object entity, Object id) {
114120
return entity;
115121
}
116122

123+
@Override
117124
public long getCas(final Object entity) {
118125
final ConvertingPropertyAccessor<Object> accessor = getPropertyAccessor(entity);
119126
final CouchbasePersistentEntity<?> persistentEntity = mappingContext.getRequiredPersistentEntity(entity.getClass());
@@ -129,6 +136,7 @@ public long getCas(final Object entity) {
129136
return cas;
130137
}
131138

139+
@Override
132140
public String getJavaNameForEntity(final Class<?> clazz) {
133141
final CouchbasePersistentEntity<?> persistentEntity = mappingContext.getRequiredPersistentEntity(clazz);
134142
MappingCouchbaseEntityInformation<?, Object> info = new MappingCouchbaseEntityInformation<>(persistentEntity);

src/main/java/org/springframework/data/couchbase/core/ExecutableFindByAnalyticsOperationSupport.java

Lines changed: 2 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.
@@ -53,7 +53,7 @@ static class ExecutableFindByAnalyticsSupport<T> implements ExecutableFindByAnal
5353
this.domainType = domainType;
5454
this.query = query;
5555
this.reactiveSupport = new ReactiveFindByAnalyticsSupport<>(template.reactive(), domainType, query,
56-
scanConsistency);
56+
scanConsistency, new NonReactiveSupportWrapper(template.support()));
5757
this.scanConsistency = scanConsistency;
5858
}
5959

src/main/java/org/springframework/data/couchbase/core/ExecutableFindByIdOperationSupport.java

Lines changed: 2 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.
@@ -48,7 +48,7 @@ static class ExecutableFindByIdSupport<T> implements ExecutableFindById<T> {
4848
this.domainType = domainType;
4949
this.collection = collection;
5050
this.fields = fields;
51-
this.reactiveSupport = new ReactiveFindByIdSupport<>(template.reactive(), domainType, collection, fields);
51+
this.reactiveSupport = new ReactiveFindByIdSupport<>(template.reactive(), domainType, collection, fields, new NonReactiveSupportWrapper(template.support()));
5252
}
5353

5454
@Override

src/main/java/org/springframework/data/couchbase/core/ExecutableFindByQueryOperationSupport.java

Lines changed: 2 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.
@@ -65,7 +65,7 @@ static class ExecutableFindByQuerySupport<T> implements ExecutableFindByQuery<T>
6565
this.returnType = returnType;
6666
this.query = query;
6767
this.reactiveSupport = new ReactiveFindByQuerySupport<T>(template.reactive(), domainType, returnType, query,
68-
scanConsistency, collection, distinctFields);
68+
scanConsistency, collection, distinctFields, new NonReactiveSupportWrapper(template.support()));
6969
this.scanConsistency = scanConsistency;
7070
this.collection = collection;
7171
this.distinctFields = distinctFields;

src/main/java/org/springframework/data/couchbase/core/ExecutableFindFromReplicasByIdOperationSupport.java

Lines changed: 2 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.
@@ -48,7 +48,7 @@ static class ExecutableFindFromReplicasByIdSupport<T> implements ExecutableFindF
4848
this.collection = collection;
4949
this.returnType = returnType;
5050
this.reactiveSupport = new ReactiveFindFromReplicasByIdSupport<>(template.reactive(), domainType, returnType,
51-
collection);
51+
collection, new NonReactiveSupportWrapper(template.support()));
5252
}
5353

5454
@Override

src/main/java/org/springframework/data/couchbase/core/ExecutableInsertByIdOperationSupport.java

Lines changed: 2 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.
@@ -62,7 +62,7 @@ static class ExecutableInsertByIdSupport<T> implements ExecutableInsertById<T> {
6262
this.durabilityLevel = durabilityLevel;
6363
this.expiry = expiry;
6464
this.reactiveSupport = new ReactiveInsertByIdSupport<>(template.reactive(), domainType, collection, persistTo,
65-
replicateTo, durabilityLevel, expiry);
65+
replicateTo, durabilityLevel, expiry, new NonReactiveSupportWrapper(template.support()));
6666
}
6767

6868
@Override

src/main/java/org/springframework/data/couchbase/core/ExecutableReplaceByIdOperationSupport.java

Lines changed: 2 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.
@@ -62,7 +62,7 @@ static class ExecutableReplaceByIdSupport<T> implements ExecutableReplaceById<T>
6262
this.durabilityLevel = durabilityLevel;
6363
this.expiry = expiry;
6464
this.reactiveSupport = new ReactiveReplaceByIdSupport<>(template.reactive(),
65-
domainType, collection, persistTo, replicateTo, durabilityLevel, expiry);
65+
domainType, collection, persistTo, replicateTo, durabilityLevel, expiry, new NonReactiveSupportWrapper(template.support()));
6666
}
6767

6868
@Override

src/main/java/org/springframework/data/couchbase/core/ExecutableUpsertByIdOperationSupport.java

Lines changed: 2 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.
@@ -62,7 +62,7 @@ static class ExecutableUpsertByIdSupport<T> implements ExecutableUpsertById<T> {
6262
this.durabilityLevel = durabilityLevel;
6363
this.expiry = expiry;
6464
this.reactiveSupport = new ReactiveUpsertByIdSupport<>(template.reactive(),
65-
domainType, collection, persistTo, replicateTo, durabilityLevel, expiry);
65+
domainType, collection, persistTo, replicateTo, durabilityLevel, expiry, new NonReactiveSupportWrapper(template.support()));
6666
}
6767

6868
@Override

0 commit comments

Comments
 (0)