Search in sources :

Example 1 with PersistenceUnitReferenceInfo

use of org.apache.openejb.assembler.classic.PersistenceUnitReferenceInfo in project tomee by apache.

the class TomcatJndiBuilder method mergeJndi.

public void mergeJndi() throws OpenEJBException {
    final NamingResourcesImpl naming = standardContext.getNamingResources();
    final URI moduleUri = URLs.uri(webAppInfo.moduleId);
    for (final EnvEntryInfo ref : webAppInfo.jndiEnc.envEntries) {
        mergeRef(naming, ref);
    }
    for (final EjbReferenceInfo ref : webAppInfo.jndiEnc.ejbReferences) {
        mergeRef(naming, ref);
    }
    for (final EjbLocalReferenceInfo ref : webAppInfo.jndiEnc.ejbLocalReferences) {
        mergeRef(naming, ref);
    }
    for (final PersistenceContextReferenceInfo ref : webAppInfo.jndiEnc.persistenceContextRefs) {
        mergeRef(naming, ref, moduleUri);
    }
    for (final PersistenceUnitReferenceInfo ref : webAppInfo.jndiEnc.persistenceUnitRefs) {
        mergeRef(naming, ref, moduleUri);
    }
    for (final ResourceReferenceInfo ref : webAppInfo.jndiEnc.resourceRefs) {
        mergeRef(naming, ref);
    }
    for (final ResourceEnvReferenceInfo ref : webAppInfo.jndiEnc.resourceEnvRefs) {
        mergeRef(naming, ref);
    }
    for (final ServiceReferenceInfo ref : webAppInfo.jndiEnc.serviceRefs) {
        mergeRef(naming, ref);
    }
    final ContextTransaction contextTransaction = new ContextTransaction();
    contextTransaction.setProperty(Constants.FACTORY, UserTransactionFactory.class.getName());
    naming.setTransaction(contextTransaction);
}
Also used : ResourceReferenceInfo(org.apache.openejb.assembler.classic.ResourceReferenceInfo) PersistenceContextReferenceInfo(org.apache.openejb.assembler.classic.PersistenceContextReferenceInfo) EjbReferenceInfo(org.apache.openejb.assembler.classic.EjbReferenceInfo) UserTransactionFactory(org.apache.tomee.common.UserTransactionFactory) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) EnvEntryInfo(org.apache.openejb.assembler.classic.EnvEntryInfo) EjbLocalReferenceInfo(org.apache.openejb.assembler.classic.EjbLocalReferenceInfo) ResourceEnvReferenceInfo(org.apache.openejb.assembler.classic.ResourceEnvReferenceInfo) ContextTransaction(org.apache.tomcat.util.descriptor.web.ContextTransaction) URI(java.net.URI) ServiceReferenceInfo(org.apache.openejb.assembler.classic.ServiceReferenceInfo) PersistenceUnitReferenceInfo(org.apache.openejb.assembler.classic.PersistenceUnitReferenceInfo)

Example 2 with PersistenceUnitReferenceInfo

use of org.apache.openejb.assembler.classic.PersistenceUnitReferenceInfo in project aries by apache.

the class EJBExtender method processJPAMappings.

private void processJPAMappings(EjbJarInfo ejbInfo) {
    for (EnterpriseBeanInfo ebi : ejbInfo.enterpriseBeans) {
        for (PersistenceUnitReferenceInfo pui : ebi.jndiEnc.persistenceUnitRefs) {
            pui.location = new ReferenceLocationInfo();
            pui.location.jndiName = "aries/integration/unit/" + pui.persistenceUnitName;
        }
        for (PersistenceContextReferenceInfo pci : ebi.jndiEnc.persistenceContextRefs) {
            pci.location = new ReferenceLocationInfo();
            pci.location.jndiName = "aries/integration/context/" + pci.persistenceUnitName;
        }
    }
}
Also used : EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) PersistenceContextReferenceInfo(org.apache.openejb.assembler.classic.PersistenceContextReferenceInfo) ReferenceLocationInfo(org.apache.openejb.assembler.classic.ReferenceLocationInfo) PersistenceUnitReferenceInfo(org.apache.openejb.assembler.classic.PersistenceUnitReferenceInfo)

