Search in sources :

Example 1 with AccessType

use of org.hibernate.jpamodelgen.util.AccessType in project hibernate-orm by hibernate.

the class AnnotationMetaEntity method addPersistentMembers.

private void addPersistentMembers(List<? extends Element> membersOfClass, AccessType membersKind) {
    for (Element memberOfClass : membersOfClass) {
        AccessType forcedAccessType = TypeUtils.determineAnnotationSpecifiedAccessType(memberOfClass);
        if (entityAccessTypeInfo.getAccessType() != membersKind && forcedAccessType == null) {
            continue;
        }
        if (TypeUtils.containsAnnotation(memberOfClass, Constants.TRANSIENT) || memberOfClass.getModifiers().contains(Modifier.TRANSIENT) || memberOfClass.getModifiers().contains(Modifier.STATIC)) {
            continue;
        }
        MetaAttributeGenerationVisitor visitor = new MetaAttributeGenerationVisitor(this, context);
        AnnotationMetaAttribute result = memberOfClass.asType().accept(visitor, memberOfClass);
        if (result != null) {
            members.put(result.getPropertyName(), result);
        }
    }
}
Also used : PackageElement(javax.lang.model.element.PackageElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) AccessType(org.hibernate.jpamodelgen.util.AccessType)

Example 2 with AccessType

use of org.hibernate.jpamodelgen.util.AccessType in project hibernate-orm by hibernate.

the class JpaDescriptorParser method determineXmlAccessTypes.

private void determineXmlAccessTypes() {
    for (EntityMappings mappings : entityMappings) {
        String fqcn;
        String packageName = mappings.getPackage();
        AccessType defaultAccessType = determineEntityAccessType(mappings);
        for (Entity entity : mappings.getEntity()) {
            String name = entity.getClazz();
            fqcn = StringUtil.determineFullyQualifiedClassName(packageName, name);
            AccessType explicitAccessType = null;
            org.hibernate.jpamodelgen.xml.jaxb.AccessType type = entity.getAccess();
            if (type != null) {
                explicitAccessType = mapXmlAccessTypeToJpaAccessType(type);
            }
            AccessTypeInformation accessInfo = new AccessTypeInformation(fqcn, explicitAccessType, defaultAccessType);
            context.addAccessTypeInformation(fqcn, accessInfo);
        }
        for (org.hibernate.jpamodelgen.xml.jaxb.MappedSuperclass mappedSuperClass : mappings.getMappedSuperclass()) {
            String name = mappedSuperClass.getClazz();
            fqcn = StringUtil.determineFullyQualifiedClassName(packageName, name);
            AccessType explicitAccessType = null;
            org.hibernate.jpamodelgen.xml.jaxb.AccessType type = mappedSuperClass.getAccess();
            if (type != null) {
                explicitAccessType = mapXmlAccessTypeToJpaAccessType(type);
            }
            AccessTypeInformation accessInfo = new AccessTypeInformation(fqcn, explicitAccessType, defaultAccessType);
            context.addAccessTypeInformation(fqcn, accessInfo);
        }
        for (org.hibernate.jpamodelgen.xml.jaxb.Embeddable embeddable : mappings.getEmbeddable()) {
            String name = embeddable.getClazz();
            fqcn = StringUtil.determineFullyQualifiedClassName(packageName, name);
            AccessType explicitAccessType = null;
            org.hibernate.jpamodelgen.xml.jaxb.AccessType type = embeddable.getAccess();
            if (type != null) {
                explicitAccessType = mapXmlAccessTypeToJpaAccessType(type);
            }
            AccessTypeInformation accessInfo = new AccessTypeInformation(fqcn, explicitAccessType, defaultAccessType);
            context.addAccessTypeInformation(fqcn, accessInfo);
        }
    }
}
Also used : Entity(org.hibernate.jpamodelgen.xml.jaxb.Entity) EntityMappings(org.hibernate.jpamodelgen.xml.jaxb.EntityMappings) AccessType(org.hibernate.jpamodelgen.util.AccessType) AccessTypeInformation(org.hibernate.jpamodelgen.util.AccessTypeInformation)

Example 3 with AccessType

use of org.hibernate.jpamodelgen.util.AccessType in project hibernate-orm by hibernate.

the class BasicAttributeVisitor method createMetaCollectionAttribute.

private AnnotationMetaAttribute createMetaCollectionAttribute(DeclaredType declaredType, Element element, String fqNameOfReturnType, String collection, String targetEntity) {
    if (TypeUtils.containsAnnotation(element, Constants.ELEMENT_COLLECTION)) {
        String explicitTargetEntity = getTargetEntity(element.getAnnotationMirrors());
        TypeMirror collectionElementType = TypeUtils.getCollectionElementType(declaredType, fqNameOfReturnType, explicitTargetEntity, context);
        final TypeElement collectionElement = (TypeElement) context.getTypeUtils().asElement(collectionElementType);
        AccessTypeInformation accessTypeInfo = context.getAccessTypeInfo(collectionElementType.toString());
        if (accessTypeInfo == null) {
            AccessType explicitAccessType = null;
            if (collectionElement != null) {
                explicitAccessType = TypeUtils.determineAnnotationSpecifiedAccessType(collectionElement);
            }
            accessTypeInfo = new AccessTypeInformation(collectionElementType.toString(), explicitAccessType, entity.getEntityAccessTypeInfo().getAccessType());
            context.addAccessTypeInformation(collectionElementType.toString(), accessTypeInfo);
        } else {
            accessTypeInfo.setDefaultAccessType(entity.getEntityAccessTypeInfo().getAccessType());
        }
    }
    if (collection.equals("javax.persistence.metamodel.MapAttribute")) {
        return createAnnotationMetaAttributeForMap(declaredType, element, collection, targetEntity);
    } else {
        return new AnnotationMetaCollection(entity, element, collection, getElementType(declaredType, targetEntity));
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) AccessTypeInformation(org.hibernate.jpamodelgen.util.AccessTypeInformation) AccessType(org.hibernate.jpamodelgen.util.AccessType)

Aggregations

AccessType (org.hibernate.jpamodelgen.util.AccessType)3 TypeElement (javax.lang.model.element.TypeElement)2 AccessTypeInformation (org.hibernate.jpamodelgen.util.AccessTypeInformation)2 Element (javax.lang.model.element.Element)1 PackageElement (javax.lang.model.element.PackageElement)1 TypeMirror (javax.lang.model.type.TypeMirror)1 Entity (org.hibernate.jpamodelgen.xml.jaxb.Entity)1 EntityMappings (org.hibernate.jpamodelgen.xml.jaxb.EntityMappings)1