[jboss-cvs] JBossAS SVN: r75487 - projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jul 8 04:38:48 EDT 2008
Author: wolfc
Date: 2008-07-08 04:38:48 -0400 (Tue, 08 Jul 2008)
New Revision: 75487
Modified:
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/DefaultPersistenceUnitDependencyResolver.java
Log:
Implemented scoping
Modified: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/DefaultPersistenceUnitDependencyResolver.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/DefaultPersistenceUnitDependencyResolver.java 2008-07-08 08:38:33 UTC (rev 75486)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/DefaultPersistenceUnitDependencyResolver.java 2008-07-08 08:38:48 UTC (rev 75487)
@@ -24,6 +24,8 @@
import org.jboss.beans.metadata.api.annotations.Inject;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.jpa.javaee.JavaEEModuleInformer;
+import org.jboss.metadata.jpa.spec.PersistenceMetaData;
+import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
/**
* @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
@@ -45,6 +47,37 @@
return "persistence.unit:unitName=" + unitName;
}
+ private String findWithinApplication(DeploymentUnit unit, String persistenceUnitName)
+ {
+ String name = findWithinModule(unit, persistenceUnitName, false);
+ if(name != null)
+ return name;
+
+ for(DeploymentUnit child : unit.getChildren())
+ {
+ name = findWithinApplication(child, persistenceUnitName);
+ if(name != null)
+ return name;
+ }
+ return null;
+ }
+
+ private String findWithinModule(DeploymentUnit unit, String persistenceUnitName, boolean allowScoped)
+ {
+ if(!allowScoped && isScoped(unit))
+ return null;
+
+ PersistenceMetaData persistenceMetaData = unit.getAttachment(PersistenceMetaData.class);
+ if(persistenceMetaData == null)
+ return null;
+ for(PersistenceUnitMetaData persistenceUnit : persistenceMetaData.getPersistenceUnits())
+ {
+ if(persistenceUnit.getName().equals(persistenceUnitName))
+ return createBeanName(unit, persistenceUnitName);
+ }
+ return null;
+ }
+
private static DeploymentUnit getDeploymentUnit(DeploymentUnit current, String path)
{
if(path.startsWith("/"))
@@ -67,19 +100,40 @@
throw new IllegalArgumentException("Can't find a deployment unit named " + name + " at " + current);
}
- public String resolverPersistenceUnitSupplier(DeploymentUnit deploymentUnit, String persistenceUnitName)
+ /*
+ * EJB3 JPA 6.2.2: Persistence Unit Scope
+ */
+ private boolean isScoped(DeploymentUnit unit)
{
+ JavaEEModuleInformer.ModuleType type = javaEEModuleInformer.getModuleType(unit);
+ if(type == JavaEEModuleInformer.ModuleType.APP_CLIENT)
+ return true;
+ if(type == JavaEEModuleInformer.ModuleType.EJB)
+ return true;
+ if(type == JavaEEModuleInformer.ModuleType.WEB)
+ return true;
+ return false;
+ }
+
+ public String resolvePersistenceUnitSupplier(DeploymentUnit deploymentUnit, String persistenceUnitName)
+ {
int i = persistenceUnitName.indexOf('#');
if(i != -1)
{
String path = persistenceUnitName.substring(0, i);
String unitName = persistenceUnitName.substring(i + 1);
DeploymentUnit targetDeploymentUnit = getDeploymentUnit(deploymentUnit, path);
+ // TODO: verify the existence of PersistenceUnitMetaData?
return createBeanName(targetDeploymentUnit, unitName);
}
else
{
- throw new RuntimeException("NYI");
+ String name = findWithinModule(deploymentUnit, persistenceUnitName, true);
+ if(name == null)
+ name = findWithinApplication(deploymentUnit.getTopLevel(), persistenceUnitName);
+ if(name == null)
+ throw new IllegalArgumentException("Can't find a persistence unit named '" + persistenceUnitName + "' in " + deploymentUnit);
+ return name;
}
}
More information about the jboss-cvs-commits
mailing list