Search in sources :

Example 1 with RepresentationMode

use of org.hibernate.metamodel.RepresentationMode in project hibernate-orm by hibernate.

the class Property method getPropertyAccessStrategy.

// todo : remove
public PropertyAccessStrategy getPropertyAccessStrategy(Class clazz) throws MappingException {
    final PropertyAccessStrategy propertyAccessStrategy = getPropertyAccessStrategy();
    if (propertyAccessStrategy != null) {
        return propertyAccessStrategy;
    }
    String accessName = getPropertyAccessorName();
    if (accessName == null) {
        if (clazz == null || java.util.Map.class.equals(clazz)) {
            accessName = "map";
        } else {
            accessName = "property";
        }
    }
    final RepresentationMode representationMode = clazz == null || java.util.Map.class.equals(clazz) ? RepresentationMode.MAP : RepresentationMode.POJO;
    return resolveServiceRegistry().getService(PropertyAccessStrategyResolver.class).resolvePropertyAccessStrategy(clazz, accessName, representationMode);
}
Also used : PropertyAccessStrategy(org.hibernate.property.access.spi.PropertyAccessStrategy) RepresentationMode(org.hibernate.metamodel.RepresentationMode) PropertyAccessStrategyResolver(org.hibernate.property.access.spi.PropertyAccessStrategyResolver)

Example 2 with RepresentationMode

use of org.hibernate.metamodel.RepresentationMode in project hibernate-orm by hibernate.

the class ManagedTypeRepresentationResolverStandard method resolveStrategy.

@Override
public EmbeddableRepresentationStrategy resolveStrategy(Component bootDescriptor, Supplier<EmbeddableMappingType> runtimeDescriptorAccess, RuntimeModelCreationContext creationContext) {
    // RepresentationMode representation = bootDescriptor.getExplicitRepresentationMode();
    RepresentationMode representation = null;
    if (representation == null) {
        if (bootDescriptor.getComponentClassName() == null) {
            representation = RepresentationMode.MAP;
        } else {
            representation = RepresentationMode.POJO;
        }
    }
    final CompositeUserType<Object> compositeUserType;
    if (bootDescriptor.getTypeName() != null) {
        compositeUserType = (CompositeUserType<Object>) creationContext.getBootstrapContext().getServiceRegistry().getService(ManagedBeanRegistry.class).getBean(creationContext.getBootstrapContext().getClassLoaderAccess().classForName(bootDescriptor.getTypeName())).getBeanInstance();
    } else {
        compositeUserType = null;
    }
    final EmbeddableInstantiator customInstantiator;
    if (bootDescriptor.getCustomInstantiator() != null) {
        final Class<? extends EmbeddableInstantiator> customInstantiatorImpl = bootDescriptor.getCustomInstantiator();
        customInstantiator = creationContext.getBootstrapContext().getServiceRegistry().getService(ManagedBeanRegistry.class).getBean(customInstantiatorImpl).getBeanInstance();
    } else if (compositeUserType != null) {
        customInstantiator = new EmbeddableCompositeUserTypeInstantiator(compositeUserType);
    } else {
        customInstantiator = null;
    }
    if (representation == RepresentationMode.MAP) {
        return new EmbeddableRepresentationStrategyMap(bootDescriptor, runtimeDescriptorAccess, customInstantiator, creationContext);
    } else {
        // StandardPojoRepresentationStrategy
        return new EmbeddableRepresentationStrategyPojo(bootDescriptor, runtimeDescriptorAccess, customInstantiator, compositeUserType, creationContext);
    }
}
Also used : ManagedBeanRegistry(org.hibernate.resource.beans.spi.ManagedBeanRegistry) RepresentationMode(org.hibernate.metamodel.RepresentationMode) EmbeddableInstantiator(org.hibernate.metamodel.spi.EmbeddableInstantiator)

Aggregations

RepresentationMode (org.hibernate.metamodel.RepresentationMode)2 EmbeddableInstantiator (org.hibernate.metamodel.spi.EmbeddableInstantiator)1 PropertyAccessStrategy (org.hibernate.property.access.spi.PropertyAccessStrategy)1 PropertyAccessStrategyResolver (org.hibernate.property.access.spi.PropertyAccessStrategyResolver)1 ManagedBeanRegistry (org.hibernate.resource.beans.spi.ManagedBeanRegistry)1