Search in sources :

Example 66 with ModuleAssembly

use of org.qi4j.bootstrap.ModuleAssembly in project qi4j-sdk by Qi4j.

the class TestAssembler method assembleContextLayer.

private void assembleContextLayer(LayerAssembly contextLayer) throws AssemblyException {
    // Role-playing entities
    ModuleAssembly entityRoleModule = contextLayer.module("CONTEXT-EntityRole");
    entityRoleModule.entities(CargoRoleMap.class, CargosRoleMap.class, HandlingEventRoleMap.class, HandlingEventsRoleMap.class).visibleIn(application);
    // Role-playing values
    ModuleAssembly valueRoleModule = contextLayer.module("CONTEXT-ValueRole");
    valueRoleModule.values(ItineraryRoleMap.class, RouteSpecificationRoleMap.class).visibleIn(application);
    ModuleAssembly contextSupportModule = contextLayer.module("CONTEXT-ContextSupport");
    contextSupportModule.addServices(RoutingService.class, ApplicationEvents.class).visibleIn(application);
    contextSupportModule.values(RegisterHandlingEventAttemptDTO.class).visibleIn(application);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) RegisterHandlingEventAttemptDTO(org.qi4j.sample.dcicargo.sample_a.context.support.RegisterHandlingEventAttemptDTO) HandlingEventsRoleMap(org.qi4j.sample.dcicargo.sample_a.context.rolemap.HandlingEventsRoleMap) RouteSpecificationRoleMap(org.qi4j.sample.dcicargo.sample_a.context.rolemap.RouteSpecificationRoleMap) CargosRoleMap(org.qi4j.sample.dcicargo.sample_a.context.rolemap.CargosRoleMap) CargoRoleMap(org.qi4j.sample.dcicargo.sample_a.context.rolemap.CargoRoleMap) ApplicationEvents(org.qi4j.sample.dcicargo.sample_a.context.support.ApplicationEvents) ItineraryRoleMap(org.qi4j.sample.dcicargo.sample_a.context.rolemap.ItineraryRoleMap) RoutingService(org.qi4j.sample.dcicargo.sample_a.context.support.RoutingService) HandlingEventRoleMap(org.qi4j.sample.dcicargo.sample_a.context.rolemap.HandlingEventRoleMap)

Example 67 with ModuleAssembly

use of org.qi4j.bootstrap.ModuleAssembly in project qi4j-sdk by Qi4j.

the class LiquibaseServiceTest method testLiquibase.

@Test
public void testLiquibase() throws SQLException, IOException, ActivationException, AssemblyException {
    final SingletonAssembler assembler = new SingletonAssembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            ModuleAssembly configModule = module;
            // Create in-memory store for configurations
            new EntityTestAssembler().assemble(configModule);
            new C3P0DataSourceServiceAssembler().identifiedBy("datasource-service").withConfig(configModule, Visibility.layer).assemble(module);
            new DataSourceAssembler().withDataSourceServiceIdentity("datasource-service").identifiedBy("testds-liquibase").withCircuitBreaker().assemble(module);
            module.values(SomeValue.class);
            // Set up Liquibase service that will create the tables
            // START SNIPPET: assembly
            new LiquibaseAssembler().withConfig(configModule, Visibility.layer).assemble(module);
            // END SNIPPET: assembly
            module.forMixin(LiquibaseConfiguration.class).declareDefaults().enabled().set(true);
            module.forMixin(LiquibaseConfiguration.class).declareDefaults().changeLog().set("changelog.xml");
        }

        @Override
        public void beforeActivation(Application application) {
            application.registerActivationEventListener(new ActivationEventListener() {

                @Override
                public void onEvent(ActivationEvent event) {
                    System.out.println(event);
                }
            });
        }
    };
    Module module = assembler.module();
    // START SNIPPET: io
    // Look up the DataSource
    DataSource ds = module.findService(DataSource.class).get();
    // Instanciate Databases helper
    Databases database = new Databases(ds);
    // Assert that insertion works
    assertTrue(database.update("insert into test values ('someid', 'bar')") == 1);
    // END SNIPPET: io
    database.query("select * from test", new Databases.ResultSetVisitor() {

        @Override
        public boolean visit(ResultSet visited) throws SQLException {
            assertThat(visited.getString("id"), equalTo("someid"));
            assertThat(visited.getString("foo"), equalTo("bar"));
            return true;
        }
    });
    Function<ResultSet, SomeValue> toValue = new Function<ResultSet, SomeValue>() {

        @Override
        public SomeValue map(ResultSet resultSet) {
            ValueBuilder<SomeValue> builder = assembler.module().newValueBuilder(SomeValue.class);
            try {
                builder.prototype().id().set(resultSet.getString("id"));
                builder.prototype().foo().set(resultSet.getString("foo"));
            } catch (SQLException e) {
                throw new IllegalArgumentException("Could not convert to SomeValue", e);
            }
            return builder.newInstance();
        }
    };
    // START SNIPPET: io
    // Select rows and load them in a List
    List<SomeValue> rows = new ArrayList<SomeValue>();
    database.query("select * from test").transferTo(map(toValue, collection(rows)));
    // Transfer all rows to System.out
    Inputs.iterable(rows).transferTo(Outputs.systemOut());
