Package com.sun.enterprise.deployment

Examples of com.sun.enterprise.deployment.EntityManagerReferenceDescriptor


    }
                                              
    public EntityManagerReferenceDescriptor
        getEntityManagerReference(String name) {

        EntityManagerReferenceDescriptor emRefDesc = null;

        try {
            emRefDesc = getEmRefContainer().
                getEntityManagerReferenceByName(name);
            // annotation has a corresponding entry
View Full Code Here


        if (entityMgrRefs==null || !entityMgrRefs.hasNext())
            return;
       
        EntityManagerReferenceNode subNode = new EntityManagerReferenceNode();
        for (;entityMgrRefs.hasNext();) {
            EntityManagerReferenceDescriptor aEntityMgrRef = (EntityManagerReferenceDescriptor)entityMgrRefs.next();
            subNode.writeDescriptor(parentNode, TagNames.PERSISTENCE_CONTEXT_REF, aEntityMgrRef);
        }       
    }
View Full Code Here

     * @param element the xml element
     * @param value it's associated value
     */   
    public void setElementValue(XMLElement element, String value) {
        if (TagNames.PERSISTENCE_CONTEXT_TYPE.equals(element.getQName())) {
            EntityManagerReferenceDescriptor entityMgrReferenceDescriptor =
                (EntityManagerReferenceDescriptor)getDescriptor();
            PersistenceContextType contextType = null;
            if (EXTENDED.equals(value)) {
                contextType = PersistenceContextType.EXTENDED;
            } else if (TRANSACTION.equals(value)) {
                contextType = PersistenceContextType.TRANSACTION;
            } else {
                throw new IllegalArgumentException(localStrings.getLocalString(
                "enterprise.deployment.node.invalidvalue",
                "Invalid value for a tag under {0} : {1}",
                new Object[] {TagNames.PERSISTENCE_CONTEXT_TYPE, value}));
            }

            entityMgrReferenceDescriptor.setPersistenceContextType(contextType);

        } else if (TagNames.NAME_VALUE_PAIR_NAME.equals(element.getQName())) {
            propertyName = value;
        } else if (TagNames.NAME_VALUE_PAIR_VALUE.equals(element.getQName())) {
            EntityManagerReferenceDescriptor entityMgrReferenceDescriptor =
                (EntityManagerReferenceDescriptor)getDescriptor();
            entityMgrReferenceDescriptor.addProperty(propertyName, value);
            propertyName = null;
        } else {
            super.setElementValue(element, value);
        }
    }   
View Full Code Here

     *
     */
    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();

View Full Code Here

     */
    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;
        }
View Full Code Here

        Set<EntityManagerReferenceDescriptor> emRefs
                = ejbDescriptor.getEntityManagerReferenceDescriptors();
        Iterator<EntityManagerReferenceDescriptor> iter = emRefs.iterator();
        Set<EEMRefInfo> eemRefInfos = new HashSet<EEMRefInfo>();
        while (iter.hasNext()) {
            EntityManagerReferenceDescriptor refDesc = iter.next();
            if (refDesc.getPersistenceContextType() ==
                    PersistenceContextType.EXTENDED) {
                String unitName = refDesc.getUnitName();
                EntityManagerFactory emf =
                        EntityManagerFactoryWrapper.lookupEntityManagerFactory(
                                ComponentInvocation.ComponentInvocationType.EJB_INVOCATION,
                                unitName, ejbDescriptor);
                if (emf != null) {
                    EntityManager em = findExtendedEMFromInvList(emf);

                    if (em == null) {
                        try {
                            Map properties = refDesc.getProperties();
                            em = emf.createEntityManager(properties);
                            if (em == null) {
                                throw new EJBException
                                        ("EM is null. Couldn't create EntityManager for"
                                                + " refName: " + refDesc.getName()
                                                + "; unitname: " + unitName);
                            }
                        } catch (Throwable th) {
                            EJBException ejbEx = new EJBException
                                    ("Couldn't create EntityManager for"
                                            + " refName: " + refDesc.getName()
                                            + "; unitname: " + unitName);
                            ejbEx.initCause(th);
                            throw ejbEx;
                        }
                    }

                    String emRefName = refDesc.getName();
                    long containerID = this.getContainerId();
                    EEMRefInfo refInfo = null;
                    synchronized (extendedEMReferenceCountMap) {
                        refInfo = extendedEMReferenceCountMap.get(em);
                        if (refInfo != null) {
                            refInfo.refCount++;
                        } else {
                            refInfo = new EEMRefInfo(emRefName, refDesc.getUnitName(), containerID,
                                    sessionKey, em, emf);
                            refInfo.refCount = 1;
                            extendedEMReferenceCountMap.put(em, refInfo);
                            eemKey2EEMMap.put(refInfo.getKey(), refInfo.getEntityManager());
                        }
                    }
                    ctx.addExtendedEntityManagerMapping(emf, refInfo);
                    eemRefInfos.add(refInfo);
                } else {
                    throw new EJBException("EMF is null. Couldn't get extended EntityManager for"
                            + " refName: " + refDesc.getName()
                            + "; unitname: " + unitName);
                }
            }
        }
