-
Notifications
You must be signed in to change notification settings - Fork 92
Configuration Parameters
Achilles comes with some configuration parameters in the class info.archinnov.achilles.configuration.ConfigurationParameters
-
MANAGED_ENTITIES (OPTIONAL): list of entities to be managed by Achilles.
Example: my.project.entity,another.project.entity
-
FORCE_SCHEMA_GENERATION (OPTIONAL): create missing column families for entities if they are not found. Default = 'false'.
If set to false and no table is found for any entity, Achilles will raise an AchillesInvalidTableException
-
VALIDATE_SCHEMA (OPTIONAL): enable or disable schema validation at start-up. Default = 'true'.
-
DML_RESULTS_DISPLAY_SIZE (OPTIONAL): set the max number of returned rows to be displayed if ACHILLES_DML_STATEMENT logger or entity logger is debug-enabled
There is a hard-coded limit of 100 rows so if you provide a greater value it will be capped to 100 and floor to 0 (e.g. disable returned results display)
- NATIVE_SESSION (OPTIONAL): provide a pre-configured Java driver session instead of letting Achilles build it
-
KEYSPACE_NAME (OPTIONAL): provide the keyspace name to connect to.
If not provided, Achilles will use the keyspace name defined on each entity using the
keyspace
attribute of the@Table
annotation.
If you do not provide the keyspace name in configuration and your entity does not define any keyspace name statically on the
@Table
annotation, Achilles will raise an exception at runtime
- JACKSON_MAPPER_FACTORY (OPTIONAL): an implementation of the info.archinnov.achilles.json.JacksonMapperFactory interface to build custom Jackson ObjectMapper based on entity class
- JACKSON_MAPPER (OPTIONAL): default Jackson ObjectMapper to use for serializing entities
If both JACKSON_MAPPER_FACTORY and JACKSON_MAPPER parameters are provided, Achilles will ignore the JACKSON_MAPPER parameter and use JACKSON_MAPPER_FACTORY
If none is provided, Achilles will use a default Jackson ObjectMapper with the following configuration:
- MapperFeature.SORT_PROPERTIES_ALPHABETICALLY = true
- SerializationInclusion = JsonInclude.Include.NON_NULL
- DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES = false
- AnnotationIntrospector pair : primary = JacksonAnnotationIntrospector, secondary = JaxbAnnotationIntrospector
-
CONSISTENCY_LEVEL_READ_DEFAULT (OPTIONAL): default read consistency level for all entities
-
CONSISTENCY_LEVEL_WRITE_DEFAULT (OPTIONAL): default write consistency level for all entities
-
CONSISTENCY_LEVEL_SERIAL_DEFAULT (OPTIONAL): default serial consistency level for all entities
-
CONSISTENCY_LEVEL_READ_MAP (OPTIONAL): map(String,String) of read consistency levels for tables
Example:
"table1" -> "ONE" "table2" -> "QUORUM" ...
-
CONSISTENCY_LEVEL_WRITE_MAP (OPTIONAL): map(String,String) of write consistency levels for tables
Example:
"table1" -> "ALL" "table2" -> "EACH_QUORUM" ...
-
CONSISTENCY_LEVEL_SERIAL_MAP (OPTIONAL): map(String,String) of serial consistency levels for tables
Example:
"table1" -> "SERIAL" "table2" -> "LOCAL_SERIAL" ...
- EVENT_INTERCEPTORS (OPTIONAL): list of events interceptors.
-
BEAN_VALIDATION_ENABLE (OPTIONAL): whether to enable Bean Validation.
-
POST_LOAD_BEAN_VALIDATION_ENABLE (OPTIONAL): whether to enable Bean Validation for POST_LOAD events. Please note that this flag is taken into account only if BEAN_VALIDATION_ENABLE is true
-
BEAN_VALIDATION_VALIDATOR (OPTIONAL): custom validator to be used.
If no validator is provided, Achilles will get the default validator provided by the default Validation provider. If Bean Validation is enabled at runtime but no default Validation provider can be found, an exception will be raised and the bootstrap is aborted
- PREPARED_STATEMENTS_CACHE_SIZE (OPTIONAL): define the LRU cache size for prepared statements cache.
By default, common operations like insert
, find
and delete
are prepared before-hand for each entity class.
For update
and all operations generated by the DSL API, since the updated fields and timestamp value are only known at runtime,
Achilless will prepare the statements only on the fly and save them into a Guava LRU cache.
The default size is 10000
entries. Once the limit is reached, oldest prepared statements are evicted, causing Achilles to re-prepare them and get warnings from the Java Driver.
You can get details on the LRU cache state by putting the logger info.archinnov.achilles.internals.cache.StatementsCache
on DEBUG
-
STATEMENTS_CACHE (OPTIONAL): provide an instance of the class
info.archinnov.achilles.internals.cache.StatementsCache
to store all prepared statements. This option is useful for unit testing to avoid re-preparing many times the same prepared statements
-
GLOBAL_INSERT_STRATEGY (OPTIONAL): define the global insert strategy for all entities. Choose between
ConfigurationParameters.InsertStrategy.ALL_FIELDS
andConfigurationParameters.InsertStrategy.NOT_NULL_FIELDS
. Default value isConfigurationParameters.InsertStrategy.ALL_FIELDS
.
For more details, please check Insert Strategy
-
GLOBAL_NAMING_STRATEGY (OPTIONAL): define the global naming strategy to be applied to keyspace, table and column names.
If no strategy is defined, Achilles will fallback to
NamingStrategy.LOWER_CASE
For more details, please check Naming Strategy
-
DEFAULT_BEAN_FACTORY OPTIONAL): inject the default bean factory to instantiate new entities and UDT classes.
The implementation class should implement the interface
info.archinnov.achilles.type.factory.BeanFactory
The default implementation is straightforward:
@Override
public <T> T newInstance(Class<T> clazz) {
try{
return clazz.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
....
}
}
-
SCHEMA_NAME_PROVIDER (OPTIONAL): define a schema name provider to bind dynamically an entity to a keyspace/table name at runtime. This feature is useful mostly in a multi-tenant context
The given provider should implement the
info.archinnov.achilles.type.SchemaNameProvider
interface
public interface SchemaNameProvider {
/**
* Provide keyspace name for entity class
*/
<T> String keyspaceFor(Class<T> entityClass);
/**
* Provide table name for entity class
*/
<T> String tableNameFor(Class<T> entityClass);
}
More details on Dynamic Schema Name
- RUNTIME_CODECS (OPTIONAL): inject a list of stateful codecs to be used by Achilles. Those codecs are instantiated at runtime.
See Runtime Codecs for more details
- EXECUTOR_SERVICE (OPTIONAL): define the executor service (thread pool) to be used by Achilles for its internal asynchronous operations
- DEFAULT_EXECUTOR_SERVICE_MIN_THREAD (OPTIONAL): define the minimum thread count for the executor service used by Achilles for its internal asynchronous operations.
- DEFAULT_EXECUTOR_SERVICE_MAX_THREAD (OPTIONAL): define the maximum thread count for the executor service used by Achilles for its internal asynchronous operations.
- DEFAULT_EXECUTOR_SERVICE_THREAD_KEEPALIVE (OPTIONAL): define the duration in seconds during which a thread is kept alive before being destroyed, on the executor service used by Achilles for its internal asynchronous operations.
- DEFAULT_EXECUTOR_SERVICE_QUEUE_SIZE (OPTIONAL): define the size of the LinkedBlockingQueue used by the executor service used by Achilles for its internal asynchronous operations
- DEFAULT_EXECUTOR_SERVICE_THREAD_FACTORY (OPTIONAL): define the thread factory used by Achilles for its internal asynchronous operations.
The default thread pool will be configured as follow:
new ThreadPoolExecutor(DEFAULT_EXECUTOR_SERVICE_MIN_THREAD, DEFAULT_EXECUTOR_SERVICE_MAX_THREAD,
DEFAULT_EXECUTOR_SERVICE_THREAD_KEEPALIVE, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>(DEFAULT_EXECUTOR_SERVICE_QUEUE_SIZE),
DEFAULT_EXECUTOR_SERVICE_THREAD_FACTORY)
To close properly the thread pool on application removal, Achilles exposes the PersistenceManagerFactory.shutDown()
method.
This method is annotated with javax.annotation.PreDestroy
so that in a managed contained, it will be invoked automatically.
Otherwise you can always manually call the shutDown()
method.
For more details, please check Asynchronous Operations
To configure Achilles with the above parameters, you need to provide a Map<info.archinnov.achilles.configuration.ConfigurationParameters, Object> of key/value as constructor argument to the PersistenceManagerFactory
class.
Example:
Map<ConfigurationParameters,Object> configMap = new HashMap<ConfigurationParameters,Object>();
Cluster cluster = Cluster.builder().contactPoints("localhost").withPort(9042).build();
configMap.put(FORCE_TABLE_CREATION,true);
ManagerFactory factory = ManagerFactoryBuilder
.build(cluster, configMap); // providing the cluster object is MANDATORY
Alternatively, you can use the the builder API from the ManagerFactoryBuilder
:
ManagerFactory factory = ManagerFactoryBuilder
.builder(cqlCluster)
.withDefaultReadConsistency(ConsistencyLevel.QUORUM)
.withDefaultWriteConsistency(ConsistencyLevel.QUORUM)
.withKeyspaceName("my_keyspace")
.withExecutorServiceMinThreadCount(5)
.withExecutorServiceMaxThreadCount(10)
.doForceTableCreation(false)
.build();
-
Bootstraping Achilles at runtime
- Runtime Configuration Parameters
-
Manager
-
Consistency Level
-
Cassandra Options at runtime
-
Lightweight Transaction (LWT)
-
JSON Serialization
-
Interceptors
-
Bean Validation (JSR-303)