// END SNIPPET: io
}
Also used : C3P0DataSourceServiceAssembler(org.qi4j.library.sql.c3p0.C3P0DataSourceServiceAssembler) DataSourceAssembler(org.qi4j.library.sql.assembly.DataSourceAssembler) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) DataSource(javax.sql.DataSource) ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) Function(org.qi4j.functional.Function) Databases(org.qi4j.library.sql.common.Databases) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) EntityTestAssembler(org.qi4j.test.EntityTestAssembler) ActivationEventListener(org.qi4j.api.activation.ActivationEventListener) ResultSet(java.sql.ResultSet) ActivationEvent(org.qi4j.api.activation.ActivationEvent) Module(org.qi4j.api.structure.Module) Application(org.qi4j.api.structure.Application) Test(org.junit.Test)

Example 68 with ModuleAssembly

use of org.qi4j.bootstrap.ModuleAssembly in project qi4j-sdk by Qi4j.

the class Assembler method assembleBootstrapLayer.

private void assembleBootstrapLayer(LayerAssembly bootstrapLayer) throws AssemblyException {
    ModuleAssembly bootstrapModule = bootstrapLayer.module("BOOTSTRAP-Bootstrap");
    bootstrapModule.objects(DCISampleApplication_a.class);
    // Load sample data on startup
    bootstrapModule.addServices(BaseDataService.class).instantiateOnStartup();
    bootstrapModule.addServices(SampleDataService.class).instantiateOnStartup();
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) BaseDataService(org.qi4j.sample.dcicargo.sample_a.bootstrap.sampledata.BaseDataService) SampleDataService(org.qi4j.sample.dcicargo.sample_a.bootstrap.sampledata.SampleDataService)

Example 69 with ModuleAssembly

use of org.qi4j.bootstrap.ModuleAssembly in project qi4j-sdk by Qi4j.

the class Assembler method assembleCommunicationLayer.

private void assembleCommunicationLayer(LayerAssembly communicationLayer) throws AssemblyException {
    ModuleAssembly queryModule = communicationLayer.module("COMMUNICATION-Query");
    queryModule.transients(BookingQueries.class).visibleIn(application);
    queryModule.values(CargoDTO.class, LocationDTO.class, HandlingEventDTO.class, VoyageDTO.class);
    queryModule.addServices(EntityToDTOService.class, OrgJsonValueSerializationService.class).visibleIn(application);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) BookingQueries(org.qi4j.sample.dcicargo.sample_a.communication.query.BookingQueries) EntityToDTOService(org.qi4j.sample.dcicargo.sample_a.infrastructure.conversion.EntityToDTOService) OrgJsonValueSerializationService(org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationService)

Example 70 with ModuleAssembly

use of org.qi4j.bootstrap.ModuleAssembly in project qi4j-sdk by Qi4j.

the class QueryPerformanceTest method createDomainLayer.

private LayerAssembly createDomainLayer(ApplicationAssembly applicationAssembly) throws AssemblyException {
    LayerAssembly domainLayer = applicationAssembly.layer(LAYER_DOMAIN);
    ModuleAssembly domainModule = domainLayer.module(MODULE_DOMAIN);
    domainModule.addServices(LeadRepositoryService.class);
    domainModule.addServices(LeadEntityFactoryService.class);
    domainModule.entities(LeadEntity.class);
    return domainLayer;
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) LayerAssembly(org.qi4j.bootstrap.LayerAssembly)

Aggregations

ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)191 SingletonAssembler (org.qi4j.bootstrap.SingletonAssembler)87 Test (org.junit.Test)82 EntityTestAssembler (org.qi4j.test.EntityTestAssembler)59 AssemblyException (org.qi4j.bootstrap.AssemblyException)27 Application (org.qi4j.api.structure.Application)26 OrgJsonValueSerializationAssembler (org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationAssembler)24 Assembler (org.qi4j.bootstrap.Assembler)23 Module (org.qi4j.api.structure.Module)19 LayerAssembly (org.qi4j.bootstrap.LayerAssembly)15 Before (org.junit.Before)12 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)12 Energy4Java (org.qi4j.bootstrap.Energy4Java)12 DataSourceAssembler (org.qi4j.library.sql.assembly.DataSourceAssembler)11 DBCPDataSourceServiceAssembler (org.qi4j.library.sql.dbcp.DBCPDataSourceServiceAssembler)9 IOException (java.io.IOException)8 ApplicationAssemblerAdapter (org.qi4j.bootstrap.ApplicationAssemblerAdapter)8 ApplicationAssembly (org.qi4j.bootstrap.ApplicationAssembly)8 File (java.io.File)7 OrgJsonValueSerializationService (org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationService)7