Skip to content

Generated Classes

DuyHai DOAN edited this page Nov 18, 2016 · 5 revisions

Using compile-time code generation through Annotation Processor, Achilles can

  1. inspect the source code at compile time
  2. perform validation on the source code at compile time
  3. have access to all generics parameters at compile time
  4. generate meta classes at compile time
  5. generate type-safe DSL builder at compile time

Warning: the generated DSL classes are stateful. You should not re-use them between different requests

Meta classes

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:

  1. public T createEntityFrom(Row row): self-explanatory
  2. public ConsistencyLevel readConsistency(Optional<ConsistencyLevel> runtimeConsistency): retrieve read consistency from runtime value, static configuration and default consistency configuration in Achilles
  3. public ConsistencyLevel writeConsistency(Optional<ConsistencyLevel> runtimeConsistency): retrieve write consistency from runtime value, static configuration and default consistency configuration in Achilles
  4. public ConsistencyLevel serialConsistency(Optional<ConsistencyLevel> runtimeConsistency): retrieve serial consistency from runtime value, static configuration and default consistency configuration in Achilles
  5. public InsertStrategy insertStrategy(): determine insert strategy using static annotation and Achilles global configuration
  6. 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:

  1. User_AchillesMeta.userId
  2. User_AchillesMeta.firstname
  3. User_AchillesMeta.lastname
  4. User_AchillesMeta.favoriteTags

Each property meta class will expose:

  1. public VALUETO encodeFromJava(VALUEFROM javaValue): encode the given Java value into CQL-compatible value using the Codec System
  2. public VALUETO encodeFromJava(VALUEFROM javaValue, Optional<CassandraOptions> options): encode the given Java value into CQL-compatible value using the Codec System. You can pass a CassandraOptions instance containing a SchemaNameProvider for dynamic schema. Use the method CassandraOptions.withSchemaNameProvider(SchemaNameProvider provider) to create an instance of this class
  3. public VALUEFROM decodeFromGettable(GettableData gettableData): decode the value of the current property from the GettableData object. The GettableData is the common interface for com.datastax.driver.core.Row, com.datastax.driver.core.UDTValue and com.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

Manager classes

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:

  1. crud(): exposes the CRUD API
  2. dsl(): exposes the DSL API
  3. index(): exposes the Indexed API
  4. raw(): exposes the RAW API

Manager Factory class

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.

Compilation Unit

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

Home

Clone this wiki locally