Manager-API

Below is a list of APIs supported by Achilles Manager:

CRUD

This API performs simple INSERT/DELETE operations on the entity. It exposes the following methods:

For each of those operations, you can specify runtime values for

  1. Consistency level/Serial consistency level
  2. Retry policy
  3. Fetch size
  4. Outgoing payload
  5. Paging state (useful only for SELECT)
  6. ifExists() for INSERT, ifNotExists() for DELETE
  7. tracing ON/OFF
  8. ResultSet async listener
  9. Row async listener
  10. LightWeight Transaction result listener for INSERT/DELETE

The ResultSet async listener is just a function Function<ResultSet, ResultSet> to spy on the returned raw
com.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 raw
com.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

DSL

The DSL API lets you create type-safe SELECT, UPDATE and DELETE queries for your entity.

Select DSL

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:

It is not mandatory to provide values for the WHERE clause, you can call the method
without_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, ...

Update DSL

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:

Similar to the CRUD API, you can define runtime values for consistency levels, retry policy, ...

Delete DSL

The Delete DSL look like:

   
    manager
        .dsl()
        .delete()
        .firstname()
        .lastname()
        .fromBaseTable()
        .where()
        .userId().Eq(id)
        .execute();   

The DSL exposes the following final methods:

Similar to the CRUD API, you can define runtime values for consistency levels, retry policy, ...

Raw Queries

The RAW queries API lets you inject any instance of:

and execute the query for you.

Typed Query

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:

Similar to the CRUD API, you can define runtime values for consistency levels, retry policy, ...

Native Query

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:

Similar to the CRUD API, you can define runtime values for consistency levels, retry policy, ...

Dynamic Schema Name

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()
        ... 
        

Raw Statement Generation

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

Other Methods

Apart from the 3 API (CRUD, DSL and Query), the Manager class also exposes some utility methods: