[jboss-cvs] JBossAS SVN: r75431 - in projects/jpa/trunk/deployers/src: main/java/org/jboss/jpa/deployers and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jul 7 05:54:16 EDT 2008
Author: wolfc
Date: 2008-07-07 05:54:16 -0400 (Mon, 07 Jul 2008)
New Revision: 75431
Added:
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/javaee/
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/javaee/JavaEEModuleInformer.java
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/DataSourceDependencyResolver.java
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/DefaultPersistenceUnitDependencyResolver.java
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/PersistenceUnitDependencyResolver.java
projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/common/SimpleJavaEEModuleInformer.java
Removed:
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/DataSourceDependencyResolver.java
Modified:
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/AbstractDeploymentVisitor.java
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/PersistenceDeployer.java
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/PersistenceUnitDeployer.java
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceDeployment.java
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java
projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/common/SimpleDataSourceDependencyResolver.java
projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/deployment/DeploymentTestCase.java
projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/deployment/DeploymentTestCase.xml
Log:
Made the PersistenceUnitDependencyResolver authoritative on kernel name
Modified: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/AbstractDeploymentVisitor.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/AbstractDeploymentVisitor.java 2008-07-07 09:43:22 UTC (rev 75430)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/AbstractDeploymentVisitor.java 2008-07-07 09:54:16 UTC (rev 75431)
@@ -45,7 +45,7 @@
*/
protected void addComponent(DeploymentUnit unit, C componentMD)
{
- String name = getName(componentMD);
+ String name = getName(unit, componentMD);
DeploymentUnit component = unit.addComponent(name);
// TODO: determine proper component meta data class
component.addAttachment(componentMD.getClass().getName(), componentMD);
@@ -78,7 +78,7 @@
protected abstract List<C> getComponents(T deployment);
- protected abstract String getName(C component);
+ protected abstract String getName(DeploymentUnit unit, C component);
/**
* Remove bean component.
@@ -89,7 +89,7 @@
protected void removeComponent(DeploymentUnit unit, C component)
{
- String name = getName(component);
+ String name = getName(unit, component);
unit.removeComponent(name);
}
Deleted: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/DataSourceDependencyResolver.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/DataSourceDependencyResolver.java 2008-07-07 09:43:22 UTC (rev 75430)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/DataSourceDependencyResolver.java 2008-07-07 09:54:16 UTC (rev 75431)
@@ -1,38 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.jpa.deployers;
-
-/**
- * Find the bean name that supplies the given DataSource. Not that
- * this bean might not be available yet.
- *
- * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
- * @version $Revision: $
- */
-public interface DataSourceDependencyResolver
-{
- /**
- * @param jndiName the jndiName of the DataSource
- * @return the bean name of the DataSource
- */
- String resolveDataSourceSupplier(String jndiName);
-}
Modified: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/PersistenceDeployer.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/PersistenceDeployer.java 2008-07-07 09:43:22 UTC (rev 75430)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/PersistenceDeployer.java 2008-07-07 09:54:16 UTC (rev 75431)
@@ -24,7 +24,10 @@
import java.util.Collections;
import java.util.List;
+import org.jboss.beans.metadata.api.annotations.Inject;
import org.jboss.deployers.spi.deployer.helpers.AbstractComponentDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.jpa.resolvers.PersistenceUnitDependencyResolver;
import org.jboss.logging.Logger;
import org.jboss.metadata.jpa.spec.PersistenceMetaData;
import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
@@ -37,13 +40,15 @@
{
private static final Logger log = Logger.getLogger(PersistenceDeployer.class);
+ private PersistenceUnitDependencyResolver persistenceUnitDependencyResolver;
+
public PersistenceDeployer()
{
//setComponentVisitor(new PersistenceUnitDeploymentVisitor());
setDeploymentVisitor(new PersistenceDeploymentVisitor());
}
- private static class PersistenceDeploymentVisitor extends AbstractDeploymentVisitor<PersistenceMetaData, PersistenceUnitMetaData>
+ private class PersistenceDeploymentVisitor extends AbstractDeploymentVisitor<PersistenceMetaData, PersistenceUnitMetaData>
{
public Class<PersistenceMetaData> getVisitorType()
{
@@ -57,14 +62,13 @@
}
@Override
- protected String getName(PersistenceUnitMetaData component)
+ protected String getName(DeploymentUnit unit, PersistenceUnitMetaData component)
{
- // TODO: fix me
- return component.getName();
+ return persistenceUnitDependencyResolver.createBeanName(unit, component.getName());
}
}
- private static class PersistenceUnitDeploymentVisitor extends AbstractDeploymentVisitor<PersistenceUnitMetaData, PersistenceUnitMetaData>
+ private class PersistenceUnitDeploymentVisitor extends AbstractDeploymentVisitor<PersistenceUnitMetaData, PersistenceUnitMetaData>
{
public Class<PersistenceUnitMetaData> getVisitorType()
{
@@ -78,10 +82,15 @@
}
@Override
- protected String getName(PersistenceUnitMetaData component)
+ protected String getName(DeploymentUnit unit, PersistenceUnitMetaData component)
{
- // TODO: fix me
- return component.getName();
+ return persistenceUnitDependencyResolver.createBeanName(unit, component.getName());
}
}
+
+ @Inject
+ public void setPersistenceUnitDependencyResolver(PersistenceUnitDependencyResolver resolver)
+ {
+ this.persistenceUnitDependencyResolver = resolver;
+ }
}
Modified: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/PersistenceUnitDeployer.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/PersistenceUnitDeployer.java 2008-07-07 09:43:22 UTC (rev 75430)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/PersistenceUnitDeployer.java 2008-07-07 09:54:16 UTC (rev 75431)
@@ -39,6 +39,8 @@
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
import org.jboss.jpa.deployment.PersistenceDeployment;
import org.jboss.jpa.deployment.PersistenceUnitDeployment;
+import org.jboss.jpa.resolvers.DataSourceDependencyResolver;
+import org.jboss.jpa.resolvers.PersistenceUnitDependencyResolver;
import org.jboss.logging.Logger;
import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
@@ -53,6 +55,8 @@
private Properties defaultPersistenceProperties;
private DataSourceDependencyResolver dataSourceDependencyResolver;
+
+ private PersistenceUnitDependencyResolver persistenceUnitDependencyResolver;
public PersistenceUnitDeployer()
{
@@ -98,17 +102,14 @@
try
{
+ String name = persistenceUnitDependencyResolver.createBeanName(unit, metaData.getName());
+
InitialContext initialContext = new InitialContext();
PersistenceDeployment persistenceDeployment = null;
List<String> explicitEntityClasses = new ArrayList<String>();
- String ear = null;
- String jar = null;
- boolean isScoped = false;
VFSDeploymentUnit deploymentUnit = (VFSDeploymentUnit) unit.getParent();
- PersistenceUnitDeployment pu = new PersistenceUnitDeployment(initialContext, persistenceDeployment, explicitEntityClasses, metaData, ear, jar, isScoped, deploymentUnit, defaultPersistenceProperties);
+ PersistenceUnitDeployment pu = new PersistenceUnitDeployment(initialContext, persistenceDeployment, explicitEntityClasses, metaData, name, deploymentUnit, defaultPersistenceProperties);
- // TODO: fix me, must match the component name in PersistenceDeployer
- String name = metaData.getName();
AbstractBeanMetaData beanMetaData = new AbstractBeanMetaData(name, PersistenceUnitDeployment.class.getName());
BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(beanMetaData);
builder.setConstructorValue(pu);
@@ -133,4 +134,10 @@
{
this.defaultPersistenceProperties = p;
}
+
+ @Inject
+ public void setPersistenceUnitDependencyResolver(PersistenceUnitDependencyResolver resolver)
+ {
+ this.persistenceUnitDependencyResolver = resolver;
+ }
}
Modified: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceDeployment.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceDeployment.java 2008-07-07 09:43:22 UTC (rev 75430)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceDeployment.java 2008-07-07 09:54:16 UTC (rev 75431)
@@ -217,7 +217,7 @@
// cache_prefix = SecondLevelCacheUtil.createCacheRegionPrefix(earShortName, jarName, metaData.getName());
// properties.put(SecondLevelCacheUtil.HIBERNATE_CACHE_REGION_PREFIX, cache_prefix);
// }
- PersistenceUnitDeployment deployment = new PersistenceUnitDeployment(initialContext, this, explicitEntityClasses, metaData, earName, unit.getSimpleName(), isScoped, getDeploymentUnit(), null);
+ PersistenceUnitDeployment deployment = new PersistenceUnitDeployment(initialContext, this, explicitEntityClasses, metaData, "wrong-kernel-name", getDeploymentUnit(), null);
PersistenceUnitRegistry.register(deployment);
persistenceUnitDeployments.add(deployment);
}
Modified: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java 2008-07-07 09:43:22 UTC (rev 75430)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java 2008-07-07 09:54:16 UTC (rev 75431)
@@ -63,14 +63,12 @@
protected PersistenceUnitMetaData metaData;
protected String kernelName;
protected PersistenceDeployment deployment;
- protected boolean scoped;
private Properties defaultPersistenceProperties;
- public PersistenceUnitDeployment(InitialContext initialContext, PersistenceDeployment deployment, List<String> explicitEntityClasses, PersistenceUnitMetaData metadata, String ear, String jar, boolean isScoped, VFSDeploymentUnit deploymentUnit, Properties defaultPersistenceProperties)
+ public PersistenceUnitDeployment(InitialContext initialContext, PersistenceDeployment deployment, List<String> explicitEntityClasses, PersistenceUnitMetaData metadata, String kernelName, VFSDeploymentUnit deploymentUnit, Properties defaultPersistenceProperties)
{
//super(new SimpleJavaEEModule((deployment.getEar() != null ? deployment.getEar().getShortName() : null), deployment.getDeploymentUnit().getShortName()));
- this.scoped = isScoped;
this.deployment = deployment;
this.initialContext = initialContext;
this.di = deploymentUnit;
@@ -78,24 +76,7 @@
this.metaData = metadata;
this.defaultPersistenceProperties = defaultPersistenceProperties;
- kernelName = "persistence.units:";
- String name = getEntityManagerName();
- if (name == null || name.length() == 0)
- throw new RuntimeException("Null string is not allowed for a persistence unit name. Fix your persistence.xml file");
-
- if (ear != null)
- {
- kernelName += "ear=" + ear;
- if (!ear.endsWith(".ear")) kernelName += ".ear";
- kernelName += ",";
- }
- if (isScoped)
- {
- kernelName += "jar=" + jar;
- if (!jar.endsWith(".jar")) kernelName += ".jar";
- kernelName += ",";
- }
- kernelName += "unitName=" + name;
+ this.kernelName = kernelName;
}
public static String getDefaultKernelName(String unitName)
@@ -110,11 +91,6 @@
return "persistence.units:unitName=" + unitName;
}
- public boolean isScoped()
- {
- return scoped;
- }
-
public PersistenceDeployment getDeployment()
{
return deployment;
Added: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/javaee/JavaEEModuleInformer.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/javaee/JavaEEModuleInformer.java (rev 0)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/javaee/JavaEEModuleInformer.java 2008-07-07 09:54:16 UTC (rev 75431)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jpa.javaee;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * Obtain information about a JavaEE module given a deployment unit.
+ * The informer should only use meta data to obtain the information
+ * being asked.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface JavaEEModuleInformer
+{
+ public enum ModuleType { APP_CLIENT, EJB, JAVA, WEB };
+
+ /**
+ * Obtain the name of the JavaEE application this module is part of, for
+ * example 'foo.ear'.
+ * If the deployment unit is not part of a JavaEE application return null.
+ *
+ * @param deployment the deployment unit of the module, application or component
+ * @return the name of the JavaEE application or null if none
+ */
+ String getApplicationName(DeploymentUnit deploymentUnit);
+
+ /**
+ * Obtain the relative path of the deployment unit within the JavaEE application
+ * or base deployment directory.
+ * The deployment unit is either a JavaEE module or a component of the JavaEE module.
+ * If the JavaEE module is part of a JavaEE application return the relative
+ * path within the JavaEE application otherwise it is considered a stand alone deployment
+ * and return the relative path within the base deployment directory.
+ * Note that the relative path includes the module name, for example 'lib/bar.jar'.
+ *
+ * @param deployment the deployment unit of the module or a component
+ * @return the relative path of the JavaEE module
+ */
+ String getModulePath(DeploymentUnit deploymentUnit);
+
+ /**
+ * Obtain the module type of the deployment unit.
+ * Based on the meta data available the informer will output the module type
+ * of the JavaEE module of which the deployment unit is part.
+ *
+ * @param deploymentUnit the deployment unit of the module or a component
+ * @return the JavaEE module type
+ */
+ ModuleType getModuleType(DeploymentUnit deploymentUnit);
+}
Copied: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/DataSourceDependencyResolver.java (from rev 75423, projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/DataSourceDependencyResolver.java)
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/DataSourceDependencyResolver.java (rev 0)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/DataSourceDependencyResolver.java 2008-07-07 09:54:16 UTC (rev 75431)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jpa.resolvers;
+
+/**
+ * Find the bean name that supplies the given DataSource. Not that
+ * this bean might not be available yet.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface DataSourceDependencyResolver
+{
+ /**
+ * @param jndiName the jndiName of the DataSource
+ * @return the bean name of the DataSource
+ */
+ String resolveDataSourceSupplier(String jndiName);
+}
Added: 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 (rev 0)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/DefaultPersistenceUnitDependencyResolver.java 2008-07-07 09:54:16 UTC (rev 75431)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jpa.resolvers;
+
+import org.jboss.beans.metadata.api.annotations.Inject;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.jpa.javaee.JavaEEModuleInformer;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class DefaultPersistenceUnitDependencyResolver implements PersistenceUnitDependencyResolver
+{
+ private JavaEEModuleInformer javaEEModuleInformer;
+
+ public String createBeanName(DeploymentUnit deploymentUnit, String persistenceUnitName)
+ {
+ // persistenceUnitName must be a simple name
+ assert persistenceUnitName.indexOf('/') == -1;
+ assert persistenceUnitName.indexOf('#') == -1;
+
+ String appName = javaEEModuleInformer.getApplicationName(deploymentUnit);
+ String modulePath = javaEEModuleInformer.getModulePath(deploymentUnit);
+ String unitName = (appName != null ? appName + "/" : "") + modulePath + "#" + persistenceUnitName;
+ return "persistence.unit:unitName=" + unitName;
+ }
+
+ private static DeploymentUnit getDeploymentUnit(DeploymentUnit current, String path)
+ {
+ if(path.startsWith("/"))
+ return getDeploymentUnit(current.getTopLevel(), path.substring(1));
+ if(path.startsWith("./"))
+ return getDeploymentUnit(current, path.substring(2));
+ if(path.startsWith("../"))
+ return getDeploymentUnit(current.getParent(), path.substring(3));
+ int i = path.indexOf('/');
+ String name;
+ if(i == -1)
+ name = path;
+ else
+ name = path.substring(0, i);
+ for(DeploymentUnit child : current.getChildren())
+ {
+ if(child.getName().equals(name))
+ return child;
+ }
+ throw new IllegalArgumentException("Can't find a deployment unit named " + name + " at " + current);
+ }
+
+ public String resolverPersistenceUnitSupplier(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);
+ return createBeanName(targetDeploymentUnit, unitName);
+ }
+ else
+ {
+ throw new RuntimeException("NYI");
+ }
+ }
+
+ @Inject
+ public void setJavaEEModuleInformer(JavaEEModuleInformer informer)
+ {
+ this.javaEEModuleInformer = informer;
+ }
+}
Added: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/PersistenceUnitDependencyResolver.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/PersistenceUnitDependencyResolver.java (rev 0)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/PersistenceUnitDependencyResolver.java 2008-07-07 09:54:16 UTC (rev 75431)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jpa.resolvers;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * Based on the available meta data resolve persistence unit references.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface PersistenceUnitDependencyResolver
+{
+ /**
+ * Create a bean name for a persistence unit (deployment).
+ *
+ * @param deploymentUnit the deployment unit in which the persistence unit is defined
+ * @param persistenceUnitName the name of the persistence unit
+ * @return the bean name
+ */
+ String createBeanName(DeploymentUnit deploymentUnit, String persistenceUnitName);
+
+ /**
+ * @param deploymentUnit the deployment unit that has a persistence unit reference
+ * @param persistenceUnitName the (relative) name of a persistence unit
+ * @return the bean name of the persistence unit
+ */
+ String resolverPersistenceUnitSupplier(DeploymentUnit deploymentUnit, String persistenceUnitName);
+}
Modified: projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/common/SimpleDataSourceDependencyResolver.java
===================================================================
--- projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/common/SimpleDataSourceDependencyResolver.java 2008-07-07 09:43:22 UTC (rev 75430)
+++ projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/common/SimpleDataSourceDependencyResolver.java 2008-07-07 09:54:16 UTC (rev 75431)
@@ -21,7 +21,7 @@
*/
package org.jboss.jpa.deployers.test.common;
-import org.jboss.jpa.deployers.DataSourceDependencyResolver;
+import org.jboss.jpa.resolvers.DataSourceDependencyResolver;
/**
* @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
Added: projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/common/SimpleJavaEEModuleInformer.java
===================================================================
--- projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/common/SimpleJavaEEModuleInformer.java (rev 0)
+++ projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/common/SimpleJavaEEModuleInformer.java 2008-07-07 09:54:16 UTC (rev 75431)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jpa.deployers.test.common;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.jpa.javaee.JavaEEModuleInformer;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.ear.jboss.JBossAppMetaData;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class SimpleJavaEEModuleInformer implements JavaEEModuleInformer
+{
+ private static final Logger log = Logger.getLogger(SimpleJavaEEModuleInformer.class);
+
+ public String getApplicationName(DeploymentUnit deploymentUnit)
+ {
+ DeploymentUnit application = deploymentUnit.getTopLevel();
+// if(application == null)
+// return null;
+ if(!application.isAttachmentPresent(JBossAppMetaData.class))
+ return null;
+ return application.getSimpleName();
+ }
+
+ public String getModulePath(DeploymentUnit deploymentUnit)
+ {
+ return deploymentUnit.getRelativePath();
+ }
+
+ public ModuleType getModuleType(DeploymentUnit deploymentUnit)
+ {
+ throw new RuntimeException("NYI");
+ }
+}
Modified: projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/deployment/DeploymentTestCase.java
===================================================================
--- projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/deployment/DeploymentTestCase.java 2008-07-07 09:43:22 UTC (rev 75430)
+++ projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/deployment/DeploymentTestCase.java 2008-07-07 09:54:16 UTC (rev 75431)
@@ -70,8 +70,7 @@
delegate.getMainDeployer().deploy(deployment);
//delegate.getMainDeployer().checkComplete(deployment);
- // TODO: this name should be persistence.units:jar=pu,unitName=dummy
- String name = "dummy";
+ String name = "persistence.unit:unitName=#dummy";
PersistenceUnit pu = delegate.getBean(name, PersistenceUnit.class);
assertNotNull(pu);
Modified: projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/deployment/DeploymentTestCase.xml
===================================================================
--- projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/deployment/DeploymentTestCase.xml 2008-07-07 09:43:22 UTC (rev 75430)
+++ projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/deployment/DeploymentTestCase.xml 2008-07-07 09:54:16 UTC (rev 75431)
@@ -2,6 +2,10 @@
<deployment xmlns="urn:jboss:bean-deployer:2.0">
<bean name="DataSourceDependencyResolver" class="org.jboss.jpa.deployers.test.common.SimpleDataSourceDependencyResolver"/>
+ <bean name="JavaEEModuleInformer" class="org.jboss.jpa.deployers.test.common.SimpleJavaEEModuleInformer"/>
+
+ <bean name="PersistenceUnitDependencyResolver" class="org.jboss.jpa.resolvers.DefaultPersistenceUnitDependencyResolver"/>
+
<bean name="PersistenceParsingDeployer" class="org.jboss.jpa.deployers.PersistenceParsingDeployer"/>
<bean name="PersistenceDeployer" class="org.jboss.jpa.deployers.PersistenceDeployer"/>
More information about the jboss-cvs-commits
mailing list