Skip to content

Commit b71cb88

Browse files
committed
Refine documentation of BeforeConvert/BeforeSave lifecycle hooks.
Closes #1448
1 parent 2d00ec4 commit b71cb88

File tree

7 files changed

+34
-13
lines changed

7 files changed

+34
-13
lines changed

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/mapping/event/AfterConvertEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import com.datastax.oss.driver.api.core.cql.Row;
2222

2323
/**
24-
* Event to be triggered after converting a {@link Row}.
24+
* Event to be triggered after converting a {@link Row} into an entity.
2525
*
2626
* @author Mark Paluch
2727
* @since 2.1

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/mapping/event/AfterLoadEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public AfterLoadEvent(Row source, Class<T> type, CqlIdentifier tableName) {
5151
/**
5252
* Returns the type for which the {@link AfterLoadEvent} shall be invoked for.
5353
*
54-
* @return
54+
* @return the type for which the {@link AfterLoadEvent} shall be invoked for.
5555
*/
5656
public Class<T> getType() {
5757
return type;

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/mapping/event/BeforeConvertCallback.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@
1818
import org.springframework.data.mapping.callback.EntityCallback;
1919

2020
import com.datastax.oss.driver.api.core.CqlIdentifier;
21+
import com.datastax.oss.driver.api.core.cql.Statement;
2122

2223
/**
23-
* Callback being invoked before a domain object is converted to be persisted.
24+
* Callback being invoked before a domain object is converted to be persisted. Entity callback invoked before converting
25+
* a domain object to a {@code INSERT}/{@code UPDATE} {@link Statement}. This is useful to apply changes to the domain
26+
* objects to that these will be reflected in the generated {@link Statement}.
2427
*
2528
* @author Mark Paluch
2629
* @since 2.2
2730
* @see org.springframework.data.mapping.callback.EntityCallbacks
31+
* @see BeforeSaveCallback
2832
*/
2933
@FunctionalInterface
3034
public interface BeforeConvertCallback<T> extends EntityCallback<T> {

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/mapping/event/BeforeSaveCallback.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,24 @@
2121
import com.datastax.oss.driver.api.core.cql.Statement;
2222

2323
/**
24-
* Entity callback triggered before save of a row.
24+
* Entity callback invoked before inserting or updating a row in the database. Before save is invoked after
25+
* {@link BeforeConvertCallback converting the entity} into a {@link Statement}. This is useful to let the mapping layer
26+
* derive values into the statement while the save callback can either update the domain object without reflecting the
27+
* changes in the statement. Another use is to inspect the {@link Statement}.
2528
*
2629
* @author Mark Paluch
2730
* @since 2.2
2831
* @see org.springframework.data.mapping.callback.EntityCallbacks
32+
* @see BeforeConvertCallback
2933
*/
3034
@FunctionalInterface
3135
public interface BeforeSaveCallback<T> extends EntityCallback<T> {
3236
// TODO: Mutable statements
3337
/**
34-
* Entity callback method invoked before a domain object is saved. Can return either the same of a modified instance
35-
* of the domain object and can modify {@link Statement} contents. This method is called after converting the
36-
* {@code entity} to {@link Statement} so effectively the row is used as outcome of invoking this callback.
38+
* Entity callback method invoked before save. That is, before running the {@code INSERT}/{@code UPDATE}
39+
* {@link Statement} derived from the intent to save an object. Can return either the same of a modified instance of
40+
* the domain object and can inspect the {@link Statement} contents. This method is called after converting the
41+
* {@code entity} to {@link Statement} so effectively the entity is propagated as outcome of invoking this callback.
3742
*
3843
* @param entity the domain object to save.
3944
* @param tableName name of the table.

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/mapping/event/BeforeSaveEvent.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
import com.datastax.oss.driver.api.core.cql.Statement;
2020

2121
/**
22-
* {@link CassandraMappingEvent} triggered before save of an object.
22+
* {@link CassandraMappingEvent Mapping event} triggered before inserting or updating a row in the database. Before save
23+
* is invoked after {@link BeforeConvertCallback converting the entity} into a {@link Statement}. This is useful to let
24+
* the mapping layer derive values into the statement while the save callback can either update the domain object
25+
* without reflecting the changes in the statement. Another use is to inspect the {@link Statement}.
2326
*
2427
* @author Lukasz Antoniak
2528
* @author Mark Paluch

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/mapping/event/ReactiveBeforeConvertCallback.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@
1919
import org.springframework.data.mapping.callback.EntityCallback;
2020

2121
import com.datastax.oss.driver.api.core.CqlIdentifier;
22+
import com.datastax.oss.driver.api.core.cql.Statement;
2223

2324
/**
24-
* Callback being invoked before a domain object is converted to be persisted.
25+
* Callback being invoked before a domain object is converted to be persisted. Entity callback invoked before converting
26+
* a domain object to a {@code INSERT}/{@code UPDATE} {@link Statement}. This is useful to apply changes to the domain
27+
* objects to that these will be reflected in the generated {@link Statement}.
2528
*
2629
* @author Mark Paluch
2730
* @since 2.2
2831
* @see org.springframework.data.mapping.callback.ReactiveEntityCallbacks
32+
* @see ReactiveBeforeSaveCallback
2933
*/
3034
@FunctionalInterface
3135
public interface ReactiveBeforeConvertCallback<T> extends EntityCallback<T> {

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/mapping/event/ReactiveBeforeSaveCallback.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,24 @@
2222
import com.datastax.oss.driver.api.core.cql.Statement;
2323

2424
/**
25-
* Entity callback triggered before save of a row.
25+
* Entity callback invoked before inserting or updating a row in the database. Before save is invoked after
26+
* {@link BeforeConvertCallback converting the entity} into a {@link Statement}. This is useful to let the mapping layer
27+
* derive values into the statement while the save callback can either update the domain object without reflecting the
28+
* changes in the statement. Another use is to inspect the {@link Statement}.
2629
*
2730
* @author Mark Paluch
2831
* @since 2.2
2932
* @see org.springframework.data.mapping.callback.ReactiveEntityCallbacks
33+
* @see ReactiveBeforeConvertCallback
3034
*/
3135
@FunctionalInterface
3236
public interface ReactiveBeforeSaveCallback<T> extends EntityCallback<T> {
3337
// TODO: Mutable statements
3438
/**
35-
* Entity callback method invoked before a domain object is saved. Can return either the same of a modified instance
36-
* of the domain object and can modify {@link Statement} contents. This method is called after converting the
37-
* {@code entity} to {@link Statement} so effectively the row is used as outcome of invoking this callback.
39+
* Entity callback method invoked before save. That is, before running the {@code INSERT}/{@code UPDATE}
40+
* {@link Statement} derived from the intent to save an object. Can return either the same of a modified instance of
41+
* the domain object and can inspect the {@link Statement} contents. This method is called after converting the
42+
* {@code entity} to {@link Statement} so effectively the entity is propagated as outcome of invoking this callback.
3843
*
3944
* @param entity the domain object to save.
4045
* @param tableName name of the table.

0 commit comments

Comments
 (0)