View Full Code Here

        Set<EntityManagerReferenceDescriptor> emRefs
                = ejbDescriptor.getEntityManagerReferenceDescriptors();
        Iterator<EntityManagerReferenceDescriptor> iter = emRefs.iterator();
        Set<EEMRefInfo> eemRefInfos = new HashSet<EEMRefInfo>();
        while (iter.hasNext()) {
            EntityManagerReferenceDescriptor refDesc = iter.next();
            if (refDesc.getPersistenceContextType() ==
                    PersistenceContextType.EXTENDED) {
                String unitName = refDesc.getUnitName();
                EntityManagerFactory emf =
                        EntityManagerFactoryWrapper.lookupEntityManagerFactory(
                                ComponentInvocation.ComponentInvocationType.EJB_INVOCATION,
                                unitName, ejbDescriptor);
                if (emf != null) {
                    PhysicalEntityManagerWrapper physicalEntityManagerWrapper = findExtendedEMFromInvList(emf);

                    if (physicalEntityManagerWrapper == null) {
                        // We did not find an extended EM that we can inherit from. Create one
                        try {
                            EntityManager em = emf.createEntityManager(refDesc.getSynchronizationType(), refDesc.getProperties());
                            physicalEntityManagerWrapper = new PhysicalEntityManagerWrapper(em, refDesc.getSynchronizationType());
                        } catch (Throwable th) {
                            EJBException ejbEx = new EJBException
                                    ("Couldn't create EntityManager for"
                                            + " refName: " + refDesc.getName()
                                            + "; unitname: " + unitName);
                            ejbEx.initCause(th);
                            throw ejbEx;
                        }
                    } else {
                        // We found an extended EM we can inherit from. Validate that sync type matches
                        if(physicalEntityManagerWrapper.getSynchronizationType() != refDesc.getSynchronizationType()) {
                            throw new EJBException("The current invocation inherits a persistence context of synchronization type '" + physicalEntityManagerWrapper.getSynchronizationType() +
                                    "' where as it references a persistence context of synchronization type '" + refDesc.getSynchronizationType() +
                                    "' refName: " + refDesc.getName() +
                                    " unitName: " + unitName );
                        }
                    }
                    String emRefName = refDesc.getName();
                    long containerID = this.getContainerId();
                    EEMRefInfo refInfo = null;
                    synchronized (extendedEMReferenceCountMap) {
                        refInfo = extendedEMReferenceCountMap.get(physicalEntityManagerWrapper.getEM());
                        if (refInfo != null) {
                            refInfo.refCount++;
                        } else {
                            refInfo = new EEMRefInfo(emRefName, refDesc.getUnitName(), refDesc.getSynchronizationType(), containerID,
                                    sessionKey, physicalEntityManagerWrapper.getEM(), emf);
                            refInfo.refCount = 1;
                            extendedEMReferenceCountMap.put(physicalEntityManagerWrapper.getEM(), refInfo);
                            eemKey2EEMMap.put(refInfo.getKey(), refInfo.getEntityManager());
                        }
                    }
                    ctx.addExtendedEntityManagerMapping(emf, refInfo);
                    eemRefInfos.add(refInfo);
                } else {
                    throw new EJBException("EMF is null. Couldn't get extended EntityManager for"
                            + " refName: " + refDesc.getName()
                            + "; unitname: " + unitName);
                }
            }
        }
