Search in sources :

Example 1 with EntityManagerReferenceDescriptor

use of com.sun.enterprise.deployment.EntityManagerReferenceDescriptor in project Payara by payara.

the class EntityManagerInjection method check.

public Result check(WebBundleDescriptor descriptor) {
    Result result = getInitializedResult();
    addWarningDetails(result, getVerifierContext().getComponentNameConstructor());
    // default status is PASSED
    result.setStatus(Result.PASSED);
    for (EntityManagerReferenceDescriptor emRefDesc : descriptor.getEntityManagerReferenceDescriptors()) {
        Set<InjectionTarget> injectionTargets = emRefDesc.getInjectionTargets();
        if (injectionTargets != null) {
            for (InjectionTarget it : injectionTargets) {
                String itClassName = it.getClassName();
                String errMsg = smh.getLocalString(className + ".warning", "Found a persistence unit by name [ {0} ] injected into [ {1} ].", new Object[] { emRefDesc.getUnitName(), itClassName });
                try {
                    Class c = Class.forName(itClassName, false, getVerifierContext().getClassLoader());
                    if (!(Servlet.class.isAssignableFrom(c))) {
                        result.warning(errMsg);
                    } else if (!(SingleThreadModel.class.isAssignableFrom(c))) {
                        result.warning(errMsg);
                    }
                } catch (Exception ex) {
                    result.warning(errMsg);
                }
            }
        }
    }
    return result;
}
Also used : InjectionTarget(com.sun.enterprise.deployment.InjectionTarget) SingleThreadModel(javax.servlet.SingleThreadModel) Result(com.sun.enterprise.tools.verifier.Result) EntityManagerReferenceDescriptor(com.sun.enterprise.deployment.EntityManagerReferenceDescriptor)

Example 2 with EntityManagerReferenceDescriptor

use of com.sun.enterprise.deployment.EntityManagerReferenceDescriptor in project Payara by payara.

the class EjbDescriptor method addEntityManagerReferenceDescriptor.

@Override
public final void addEntityManagerReferenceDescriptor(EntityManagerReferenceDescriptor reference) {
    try {
        EntityManagerReferenceDescriptor existing = this.getEntityManagerReferenceByName(reference.getName());
        for (InjectionTarget next : reference.getInjectionTargets()) {
            existing.addInjectionTarget(next);
        }
    } catch (IllegalArgumentException e) {
        if (getEjbBundleDescriptor() != null) {
            reference.setReferringBundleDescriptor(getEjbBundleDescriptor());
        }
        if (env != null)
            env.addEntityManagerReferenceDescriptor(reference);
        else
            getEntityManagerReferenceDescriptors().add(reference);
    }
}
Also used : InjectionTarget(com.sun.enterprise.deployment.InjectionTarget) EntityManagerReferenceDescriptor(com.sun.enterprise.deployment.EntityManagerReferenceDescriptor)

Example 3 with EntityManagerReferenceDescriptor

use of com.sun.enterprise.deployment.EntityManagerReferenceDescriptor in project Payara by payara.

the class EjbDescriptor method applyInterceptors.

/**
 * Derive all interceptors that are applicable to this bean.
 * @param bindingTranslator
 */
