Search in sources :

Example 1 with EmbeddedParameters

use of io.jmix.core.entity.annotation.EmbeddedParameters in project jmix by jmix-framework.

the class EmbeddedAttributesMappingProcessor method process.

@Override
public void process(MappingProcessorContext context) {
    DatabaseMapping mapping = context.getMapping();
    if (mapping instanceof AggregateObjectMapping) {
        MetaClass metaClass = metadata.getClass(mapping.getDescriptor().getJavaClass());
        MetaProperty metaProperty = metaClass.getProperty(mapping.getAttributeName());
        EmbeddedParameters embeddedParameters = metaProperty.getAnnotatedElement().getAnnotation(EmbeddedParameters.class);
        if (embeddedParameters != null && !embeddedParameters.nullAllowed()) {
            ((AggregateObjectMapping) mapping).setIsNullAllowed(false);
        }
    }
}
Also used : EmbeddedParameters(io.jmix.core.entity.annotation.EmbeddedParameters) AggregateObjectMapping(org.eclipse.persistence.mappings.AggregateObjectMapping) MetaClass(io.jmix.core.metamodel.model.MetaClass) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 2 with EmbeddedParameters

use of io.jmix.core.entity.annotation.EmbeddedParameters in project jmix by jmix-framework.

the class EntityEmbeddedInitializer method initEntity.

@Override
public void initEntity(Object entity) {
    MetaClass metaClass = metadata.getClass(entity.getClass());
    for (MetaProperty property : metaClass.getProperties()) {
        if (property.getRange().isClass() && metadataTools.isEmbedded(property)) {
            EmbeddedParameters embeddedParameters = property.getAnnotatedElement().getAnnotation(EmbeddedParameters.class);
            if (embeddedParameters != null && !embeddedParameters.nullAllowed()) {
                MetaClass embeddableMetaClass = property.getRange().asClass();
                Object embeddableEntity = metadata.create(embeddableMetaClass);
                EntityValues.setValue(entity, property.getName(), embeddableEntity);
            }
        }
    }
}
Also used : EmbeddedParameters(io.jmix.core.entity.annotation.EmbeddedParameters) MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Aggregations

EmbeddedParameters (io.jmix.core.entity.annotation.EmbeddedParameters)2 MetaClass (io.jmix.core.metamodel.model.MetaClass)2 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)2 AggregateObjectMapping (org.eclipse.persistence.mappings.AggregateObjectMapping)1 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)1