Search in sources :

Example 1 with BuilderEntityState

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;
}
Also used : NamedAssociation(org.qi4j.api.association.NamedAssociation) NamedAssociationModel(org.qi4j.runtime.association.NamedAssociationModel) AccessibleObject(java.lang.reflect.AccessibleObject) AccessibleObject(java.lang.reflect.AccessibleObject) BuilderEntityState(org.qi4j.runtime.unitofwork.BuilderEntityState)

Example 2 with BuilderEntityState

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;
}
Also used : ManyAssociation(org.qi4j.api.association.ManyAssociation) Association(org.qi4j.api.association.Association) EntityReference(org.qi4j.api.entity.EntityReference) AccessibleObject(java.lang.reflect.AccessibleObject) AccessibleObject(java.lang.reflect.AccessibleObject) BuilderEntityState(org.qi4j.runtime.unitofwork.BuilderEntityState) Property(org.qi4j.api.property.Property) ManyAssociationModel(org.qi4j.runtime.association.ManyAssociationModel) AssociationModel(org.qi4j.runtime.association.AssociationModel)

Example 3 with BuilderEntityState

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;
}
Also used : AccessibleObject(java.lang.reflect.AccessibleObject) AccessibleObject(java.lang.reflect.AccessibleObject) BuilderEntityState(org.qi4j.runtime.unitofwork.BuilderEntityState) ManyAssociationModel(org.qi4j.runtime.association.ManyAssociationModel) ManyAssociation(org.qi4j.api.association.ManyAssociation)

Example 4 with BuilderEntityState

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;
}
Also used : PropertyModel(org.qi4j.runtime.property.PropertyModel) AccessibleObject(java.lang.reflect.AccessibleObject) AccessibleObject(java.lang.reflect.AccessibleObject) BuilderEntityState(org.qi4j.runtime.unitofwork.BuilderEntityState) Property(org.qi4j.api.property.Property)

Aggregations

AccessibleObject (java.lang.reflect.AccessibleObject)4 BuilderEntityState (org.qi4j.runtime.unitofwork.BuilderEntityState)4 ManyAssociation (org.qi4j.api.association.ManyAssociation)2 Property (org.qi4j.api.property.Property)2 ManyAssociationModel (org.qi4j.runtime.association.ManyAssociationModel)2 Association (org.qi4j.api.association.Association)1 NamedAssociation (org.qi4j.api.association.NamedAssociation)1 EntityReference (org.qi4j.api.entity.EntityReference)1 AssociationModel (org.qi4j.runtime.association.AssociationModel)1 NamedAssociationModel (org.qi4j.runtime.association.NamedAssociationModel)1 PropertyModel (org.qi4j.runtime.property.PropertyModel)1