Search in sources :

Example 1 with ManyAssociation

use of org.qi4j.api.association.ManyAssociation in project qi4j-sdk by Qi4j.

the class EntityAssemblyImpl method newManyAssociationModel.

public ManyAssociationModel newManyAssociationModel(AccessibleObject accessor, Iterable<Class<? extends Constraint<?, ?>>> constraintClasses) {
    Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn(accessor);
    boolean optional = first(filter(isType(Optional.class), annotations)) != null;
    // Constraints for entities in ManyAssociation
    ValueConstraintsModel valueConstraintsModel = constraintsFor(annotations, GenericAssociationInfo.associationTypeOf(accessor), ((Member) accessor).getName(), optional, constraintClasses, accessor);
    ValueConstraintsInstance valueConstraintsInstance = null;
    if (valueConstraintsModel.isConstrained()) {
        valueConstraintsInstance = valueConstraintsModel.newInstance();
    }
    // Constraints for the ManyAssociation itself
    valueConstraintsModel = constraintsFor(annotations, ManyAssociation.class, ((Member) accessor).getName(), optional, constraintClasses, accessor);
    ValueConstraintsInstance manyValueConstraintsInstance = null;
    if (valueConstraintsModel.isConstrained()) {
        manyValueConstraintsInstance = valueConstraintsModel.newInstance();
    }
    MetaInfo metaInfo = manyAssociationDeclarations.metaInfoFor(accessor);
    ManyAssociationModel associationModel = new ManyAssociationModel(accessor, valueConstraintsInstance, manyValueConstraintsInstance, metaInfo);
    return associationModel;
}
Also used : Optional(org.qi4j.api.common.Optional) MetaInfo(org.qi4j.api.common.MetaInfo) ValueConstraintsModel(org.qi4j.runtime.composite.ValueConstraintsModel) ManyAssociationModel(org.qi4j.runtime.association.ManyAssociationModel) ManyAssociation(org.qi4j.api.association.ManyAssociation) ValueConstraintsInstance(org.qi4j.runtime.composite.ValueConstraintsInstance) Member(java.lang.reflect.Member) Annotation(java.lang.annotation.Annotation)

Example 2 with ManyAssociation

use of org.qi4j.api.association.ManyAssociation in project qi4j-sdk by Qi4j.

the class ValueAssemblyImpl method newManyAssociationModel.

public ManyAssociationModel newManyAssociationModel(AccessibleObject accessor, Iterable<Class<? extends Constraint<?, ?>>> constraintClasses) {
    Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn(accessor);
    boolean optional = first(filter(isType(Optional.class), annotations)) != null;
    // Constraints for entities in ManyAssociation
    ValueConstraintsModel valueConstraintsModel = constraintsFor(annotations, GenericAssociationInfo.associationTypeOf(accessor), ((Member) accessor).getName(), optional, constraintClasses, accessor);
    ValueConstraintsInstance valueConstraintsInstance = null;
    if (valueConstraintsModel.isConstrained()) {
        valueConstraintsInstance = valueConstraintsModel.newInstance();
    }
    // Constraints for the ManyAssociation itself
    valueConstraintsModel = constraintsFor(annotations, ManyAssociation.class, ((Member) accessor).getName(), optional, constraintClasses, accessor);
    ValueConstraintsInstance manyValueConstraintsInstance = null;
    if (valueConstraintsModel.isConstrained()) {
        manyValueConstraintsInstance = valueConstraintsModel.newInstance();
    }
    MetaInfo metaInfo = stateDeclarations.metaInfoFor(accessor);
    ManyAssociationModel associationModel = new ManyAssociationModel(accessor, valueConstraintsInstance, manyValueConstraintsInstance, metaInfo);
    return associationModel;
}
Also used : Optional(org.qi4j.api.common.Optional) MetaInfo(org.qi4j.api.common.MetaInfo) ValueConstraintsModel(org.qi4j.runtime.composite.ValueConstraintsModel) ManyAssociationModel(org.qi4j.runtime.association.ManyAssociationModel) ManyAssociation(org.qi4j.api.association.ManyAssociation) ValueConstraintsInstance(org.qi4j.runtime.composite.ValueConstraintsInstance) Member(java.lang.reflect.Member) Annotation(java.lang.annotation.Annotation)

Example 3 with ManyAssociation

use of org.qi4j.api.association.ManyAssociation in project qi4j-sdk by Qi4j.

the class EntityStateInstance method manyAssociationFor.

