use of com.blazebit.persistence.view.impl.update.DefaultEntityTupleizer in project blaze-persistence by Blazebit.
the class Mappers method forViewConvertToViewAttributeMapping.
public static <S, T> Mapper<S, T> forViewConvertToViewAttributeMapping(EntityViewManagerImpl evm, ViewType<S> sourceViewType, ViewType<T> targetViewType, Map<String, String> mapping, Mapper<S, T> additionalMapper) {
List<Mapper<S, T>> mappers = new ArrayList<>();
ExpressionFactory ef = evm.getCriteriaBuilderFactory().getService(ExpressionFactory.class);
for (MethodAttribute<?, ?> attribute : targetViewType.getAttributes()) {
if (attribute.isUpdatable() && attribute instanceof MappingAttribute<?, ?> && attribute instanceof SingularAttribute<?, ?>) {
for (Map.Entry<String, String> entry : mapping.entrySet()) {
if (entry.getValue().equals(((MappingAttribute) attribute).getMapping())) {
Type<?> attributeType = ((SingularAttribute<?, ?>) attribute).getType();
AttributeAccessor entityAccessor;
if (entry.getKey().isEmpty()) {
entityAccessor = Accessors.forEntityMapping(evm, sourceViewType.getEntityClass(), ((MappingAttribute<?, ?>) sourceViewType.getIdAttribute()).getMapping());
} else {
entityAccessor = Accessors.forEntityMapping(evm, sourceViewType.getEntityClass(), entry.getKey());
}
AttributeAccessor targetAttributeAccessor = Accessors.forMutableViewAttribute(evm, attribute);
if (attributeType instanceof ViewType<?>) {
ViewType<?> viewType = (ViewType<?>) attributeType;
Type<?> attributeViewIdType = ((SingularAttribute<?, ?>) viewType.getIdAttribute()).getType();
EntityTupleizer entityTupleizer = null;
ObjectBuilder<?> idViewBuilder = null;
if (attributeViewIdType instanceof ManagedViewType<?>) {
entityTupleizer = new DefaultEntityTupleizer(evm, (ManagedViewType<?>) attributeViewIdType);
idViewBuilder = (ObjectBuilder<Object>) evm.getTemplate(new MacroConfigurationExpressionFactory(ef, ef.getDefaultMacroConfiguration()), (ManagedViewTypeImplementor<?>) attributeViewIdType, null, null, new MutableViewJpqlMacro(), null, new MutableEmbeddingViewJpqlMacro(), 0).createObjectBuilder(null, null, null, 0, false, false);
}
mappers.add(new ReferenceViewAttributeMapper<S, T>(evm, entityAccessor, viewType.getJavaType(), entityTupleizer, targetAttributeAccessor, idViewBuilder));
} else {
mappers.add((Mapper<S, T>) new AttributeMapper<>(Collections.singletonList(entityAccessor), Collections.singletonList(targetAttributeAccessor)));
}
}
}
}
}
if (mappers.isEmpty()) {
return additionalMapper;
}
return new CompositeMapper<>(mappers.toArray(new Mapper[mappers.size()]));
}
use of com.blazebit.persistence.view.impl.update.DefaultEntityTupleizer in project blaze-persistence by Blazebit.
the class Mappers method forViewConvertToViewAttributeMapping.
public static <S, T> Mapper<S, T> forViewConvertToViewAttributeMapping(EntityViewManagerImpl evm, ViewType<S> sourceViewType, ViewType<T> targetViewType, String mappedBy, Mapper<S, T> additionalMapper) {
List<Mapper<S, T>> mappers = new ArrayList<>();
AttributeAccessor entityAccessor = Accessors.forEntityMapping(evm, sourceViewType.getEntityClass(), ((MappingAttribute<?, ?>) sourceViewType.getIdAttribute()).getMapping());
ExpressionFactory ef = evm.getCriteriaBuilderFactory().getService(ExpressionFactory.class);
for (MethodAttribute<?, ?> attribute : targetViewType.getAttributes()) {
if (attribute.isUpdatable() && attribute instanceof MappingAttribute<?, ?> && attribute instanceof SingularAttribute<?, ?>) {
if (mappedBy.equals(((MappingAttribute) attribute).getMapping())) {
ViewType<?> attributeType = (ViewType<?>) ((SingularAttribute<?, ?>) attribute).getType();
Type<?> attributeViewIdType = ((SingularAttribute<?, ?>) attributeType.getIdAttribute()).getType();
EntityTupleizer entityTupleizer = null;
ObjectBuilder<?> idViewBuilder = null;
if (attributeViewIdType instanceof ManagedViewType<?>) {
entityTupleizer = new DefaultEntityTupleizer(evm, (ManagedViewType<?>) attributeViewIdType);
idViewBuilder = (ObjectBuilder<Object>) evm.getTemplate(new MacroConfigurationExpressionFactory(ef, ef.getDefaultMacroConfiguration()), (ManagedViewTypeImplementor<?>) attributeViewIdType, null, null, new MutableViewJpqlMacro(), null, new MutableEmbeddingViewJpqlMacro(), 0).createObjectBuilder(null, null, null, 0, false, false);
}
mappers.add(new ReferenceViewAttributeMapper<S, T>(evm, entityAccessor, attributeType.getJavaType(), entityTupleizer, Accessors.forMutableViewAttribute(evm, attribute), idViewBuilder));
}
}
}
if (mappers.isEmpty()) {
return additionalMapper;
}
if (additionalMapper != null) {
mappers.add(additionalMapper);
}
return new CompositeMapper<>(mappers.toArray(new Mapper[mappers.size()]));
}
Aggregations