View Full Code Here

    @Override
    public 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());
View Full Code Here

        Set<EntityManagerReferenceDescriptor> emRefs
                = ejbDescriptor.getEntityManagerReferenceDescriptors();
        Iterator<EntityManagerReferenceDescriptor> iter = emRefs.iterator();
        Set<EEMRefInfo> eemRefInfos = new HashSet<EEMRefInfo>();
        while (iter.hasNext()) {
            EntityManagerReferenceDescriptor refDesc = iter.next();
            if (refDesc.getPersistenceContextType() ==
                    PersistenceContextType.EXTENDED) {
                String unitName = refDesc.getUnitName();
                EntityManagerFactory emf =
                        EntityManagerFactoryWrapper.lookupEntityManagerFactory(
                                ComponentInvocation.ComponentInvocationType.EJB_INVOCATION,
                                unitName, ejbDescriptor);
                if (emf != null) {
                    PhysicalEntityManagerWrapper physicalEntityManagerWrapper = findExtendedEMFromInvList(emf);

                    if (physicalEntityManagerWrapper == null) {
                        // We did not find an extended EM that we can inherit from. Create one
                        try {
                            EntityManager em = emf.createEntityManager(refDesc.getSynchronizationType(), refDesc.getProperties());
                            physicalEntityManagerWrapper = new PhysicalEntityManagerWrapper(em, refDesc.getSynchronizationType());
                        } catch (Throwable th) {
                            EJBException ejbEx = new EJBException
                                    ("Couldn't create EntityManager for"
                                            + " refName: " + refDesc.getName()
                                            + "; unitname: " + unitName);
                            ejbEx.initCause(th);
                            throw ejbEx;
                        }
                    } else {
                        // We found an extended EM we can inherit from. Validate that sync type matches
                        if(physicalEntityManagerWrapper.getSynchronizationType() != refDesc.getSynchronizationType()) {
                            throw new EJBException("The current invocation inherits a persistence context of synchronization type '" + physicalEntityManagerWrapper.getSynchronizationType() +
                                    "' where as it references a persistence context of synchronization type '" + refDesc.getSynchronizationType() +
                                    "' refName: " + refDesc.getName() +
                                    " unitName: " + unitName );
                        }
                    }
                    String emRefName = refDesc.getName();
                    long containerID = this.getContainerId();
                    EEMRefInfo refInfo = null;
                    synchronized (extendedEMReferenceCountMap) {
                        refInfo = extendedEMReferenceCountMap.get(physicalEntityManagerWrapper.getEM());
                        if (refInfo != null) {
                            refInfo.refCount++;
                        } else {
                            refInfo = new EEMRefInfo(emRefName, refDesc.getUnitName(), refDesc.getSynchronizationType(), containerID,
                                    sessionKey, physicalEntityManagerWrapper.getEM(), emf);
                            refInfo.refCount = 1;
                            extendedEMReferenceCountMap.put(physicalEntityManagerWrapper.getEM(), refInfo);
                            eemKey2EEMMap.put(refInfo.getKey(), refInfo.getEntityManager());
                        }
                    }
                    ctx.addExtendedEntityManagerMapping(emf, refInfo);
                    eemRefInfos.add(refInfo);
                } else {
                    throw new EJBException("EMF is null. Couldn't get extended EntityManager for"
                            + " refName: " + refDesc.getName()
                            + "; unitname: " + unitName);
                }
            }
        }
View Full Code Here

    @Override
    public 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());
View Full Code Here

TOP

Related Classes of com.sun.enterprise.deployment.EntityManagerReferenceDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.