Search in sources :

Example 1 with MetaModelGenerationException

use of org.hibernate.jpamodelgen.MetaModelGenerationException in project hibernate-orm by hibernate.

the class XmlMetaEntity method parseElementCollection.

private boolean parseElementCollection(ElementCollection collection) {
    String[] types;
    XmlMetaCollection metaCollection;
    ElementKind elementKind = getElementKind(collection.getAccess());
    String explicitTargetClass = determineExplicitTargetEntity(collection.getTargetClass());
    String explicitMapKey = determineExplicitMapKeyClass(collection.getMapKeyClass());
    try {
        types = getCollectionTypes(collection.getName(), explicitTargetClass, explicitMapKey, elementKind);
    } catch (MetaModelGenerationException e) {
        logMetaModelException(collection.getName(), e);
        return true;
    }
    if (types != null) {
        if (types[2] == null) {
            metaCollection = new XmlMetaCollection(this, collection.getName(), types[0], types[1]);
        } else {
            metaCollection = new XmlMetaMap(this, collection.getName(), types[0], types[1], types[2]);
        }
        members.add(metaCollection);
    }
    return false;
}
Also used : ElementKind(javax.lang.model.element.ElementKind) MetaModelGenerationException(org.hibernate.jpamodelgen.MetaModelGenerationException)

Example 2 with MetaModelGenerationException

use of org.hibernate.jpamodelgen.MetaModelGenerationException in project hibernate-orm by hibernate.

the class XmlMetaEntity method parseManyToMany.

private boolean parseManyToMany(ManyToMany manyToMany) {
    String[] types;
    XmlMetaCollection metaCollection;
    ElementKind elementKind = getElementKind(manyToMany.getAccess());
    String explicitTargetClass = determineExplicitTargetEntity(manyToMany.getTargetEntity());
    String explicitMapKey = determineExplicitMapKeyClass(manyToMany.getMapKeyClass());
    try {
        types = getCollectionTypes(manyToMany.getName(), explicitTargetClass, explicitMapKey, elementKind);
    } catch (MetaModelGenerationException e) {
        logMetaModelException(manyToMany.getName(), e);
        return true;
    }
    if (types != null) {
        if (types[2] == null) {
            metaCollection = new XmlMetaCollection(this, manyToMany.getName(), types[0], types[1]);
        } else {
            metaCollection = new XmlMetaMap(this, manyToMany.getName(), types[0], types[1], types[2]);
        }
        members.add(metaCollection);
    }
    return false;
}
Also used : ElementKind(javax.lang.model.element.ElementKind) MetaModelGenerationException(org.hibernate.jpamodelgen.MetaModelGenerationException)

Example 3 with MetaModelGenerationException

use of org.hibernate.jpamodelgen.MetaModelGenerationException in project hibernate-orm by hibernate.

the class XmlMetaEntity method parseOneToMany.

private boolean parseOneToMany(OneToMany oneToMany) {
    String[] types;
    XmlMetaCollection metaCollection;
    ElementKind elementKind = getElementKind(oneToMany.getAccess());
    String explicitTargetClass = determineExplicitTargetEntity(oneToMany.getTargetEntity());
    String explicitMapKey = determineExplicitMapKeyClass(oneToMany.getMapKeyClass());
    try {
        types = getCollectionTypes(oneToMany.getName(), explicitTargetClass, explicitMapKey, elementKind);
    } catch (MetaModelGenerationException e) {
        logMetaModelException(oneToMany.getName(), e);
        return true;
    }
    if (types != null) {
        if (types[2] == null) {
            metaCollection = new XmlMetaCollection(this, oneToMany.getName(), types[0], types[1]);
        } else {
            metaCollection = new XmlMetaMap(this, oneToMany.getName(), types[0], types[1], types[2]);
        }
        members.add(metaCollection);
    }
    return false;
}
Also used : ElementKind(javax.lang.model.element.ElementKind) MetaModelGenerationException(org.hibernate.jpamodelgen.MetaModelGenerationException)

Example 4 with MetaModelGenerationException

use of org.hibernate.jpamodelgen.MetaModelGenerationException in project hibernate-orm by hibernate.

the class TypeUtils method getCollectionElementType.

public static TypeMirror getCollectionElementType(DeclaredType t, String fqNameOfReturnedType, String explicitTargetEntityName, Context context) {
    TypeMirror collectionElementType;
    if (explicitTargetEntityName != null) {
        Elements elements = context.getElementUtils();
        TypeElement element = elements.getTypeElement(explicitTargetEntityName);
        collectionElementType = element.asType();
    } else {
        List<? extends TypeMirror> typeArguments = t.getTypeArguments();
        if (typeArguments.size() == 0) {
            throw new MetaModelGenerationException("Unable to determine collection type");
        } else if (Map.class.getCanonicalName().equals(fqNameOfReturnedType)) {
            collectionElementType = t.getTypeArguments().get(1);
        } else {
            collectionElementType = t.getTypeArguments().get(0);
        }
    }
    return collectionElementType;
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) MetaModelGenerationException(org.hibernate.jpamodelgen.MetaModelGenerationException) Elements(javax.lang.model.util.Elements)

Aggregations

MetaModelGenerationException (org.hibernate.jpamodelgen.MetaModelGenerationException)4 ElementKind (javax.lang.model.element.ElementKind)3 TypeElement (javax.lang.model.element.TypeElement)1 TypeMirror (javax.lang.model.type.TypeMirror)1 Elements (javax.lang.model.util.Elements)1