Annotation Type SetEntity
-
@Target(METHOD) @Retention(RUNTIME) public @interface SetEntity
Annotates aDaomethod that fills a core driver data structure from an instance of anEntityclass.Example:
public interface ProductDao { @SetEntity BoundStatement bind(Product product, BoundStatement boundStatement); }The generated code will set each entity property on the target, such as:boundStatement = boundStatement.set("id", product.getId(), UUID.class); boundStatement = boundStatement.set("description", product.getDescription(), String.class); ...It does not perform a query. Instead, those methods are intended for cases where you will execute the query yourself, and just need the conversion logic.Parameters
The method must have two parameters: one is the entity instance, the other must be a subtype ofSettableByName(the most likely candidates areBoundStatement,BoundStatementBuilderandUdtValue). Note that you can't useSettableByNameitself.The order of the parameters does not matter.
Return type
The method can either be void, or return the exact same type as its settable parameter.@SetEntity void bind(Product product, UdtValue udtValue); @SetEntity void bind(Product product, BoundStatementBuilder builder);
Note that if the settable parameter is immutable, the method should return a new instance, because the generated code won't be able to modify the argument in place. This is the case forBoundStatement, which is immutable in the driver:// Wrong: statement won't be modified @SetEntity void bind(Product product, BoundStatement statement); // Do this instead: @SetEntity BoundStatement bind(Product product, BoundStatement statement);
If you use a void method withBoundStatement, the mapper processor will issue a compile-time warning.
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description booleanlenientWhether to tolerate missing columns in the target data structure.NullSavingStrategynullSavingStrategyHow to handle null entity properties.
-
-
-
Element Detail
-
nullSavingStrategy
NullSavingStrategy nullSavingStrategy
How to handle null entity properties.This defaults either to the
DAO-level strategy(if set), orNullSavingStrategy.DO_NOT_SET.- Default:
- com.datastax.oss.driver.api.mapper.entity.saving.NullSavingStrategy.DO_NOT_SET
-
-
-
lenient
boolean lenient
Whether to tolerate missing columns in the target data structure.If
false(the default), then the target must contain a matching column for every property in the entity definition, except computed ones. If such a column is not found, anIllegalArgumentExceptionwill be thrown.If
true, the mapper will operate on a best-effort basis and attempt to write all entity properties that have a matching column in the target, leaving unmatched properties untouched. Beware that this may result in a partially-populated target.- Default:
- false
-
-