use of org.hibernate.metamodel.model.domain.internal.EmbeddableTypeImpl in project hibernate-orm by hibernate.
the class MetadataContext method applyIdClassMetadata.
private EmbeddableTypeImpl<?> applyIdClassMetadata(Component idClassComponent) {
final JavaTypeRegistry registry = getTypeConfiguration().getJavaTypeRegistry();
final Class<?> componentClass = idClassComponent.getComponentClass();
final JavaType<?> javaType = registry.resolveManagedTypeDescriptor(componentClass);
final EmbeddableTypeImpl<?> embeddableType = new EmbeddableTypeImpl<>(javaType, false, getJpaMetamodel());
registerEmbeddableType(embeddableType, idClassComponent);
return embeddableType;
}
use of org.hibernate.metamodel.model.domain.internal.EmbeddableTypeImpl in project igloo-parent by igloo-project.
the class AbstractTestCase method testMetaModel.
/**
* Méthode utilisée à des fins de tests.
*/
protected void testMetaModel(Attribute<?, ?> attribute, List<Class<?>> classesAutorisees, List<Attribute<?, ?>> ignoredAttributes) throws NoSuchFieldException, SecurityException {
for (Attribute<?, ?> ignoredAttribute : ignoredAttributes) {
if (ignoredAttribute.getJavaMember().equals(attribute.getJavaMember())) {
// champ ignoré
return;
}
}
Enumerated enumerated = attribute.getJavaMember().getDeclaringClass().getDeclaredField(attribute.getName()).getAnnotation(Enumerated.class);
MapKeyEnumerated mapKeyEnumerated = attribute.getJavaMember().getDeclaringClass().getDeclaredField(attribute.getName()).getAnnotation(MapKeyEnumerated.class);
MapKey mapKey = attribute.getJavaMember().getDeclaringClass().getDeclaredField(attribute.getName()).getAnnotation(MapKey.class);
// cas des embeddable et des collectionOfElements d'embeddable
if (attribute.getPersistentAttributeType().equals(PersistentAttributeType.ELEMENT_COLLECTION) && EmbeddableTypeImpl.class.isInstance(((PluralAttribute<?, ?, ?>) attribute).getElementType())) {
PluralAttribute<?, ?, ?> pluralAttribute = (PluralAttribute<?, ?, ?>) attribute;
if (classesAutorisees.contains(pluralAttribute.getElementType().getJavaType())) {
// type autorisé de manière explicite
return;
}
for (Attribute<?, ?> embeddedAttribute : ((EmbeddableTypeImpl<?>) pluralAttribute.getElementType()).getAttributes()) {
testMetaModel(embeddedAttribute, classesAutorisees, ignoredAttributes);
}
return;
} else if (attribute.getPersistentAttributeType().equals(PersistentAttributeType.EMBEDDED)) {
SingularAttribute<?, ?> singularAttribute = (SingularAttribute<?, ?>) attribute;
if (classesAutorisees.contains(singularAttribute.getJavaType())) {
// type autorisé de manière explicite
return;
}
if (EmbeddableTypeImpl.class.isInstance(singularAttribute.getType())) {
for (Attribute<?, ?> embeddedAttribute : ((EmbeddableTypeImpl<?>) singularAttribute.getType()).getAttributes()) {
testMetaModel(embeddedAttribute, classesAutorisees, ignoredAttributes);
}
return;
}
}
if (attribute.getPersistentAttributeType().equals(PersistentAttributeType.BASIC) && !classesAutorisees.contains(attribute.getJavaType()) && (enumerated == null || EnumType.ORDINAL.equals(enumerated.value()))) {
throw new IllegalStateException("Champ \"" + attribute.getName() + "\", de type " + attribute.getJavaType().getSimpleName() + " refusé");
} else if (attribute.getPersistentAttributeType().equals(PersistentAttributeType.ELEMENT_COLLECTION) && PluralAttribute.class.isInstance(attribute) && !classesAutorisees.contains(((PluralAttribute<?, ?, ?>) attribute).getElementType().getJavaType()) && (enumerated == null || EnumType.ORDINAL.equals(enumerated.value()))) {
PluralAttribute<?, ?, ?> pluralAttribute = (PluralAttribute<?, ?, ?>) attribute;
throw new IllegalStateException("Collection \"" + attribute.getName() + "\" de " + pluralAttribute.getElementType().getJavaType().getSimpleName() + " refusée");
} else if (attribute instanceof MapAttribute) {
MapAttribute<?, ?, ?> mapAttribute = (MapAttribute<?, ?, ?>) attribute;
if (Enum.class.isAssignableFrom(mapAttribute.getKeyJavaType()) && (mapKeyEnumerated == null || EnumType.ORDINAL.equals(mapKeyEnumerated.value())) && mapKey == null) /* if @MapKey present, then field format is defined elsewhere and check is useless */
{
throw new IllegalStateException("Map \"" + attribute.getName() + "\" de clés ordinales " + ((PluralAttribute<?, ?, ?>) attribute).getElementType().getJavaType().getSimpleName() + " refusée");
}
if (Enum.class.isAssignableFrom(mapAttribute.getElementType().getJavaType()) && (enumerated == null || EnumType.ORDINAL.equals(enumerated.value()))) {
throw new IllegalStateException("Map \"" + attribute.getName() + "\" de valeurs ordinales " + ((PluralAttribute<?, ?, ?>) attribute).getElementType().getJavaType().getSimpleName() + " refusée");
}
}
}
Aggregations