-
Notifications
You must be signed in to change notification settings - Fork 192
Add missing hooks for callbacks. #1142
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity; | ||
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty; | ||
import org.springframework.data.couchbase.core.mapping.event.AfterConvertCallback; | ||
import org.springframework.data.couchbase.core.mapping.event.AfterSaveEvent; | ||
import org.springframework.data.couchbase.core.mapping.event.BeforeConvertCallback; | ||
import org.springframework.data.couchbase.core.mapping.event.BeforeConvertEvent; | ||
import org.springframework.data.couchbase.core.mapping.event.BeforeSaveEvent; | ||
|
@@ -95,16 +96,21 @@ public <T> T decodeEntity(String id, String source, long cas, Class<T> entityCla | |
} | ||
|
||
@Override | ||
public Object applyUpdatedCas(final Object entity, final long cas) { | ||
public Object applyUpdatedCas(final Object entity, CouchbaseDocument converted, final long cas) { | ||
Object returnValue; | ||
final ConvertingPropertyAccessor<Object> accessor = getPropertyAccessor(entity); | ||
final CouchbasePersistentEntity<?> persistentEntity = mappingContext.getRequiredPersistentEntity(entity.getClass()); | ||
final CouchbasePersistentProperty versionProperty = persistentEntity.getVersionProperty(); | ||
|
||
if (versionProperty != null) { | ||
accessor.setProperty(versionProperty, cas); | ||
return accessor.getBean(); | ||
returnValue = accessor.getBean(); | ||
} else { | ||
returnValue = entity; | ||
} | ||
return entity; | ||
maybeEmitEvent(new AfterSaveEvent(returnValue, converted)); | ||
|
||
return returnValue; | ||
} | ||
|
||
@Override | ||
|
@@ -172,7 +178,7 @@ public void setEntityCallbacks(EntityCallbacks entityCallbacks) { | |
this.entityCallbacks = entityCallbacks; | ||
} | ||
|
||
void maybeEmitEvent(CouchbaseMappingEvent<?> event) { | ||
public void maybeEmitEvent(CouchbaseMappingEvent<?> event) { | ||
if (canPublishEvent()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to call from ReactiveRemoveByIdOperationSupport |
||
try { | ||
this.applicationContext.publishEvent(event); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2020 the original author or authors. | ||
* Copyright 2020-2021 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. | ||
|
@@ -15,29 +15,27 @@ | |
*/ | ||
package org.springframework.data.couchbase.core.mapping.event; | ||
|
||
import org.springframework.data.couchbase.core.mapping.Document; | ||
import org.springframework.data.couchbase.core.mapping.CouchbaseDocument; | ||
import org.springframework.data.mapping.callback.EntityCallback; | ||
|
||
/** | ||
* Callback being invoked after a domain object is materialized from a {@link Document} when reading results. | ||
* Callback being invoked after a domain object is materialized from a {@link CouchbaseDocument} when reading results. | ||
* | ||
* @author Roman Puchkovskiy | ||
* @author Mark Paluch | ||
* @author Michael Reiche | ||
* @see org.springframework.data.mapping.callback.EntityCallbacks | ||
* @since 3.0 | ||
* @since 4.2 | ||
*/ | ||
@FunctionalInterface | ||
public interface AfterConvertCallback<T> extends EntityCallback<T> { | ||
|
||
/** | ||
* Entity callback method invoked after a domain object is materialized from a {@link Document}. Can return either the | ||
* same or a modified instance of the domain object. | ||
* Entity callback method invoked after a domain object is materialized from a {@link CouchbaseDocument}. Can return | ||
* either the same or a modified instance of the domain object. | ||
* | ||
* @param entity the domain object (the result of the conversion). | ||
* @param document must not be {@literal null}. | ||
* @param collection name of the collection. | ||
* @return the domain object that is the result of reading it from the {@link Document}. | ||
* @return the domain object that is the result of reading it from the {@link CouchbaseDocument}. | ||
*/ | ||
T onAfterConvert(T entity, Document document, String collection); | ||
T onAfterConvert(T entity, CouchbaseDocument document, String collection); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was copied incorrectly from Mongo with the second arg of Document instead of CouchbaseDocument. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added converted CouchbaseDocument to args as AfterSaveEvent takes a CouchbaseDocument.