public interface EntityHelper<EntityT>
The mapper processor generates an implementation of this interface for each Entity
-annotated class. It is used internally by other mapper components, and can also be
injected in custom query providers.
Modifier and Type | Method and Description |
---|---|
Delete |
deleteByPrimaryKey()
Builds a delete query to delete an instance of the entity by primary key (partition key +
clustering columns).
|
EntityT |
get(GettableByName source)
Deprecated.
Use
get(GettableByName, boolean) instead. |
default EntityT |
get(GettableByName source,
boolean lenient)
Gets values from a data structure to fill an entity instance.
|
Class<EntityT> |
getEntityClass()
The class of the mapped entity.
|
CqlIdentifier |
getKeyspaceId()
The keyspace used in the queries generated by this helper.
|
CqlIdentifier |
getTableId()
The table used in the queries generated by this helper.
|
RegularInsert |
insert()
Builds an insert query for this entity.
|
Select |
selectByPrimaryKey()
Builds a select query to fetch an instance of the entity by primary key (partition key +
clustering columns).
|
Select |
selectStart()
Builds the beginning of a select query to fetch one or more instances of the entity.
|
<SettableT extends SettableByName<SettableT>> |
set(EntityT entity,
SettableT target,
NullSavingStrategy nullSavingStrategy)
Deprecated.
|
default <SettableT extends SettableByName<SettableT>> |
set(EntityT entity,
SettableT target,
NullSavingStrategy nullSavingStrategy,
boolean lenient)
Sets the properties of an entity instance into a target data structure.
|
Update |
updateByPrimaryKey()
Builds a Update query to update an instance of the entity by primary key (partition key +
clustering columns).
|
Update |
updateStart()
Builds the beginning of a Update query to update an entity.
|
@NonNull @Deprecated <SettableT extends SettableByName<SettableT>> SettableT set(@NonNull EntityT entity, @NonNull SettableT target, @NonNull NullSavingStrategy nullSavingStrategy)
set(Object, SettableByName, NullSavingStrategy, boolean)
instead.@NonNull default <SettableT extends SettableByName<SettableT>> SettableT set(@NonNull EntityT entity, @NonNull SettableT target, @NonNull NullSavingStrategy nullSavingStrategy, boolean lenient)
The generated code will attempt to write all entity properties in the target data structure. For example:
target = target.set("id", entity.getId(), UUID.class);
target = target.set("name", entity.getName(), String.class);
...
The column names are inferred from the naming strategy for this entity.
The target will typically be one of the built-in driver subtypes: BoundStatement
,
BoundStatementBuilder
or UdtValue
. Note that the default BoundStatement
implementation is immutable, therefore this argument won't be modified in-place: you need to
use the return value to get the resulting structure.
If lenient
is 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.
If lenient
is false
, 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, an IllegalArgumentException
will be thrown.
entity
- the entity that the values will be read from.target
- the data structure to fill.lenient
- whether to tolerate incomplete targets.target
.IllegalArgumentException
- if lenient is false and the target does not contain matching
columns for every entity property.@NonNull @Deprecated EntityT get(@NonNull GettableByName source)
get(GettableByName, boolean)
instead.@NonNull default EntityT get(@NonNull GettableByName source, boolean lenient)
The generated code will attempt to read all entity properties from the source data structure. For example:
User returnValue = new User();
returnValue.setId(source.get("id", UUID.class));
returnValue.setName(source.get("name", String.class));
...
The column names are inferred from the naming strategy for this entity.
The source will typically be one of the built-in driver subtypes: Row
or UdtValue
(BoundStatement
and BoundStatementBuilder
are also possible, although
it's less likely that data would be read back from them in this manner).
If lenient
is true
, the mapper will operate on a best-effort basis and
attempt to read all entity properties that have a matching column in the source, leaving
unmatched properties untouched. Beware that this may result in a partially-populated entity
instance.
If lenient
is false
, then the source must contain a matching column for
every property in the entity definition, including computed ones. If such a column is
not found, an IllegalArgumentException
will be thrown.
source
- the data structure to read from.lenient
- whether to tolerate incomplete sources.IllegalArgumentException
- if lenient is false and the source does not contain matching
columns for every entity property.@NonNull RegularInsert insert()
The returned query is roughly the equivalent of:
QueryBuilder.insertInto(keyspaceId, tableId)
.value("id", QueryBuilder.bindMarker("id"))
.value("name", QueryBuilder.bindMarker("name"))
...
All mapped properties of the entity are included as bindable values (the bind markers have the
same names as the columns).
The column names are inferred from the naming strategy for this entity.
The keyspace and table identifiers are those of the DAO that this helper was obtained from; if the DAO was built without a specific keyspace and table, the query doesn't specify a keyspace, and the table name is inferred from the naming strategy.
@NonNull Update updateStart()
This is the same as updateByPrimaryKey()
()}, but without the WHERE
clause.
This would typically not be executed as-is, but instead completed with a custom WHERE
clause (either added with the query builder DSL, or concatenated to the built query).
@NonNull Update updateByPrimaryKey()
The returned query is roughly the equivalent of:
QueryBuilder.update(keyspaceId, tableId)
.setColumn("description", QueryBuilder.bindMarker("description"))
... // (other non-PK columns)
.where(Relation.column("id").isEqualTo(QueryBuilder.bindMarker("id"))
... // (other PK columns)
All non-PK properties of the entity are set, with bind markers that have the same names as the
columns.
All components of the primary key are listed in the WHERE
clause as bindable values
(the bind markers have the same names as the columns). They are listed in the natural order,
i.e. partition key columns first, followed by clustering columns (in the order defined by the
PartitionKey
and ClusteringColumn
annotations on the entity class).
The keyspace and table identifiers are those of the DAO that this helper was obtained from; if the DAO was built without a specific keyspace and table, the query doesn't specify a keyspace, and the table name is inferred from the naming strategy.
@NonNull Select selectByPrimaryKey()
The returned query is roughly the equivalent of:
QueryBuilder.selectFrom(keyspaceId, tableId)
.column("id")
.column("name")
.whereColumn("id").isEqualTo(QueryBuilder.bindMarker("id"));
...
All mapped properties of the entity are included in the result set.
All components of the primary key are listed in the WHERE
clause as bindable values
(the bind markers have the same names as the columns). They are listed in the natural order,
i.e. partition key columns first, followed by clustering columns (in the order defined by the
PartitionKey
and ClusteringColumn
annotations on the entity class).
The keyspace and table identifiers are those of the DAO that this helper was obtained from; if the DAO was built without a specific keyspace and table, the query doesn't specify a keyspace, and the table name is inferred from the naming strategy.
@NonNull Select selectStart()
This is the same as selectByPrimaryKey()
, but without the WHERE
clause.
This would typically not be executed as-is, but instead completed with a custom WHERE
clause (either added with the query builder DSL, or concatenated to the built query).
@NonNull Delete deleteByPrimaryKey()
The returned query is roughly the equivalent of:
Delete delete = QueryBuilder.deleteFrom(keyspaceId, tableId)
.whereColumn("id").isEqualTo(QueryBuilder.bindMarker("id"));
All components of the primary key are listed in the WHERE
clause as bindable values
(the bind markers have the same names as the columns). They are listed in the natural order,
i.e. partition key columns first, followed by clustering columns (in the order defined by the
PartitionKey
and ClusteringColumn
annotations on the entity class).
The keyspace and table identifiers are those of the DAO that this helper was obtained from; * if the DAO was built without a specific keyspace and table, the query doesn't specify a keyspace, and the table name is inferred from the naming strategy.
@Nullable CqlIdentifier getKeyspaceId()
This is determined by the following rules:
DaoKeyspace
), use that;
Entity.defaultKeyspace()
is set for the entity class, use that;
null
.
@NonNull CqlIdentifier getTableId()
This is determined by the following rules:
DaoTable
),
use that;
CqlName
, use that;
NamingStrategy
.
Copyright © 2017–2022. All rights reserved.