Search in sources :

Example 1 with EntityComposite

use of org.qi4j.api.entity.EntityComposite in project qi4j-sdk by Qi4j.

the class ModuleUnitOfWork method get.

@Override
@SuppressWarnings("unchecked")
public <T> T get(T entity) throws EntityTypeNotFoundException {
    EntityComposite entityComposite = (EntityComposite) entity;
    EntityInstance compositeInstance = EntityInstance.entityInstanceOf(entityComposite);
    ModelModule<EntityModel> model = new ModelModule<>(compositeInstance.module(), compositeInstance.entityModel());
    Class<T> type = (Class<T>) first(compositeInstance.types());
    return uow.get(compositeInstance.identity(), this, Collections.singletonList(model), type);
}
Also used : EntityComposite(org.qi4j.api.entity.EntityComposite) EntityModel(org.qi4j.runtime.entity.EntityModel) EntityInstance(org.qi4j.runtime.entity.EntityInstance)

Example 2 with EntityComposite

use of org.qi4j.api.entity.EntityComposite in project qi4j-sdk by Qi4j.

the class ModuleUnitOfWork method remove.

@Override
public void remove(Object entity) throws LifecycleException {
    uow.checkOpen();
    EntityComposite entityComposite = (EntityComposite) entity;
    EntityInstance compositeInstance = EntityInstance.entityInstanceOf(entityComposite);
    if (compositeInstance.status() == EntityStatus.NEW) {
        compositeInstance.remove(this);
        uow.remove(compositeInstance.identity());
    } else if (compositeInstance.status() == EntityStatus.LOADED || compositeInstance.status() == EntityStatus.UPDATED) {
        compositeInstance.remove(this);
    } else {
        throw new NoSuchEntityException(compositeInstance.identity(), compositeInstance.types());
    }
}
Also used : EntityComposite(org.qi4j.api.entity.EntityComposite) EntityInstance(org.qi4j.runtime.entity.EntityInstance) NoSuchEntityException(org.qi4j.api.unitofwork.NoSuchEntityException)

Example 3 with EntityComposite

use of org.qi4j.api.entity.EntityComposite in project qi4j-sdk by Qi4j.

the class ValueToEntityMixin method update.

@Override
public void update(Object entity, Object value) throws NoSuchEntityException {
    EntityComposite eComposite = (EntityComposite) entity;
    ValueComposite vComposite = (ValueComposite) value;
    EntityDescriptor eDesc = spi.entityDescriptorFor(eComposite);
    AssociationStateHolder eState = spi.stateOf(eComposite);
    AssociationStateDescriptor eStateDesc = eDesc.state();
    ValueDescriptor vDesc = spi.valueDescriptorFor(vComposite);
    AssociationStateHolder vState = spi.stateOf(vComposite);
    AssociationStateDescriptor vStateDesc = vDesc.state();
    Unqualified unqualified = vDesc.metaInfo(Unqualified.class);
    if (unqualified == null || !unqualified.value()) {
        doQualifiedUpdate(eState, eStateDesc, vState, vStateDesc);
    } else {
        doUnQualifiedUpdate(eState, eStateDesc, vState, vStateDesc);
    }
}
Also used : EntityDescriptor(org.qi4j.api.entity.EntityDescriptor) EntityComposite(org.qi4j.api.entity.EntityComposite) ValueDescriptor(org.qi4j.api.value.ValueDescriptor) AssociationStateHolder(org.qi4j.api.association.AssociationStateHolder) ValueComposite(org.qi4j.api.value.ValueComposite) AssociationStateDescriptor(org.qi4j.api.association.AssociationStateDescriptor)

Example 4 with EntityComposite

use of org.qi4j.api.entity.EntityComposite in project qi4j-sdk by Qi4j.

the class TraceServiceMixin method createTraceRecord.

private void createTraceRecord(UnitOfWork uow, Class compositeType, Composite object, Method method, Object[] args, long entryTime, long durationNano, Throwable exception) {
    if (object instanceof EntityComposite) {
        EntityComposite entity = (EntityComposite) object;
        String identity = entity.identity().get();
        EntityComposite source = (EntityComposite) uow.get((Class<?>) first(Qi4j.FUNCTION_DESCRIPTOR_FOR.map(entity).types()), identity);
        EntityBuilder<EntityTraceRecordEntity> builder = uow.newEntityBuilder(EntityTraceRecordEntity.class);
        EntityTraceRecordEntity state = builder.instance();
        setStandardStuff(compositeType, method, args, entryTime, durationNano, state, exception);
        state.source().set(source);
        // Record is created.
        EntityTraceRecordEntity etr = builder.newInstance();
    } else if (object instanceof ServiceComposite) {
        ServiceComposite service = (ServiceComposite) object;
        EntityBuilder<ServiceTraceRecordEntity> builder = uow.newEntityBuilder(ServiceTraceRecordEntity.class);
        ServiceTraceRecordEntity state = builder.instance();
        setStandardStuff(compositeType, method, args, entryTime, durationNano, state, exception);
        state.source().set(service.toString());
        // Record is created.
        ServiceTraceRecordEntity str = builder.newInstance();
    } else {
        EntityBuilder<CompositeTraceRecordEntity> builder = uow.newEntityBuilder(CompositeTraceRecordEntity.class);
        CompositeTraceRecordEntity state = builder.instance();
        state.source().set(object);
        setStandardStuff(compositeType, method, args, entryTime, durationNano, state, exception);
        // Record is created.
        CompositeTraceRecordEntity ctr = builder.newInstance();
    }
}
Also used : EntityTraceRecordEntity(org.qi4j.logging.trace.records.EntityTraceRecordEntity) EntityComposite(org.qi4j.api.entity.EntityComposite) EntityBuilder(org.qi4j.api.entity.EntityBuilder) ServiceComposite(org.qi4j.api.service.ServiceComposite) CompositeTraceRecordEntity(org.qi4j.logging.trace.records.CompositeTraceRecordEntity) ServiceTraceRecordEntity(org.qi4j.logging.trace.records.ServiceTraceRecordEntity)

Example 5 with EntityComposite

use of org.qi4j.api.entity.EntityComposite 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

EntityComposite (org.qi4j.api.entity.EntityComposite)8 EntityBuilder (org.qi4j.api.entity.EntityBuilder)3 ServiceComposite (org.qi4j.api.service.ServiceComposite)3 EntityInstance (org.qi4j.runtime.entity.EntityInstance)3 NoSuchEntityException (org.qi4j.api.unitofwork.NoSuchEntityException)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Test (org.junit.Test)1 AssociationStateDescriptor (org.qi4j.api.association.AssociationStateDescriptor)1 AssociationStateHolder (org.qi4j.api.association.AssociationStateHolder)1 EntityDescriptor (org.qi4j.api.entity.EntityDescriptor)1 EntityReference (org.qi4j.api.entity.EntityReference)1 ConcurrentEntityModificationException (org.qi4j.api.unitofwork.ConcurrentEntityModificationException)1 EntityTypeNotFoundException (org.qi4j.api.unitofwork.EntityTypeNotFoundException)1 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)1 UnitOfWorkCompletionException (org.qi4j.api.unitofwork.UnitOfWorkCompletionException)1 UnitOfWorkException (org.qi4j.api.unitofwork.UnitOfWorkException)1 Usecase (org.qi4j.api.usecase.Usecase)1 ValueComposite (org.qi4j.api.value.ValueComposite)1 ValueDescriptor (org.qi4j.api.value.ValueDescriptor)1