-
Notifications
You must be signed in to change notification settings - Fork 92
Materialized View Mapping
DuyHai DOAN edited this page Sep 6, 2016
·
3 revisions
Achilles supports the new Cassandra 3.0 materialized view feature. To mark an entity as
a materialized view, you can use the @MaterializedView
annotation.
@Table(table = "user")
public class UserEntity {
...
}
@MaterializedView(baseEntity = UserEntity.class, view = "user_by_country")
public class UserByCountryView {
}
The @MaterializedView
annotation defines 3 attributes:
- baseEntity (MANDATORY): the entity class from which this materialized view is derived
- keyspace (OPTIONAL): the name of the keyspace in which this materialized view belongs to
- view (OPTIONAL): the name of the materialized view. Defaults to the short class name if not provided
A materialized view must comply to some rules:
- the materialized view can declare a subset or all of the base entity fields
- each field in the materialized view should match the name, source type and target type of the same field in the base entity
- all base entity primary key fields should be in the materialized view primary key
- all collection and UDT types of the base entity should be duplicated to the materialized view
- a materialized view is allowed to have among its primary key fields maximum 1 field which is not a primary key from the base table
Failing one of these rules will trigger a compilation error.
Furthermore, since only read operations are allowed on a materialized view, the generated manager for the view has a restricted API:
crud().findById(...)
dsl().select()...
raw().typedQueryForSelect(...)
raw().nativeQuery(...)
For raw().nativeQuery(...)
, a runtime check is performed on the provided statement to ensure it is a SELECT statement
-
Bootstraping Achilles at runtime
- Runtime Configuration Parameters
-
Manager
-
Consistency Level
-
Cassandra Options at runtime
-
Lightweight Transaction (LWT)
-
JSON Serialization
-
Interceptors
-
Bean Validation (JSR-303)