public void applyInterceptors(InterceptorBindingTranslator bindingTranslator) {
    // Apply this ejb to the ordered set of all interceptor bindings
    // for this ejb-jar.  The results will contain all interceptor
    // information that applies to the ejb.  There is no notion of
    // default interceptors within the results.  Default interceptors
    // are used during the translation process but once we derive
    // the per-ejb interceptor information there is only a notion of
    // class-level ordering and method-level ordering.  Any applicable
    // default interceptors will have been applied to the class-level.
    TranslationResults results = bindingTranslator.apply(getName());
    allInterceptorClasses.clear();
    allInterceptorClasses.addAll(results.allInterceptorClasses);
    interceptorChain.clear();
    interceptorChain.addAll(results.classInterceptorChain);
    methodInterceptorsMap.clear();
    methodInterceptorsMap.putAll(results.methodInterceptorsMap);
    for (EjbInterceptor interceptor : allInterceptorClasses) {
        for (Object ejbRefObj : interceptor.getEjbReferenceDescriptors()) {
            addEjbReferenceDescriptor((EjbReference) ejbRefObj);
        }
        for (Object msgDestRefObj : interceptor.getMessageDestinationReferenceDescriptors()) {
            addMessageDestinationReferenceDescriptor((MessageDestinationReferenceDescriptor) msgDestRefObj);
        }
        for (Object envPropObj : interceptor.getEnvironmentProperties()) {
            addOrMergeEnvironmentProperty((EnvironmentProperty) envPropObj);
        }
        for (Object servRefObj : interceptor.getServiceReferenceDescriptors()) {
            addServiceReferenceDescriptor((ServiceReferenceDescriptor) servRefObj);
        }
        for (Object resRefObj : interceptor.getResourceReferenceDescriptors()) {
            addResourceReferenceDescriptor((ResourceReferenceDescriptor) resRefObj);
        }
        for (Object resourceEnvRefObj : interceptor.getResourceEnvReferenceDescriptors()) {
            addResourceEnvReferenceDescriptor((ResourceEnvReferenceDescriptor) resourceEnvRefObj);
        }
        for (EntityManagerFactoryReferenceDescriptor entMgrFacRef : interceptor.getEntityManagerFactoryReferenceDescriptors()) {
            addEntityManagerFactoryReferenceDescriptor(entMgrFacRef);
        }
        for (EntityManagerReferenceDescriptor entMgrRef : interceptor.getEntityManagerReferenceDescriptors()) {
            addEntityManagerReferenceDescriptor(entMgrRef);
        }
    }
}
Also used : EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor) TranslationResults(org.glassfish.ejb.deployment.util.InterceptorBindingTranslator.TranslationResults) EntityManagerFactoryReferenceDescriptor(com.sun.enterprise.deployment.EntityManagerFactoryReferenceDescriptor) EntityManagerReferenceDescriptor(com.sun.enterprise.deployment.EntityManagerReferenceDescriptor)

Example 4 with EntityManagerReferenceDescriptor

use of com.sun.enterprise.deployment.EntityManagerReferenceDescriptor in project Payara by payara.

the class EntityManagerReferenceHandler method getEmReferenceDescriptors.

/**
 * Return EntityManagerReferenceDescriptors with given name
 * if exists or a new one without name being set.
 */
private EntityManagerReferenceDescriptor[] getEmReferenceDescriptors(String logicalName, ResourceContainerContext[] rcContexts) {
    EntityManagerReferenceDescriptor[] emRefs = new EntityManagerReferenceDescriptor[rcContexts.length];
    for (int i = 0; i < rcContexts.length; i++) {
        EntityManagerReferenceDescriptor emRef = (EntityManagerReferenceDescriptor) rcContexts[i].getEntityManagerReference(logicalName);
        if (emRef == null) {
            emRef = new EntityManagerReferenceDescriptor();
            rcContexts[i].addEntityManagerReferenceDescriptor(emRef);
        }
        emRefs[i] = emRef;
    }
    return emRefs;
}
Also used : EntityManagerReferenceDescriptor(com.sun.enterprise.deployment.EntityManagerReferenceDescriptor)

Example 5 with EntityManagerReferenceDescriptor

use of com.sun.enterprise.deployment.EntityManagerReferenceDescriptor in project Payara by payara.

the class EntityManagerReferenceHandler method processEmRef.

/**
 * Process a particular annotation which type is the same as the
 * one returned by @see getAnnotationType(). All information
 * pertinent to the annotation and its context is encapsulated
 * in the passed AnnotationInfo instance.
 */
