Search in sources :

Example 1 with MappingProcessorContext

use of io.jmix.eclipselink.persistence.MappingProcessorContext in project jmix by jmix-framework.

the class JoinCriteriaMappingProcessor method process.

@Override
public void process(MappingProcessorContext context) {
    DatabaseMapping mapping = context.getMapping();
    Expression expression = beanFactory.getBeansOfType(JoinExpressionProvider.class).values().stream().map(provider -> provider.getJoinCriteriaExpression(mapping)).filter(Objects::nonNull).reduce(Expression::and).orElse(null);
    // Applying additional join criteria, e.g. for soft delete or etc
    if (mapping.isOneToManyMapping() || mapping.isOneToOneMapping()) {
        // Apply expression to mappings
        if (mapping.isOneToManyMapping()) {
            ((OneToManyMapping) mapping).setAdditionalJoinCriteria(expression);
        } else if (mapping.isOneToOneMapping()) {
            ((OneToOneMapping) mapping).setAdditionalJoinCriteria(expression);
        }
    }
}
Also used : MappingProcessor(io.jmix.eclipselink.persistence.MappingProcessor) Objects(java.util.Objects) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping) Component(org.springframework.stereotype.Component) Expression(org.eclipse.persistence.expressions.Expression) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) JoinExpressionProvider(io.jmix.eclipselink.persistence.JoinExpressionProvider) MappingProcessorContext(io.jmix.eclipselink.persistence.MappingProcessorContext) Autowired(org.springframework.beans.factory.annotation.Autowired) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory) Expression(org.eclipse.persistence.expressions.Expression) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) Objects(java.util.Objects) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping)

Aggregations

JoinExpressionProvider (io.jmix.eclipselink.persistence.JoinExpressionProvider)1 MappingProcessor (io.jmix.eclipselink.persistence.MappingProcessor)1 MappingProcessorContext (io.jmix.eclipselink.persistence.MappingProcessorContext)1 Objects (java.util.Objects)1 Expression (org.eclipse.persistence.expressions.Expression)1 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)1 OneToManyMapping (org.eclipse.persistence.mappings.OneToManyMapping)1 OneToOneMapping (org.eclipse.persistence.mappings.OneToOneMapping)1 ListableBeanFactory (org.springframework.beans.factory.ListableBeanFactory)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Component (org.springframework.stereotype.Component)1