private AnnotatedField decorateContext()

in jpa-cdi/src/main/java/org/apache/aries/jpa/cdi/PersistenceAnnotatedType.java [78:103]


    private <X> AnnotatedField<X> decorateContext(AnnotatedField<X> field) {
        final PersistenceContext persistenceContext = field.getAnnotation(PersistenceContext.class);
        final UniqueIdentifier identifier = UniqueIdentifierLitteral.random();

        Set<Annotation> templateQualifiers = new HashSet<>();
        templateQualifiers.add(ServiceLiteral.SERVICE);
        if (hasUnitName(persistenceContext)) {
            templateQualifiers.add(new FilterLiteral("(osgi.unit.name=" + persistenceContext.unitName() + ")"));
        }
        Bean<JpaTemplate> bean = manager.getExtension(OsgiExtension.class)
                .globalDependency(JpaTemplate.class, templateQualifiers);

        Set<Annotation> qualifiers = new HashSet<>();
        qualifiers.add(identifier);
        Bean<EntityManager> b = new SimpleBean<>(EntityManager.class, Dependent.class, Collections.singleton(EntityManager.class), qualifiers, () -> {
            CreationalContext<JpaTemplate> context = manager.createCreationalContext(bean);
            JpaTemplate template = (JpaTemplate) manager.getReference(bean, JpaTemplate.class, context);
            return EntityManagerProducer.create(template);
        });
        beans.add(b);

        Set<Annotation> fieldAnnotations = new HashSet<>();
        fieldAnnotations.add(InjectLiteral.INJECT);
        fieldAnnotations.add(identifier);
        return new SyntheticAnnotatedField<>(field, fieldAnnotations);
    }