FileDocCategorySizeDatePackage
DeploymentPersistenceUnitResolver.javaAPI DocJBoss 4.2.14839Fri Jul 13 20:53:50 BST 2007org.jboss.ejb3.enc

DeploymentPersistenceUnitResolver

public class DeploymentPersistenceUnitResolver extends Object
Resolves persistence units for @PersistenceContext and @PersistenceUnit
author
Bill Burke
version
$Revision: 60233 $

Fields Summary
protected List
persistenceUnitDeployments
protected org.jboss.ejb3.DeploymentScope
deploymentScope
protected LinkedHashMap
ejbContainers
Constructors Summary
public DeploymentPersistenceUnitResolver(List persistenceUnitDeployments, org.jboss.ejb3.DeploymentScope deploymentScope, LinkedHashMap ejbContainers)

      this.persistenceUnitDeployments = persistenceUnitDeployments;
      this.deploymentScope = deploymentScope;
      this.ejbContainers = ejbContainers;
   
Methods Summary
public org.jboss.ejb3.entity.PersistenceUnitDeploymentgetPersistenceUnitDeployment(java.lang.String unitName)

      if ("".equals(unitName))
      {
         if (persistenceUnitDeployments == null)
         {
            throw new NameNotFoundException("EMPTY STRING unitName but there is no deployments in scope");
         }
         if (persistenceUnitDeployments.size() == 1 && ejbContainers.size() > 0)
         {
            return persistenceUnitDeployments.get(0);
         }
         else if (persistenceUnitDeployments.size() > 1)
         {
            throw new NameNotFoundException("EMPTY STRING unitName and there is more than one scoped persistence unit");
         }
         throw new NameNotFoundException("There is no default persistence unit in this deployment.");
      }
      int hashIndex = unitName.indexOf('#");
      if (hashIndex != -1)
      {
         String relativePath = unitName.substring(0, hashIndex);
         String name = unitName.substring(hashIndex + 1);
         if (deploymentScope == null)
         {
            String relativeJarName = relativePath.substring(3);
            // look in global EJB jars.
            for (PersistenceUnitDeployment pud : PersistenceUnitRegistry.getPersistenceUnits())
            {
               String jarName = pud.getDeployment().getDeploymentUnit().getShortName() + ".jar";
               if (pud.getDeployment().getEar() == null
                       && jarName.equals(relativeJarName)
                       && pud.getEntityManagerName().equals(name)
                       && pud.isScoped())
               {
                  return pud;
               }
            }
            return null;
         }
         Ejb3Deployment dep = deploymentScope.findRelativeDeployment(relativePath);
         if (dep == null)
         {
            return null;
         }
         PersistenceUnitDeployment rtn = dep.getPersistenceUnitDeploymentInternal(name);
         return rtn;
      }
      PersistenceUnitDeployment rtn = getPersistenceUnitDeploymentInternal(unitName);
      if (rtn != null) return rtn;

      for (PersistenceUnitDeployment deployment : PersistenceUnitRegistry.getPersistenceUnits())
      {
         if (deployment.isScoped()) continue;
         if (deployment.getEntityManagerName().equals(unitName)) return deployment;
      }
      return rtn;
   
public org.jboss.ejb3.entity.PersistenceUnitDeploymentgetPersistenceUnitDeploymentInternal(java.lang.String unitName)

      if (persistenceUnitDeployments != null)
      {
         for (PersistenceUnitDeployment deployment : persistenceUnitDeployments)
         {
            if (deployment.getEntityManagerName().equals(unitName))
            {
               return deployment;
            }
         }
      }
      return null;