Skip to content

Multi Project Support

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

Normally, all entity classes and related UDT classes/function registries should be in the same compilation unit. If you compile different projects wit Achilles, you'll get different versions of info.archinnov.achilles.generated.ManagerFactory instance, one for each project.

Now if you import the source code of one project into another, there will be 2 instances of ManagerFactory in the classpath and the latest generated instance will shadow the one generated by the imported project.

To solve this issue, just five a different name for each of your project using the projectName() attribute of the @CompileTimeConfig annotation, Achilles will then generate:

  • ManagerFactoryBuilder_For_<project_name>
  • ManagerFactory_For_<project_name>

As an example, let's say you have Project1 and Project2.

  • Project1
    • UserEntity
    • CredentialsEntity
    • @CompileTimeConfig(projectName = "Project1")
  • Project2
    • ClickStreamEntity
    • ActionEntity
    • @CompileTimeConfig(projectName = "Project2")

To bootstrap Achilles for Project1:

    Cluster cluster = Cluster.builder()....build();
    ManagerFactory_For_Project1 project1ManagerFactory = ManagerFactoryBuilder_For_Project1
        .builder(cluster)
        .withDefaultKeyspaceName("project1")
        .build();
                
    UserEntity_Manager userManager = project1ManagerFactory.forUserEntity();
    CredentialsEntity_Manager credentialsManager = project1ManagerFactory.forCredentialsEntity();
        

To bootstrap Achilles for Project2:

    Cluster cluster = Cluster.builder()....build();
    ManagerFactory_For_Project2 project2ManagerFactory = ManagerFactoryBuilder_For_Project2
        .builder(cluster)
        .withDefaultKeyspaceName("project2")
        .build();
                
    ClickStream_Manager clickStreamManager = project2ManagerFactory.forClickStreamEntity();
    ActionEntity_Manager actionManager = project2ManagerFactory.forActionEntity();
        

With this feature, you can import source code of Project1 into Project2 and use them together even if they come from different compilation units

Home

Clone this wiki locally