Example 3 with PersistenceUnitReferenceInfo

use of org.apache.openejb.assembler.classic.PersistenceUnitReferenceInfo in project aries by apache.

the class RunningApplication method addingService.

public Object addingService(ServiceReference reference) {
    if (isTrue(reference, PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT) && !!!isTrue(reference, PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE)) {
        Map<Context, PersistenceUnitReferenceInfo> pUnitRefs = unitRegistrations.get(reference.getProperty(PersistenceUnitConstants.OSGI_UNIT_NAME));
        Map<Context, PersistenceContextReferenceInfo> pCtxRefs = contextRegistrations.get(reference.getProperty(PersistenceUnitConstants.OSGI_UNIT_NAME));
        if (pUnitRefs == null) {
            pUnitRefs = new HashMap<Context, PersistenceUnitReferenceInfo>();
        }
        if (pCtxRefs == null) {
            pCtxRefs = new HashMap<Context, PersistenceContextReferenceInfo>();
        }
        if (pUnitRefs.size() > 0 || pCtxRefs.size() > 0) {
            EntityManagerFactory emf = (EntityManagerFactory) bundle.getBundleContext().getService(reference);
            for (Entry<Context, PersistenceUnitReferenceInfo> e : pUnitRefs.entrySet()) {
                try {
                    e.getKey().bind(e.getValue().referenceName, emf);
                } catch (NamingException ex) {
                    // TODO Auto-generated catch block
                    ex.printStackTrace();
                }
            }
            for (Entry<Context, PersistenceContextReferenceInfo> e : pCtxRefs.entrySet()) {
                PersistenceContextReferenceInfo pci = e.getValue();
                try {
                    e.getKey().bind(pci.referenceName, new JtaEntityManager((String) reference.getProperty(PersistenceUnitConstants.OSGI_UNIT_NAME), AriesPersistenceContextIntegration.get(), emf, pci.properties, pci.extended));
                } catch (NamingException ex) {
                    // TODO Auto-generated catch block
                    ex.printStackTrace();
                }
            }
            return emf;
        }
    }
    return null;
}
Also used : BeanContext(org.apache.openejb.BeanContext) Context(javax.naming.Context) AppContext(org.apache.openejb.AppContext) PersistenceContextReferenceInfo(org.apache.openejb.assembler.classic.PersistenceContextReferenceInfo) JtaEntityManager(org.apache.openejb.persistence.JtaEntityManager) PersistenceUnitReferenceInfo(org.apache.openejb.assembler.classic.PersistenceUnitReferenceInfo) EntityManagerFactory(javax.persistence.EntityManagerFactory) NamingException(javax.naming.NamingException)

Example 4 with PersistenceUnitReferenceInfo

use of org.apache.openejb.assembler.classic.PersistenceUnitReferenceInfo in project aries by apache.

the class RunningApplication method removedService.

