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;