Skip to content

Migration Guide 3 to 4

DuyHai DOAN edited this page Sep 6, 2016 · 1 revision

If you are migrating from Achilles 3.x to Achilles 4.x, below are the changes and how to transition:

Annotation Changes

  • @Entity: renamed to @Table
  • @CompoundPrimaryKey: removed, now you can use directly @PartitionKey and @ClusteringColumn in the entity without having to declare a separated class for the compound primary key
  • @TypeTransformer: removed, use @Codec or @RuntimeCodec instead. See Codec System for more details

Custom Types Changes

  • Counter: removed, use @Counter annotation on a Long field instead
  • CounterBuilder: removed. Now use the DSL API to increment/decrement counters
  • Options and OptionsBuilder: removed. Now all options are exposed as methods in CRUD API and DSL API
  • IndexCondition: removed. Will be replace by a Index API later
  • AchillesFuture<T>: removed and replaced by CompletableFuture<T>
  • EntityWithPagingState<T>: removed, replaced by com.datastax.driver.core.ExecutionInfo
  • TypedMapsWithPagingState: removed.

Dirty Checking And Proxy

The feature has been removed because it added more complexity. The flexible DSL API can cover most of related use-cases

PersistenceManager

The old PersistenceManager is now replaced by compile-time generated Manager where X is the entity class

PersistenceManager API

  • insert(...): replaced by crud().insert(...)
  • update(...): removed. Feature covered by dsl().update()
  • forUpdate(...): removed. Feature covered by dsl().update()
  • delete(...): replaced by crud().delete(...)
  • deleteById(...): replaced by crud().deleteById(...) and crud.deleteByPartitionKeys(...)
  • find(...): replaced by crud().findById(...)
  • initialize(...): removed. No more needed because proxy is no longer supported
  • removeProxy(...): removed. No more needed because proxy is no longer supported
  • initAndRemoveProxy(...): removed. No more needed because proxy is no longer supported
  • serializeToJson(...): removed. If needed, use XXX_AchillesMeta..encode()

Slice Query API

The Slice Query API is replaced by the DSL API

Query API

The Typed Query API is replaced by query().typeQueryForSelect(...). See RAW API The Native Query API is replaced by query().nativeQuery(...). See RAW API The Indexed Query API has been removed and will be replaced by a indexQuery() API later

Counter API

All the Counter API and related methods have been removed. Now just use dsl().update() to handle counter increment/decrement. Counter deletion is achieved using crud().deleteById() or crud().deleteByPartitionKeys() for static counters

Consistency Level

The @Consistency annotation can now only be used on a class. Runtime ad-hoc consistency level setting is handled by the appropriate method for each existing API

Runtime Options

Options at runtime are now handled seamlessly by the appropriate methods for each existing API.

LightWeight Transaction

LightWeight Transaction operations are handled seamlessly by the appropriate methods (ifNotExists(), ifExists(), if_XXX_Eq(..) ...) on each existing API

Batch Support

The Batch mode has been removed. Now Achilles relies on native Java driver BatchStatement to handle batches

Dynamic Schema Update

This feature is no longer supported. Schema changes are sensitive operations in production and should be handled by human operator, not automatically by a software.

Bootstrapping

Achilles 3.x:

    Cluster cluster = Cluster.builder()....build();
    PersistenceManagerFactory persistenceManagerFactory = PersistenceManagerFactoryBuilder
        .builder(cluster)
        .withEntityPackages("my.package1,my.package2")
        .withConnectionContactPoints("localhost")
        .withCQLPort(9041)
        .withKeyspaceName("Test Keyspace")
        .forceTableCreation(true).build();

Achilles 4.x:

	
    Cluster cluster = Cluster.builder()....build();
    ManagerFactory managerFactory = ManagerFactoryBuilder
        .builder(cluster)
        .withDefaultKeyspaceName("Test Keyspace")
        .forceTableCreation(true)
        .build();

    User_Manager manager = managerFactory.forUser();
    

JUnit Support

The old JUnit bootstrap has been changed:

Achilles 3.x:

    @Rule
    public AchillesResource resource = AchillesResourceBuilder
        .withEntityPackages("com.project.entity")
        .withKeyspaceName("myKeyspace")
        .tablesToTruncate("table1","anotherTable")
        .build();

Achilles 4.x:

	
    @Rule
    public AchillesTestResource resource =  AchillesTestResourceBuilder
        .forJunit()
        .withScript("script1.cql")
        .withScript("script2.cql")
        .tablesToTruncate("users", "tweet_lines") // entityClassesToTruncate(User.class, TweetLine.class)
        .createAndUseKeyspace("unit_test")
        .
        ...
        .build((cluster, statementsCache) -> ManagerFactoryBuilder
            .builder(cluster)
            .doForceSchemaCreation(true)
            .withStatementCache(statementsCache) //MANDATORY
            .withDefaultKeyspaceName("achilles_embedded")
            .build()
        );

Home

Clone this wiki locally