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);
}
}
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();
}
}
}
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);
}
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);
}
Aggregations