You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2007/05/03 10:07:12 UTC
svn commit: r534748 [2/2] - in /geronimo/server/trunk:
assemblies/geronimo-boilerplate-minimal/src/main/resources/var/log/
configs/j2ee-security/src/plan/ configs/j2ee-server/src/plan/
configs/jetty6-deployer/src/plan/ configs/openejb-deployer/src/plan...
Modified: geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitRefBuilder.java?view=diff&rev=534748&r1=534747&r2=534748
==============================================================================
--- geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitRefBuilder.java (original)
+++ geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitRefBuilder.java Thu May 3 01:07:09 2007
@@ -16,12 +16,13 @@
*/
package org.apache.geronimo.persistence.builder;
+import java.util.ArrayList;
import java.util.Collections;
-import java.util.Map;
-import java.util.Set;
import java.util.HashMap;
import java.util.List;
-import java.util.ArrayList;
+import java.util.Map;
+import java.util.Set;
+import java.util.LinkedHashSet;
import javax.xml.namespace.QName;
@@ -29,9 +30,11 @@
import org.apache.geronimo.gbean.AbstractNameQuery;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
-import org.apache.geronimo.j2ee.deployment.annotation.PersistenceUnitAnnotationHelper;
+import org.apache.geronimo.gbean.GBeanData;
+import org.apache.geronimo.gbean.AbstractName;
import org.apache.geronimo.j2ee.deployment.Module;
import org.apache.geronimo.j2ee.deployment.NamingBuilder;
+import org.apache.geronimo.j2ee.deployment.annotation.PersistenceUnitAnnotationHelper;
import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
import org.apache.geronimo.kernel.GBeanNotFoundException;
import org.apache.geronimo.kernel.config.Configuration;
@@ -40,9 +43,9 @@
import org.apache.geronimo.naming.reference.PersistenceUnitReference;
import org.apache.geronimo.schema.NamespaceElementConverter;
import org.apache.geronimo.schema.SchemaConversionUtils;
+import org.apache.geronimo.xbeans.geronimo.naming.GerPatternType;
import org.apache.geronimo.xbeans.geronimo.naming.GerPersistenceUnitRefDocument;
import org.apache.geronimo.xbeans.geronimo.naming.GerPersistenceUnitRefType;
-import org.apache.geronimo.xbeans.geronimo.naming.GerPatternType;
import org.apache.geronimo.xbeans.javaee.PersistenceUnitRefType;
import org.apache.xmlbeans.QNameSet;
import org.apache.xmlbeans.XmlObject;
@@ -86,18 +89,18 @@
List<PersistenceUnitRefType> specPersistenceUnitRefsUntyped = convert(specDD.selectChildren(PersistenceUnitRefBuilder.PERSISTENCE_UNIT_REF_QNAME_SET), JEE_CONVERTER, PersistenceUnitRefType.class, PersistenceUnitRefType.type);
Map<String, GerPersistenceUnitRefType> gerPersistenceUnitRefsUntyped = getGerPersistenceUnitRefs(plan);
List<DeploymentException> problems = new ArrayList<DeploymentException>();
- for (PersistenceUnitRefType PersistenceUnitRef: specPersistenceUnitRefsUntyped) {
+ for (PersistenceUnitRefType persistenceUnitRef : specPersistenceUnitRefsUntyped) {
try {
- String persistenceUnitRefName = PersistenceUnitRef.getPersistenceUnitRefName().getStringValue().trim();
+ String persistenceUnitRefName = persistenceUnitRef.getPersistenceUnitRefName().getStringValue().trim();
- addInjections(persistenceUnitRefName, PersistenceUnitRef.getInjectionTargetArray(), componentContext);
+ addInjections(persistenceUnitRefName, persistenceUnitRef.getInjectionTargetArray(), componentContext);
AbstractNameQuery persistenceUnitNameQuery;
GerPersistenceUnitRefType gerPersistenceUnitRef = gerPersistenceUnitRefsUntyped.remove(persistenceUnitRefName);
if (gerPersistenceUnitRef != null) {
persistenceUnitNameQuery = findPersistenceUnit(gerPersistenceUnitRef);
checkForGBean(localConfiguration, persistenceUnitNameQuery, true);
- } else if (PersistenceUnitRef.isSetPersistenceUnitName()) {
- String persistenceUnitName = PersistenceUnitRef.getPersistenceUnitName().getStringValue().trim();
+ } else if (persistenceUnitRef.isSetPersistenceUnitName() && persistenceUnitRef.getPersistenceUnitName().getStringValue().trim().length() > 0) {
+ String persistenceUnitName = persistenceUnitRef.getPersistenceUnitName().getStringValue().trim();
persistenceUnitNameQuery = new AbstractNameQuery(null, Collections.singletonMap("name", persistenceUnitName), PERSISTENCE_UNIT_INTERFACE_TYPES);
if (!checkForGBean(localConfiguration, persistenceUnitNameQuery, strictMatching)) {
persistenceUnitName = "persistence/" + persistenceUnitName;
@@ -105,12 +108,25 @@
checkForGBean(localConfiguration, persistenceUnitNameQuery, true);
}
} else {
- persistenceUnitNameQuery = defaultPersistenceUnitAbstractNameQuery;
- checkForGBean(localConfiguration, persistenceUnitNameQuery, true);
+ persistenceUnitNameQuery = new AbstractNameQuery(null, Collections.EMPTY_MAP, PERSISTENCE_UNIT_INTERFACE_TYPES);
+ Set<AbstractNameQuery> patterns = Collections.singleton(persistenceUnitNameQuery);
+ LinkedHashSet<GBeanData> gbeans = localConfiguration.findGBeanDatas(localConfiguration, patterns);
+ persistenceUnitNameQuery = checkForDefaultPersistenceUnit(gbeans);
+ if (gbeans.isEmpty()) {
+ gbeans = localConfiguration.findGBeanDatas(patterns);
+ persistenceUnitNameQuery = checkForDefaultPersistenceUnit(gbeans);
+
+ if (gbeans.isEmpty()) {
+ if (defaultPersistenceUnitAbstractNameQuery == null) {
+ throw new DeploymentException("No default PersistenceUnit specified, and none located");
+ }
+ persistenceUnitNameQuery = defaultPersistenceUnitAbstractNameQuery;
+ }
+ }
}
+ checkForGBean(localConfiguration, persistenceUnitNameQuery, true);
-
- PersistenceUnitReference reference = new PersistenceUnitReference(localConfiguration.getId(), persistenceUnitNameQuery);
+ PersistenceUnitReference reference = new PersistenceUnitReference(getConfigId(localConfiguration, remoteConfiguration), persistenceUnitNameQuery);
NamingBuilder.JNDI_KEY.get(componentContext).put(ENV + persistenceUnitRefName, reference);
} catch (DeploymentException e) {
@@ -120,7 +136,7 @@
}
- for (GerPersistenceUnitRefType gerPersistenceUnitRef: gerPersistenceUnitRefsUntyped.values()) {
+ for (GerPersistenceUnitRefType gerPersistenceUnitRef : gerPersistenceUnitRefsUntyped.values()) {
try {
String PersistenceUnitRefName = gerPersistenceUnitRef.getPersistenceUnitRefName();
@@ -128,7 +144,7 @@
checkForGBean(localConfiguration, persistenceUnitNameQuery, true);
- PersistenceUnitReference reference = new PersistenceUnitReference(localConfiguration.getId(), persistenceUnitNameQuery);
+ PersistenceUnitReference reference = new PersistenceUnitReference(getConfigId(localConfiguration, remoteConfiguration), persistenceUnitNameQuery);
NamingBuilder.JNDI_KEY.get(componentContext).put(ENV + PersistenceUnitRefName, reference);
} catch (DeploymentException e) {
@@ -138,8 +154,26 @@
}
if (!problems.isEmpty()) {
//TODO make DeploymentException accept a list of exceptions as causes.
- throw new DeploymentException("At least one deployment problem:" + problems.toArray());
+ throw new DeploymentException("At least one deployment problem:" + problems);
+ }
+ }
+
+ private AbstractNameQuery checkForDefaultPersistenceUnit(LinkedHashSet<GBeanData> gbeans) throws DeploymentException {
+ AbstractNameQuery persistenceUnitNameQuery = null;
+ for (java.util.Iterator it = gbeans.iterator(); it.hasNext();) {
+ GBeanData gbean = (GBeanData) it.next();
+ AbstractName name = gbean.getAbstractName();
+ Map nameMap = name.getName();
+ if ("cmp".equals(nameMap.get("name"))) {
+ it.remove();
+ } else {
+ persistenceUnitNameQuery = new AbstractNameQuery(name);
+ }
}
+ if (gbeans.size() > 1) {
+ throw new DeploymentException("Too many matches for no-name persistence unit: " + gbeans);
+ }
+ return persistenceUnitNameQuery;
}
private boolean checkForGBean(Configuration localConfiguration, AbstractNameQuery persistenceUnitNameQuery, boolean complainIfMissing) throws DeploymentException {
@@ -147,7 +181,7 @@
localConfiguration.findGBeanData(persistenceUnitNameQuery);
return true;
} catch (GBeanNotFoundException e) {
- if (complainIfMissing || e.hasMatches()) {
+ if (complainIfMissing || e.hasMatches()) {
String reason = e.hasMatches() ? "More than one GBean reference found." : "No GBean references found.";
throw new DeploymentException("Could not resolve reference at deploy time for query " + persistenceUnitNameQuery + ". " + reason, e);
}
@@ -186,7 +220,7 @@
Map<String, GerPersistenceUnitRefType> map = new HashMap<String, GerPersistenceUnitRefType>();
if (plan != null) {
List<GerPersistenceUnitRefType> refs = convert(plan.selectChildren(PersistenceUnitRefBuilder.GER_PERSISTENCE_UNIT_REF_QNAME_SET), NAMING_CONVERTER, GerPersistenceUnitRefType.class, GerPersistenceUnitRefType.type);
- for (GerPersistenceUnitRefType ref: refs) {
+ for (GerPersistenceUnitRefType ref : refs) {
map.put(ref.getPersistenceUnitRefName().trim(), ref);
}
}
Modified: geronimo/server/trunk/modules/geronimo-persistence-jpa10/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-persistence-jpa10/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java?view=diff&rev=534748&r1=534747&r2=534748
==============================================================================
--- geronimo/server/trunk/modules/geronimo-persistence-jpa10/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java (original)
+++ geronimo/server/trunk/modules/geronimo-persistence-jpa10/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java Thu May 3 01:07:09 2007
@@ -17,28 +17,30 @@
package org.apache.geronimo.persistence;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
import java.util.List;
-import java.util.Properties;
import java.util.Map;
-import java.util.ArrayList;
-import java.net.URL;
+import java.util.Properties;
-import javax.persistence.spi.PersistenceUnitInfo;
-import javax.persistence.spi.PersistenceUnitTransactionType;
-import javax.persistence.spi.ClassTransformer;
-import javax.persistence.spi.PersistenceProvider;
+import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceException;
-import javax.persistence.EntityManager;
+import javax.persistence.spi.ClassTransformer;
+import javax.persistence.spi.PersistenceProvider;
+import javax.persistence.spi.PersistenceUnitInfo;
+import javax.persistence.spi.PersistenceUnitTransactionType;
import javax.sql.DataSource;
+import org.apache.geronimo.connector.outbound.ConnectionFactorySource;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
import org.apache.geronimo.gbean.GBeanLifecycle;
-import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
-import org.apache.geronimo.connector.outbound.ConnectionFactorySource;
-import org.apache.geronimo.persistence.TemporaryClassLoader;
+import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
import org.apache.geronimo.transformer.TransformerAgent;
/**
@@ -62,15 +64,22 @@
ConnectionFactorySource jtaDataSourceWrapper,
ConnectionFactorySource nonJtaDataSourceWrapper,
List mappingFileNamesUntyped,
- List jarFileUrlsUntyped,
- URL persistenceUnitRootUrl,
+ List<String> jarFileUrlsUntyped,
+ String persistenceUnitRoot,
List managedClassNamesUntyped,
boolean excludeUnlistedClassesValue,
Properties properties,
TransactionManagerImpl transactionManager,
- ClassLoader classLoader) {
+ URL configurationBaseURL,
+ ClassLoader classLoader) throws URISyntaxException, MalformedURLException {
List<String> mappingFileNames = mappingFileNamesUntyped == null? new ArrayList<String>(): new ArrayList<String>(mappingFileNamesUntyped);
- List<URL> jarFileUrls = jarFileUrlsUntyped == null? new ArrayList<URL>(): new ArrayList<URL>(jarFileUrlsUntyped);
+ URI configurationBaseURI = configurationBaseURL.toURI();
+ URL rootURL = configurationBaseURI.resolve(persistenceUnitRoot).normalize().toURL();
+ List<URL> jarFileUrls = new ArrayList<URL>();
+ for (String urlString: jarFileUrlsUntyped) {
+ URL url = configurationBaseURI.resolve(urlString).normalize().toURL();
+ jarFileUrls.add(url);
+ }
List<String> managedClassNames = managedClassNamesUntyped == null? new ArrayList<String>(): new ArrayList<String>(managedClassNamesUntyped);
PersistenceUnitTransactionType persistenceUnitTransactionType = persistenceUnitTransactionTypeString == null? PersistenceUnitTransactionType.JTA: PersistenceUnitTransactionType.valueOf(persistenceUnitTransactionTypeString);
@@ -83,7 +92,7 @@
nonJtaDataSourceWrapper == null? null: (DataSource)nonJtaDataSourceWrapper.$getResource(),
mappingFileNames,
jarFileUrls,
- persistenceUnitRootUrl,
+ rootURL,
managedClassNames,
excludeUnlistedClassesValue,
properties,
@@ -301,13 +310,16 @@
infoBuilder.addAttribute("persistenceUnitTransactionType", String.class, true, true);
infoBuilder.addAttribute("mappingFileNames", List.class, true, true);
infoBuilder.addAttribute("jarFileUrls", List.class, true, true);
- infoBuilder.addAttribute("persistenceUnitRootUrl", URL.class, true, true);
+ infoBuilder.addAttribute("persistenceUnitRoot", String.class, true, true);
infoBuilder.addAttribute("managedClassNames", List.class, true, true);
infoBuilder.addAttribute("excludeUnlistedClasses", boolean.class, true, true);
infoBuilder.addAttribute("properties", Properties.class, true, true);
+ infoBuilder.addAttribute("configurationBaseUrl", URL.class, true);
+
infoBuilder.addReference("TransactionManager", TransactionManagerImpl.class, NameFactory.TRANSACTION_MANAGER);
infoBuilder.addReference("JtaDataSourceWrapper", ConnectionFactorySource.class, NameFactory.JCA_MANAGED_CONNECTION_FACTORY);
infoBuilder.addReference("NonJtaDataSourceWrapper", ConnectionFactorySource.class, NameFactory.JCA_MANAGED_CONNECTION_FACTORY);
+
infoBuilder.addOperation("getEntityManagerFactory");
infoBuilder.addOperation("getEntityManager", new Class[] {boolean.class, Map.class});
@@ -319,11 +331,12 @@
"NonJtaDataSourceWrapper",
"mappingFileNames",
"jarFileUrls",
- "persistenceUnitRootUrl",
+ "persistenceUnitRoot",
"managedClassNames",
"excludeUnlistedClasses",
"properties",
"TransactionManager",
+ "configurationBaseUrl",
"classLoader"
});
Modified: geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/main/java/org/apache/geronimo/web25/deployment/AbstractWebModuleBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/main/java/org/apache/geronimo/web25/deployment/AbstractWebModuleBuilder.java?view=diff&rev=534748&r1=534747&r2=534748
==============================================================================
--- geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/main/java/org/apache/geronimo/web25/deployment/AbstractWebModuleBuilder.java (original)
+++ geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/main/java/org/apache/geronimo/web25/deployment/AbstractWebModuleBuilder.java Thu May 3 01:07:09 2007
@@ -273,6 +273,7 @@
module.setRootEarContext(earContext);
try {
+ LinkedHashSet<String> manifestcp = new LinkedHashSet<String>();
// add the warfile's content to the configuration
JarFile warFile = module.getModuleFile();
Enumeration<JarEntry> entries = warFile.entries();
@@ -283,6 +284,8 @@
moduleContext.addFile(targetPath, module.getOriginalSpecDD());
} else if (entry.getName().startsWith("WEB-INF/lib") && entry.getName().endsWith(".jar")) {
moduleContext.addInclude(targetPath, warFile, entry);
+// manifestcp.add(module.getTargetPath() + "/" + entry.getName());
+ manifestcp.add(entry.getName());
} else {
moduleContext.addFile(targetPath, warFile, entry);
}
@@ -291,11 +294,14 @@
//always add WEB-INF/classes to the classpath regardless of whether
//any classes exist
moduleContext.getConfiguration().addToClassPath("WEB-INF/classes/");
-
+// manifestcp.add(module.getTargetPath() + "/WEB-INF/classes/");
+ manifestcp.add("WEB-INF/classes/");
// add the manifest classpath entries declared in the war to the class loader
// we have to explicitly add these since we are unpacking the web module
// and the url class loader will not pick up a manifest from an unpacked dir
moduleContext.addManifestClassPath(warFile, RELATIVE_MODULE_BASE_URI);
+ moduleContext.getCompleteManifestClassPath(warFile, URI.create(module.getTargetPath()), manifestcp);
+ moduleContext.getGeneralData().put("ManifestClassPath", manifestcp);
} catch (IOException e) {
throw new DeploymentException("Problem deploying war", e);
@@ -796,9 +802,11 @@
webModule.setClassFinder(createWebAppClassFinder(webApp, webModule));
}
//N.B. we use the ear context which has all the gbeans we could possibly be looking up from this ear.
+ //nope, persistence units can be in the war.
//This means that you cannot use the default environment of the web builder to add configs that will be searched.
Configuration earConfiguration = earContext.getConfiguration();
- getNamingBuilders().buildNaming(webApp, vendorPlan, earConfiguration, earConfiguration, webModule, buildingContext);
+ Configuration localConfiguration = moduleContext.getConfiguration();
+ getNamingBuilders().buildNaming(webApp, vendorPlan, localConfiguration, earConfiguration, webModule, buildingContext);
Map compContext = NamingBuilder.JNDI_KEY.get(buildingContext);
Holder holder = NamingBuilder.INJECTION_KEY.get(buildingContext);