Below is a list of APIs supported by Achilles Manager:
This API performs simple INSERT/DELETE operations on the entity. It exposes the following methods:
findById(...): find an entity providing the complete primary keyinsert(ENTITY instance): insert an instance of the entitydelete(ENTITY instance): delete the entitydeleteById(...): delete the entity with the provided complete primary keydeleteByPartitionKeys(...): delete the entity with the provided complete partition key component(s)For each of those operations, you can specify runtime values for
The ResultSet async listener is just a function Function<ResultSet, ResultSet> to spy on the returned rawcom.datastax.driver.core.ResultSet object. You are not allowed to call methods that will consume this resultset
like one(), all(), iterator(), fetchMoreResults()
The Row async listener is a function Function<Row, Row> and lets you manipulate the rawcom.datastax.driver.core.ResultSet object. This time, it is possible to read values from the row because it is
already fetched
LightWeight Transaction result listener should implement the interface LWTResultListener
The DSL API lets you create type-safe SELECT, UPDATE and DELETE queries for your entity.
The Select DSL look like:
User user = manager
.dsl()
.select()
.id()
.firstname()
.lastname()
.fromBaseTable()
.where()
.userId().Eq(id)
.getOne();
The DSL exposes the following final methods:
ENTITY getOne(): get the first found entityCompletableFuture<ENTITY> getOneAsync(): get the first found entity asynchronouslyTuple2<ENTITY, ExecutionInfo> getOneWithStats(): get the first found entity with execution infoCompletableFuture<Tuple2<ENTITY, ExecutionInfo>> getOneAsyncWithStats(): get the first found entity with execution info asynchronously
List<ENTITY> getList(): get found entitiesCompletableFuture<List<ENTITY>> getListAsync(): get found entities asynchronouslyTuple2<List<ENTITY>, ExecutionInfo> getListWithStats(): get found entities with execution infoCompletableFuture<Tuple2<List<ENTITY>, ExecutionInfo>> getListAsyncWithStats(): get found entities with execution info asynchronously
Iterator<ENTITY> iterator(): return an iterator for found entities
TypedMap getTypedMap(): get the first found CQL row as an instance of TypedMapTuple2<TypedMap, ExecutionInfo> getTypedMapWithStatus(): get the first found CQL row with execution info as an instance of TypedMapCompletableFuture<TypedMap> getTypedMapAsync(): get the first found CQL row asynchronously as an instance of TypedMapCompletableFuture<Tuple2<TypedMap, ExecutionInfo>> getTypedMapAsyncWithStats(): get the first found CQL row with execution info asynchronously an instance of TypedMap
List<TypedMap> getTypedMaps(): get the found CQL rows as a list of TypedMapList<Tuple2<TypedMap, ExecutionInfo>> getTypedMapsWithStats(): get the found CQL rows with execution info as a list of TypedMapCompletableFuture<List<TypedMap>> getTypedMapsAsync(): get the found CQL rows asynchronously as a list of TypedMapCompletableFuture<Tuple2<List<TypedMap>, ExecutionInfo>> getTypedMapsAsyncWithStats(): get the found CQL rows with execution info asynchronously as a list of TypedMap
Iterator<TypedMap> typedMapIterator(): return an iterator for found CQL rows as TypedMap
It is not mandatory to provide values for the WHERE clause, you can call the methodwithout_WHERE_Clause() to retrieve values
Please note that as soon as you invoke a function call (with .function(), Achilles can only return the results as TypedMap and not as entities) because it cannot map the result of the function call into a field of your entity.
If you need to map the result of a function call into a field of your entity, use the @Computed annotation instead.
Similar to the CRUD API, you can define runtime values for consistency levels, retry policy, ...
The Update DSL look like:
manager
.dsl()
.update()
.fromBaseTable()
.firstname().Set("new firstname")
.where()
.userId().Eq(id)
.execute();
The DSL exposes the following final methods:
execute(): execute the updateCompletableFuture<Empty> executeAsync(): execute the update asynchronouslyExecutionInfo executeWithStats(): execute the update and return the execution infoCompletableFuture<ExecutionInfo>> executeAsyncWithStats(): execute the update and return the execution info asynchronouslySimilar to the CRUD API, you can define runtime values for consistency levels, retry policy, ...
The Delete DSL look like:
manager
.dsl()
.delete()
.firstname()
.lastname()
.fromBaseTable()
.where()
.userId().Eq(id)
.execute();
The DSL exposes the following final methods:
execute(): execute the deleteCompletableFuture<Empty> executeAsync(): execute the delete asynchronouslyExecutionInfo executeWithStats(): execute the delete and return the execution infoCompletableFuture<ExecutionInfo>> executeAsyncWithStats(): execute the delete and return the execution info asynchronouslySimilar to the CRUD API, you can define runtime values for consistency levels, retry policy, ...
The RAW queries API lets you inject any instance of:
com.datastax.driver.core.RegularStatementcom.datastax.driver.core.PreparedStatementcom.datastax.driver.core.BoundStatementand execute the query for you.
The Typed Query API execute the statement and map the returned com.datastax.driver.core.Row object(s) back to entity
instance. Thus this API can only be used for SELECT statements.
Statement statement = ...;
User instance = userManager
.raw()
.typedQueryForSelect(statement)
.getOne();
This API exposes the following final methods:
ENTITY getOne(): get the first found entityCompletableFuture<ENTITY> getOneAsync(): get the first found entity asynchronouslyTuple2<ENTITY, ExecutionInfo> getOneWithStats(): get the first found entity with execution infoCompletableFuture<Tuple2<ENTITY, ExecutionInfo>> getOneAsyncWithStats(): get the first found entity with execution info asynchronously
List<ENTITY> getList(): get found entitiesCompletableFuture<List<ENTITY>> getListAsync(): get found entities asynchronouslyTuple2<List<ENTITY>, ExecutionInfo> getListWithStats(): get found entities with execution infoCompletableFuture<Tuple2<List<ENTITY>, ExecutionInfo>> getListAsyncWithStats(): get found entities with execution info asynchronously
Iterator<ENTITY> iterator(): return an iterator for found entities
Similar to the CRUD API, you can define runtime values for consistency levels, retry policy, ...
The Native Query API execute the statement and map the returned com.datastax.driver.core.Row object(s) back to
instance(s) of TypedMap.
Statement statement = ...;
final TypedMap found = userManager
.raw()
.nativeQuery(statement)
.getOne();
This API exposes the following final methods:
TypedMap getOne(): get the first found rowCompletableFuture<TypedMap> getOneAsync(): get the first found row asynchronouslyTuple2<TypedMap, ExecutionInfo> getOneWithStats(): get the first found row with execution infoCompletableFuture<Tuple2<TypedMap, ExecutionInfo>> getOneAsyncWithStats(): get the first found row with execution info asynchronously
List<TypedMap> getList(): get found entitiesCompletableFuture<List<TypedMap>> getListAsync(): get found rows asynchronouslyTuple2<List<TypedMap>, ExecutionInfo> getListWithStats(): get found rows with execution infoCompletableFuture<Tuple2<List<TypedMap>, ExecutionInfo>> getListAsyncWithStats(): get found rows with execution info asynchronously
Iterator<ENTITY> iterator(): return an iterator for found rows
execute(): execute the statementCompletableFuture<Empty> executeAsync(): execute the statement asynchronouslyExecutionInfo executeWithStats(): execute the statement and return the execution infoCompletableFuture<ExecutionInfo>> executeAsyncWithStats(): execute the statement and return the execution info asynchronously
Similar to the CRUD API, you can define runtime values for consistency levels, retry policy, ...
In some multi-tenant environment, the keyspace/table name cannot be known ahead of time but only during runtime.
For this purpose, Achilles introduces a SchemaNameProvider interface to let people bind keyspace/table names
dynamically at runtime.
This provider can be used with CRUD API and DSL API:
final SchemaNameProvider dynamicProvider = ...;
userManager
.crud()
...
.withSchemaNameProvider(dynamicProvider)
.execute();
userManager
.dsl()
.select()
...
.from(dynamicProvider)
.where()
...
userManager
.dsl()
.update()
.from(dynamicProvider)
...
.where()
...
userManager
.dsl()
.delete()
...
.from(dynamicProvider)
...
.where()
...
The Manager instance also exposes the following methods to generate raw com.datastax.driver.core.BoundStatement
and bound values. They are available for all both CRUD API and DSL API
BoundStatement generateAndGetBoundStatement():
com.datastax.driver.core.BoundStatement instanceString getStatementAsString(): self-explanatoryList<Object> getBoundValues(): extract raw Java values from entity or from the given APIList<Object> getEncodedBoundValues(): similar as getBoundValues() but encode the values using the Codec System
Apart from the 3 API (CRUD, DSL and Query), the Manager class also exposes some utility methods:
public ENTITY mapFromRow(Row row): map a given instance of com.datastax.driver.core.Rowpublic Session getNativeSession(): return the native com.datastax.driver.core.Session object used by thisManagerpublic Cluster getNativeCluster(): return the native com.datastax.driver.core.Cluster object used by thisManager