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