Search in sources :

Example 36 with Energy4Java

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

the class WicketQi4jApplication method startQi4j.

private void startQi4j() {
    try {
        logger.info("Starting Qi4j application");
        Energy4Java qi4j = new Energy4Java();
        qi4jApp = qi4j.newApplication(getAssembler());
        qi4jApp.activate();
        qi4jModule = qi4jApp.findModule(defaultLayerName(), defaultModuleName());
        // Qi4j injects @Structure and @Service elements into this application instance
        qi4jModule.injectTo(this);
        logger.info("Started Qi4j application");
    } catch (Exception e) {
        logger.error("Could not start Qi4j application.");
        e.printStackTrace();
        System.exit(100);
    }
}
Also used : Energy4Java(org.qi4j.bootstrap.Energy4Java) UnitOfWorkCompletionException(org.qi4j.api.unitofwork.UnitOfWorkCompletionException)

Example 37 with Energy4Java

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

the class PostgreSQLEntityStorePerformanceTest method cleanUp.

@Override
protected void cleanUp() throws Exception {
    try {
        super.cleanUp();
    } finally {
        Energy4Java qi4j = new Energy4Java();
        Assembler[][][] assemblers = new Assembler[][][] { { { createAssembler() } } };
        Application application = qi4j.newApplication(new ApplicationAssemblerAdapter(assemblers) {
        });
        application.activate();
        Module moduleInstance = application.findModule("Layer 1", "config");
        UnitOfWorkFactory uowf = moduleInstance;
        UnitOfWork uow = uowf.newUnitOfWork();
        try {
            SQLConfiguration config = uow.get(SQLConfiguration.class, PostgreSQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY);
            // TODO fix AbstractEntityStorePerformanceTest to extend from AbstractQi4jTest
            // SQLUtil.getConnection( this.serviceLocator );
            Connection connection = null;
            String schemaName = config.schemaName().get();
            if (schemaName == null) {
                schemaName = SQLs.DEFAULT_SCHEMA_NAME;
            }
            Statement stmt = null;
            try {
                stmt = connection.createStatement();
                stmt.execute(String.format("DELETE FROM %s." + SQLs.TABLE_NAME, schemaName));
                connection.commit();
            } finally {
                SQLUtil.closeQuietly(stmt);
            }
        } finally {
            uow.discard();
        }
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) Statement(java.sql.Statement) Connection(java.sql.Connection) Energy4Java(org.qi4j.bootstrap.Energy4Java) UnitOfWorkFactory(org.qi4j.api.unitofwork.UnitOfWorkFactory) SQLConfiguration(org.qi4j.library.sql.common.SQLConfiguration) DBCPDataSourceServiceAssembler(org.qi4j.library.sql.dbcp.DBCPDataSourceServiceAssembler) PostgreSQLEntityStoreAssembler(org.qi4j.entitystore.sql.assembly.PostgreSQLEntityStoreAssembler) Assembler(org.qi4j.bootstrap.Assembler) DataSourceAssembler(org.qi4j.library.sql.assembly.DataSourceAssembler) Module(org.qi4j.api.structure.Module) Application(org.qi4j.api.structure.Application) ApplicationAssemblerAdapter(org.qi4j.bootstrap.ApplicationAssemblerAdapter)

Example 38 with Energy4Java

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

the class Main method main.

public static void main(String[] args) throws Exception {
    final Application application = new Energy4Java().newApplication(new AppAssembler());
    application.activate();
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

        @Override
        @SuppressWarnings("CallToThreadDumpStack")
        public void run() {
            try {
                application.passivate();
            } catch (Exception ex) {
                System.err.println("Unable to passivate Qi4j application!");
                ex.printStackTrace();
            }
        }
    }));
    Module domainModule = application.findModule("app", "domain");
    int exitStatus = 0;
    try {
        UnitOfWork uow = domainModule.newUnitOfWork();
        EntityBuilder<PretextEntity> builder = uow.newEntityBuilder(PretextEntity.class);
        PretextEntity pretext = builder.instance();
        pretext.reason().set("Testing purpose");
        builder.newInstance();
        uow.complete();
        uow = domainModule.newUnitOfWork();
        QueryBuilder<PretextEntity> queryBuilder = domainModule.newQueryBuilder(PretextEntity.class);
        queryBuilder = queryBuilder.where(eq(templateFor(PretextEntity.class).reason(), "Testing purpose"));
        Query<PretextEntity> query = uow.newQuery(queryBuilder);
        pretext = query.find();
        if (pretext == null) {
            System.err.println("ERROR: Unable to find pretext!");
            exitStatus = -1;
        } else {
            System.out.println("SUCCESS: Found Pretext with reason: " + pretext.reason().get());
        }
        uow.discard();
    } finally {
        deleteData(application.findModule("infra", "persistence"));
    }
    System.exit(exitStatus);
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) SQLException(java.sql.SQLException) Energy4Java(org.qi4j.bootstrap.Energy4Java) Module(org.qi4j.api.structure.Module) Application(org.qi4j.api.structure.Application)

Example 39 with Energy4Java

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

the class Main method main.

public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, AssemblyException {
    String applicationAssemblerName = args[0];
    System.out.println("Assembler:" + applicationAssemblerName);
    Class applicationAssemblerClass = Class.forName(applicationAssemblerName);
    ApplicationAssembler assembler = (ApplicationAssembler) applicationAssemblerClass.newInstance();
    Energy4Java energy4Java = new Energy4Java();
    ApplicationDescriptor application = energy4Java.newApplicationModel(assembler);
    new Envisage().run(application);
}
Also used : ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) Energy4Java(org.qi4j.bootstrap.Energy4Java) ApplicationDescriptor(org.qi4j.api.structure.ApplicationDescriptor)

Aggregations

Energy4Java (org.qi4j.bootstrap.Energy4Java)39 Assembler (org.qi4j.bootstrap.Assembler)19 Application (org.qi4j.api.structure.Application)18 ApplicationAssemblerAdapter (org.qi4j.bootstrap.ApplicationAssemblerAdapter)17 Test (org.junit.Test)15 ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)12 ApplicationAssembler (org.qi4j.bootstrap.ApplicationAssembler)11 ApplicationDescriptor (org.qi4j.api.structure.ApplicationDescriptor)8 AssemblyException (org.qi4j.bootstrap.AssemblyException)8 Before (org.junit.Before)7 ApplicationAssembly (org.qi4j.bootstrap.ApplicationAssembly)7 ApplicationAssemblyFactory (org.qi4j.bootstrap.ApplicationAssemblyFactory)7 Module (org.qi4j.api.structure.Module)6 EntityTestAssembler (org.qi4j.test.EntityTestAssembler)6 LayerAssembly (org.qi4j.bootstrap.LayerAssembly)4 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)3 Envisage (org.qi4j.envisage.Envisage)3 UnitOfWorkCompletionException (org.qi4j.api.unitofwork.UnitOfWorkCompletionException)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1