@Override
@SuppressWarnings("unchecked")
public <T> ManyAssociation<T> manyAssociationFor(AccessibleObject accessor) {
    Map<AccessibleObject, Object> state = state();
    ManyAssociation<T> manyAssociation = (ManyAssociation<T>) state.get(accessor);
    if (manyAssociation == null) {
        ManyAssociationModel associationModel = stateModel.getManyAssociation(accessor);
        manyAssociation = new ManyAssociationInstance<>(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 ManyAssociation

use of org.qi4j.api.association.ManyAssociation in project qi4j-sdk by Qi4j.

the class ManyAssociationInstance method equals.

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }
    if (o == null || getClass() != o.getClass()) {
        return false;
    }
    ManyAssociation<?> that = (ManyAssociation) o;
    // Unwrap if needed
    while (that instanceof ManyAssociationWrapper) {
        that = ((ManyAssociationWrapper) that).next();
    }
    // Descriptor equality
    ManyAssociationInstance<?> thatInstance = (ManyAssociationInstance) that;
    AssociationDescriptor thatDescriptor = (AssociationDescriptor) thatInstance.associationInfo();
    if (!associationInfo.equals(thatDescriptor)) {
        return false;
    }
    // State equality
    if (manyAssociationState.count() != thatInstance.manyAssociationState.count()) {
        return false;
    }
    for (EntityReference ref : manyAssociationState) {
        if (!thatInstance.manyAssociationState.contains(ref)) {
            return false;
        }
    }
    return true;
}
Also used : ManyAssociationWrapper(org.qi4j.api.association.ManyAssociationWrapper) EntityReference(org.qi4j.api.entity.EntityReference) AssociationDescriptor(org.qi4j.api.association.AssociationDescriptor) ManyAssociation(org.qi4j.api.association.ManyAssociation)

Example 5 with ManyAssociation

use of org.qi4j.api.association.ManyAssociation in project qi4j-sdk by Qi4j.

the class StateFinder method doFilter.

/**
     * Do the filter for method return type (Property, Association, ManyAssociation, NamedAssociation)
     * by removing the entry from the list if not the above.
     *
     * @param list list of CompositeMethodDetailDescriptor
     */
private void doFilter(List<CompositeMethodDetailDescriptor> list) {
    if (list.isEmpty()) {
        return;
    }
    Iterator<CompositeMethodDetailDescriptor> iter = list.iterator();
    while (iter.hasNext()) {
        CompositeMethodDetailDescriptor descriptor = iter.next();
        Method method = descriptor.descriptor().method();
        if (Property.class.isAssignableFrom(method.getReturnType()) || Association.class.isAssignableFrom(method.getReturnType()) || ManyAssociation.class.isAssignableFrom(method.getReturnType()) || NamedAssociation.class.isAssignableFrom(method.getReturnType())) {
            continue;
        }
        iter.remove();
    }
}
Also used : Association(org.qi4j.api.association.Association) ManyAssociation(org.qi4j.api.association.ManyAssociation) NamedAssociation(org.qi4j.api.association.NamedAssociation) CompositeMethodDetailDescriptor(org.qi4j.tools.model.descriptor.CompositeMethodDetailDescriptor) NamedAssociation(org.qi4j.api.association.NamedAssociation) Method(java.lang.reflect.Method) Property(org.qi4j.api.property.Property)

Aggregations

ManyAssociation (org.qi4j.api.association.ManyAssociation)7 Association (org.qi4j.api.association.Association)3 NamedAssociation (org.qi4j.api.association.NamedAssociation)3 ManyAssociationModel (org.qi4j.runtime.association.ManyAssociationModel)3 Annotation (java.lang.annotation.Annotation)2 Member (java.lang.reflect.Member)2 Method (java.lang.reflect.Method)2 AssociationDescriptor (org.qi4j.api.association.AssociationDescriptor)2 MetaInfo (org.qi4j.api.common.MetaInfo)2 Optional (org.qi4j.api.common.Optional)2 ValueConstraintsInstance (org.qi4j.runtime.composite.ValueConstraintsInstance)2 ValueConstraintsModel (org.qi4j.runtime.composite.ValueConstraintsModel)2 CompositeMethodDetailDescriptor (org.qi4j.tools.model.descriptor.CompositeMethodDetailDescriptor)2 AccessibleObject (java.lang.reflect.AccessibleObject)1 AbstractAssociation (org.qi4j.api.association.AbstractAssociation)1 AssociationStateDescriptor (org.qi4j.api.association.AssociationStateDescriptor)1 ManyAssociationWrapper (org.qi4j.api.association.ManyAssociationWrapper)1 StateDescriptor (org.qi4j.api.composite.StateDescriptor)1 EntityDescriptor (org.qi4j.api.entity.EntityDescriptor)1 EntityReference (org.qi4j.api.entity.EntityReference)1