use of org.qi4j.runtime.composite.FunctionStateResolver in project qi4j-sdk by Qi4j.
the class ModuleInstance method newValueBuilderWithState.
@Override
public <T> ValueBuilder<T> newValueBuilderWithState(Class<T> mixinType, Function<PropertyDescriptor, Object> propertyFunction, Function<AssociationDescriptor, EntityReference> associationFunction, Function<AssociationDescriptor, Iterable<EntityReference>> manyAssociationFunction, Function<AssociationDescriptor, Map<String, EntityReference>> namedAssociationFunction) {
NullArgumentException.validateNotNull("propertyFunction", propertyFunction);
NullArgumentException.validateNotNull("associationFunction", associationFunction);
NullArgumentException.validateNotNull("manyAssociationFunction", manyAssociationFunction);
NullArgumentException.validateNotNull("namedAssociationFunction", namedAssociationFunction);
ModelModule<ValueModel> compositeModelModule = typeLookup.lookupValueModel(mixinType);
if (compositeModelModule == null) {
throw new NoSuchValueException(mixinType.getName(), name());
}
StateResolver stateResolver = new FunctionStateResolver(propertyFunction, associationFunction, manyAssociationFunction, namedAssociationFunction);
return new ValueBuilderWithState<>(compositeModelModule, this, stateResolver);
}
use of org.qi4j.runtime.composite.FunctionStateResolver in project qi4j-sdk by Qi4j.
the class ModuleUnitOfWork method newEntityBuilderWithState.
@Override
public <T> EntityBuilder<T> newEntityBuilderWithState(Class<T> type, String identity, Function<PropertyDescriptor, Object> propertyFunction, Function<AssociationDescriptor, EntityReference> associationFunction, Function<AssociationDescriptor, Iterable<EntityReference>> manyAssociationFunction, Function<AssociationDescriptor, Map<String, EntityReference>> namedAssociationFunction) throws EntityTypeNotFoundException {
NullArgumentException.validateNotNull("propertyFunction", propertyFunction);
NullArgumentException.validateNotNull("associationFunction", associationFunction);
NullArgumentException.validateNotNull("manyAssociationFunction", manyAssociationFunction);
NullArgumentException.validateNotNull("namedAssociationFunction", namedAssociationFunction);
ModelModule<EntityModel> model = moduleInstance.typeLookup().lookupEntityModel(type);
if (model == null) {
throw new EntityTypeNotFoundException(type.getName());
}
EntityStore entityStore = model.module().entityStore();
StateResolver stateResolver = new FunctionStateResolver(propertyFunction, associationFunction, manyAssociationFunction, namedAssociationFunction);
if (identity == null) {
// Use identity from StateResolver if available
PropertyModel identityModel = model.model().state().findPropertyModelByQualifiedName(IDENTITY_STATE_NAME);
identity = (String) stateResolver.getPropertyState(identityModel);
if (identity == null) {
// Generate identity
IdentityGenerator idGen = model.module().identityGenerator();
if (idGen == null) {
throw new NoSuchServiceException(IdentityGenerator.class.getName(), model.module().name());
}
identity = idGen.generate(first(model.model().types()));
}
}
return new EntityBuilderInstance<>(model, this, uow.getEntityStoreUnitOfWork(entityStore, moduleInstance), identity, stateResolver);
}
Aggregations