use of org.qi4j.runtime.unitofwork.BuilderEntityState in project qi4j-sdk by Qi4j.
the class EntityStateInstance method namedAssociationFor.
@Override
@SuppressWarnings("unchecked")
public <T> NamedAssociation<T> namedAssociationFor(AccessibleObject accessor) {
Map<AccessibleObject, Object> state = state();
NamedAssociation<T> namedAssociation = (NamedAssociation<T>) state.get(accessor);
if (namedAssociation == null) {
NamedAssociationModel associationModel = stateModel.getNamedAssociation(accessor);
namedAssociation = new NamedAssociationInstance<>(entityState instanceof BuilderEntityState ? associationModel.getBuilderInfo() : associationModel, entityFunction, entityState.namedAssociationValueOf(associationModel.qualifiedName()));
state.put(accessor, namedAssociation);
}
return namedAssociation;
}
use of org.qi4j.runtime.unitofwork.BuilderEntityState in project qi4j-sdk by Qi4j.
the class EntityStateInstance method associationFor.
@Override
public <T> Association<T> associationFor(AccessibleObject accessor) throws IllegalArgumentException {
Map<AccessibleObject, Object> state = state();
Association<T> association = (Association<T>) state.get(accessor);
if (association == null) {
final AssociationModel associationModel = stateModel.getAssociation(accessor);
if (associationModel == null) {
throw new IllegalArgumentException("No such association:" + accessor);
}
association = new AssociationInstance<T>(entityState instanceof BuilderEntityState ? associationModel.getBuilderInfo() : associationModel, entityFunction, new Property<EntityReference>() {
@Override
public EntityReference get() {
return entityState.associationValueOf(associationModel.qualifiedName());
}
@Override
public void set(EntityReference newValue) throws IllegalArgumentException, IllegalStateException {
entityState.setAssociationValue(associationModel.qualifiedName(), newValue);
}
});
state.put(accessor, association);
}
return association;
}
use of org.qi4j.runtime.unitofwork.BuilderEntityState in project qi4j-sdk by Qi4j.
the class EntityStateInstance method manyAssociationFor.
@Override
public <T> ManyAssociation<T> manyAssociationFor(AccessibleObject accessor) {
Map<AccessibleObject, Object> state = state();
ManyAssociation<T> manyAssociation = (ManyAssociation<T>) state.get(accessor);
if (manyAssociation == null) {
final ManyAssociationModel associationModel = stateModel.getManyAssociation(accessor);
if (associationModel == null) {
throw new IllegalArgumentException("No such many-association:" + accessor);
}
manyAssociation = new ManyAssociationInstance<T>(entityState instanceof BuilderEntityState ? associationModel.getBuilderInfo() : associationModel, entityFunction, entityState.manyAssociationValueOf(associationModel.qualifiedName()));
state.put(accessor, manyAssociation);
}
return manyAssociation;
}
use of org.qi4j.runtime.unitofwork.BuilderEntityState in project qi4j-sdk by Qi4j.
the class EntityStateInstance method propertyFor.
@Override
public <T> Property<T> propertyFor(AccessibleObject accessor) throws IllegalArgumentException {
Map<AccessibleObject, Object> state = state();
Property<T> property = (Property<T>) state.get(accessor);
if (property == null) {
PropertyModel entityPropertyModel = stateModel.propertyModelFor(accessor);
if (entityPropertyModel == null) {
throw new IllegalArgumentException("No such property:" + accessor);
}
property = new EntityPropertyInstance<T>(entityState instanceof BuilderEntityState ? entityPropertyModel.getBuilderInfo() : entityPropertyModel, entityState);
state.put(accessor, property);
}
return property;
}
Aggregations