-
Notifications
You must be signed in to change notification settings - Fork 92
Generated Classes
Using compile-time code generation through Annotation Processor, Achilles can
- inspect the source code at compile time
- perform validation on the source code at compile time
- have access to all generics parameters at compile time
- generate meta classes at compile time
- generate type-safe DSL builder at compile time
Warning: the generated DSL classes are stateful. You should not re-use them between different requests
For each entity class annotated with @Table
, Achilles will generate a corresponding
info.archinnov.achilles.generated.meta.entity.<entity_class_name>_AchillesMeta
class
This meta class exposes the following useful methods:
-
public T createEntityFrom(Row row)
: self-explanatory -
public ConsistencyLevel readConsistency(Optional<ConsistencyLevel> runtimeConsistency)
: retrieve read consistency from runtime value, static configuration and default consistency configuration in Achilles -
public ConsistencyLevel writeConsistency(Optional<ConsistencyLevel> runtimeConsistency)
: retrieve write consistency from runtime value, static configuration and default consistency configuration in Achilles -
public ConsistencyLevel serialConsistency(Optional<ConsistencyLevel> runtimeConsistency)
: retrieve serial consistency from runtime value, static configuration and default consistency configuration in Achilles -
public InsertStrategy insertStrategy()
: determine insert strategy using static annotation and Achilles global configuration -
public void triggerInterceptorsForEvent(Event event, T instance)
: trigger all registered interceptors for this entity type on the provided instance, given the event type
Each meta class contains a public static
field for each property. For example, given the following entity:
@Table
public static User {
@PartitionKey
private Long userId;
@Column
private String firstname;
@Column
private String lastname;
@Column
private Set<String> favoriteTags;
...
}
The User_AchillesMeta
class will expose the following static property meta:
User_AchillesMeta.userId
User_AchillesMeta.firstname
User_AchillesMeta.lastname
User_AchillesMeta.favoriteTags
Each property meta class will expose:
-
public VALUETO encodeFromJava(VALUEFROM javaValue)
: encode the given Java value into CQL-compatible value using the Codec System -
public VALUETO encodeFromJava(VALUEFROM javaValue, Optional<CassandraOptions> options)
: encode the given Java value into CQL-compatible value using the Codec System. You can pass aCassandraOptions
instance containing aSchemaNameProvider
for dynamic schema. Use the methodCassandraOptions.withSchemaNameProvider(SchemaNameProvider provider)
to create an instance of this class -
public VALUEFROM decodeFromGettable(GettableData gettableData)
: decode the value of the current property from theGettableData
object. TheGettableData
is the common interface forcom.datastax.driver.core.Row
,com.datastax.driver.core.UDTValue
andcom.datastax.driver.core.TupleValue
For type-safe function call (from Cassandra_2_2_X and after), Achilles also generates a COLUMNS
field inside the info.archinnov.achilles.generated.meta.entity.<entity_class_name>_AchillesMeta
class. This field will expose all the entity fields with the correct mirror type useful for type-safe function calls.
For more details, see Functions Mapping
In addition to meta classes, Achilles also generates for each entity a
info.archinnov.achilles.generated.manager.<entity_class_name>_Manager
class that exposes the following methods:
-
crud()
: exposes the CRUD API -
dsl()
: exposes the DSL API -
index()
: exposes the Indexed API -
raw()
: exposes the RAW API
To be type-safe, Achilles also generates one info.archinnov.achilles.generated.ManagerFactory
class
that exposes as many public <entity_class_name>_Manager for<entity_class_name>()
methods as there are
different entity classes.
Please note that all entity classes and related UDT classes should be in the same compilation unit, e.g. the source code of all entity classes and related UDT classes should be compiled together in one go.
If your project import some external entity classes shipped in a .jar file, Achilles does not have access to its source code, thus cannot generate all the meta and manager classes for those entities.
Read multi-project support if you need this feature
-
Bootstraping Achilles at runtime
- Runtime Configuration Parameters
-
Manager
-
Consistency Level
-
Cassandra Options at runtime
-
Lightweight Transaction (LWT)
-
JSON Serialization
-
Interceptors
-
Bean Validation (JSR-303)