Search in sources :

Example 1 with ServiceDebugRecordEntity

use of org.qi4j.logging.debug.records.ServiceDebugRecordEntity in project qi4j-sdk by Qi4j.

the class DebuggingTest method whenCallingMethodThenExpectDebugEntityCreated.

@Test
public void whenCallingMethodThenExpectDebugEntityCreated() {
    UnitOfWork uow = module.newUnitOfWork();
    try {
        // There is no Query capability available for Libraries, since that sits in Extensions.
        // Obtaining the EntityStore directly is a very ugly hack to get around this problem, and only related
        // to the test sitting in qi4j-libraries source repository.
        //            QueryBuilder<DebugRecord> builder = module.newQueryBuilder( DebugRecord.class );
        //            Query<DebugRecord> query = builder.newQuery( uow );
        //            assertEquals( 0, query.count() );
        Some service = (Some) module.findService(Some.class).get();
        String message = service.doSomething("World!", 10);
        assertEquals(message, "Hello!");
        EntityStore es = (EntityStore) module.findService(EntityStore.class).get();
        final String[] result = new String[1];
        es.entityStates(module).transferTo(Transforms.map(new Function<EntityState, EntityState>() {

            public EntityState map(EntityState entityState) {
                if (ServiceDebugRecordEntity.class.getName().equals(first(entityState.entityDescriptor().types()).getName())) {
                    result[0] = entityState.identity().identity();
                }
                return entityState;
            }
        }, Outputs.<EntityState>noop()));
        ServiceDebugRecordEntity debugEntry = uow.get(ServiceDebugRecordEntity.class, result[0]);
        String mess = debugEntry.message().get();
        System.out.println(mess);
        assertEquals("some message.", mess);
        uow.complete();
    } catch (ConcurrentEntityModificationException e) {
        e.printStackTrace();
        uow.discard();
    } catch (UnitOfWorkCompletionException e) {
        e.printStackTrace();
        uow.discard();
    } finally {
        if (uow.isOpen()) {
            uow.discard();
        }
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) Function(org.qi4j.functional.Function) ConcurrentEntityModificationException(org.qi4j.api.unitofwork.ConcurrentEntityModificationException) UnitOfWorkCompletionException(org.qi4j.api.unitofwork.UnitOfWorkCompletionException) EntityStore(org.qi4j.spi.entitystore.EntityStore) EntityState(org.qi4j.spi.entity.EntityState) ServiceDebugRecordEntity(org.qi4j.logging.debug.records.ServiceDebugRecordEntity) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 2 with ServiceDebugRecordEntity

use of org.qi4j.logging.debug.records.ServiceDebugRecordEntity in project qi4j-sdk by Qi4j.

the class DebuggingServiceMixin method createDebugRecord.

private void createDebugRecord(UnitOfWork uow, Composite composite, String message, List<Serializable> params) {
    if (composite instanceof ServiceComposite) {
        EntityBuilder<ServiceDebugRecordEntity> builder = uow.newEntityBuilder(ServiceDebugRecordEntity.class);
        ServiceDebugRecordEntity state = builder.instance();
        setStandardStuff(composite, message, state, params);
        state.source().set(((ServiceComposite) composite).identity().get());
        ServiceDebugRecordEntity slr = builder.newInstance();
    } else if (composite instanceof EntityComposite) {
        EntityBuilder<EntityDebugRecordEntity> builder = uow.newEntityBuilder(EntityDebugRecordEntity.class);
        EntityDebugRecordEntity state = builder.instance();
        setStandardStuff(composite, message, state, params);
        state.source().set((EntityComposite) composite);
        EntityDebugRecordEntity elr = builder.newInstance();
    } else {
        EntityBuilder<CompositeDebugRecordEntity> builder = uow.newEntityBuilder(CompositeDebugRecordEntity.class);
        CompositeDebugRecordEntity state = builder.instance();
        setStandardStuff(composite, message, state, params);
        state.source().set(composite);
        CompositeDebugRecordEntity clr = builder.newInstance();
    }
}
Also used : EntityComposite(org.qi4j.api.entity.EntityComposite) EntityBuilder(org.qi4j.api.entity.EntityBuilder) EntityDebugRecordEntity(org.qi4j.logging.debug.records.EntityDebugRecordEntity) ServiceComposite(org.qi4j.api.service.ServiceComposite) ServiceDebugRecordEntity(org.qi4j.logging.debug.records.ServiceDebugRecordEntity) CompositeDebugRecordEntity(org.qi4j.logging.debug.records.CompositeDebugRecordEntity)

Aggregations

ServiceDebugRecordEntity (org.qi4j.logging.debug.records.ServiceDebugRecordEntity)2 Test (org.junit.Test)1 EntityBuilder (org.qi4j.api.entity.EntityBuilder)1 EntityComposite (org.qi4j.api.entity.EntityComposite)1 ServiceComposite (org.qi4j.api.service.ServiceComposite)1 ConcurrentEntityModificationException (org.qi4j.api.unitofwork.ConcurrentEntityModificationException)1 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)1 UnitOfWorkCompletionException (org.qi4j.api.unitofwork.UnitOfWorkCompletionException)1 Function (org.qi4j.functional.Function)1 CompositeDebugRecordEntity (org.qi4j.logging.debug.records.CompositeDebugRecordEntity)1 EntityDebugRecordEntity (org.qi4j.logging.debug.records.EntityDebugRecordEntity)1 EntityState (org.qi4j.spi.entity.EntityState)1 EntityStore (org.qi4j.spi.entitystore.EntityStore)1 AbstractQi4jTest (org.qi4j.test.AbstractQi4jTest)1