public void removedService(ServiceReference reference, Object service) {
    Map<Context, PersistenceUnitReferenceInfo> pUnitRefs = unitRegistrations.get(reference.getProperty(PersistenceUnitConstants.OSGI_UNIT_NAME));
    Map<Context, PersistenceContextReferenceInfo> pCtxRefs = contextRegistrations.get(reference.getProperty(PersistenceUnitConstants.OSGI_UNIT_NAME));
    if (pUnitRefs == null) {
        pUnitRefs = new HashMap<Context, PersistenceUnitReferenceInfo>();
    }
    if (pCtxRefs == null) {
        pCtxRefs = new HashMap<Context, PersistenceContextReferenceInfo>();
    }
    if (pUnitRefs.size() > 0 || pCtxRefs.size() > 0) {
        for (Entry<Context, PersistenceUnitReferenceInfo> e : pUnitRefs.entrySet()) {
            try {
                e.getKey().unbind(e.getValue().referenceName);
            } catch (NamingException ex) {
                // TODO Auto-generated catch block
                ex.printStackTrace();
            }
        }
        for (Entry<Context, PersistenceContextReferenceInfo> e : pCtxRefs.entrySet()) {
            PersistenceContextReferenceInfo pci = e.getValue();
            try {
                e.getKey().unbind(pci.referenceName);
            } catch (NamingException ex) {
                // TODO Auto-generated catch block
                ex.printStackTrace();
            }
        }
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) Context(javax.naming.Context) AppContext(org.apache.openejb.AppContext) PersistenceContextReferenceInfo(org.apache.openejb.assembler.classic.PersistenceContextReferenceInfo) NamingException(javax.naming.NamingException) PersistenceUnitReferenceInfo(org.apache.openejb.assembler.classic.PersistenceUnitReferenceInfo)

Example 5 with PersistenceUnitReferenceInfo

use of org.apache.openejb.assembler.classic.PersistenceUnitReferenceInfo in project tomee by apache.

the class JndiEncInfoBuilder method buildPersistenceUnitRefInfos.

private void buildPersistenceUnitRefInfos(final JndiConsumer jndiConsumer, final JndiEncInfo moduleJndiEnc, final JndiEncInfo compJndiEnc) {
    for (final PersistenceUnitRef puRef : jndiConsumer.getPersistenceUnitRef()) {
        final PersistenceUnitReferenceInfo info = new PersistenceUnitReferenceInfo();
        info.referenceName = puRef.getPersistenceUnitRefName();
        info.persistenceUnitName = puRef.getPersistenceUnitName();
        info.unitId = puRef.getMappedName();
        info.location = buildLocationInfo(puRef);
        info.targets.addAll(buildInjectionInfos(puRef));
        insert(info, appInfo.globalJndiEnc.persistenceUnitRefs, appInfo.appJndiEnc.persistenceUnitRefs, moduleJndiEnc.persistenceUnitRefs, compJndiEnc.persistenceUnitRefs);
    }
}
Also used : PersistenceUnitRef(org.apache.openejb.jee.PersistenceUnitRef) PersistenceUnitReferenceInfo(org.apache.openejb.assembler.classic.PersistenceUnitReferenceInfo)

Aggregations

PersistenceUnitReferenceInfo (org.apache.openejb.assembler.classic.PersistenceUnitReferenceInfo)6 PersistenceContextReferenceInfo (org.apache.openejb.assembler.classic.PersistenceContextReferenceInfo)5 Context (javax.naming.Context)2 NamingException (javax.naming.NamingException)2 AppContext (org.apache.openejb.AppContext)2 BeanContext (org.apache.openejb.BeanContext)2 EnterpriseBeanInfo (org.apache.openejb.assembler.classic.EnterpriseBeanInfo)2 EnvEntryInfo (org.apache.openejb.assembler.classic.EnvEntryInfo)2 ResourceReferenceInfo (org.apache.openejb.assembler.classic.ResourceReferenceInfo)2 PersistenceUnitRef (org.apache.openejb.jee.PersistenceUnitRef)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 PersistenceUnit (javax.persistence.PersistenceUnit)1 NamingResourcesImpl (org.apache.catalina.deploy.NamingResourcesImpl)1 AppInfo (org.apache.openejb.assembler.classic.AppInfo)1 Assembler (org.apache.openejb.assembler.classic.Assembler)1 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)1 EjbLocalReferenceInfo (org.apache.openejb.assembler.classic.EjbLocalReferenceInfo)1 EjbReferenceInfo (org.apache.openejb.assembler.classic.EjbReferenceInfo)1