protected HandlerProcessingResult processEmRef(AnnotationInfo ainfo, ResourceContainerContext[] rcContexts, PersistenceContext emRefAn) throws AnnotationProcessorException {
    EntityManagerReferenceDescriptor[] emRefs = null;
    if (ElementType.FIELD.equals(ainfo.getElementType())) {
        Field f = (Field) ainfo.getAnnotatedElement();
        String targetClassName = f.getDeclaringClass().getName();
        String logicalName = emRefAn.name();
        // applying with default
        if (logicalName.equals("")) {
            logicalName = targetClassName + "/" + f.getName();
        }
        emRefs = getEmReferenceDescriptors(logicalName, rcContexts);
        InjectionTarget target = new InjectionTarget();
        target.setFieldName(f.getName());
        target.setClassName(targetClassName);
        target.setMetadataSource(MetadataSource.ANNOTATION);
        for (EntityManagerReferenceDescriptor emRef : emRefs) {
            emRef.addInjectionTarget(target);
            if (emRef.getName().length() == 0) {
                // a new one
                processNewEmRefAnnotation(emRef, logicalName, emRefAn);
            }
        }
    } else if (ElementType.METHOD.equals(ainfo.getElementType())) {
        Method m = (Method) ainfo.getAnnotatedElement();
        String targetClassName = m.getDeclaringClass().getName();
        String logicalName = emRefAn.name();
        if (logicalName.equals("")) {
            // Derive javabean property name.
            String propertyName = getInjectionMethodPropertyName(m, ainfo);
            // prefixing with fully qualified type name
            logicalName = targetClassName + "/" + propertyName;
        }
        validateInjectionMethod(m, ainfo);
        emRefs = getEmReferenceDescriptors(logicalName, rcContexts);
        InjectionTarget target = new InjectionTarget();
        target.setMethodName(m.getName());
        target.setClassName(targetClassName);
        target.setMetadataSource(MetadataSource.ANNOTATION);
        for (EntityManagerReferenceDescriptor emRef : emRefs) {
            emRef.addInjectionTarget(target);
            if (emRef.getName().length() == 0) {
                // a new one
                processNewEmRefAnnotation(emRef, logicalName, emRefAn);
            }
        }
    } else if (ElementType.TYPE.equals(ainfo.getElementType())) {
        // name() is required for TYPE-level usage
        String logicalName = emRefAn.name();
        if ("".equals(logicalName)) {
            log(Level.SEVERE, ainfo, localStrings.getLocalString("enterprise.deployment.annotation.handlers.nonametypelevel", "TYPE-Level annotation symbol on class must specify name."));
            return getDefaultFailedResult();
        }
        emRefs = getEmReferenceDescriptors(logicalName, rcContexts);
        for (EntityManagerReferenceDescriptor emRef : emRefs) {
            if (emRef.getName().length() == 0) {
                // a new one
                processNewEmRefAnnotation(emRef, logicalName, emRefAn);
            }
        }
    }
    return getDefaultProcessedResult();
}
Also used : Field(java.lang.reflect.Field) InjectionTarget(com.sun.enterprise.deployment.InjectionTarget) Method(java.lang.reflect.Method) EntityManagerReferenceDescriptor(com.sun.enterprise.deployment.EntityManagerReferenceDescriptor)

Aggregations

EntityManagerReferenceDescriptor (com.sun.enterprise.deployment.EntityManagerReferenceDescriptor)7 InjectionTarget (com.sun.enterprise.deployment.InjectionTarget)3 PhysicalEntityManagerWrapper (com.sun.enterprise.container.common.impl.PhysicalEntityManagerWrapper)1 EjbInterceptor (com.sun.enterprise.deployment.EjbInterceptor)1 EntityManagerFactoryReferenceDescriptor (com.sun.enterprise.deployment.EntityManagerFactoryReferenceDescriptor)1 Result (com.sun.enterprise.tools.verifier.Result)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 HashSet (java.util.HashSet)1 EJBException (javax.ejb.EJBException)1 EntityManager (javax.persistence.EntityManager)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 PersistenceContextType (javax.persistence.PersistenceContextType)1 SynchronizationType (javax.persistence.SynchronizationType)1 SingleThreadModel (javax.servlet.SingleThreadModel)1 TranslationResults (org.glassfish.ejb.deployment.util.InterceptorBindingTranslator.TranslationResults)1