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)
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)
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 <SettableT extends SettableByName<SettableT>> SettableT set(@NonNull EntityT entity, @NonNull SettableT target, @NonNull NullSavingStrategy nullSavingStrategy)
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.entity
- the entity that the values will be read from.target
- the data structure to fill. This 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.target
.@NonNull EntityT get(@NonNull GettableByName source)
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.source
- the data structure to read from. This 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).@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–2019. All rights reserved.