You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2011/12/28 22:39:26 UTC
svn commit: r1225350 - in /openejb/trunk/openejb:
container/openejb-core/src/main/java/org/apache/openejb/config/
container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/fragment/
container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/un...
Author: rmannibucau
Date: Wed Dec 28 21:39:25 2011
New Revision: 1225350
URL: http://svn.apache.org/viewvc?rev=1225350&view=rev
Log:
TOMEE-58 first draft of persistence-fragment.xml usage
Added:
openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/fragment/
openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/fragment/PersistenceFragment.java
openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/fragment/PersistenceUnitFragment.java
openejb/trunk/openejb/examples/persistence-fragment/
openejb/trunk/openejb/examples/persistence-fragment/pom.xml
openejb/trunk/openejb/examples/persistence-fragment/src/
openejb/trunk/openejb/examples/persistence-fragment/src/main/
openejb/trunk/openejb/examples/persistence-fragment/src/main/java/
openejb/trunk/openejb/examples/persistence-fragment/src/main/java/org/
openejb/trunk/openejb/examples/persistence-fragment/src/main/java/org/superbiz/
openejb/trunk/openejb/examples/persistence-fragment/src/main/java/org/superbiz/injection/
openejb/trunk/openejb/examples/persistence-fragment/src/main/java/org/superbiz/injection/jpa/
openejb/trunk/openejb/examples/persistence-fragment/src/main/java/org/superbiz/injection/jpa/Movie.java
openejb/trunk/openejb/examples/persistence-fragment/src/main/resources/
openejb/trunk/openejb/examples/persistence-fragment/src/main/resources/META-INF/
openejb/trunk/openejb/examples/persistence-fragment/src/main/resources/META-INF/persistence-fragment.xml
openejb/trunk/openejb/examples/persistence-fragment/src/test/
openejb/trunk/openejb/examples/persistence-fragment/src/test/java/
openejb/trunk/openejb/examples/persistence-fragment/src/test/java/org/
openejb/trunk/openejb/examples/persistence-fragment/src/test/java/org/superbiz/
openejb/trunk/openejb/examples/persistence-fragment/src/test/java/org/superbiz/injection/
openejb/trunk/openejb/examples/persistence-fragment/src/test/java/org/superbiz/injection/jpa/
openejb/trunk/openejb/examples/persistence-fragment/src/test/java/org/superbiz/injection/jpa/MoviesTest.java
openejb/trunk/openejb/examples/persistence-fragment/src/test/resources/
openejb/trunk/openejb/examples/persistence-fragment/src/test/resources/META-INF/
openejb/trunk/openejb/examples/persistence-fragment/src/test/resources/META-INF/persistence.xml
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/JaxbPersistenceFactory.java
openejb/trunk/openejb/examples/pom.xml
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java?rev=1225350&r1=1225349&r2=1225350&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java Wed Dec 28 21:39:25 2011
@@ -200,65 +200,8 @@ public class DeploymentLoader implements
otherDD = new HashMap<String, URL>();
}
- URL persistenceUrl = null;
- if (file.isDirectory()) {
- File persistenceXml = new File(file, "WEB-INF/classes/META-INF/persistence.xml");
- if (persistenceXml.exists() && persistenceXml.isFile()) {
- try {
- persistenceUrl = persistenceXml.toURI().toURL();
- } catch (MalformedURLException e) {
- // no-op
- }
- }
- } else { // .war
- JarFile jf = null;
- try {
- jf = new JarFile(file);
- } catch (IOException e) {
- return appModule;
- }
- ZipEntry entry = jf.getEntry("WEB-INF/classes/META-INF/persistence.xml");
- if (entry != null) {
- String base = baseUrl.toString();
- if (!base.startsWith("jar:")) {
- base = "jar:" + base;
- try {
- baseUrl = new URL(base + "!/WEB-INF/classes");
- } catch (MalformedURLException e) {
- // ignored
- }
- }
-
- try {
- persistenceUrl = new URL(base + "!/WEB-INF/classes/META-INF/persistence.xml");
- } catch (MalformedURLException e) {
- // no-op
- }
- }
- }
-
- if (persistenceUrl != null || otherDD.containsKey("persistence.xml")) {
- List<URL> persistenceUrls = (List<URL>) appModule.getAltDDs().get("persistence.xml");
- if (persistenceUrls == null) {
- persistenceUrls = new ArrayList<URL>();
- appModule.getAltDDs().put("persistence.xml", persistenceUrls);
- }
-
- if (persistenceUrl != null) {
- try {
- persistenceUrls.add(persistenceUrl);
- } catch (Exception e) {
- // no-op
- }
- }
- if (otherDD.containsKey("persistence.xml")) {
- final URL otherUrl = otherDD.get("persistence.xml");
- if (!persistenceUrls.contains(otherUrl)) {
- persistenceUrls.add(otherDD.get("persistence.xml"));
- }
- }
- }
-
+ addWebPersistenceDD("persistence.xml", file, baseUrl, otherDD, appModule);
+ addWebPersistenceDD("persistence-fragment.xml", file, baseUrl, otherDD, appModule);
addPersistenceUnits(appModule, baseUrl);
return appModule;
}
@@ -296,6 +239,67 @@ public class DeploymentLoader implements
}
}
+ private void addWebPersistenceDD(final String name, final File file, URL baseUrl, final Map<String, URL> otherDD, final AppModule appModule) {
+ URL persistenceUrl = null;
+ if (file.isDirectory()) {
+ File persistenceXml = new File(file, "WEB-INF/classes/META-INF/" + name);
+ if (persistenceXml.exists() && persistenceXml.isFile()) {
+ try {
+ persistenceUrl = persistenceXml.toURI().toURL();
+ } catch (MalformedURLException e) {
+ // no-op
+ }
+ }
+ } else { // .war
+ JarFile jf;
+ try {
+ jf = new JarFile(file);
+ ZipEntry entry = jf.getEntry("WEB-INF/classes/META-INF/" + name);
+ if (entry != null) {
+ String base = baseUrl.toString();
+ if (!base.startsWith("jar:")) {
+ base = "jar:" + base;
+ try {
+ baseUrl = new URL(base + "!/WEB-INF/classes");
+ } catch (MalformedURLException e) {
+ // ignored
+ }
+ }
+
+ try {
+ persistenceUrl = new URL(base + "!/WEB-INF/classes/META-INF/" + name);
+ } catch (MalformedURLException e) {
+ // no-op
+ }
+ }
+ } catch (IOException e) {
+ // ignored
+ }
+ }
+
+ if (persistenceUrl != null || otherDD.containsKey(name)) {
+ List<URL> persistenceUrls = (List<URL>) appModule.getAltDDs().get(name);
+ if (persistenceUrls == null) {
+ persistenceUrls = new ArrayList<URL>();
+ appModule.getAltDDs().put(name, persistenceUrls);
+ }
+
+ if (persistenceUrl != null) {
+ try {
+ persistenceUrls.add(persistenceUrl);
+ } catch (Exception e) {
+ // no-op
+ }
+ }
+ if (otherDD.containsKey(name)) {
+ final URL otherUrl = otherDD.get(name);
+ if (!persistenceUrls.contains(otherUrl)) {
+ persistenceUrls.add(otherDD.get(name));
+ }
+ }
+ }
+ }
+
protected ClassLoader getOpenEJBClassLoader(final URL url) {
return OpenEJB.class.getClassLoader();
}
@@ -1248,6 +1252,12 @@ public class DeploymentLoader implements
appModule.getAltDDs().put("persistence.xml", persistenceUrls);
}
+ List<URL> persistenceFragmentsUrls = (List<URL>) appModule.getAltDDs().get("persistence-fragment.xml");
+ if (persistenceFragmentsUrls == null) {
+ persistenceFragmentsUrls = new ArrayList<URL>();
+ appModule.getAltDDs().put("persistence-fragment.xml", persistenceFragmentsUrls);
+ }
+
for (URL url : urls) {
// OPENEJB-1059: looking for an altdd persistence.xml file in all urls
@@ -1271,6 +1281,31 @@ public class DeploymentLoader implements
persistenceUrls.add(descriptor);
}
}
+
+ // look for persistence-fragment.xml
+ for (URL url : urls) {
+ // OPENEJB-1059: looking for an altdd persistence.xml file in all urls
+ // delegates to xbean finder for going throughout the list
+ ResourceFinder finder = new ResourceFinder("", appModule.getClassLoader(), url);
+ Map<String, URL> descriptors = getDescriptors(finder, false);
+
+ // if a persistence.xml has been found, just pull it to the list
+ if (descriptors.containsKey("persistence-fragment.xml")) {
+ URL descriptor = descriptors.get("persistence-fragment.xml");
+
+ if (persistenceFragmentsUrls.contains(descriptor)) {
+ continue;
+ }
+
+ // log if it is an altdd
+ String urlString = descriptor.toExternalForm();
+ if (!urlString.contains("META-INF/persistence-fragment.xml")) {
+ logger.info("AltDD persistence-fragment.xml -> " + urlString);
+ }
+
+ persistenceFragmentsUrls.add(descriptor);
+ }
+ }
}
public static Map<String, URL> getDescriptors(URL moduleUrl) throws OpenEJBException {
@@ -1300,7 +1335,7 @@ public class DeploymentLoader implements
if (map.size() == 0) {
- String[] known = {"web.xml", "ejb-jar.xml", "openejb-jar.xml", "env-entries.properties", "beans.xml", "ra.xml", "application.xml", "application-client.xml", "persistence.xml", "validation.xml"};
+ String[] known = {"web.xml", "ejb-jar.xml", "openejb-jar.xml", "env-entries.properties", "beans.xml", "ra.xml", "application.xml", "application-client.xml", "persistence-fragment.xml", "persistence.xml", "validation.xml"};
for (String descriptor : known) {
final URL url = finder.getResource(ddDir + descriptor);
@@ -1518,7 +1553,7 @@ public class DeploymentLoader implements
Class<? extends DeploymentModule> cls = checkAnnotations(baseUrl, classLoader, scanPotentialEjbModules, scanPotentialClientModules);
if (cls != null) return cls;
- if (descriptors.containsKey("persistence.xml")) {
+ if (descriptors.containsKey("persistence.xml") || descriptors.containsKey("persistence-fragment.xml")) {
return PersistenceModule.class;
}
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java?rev=1225350&r1=1225349&r2=1225350&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java Wed Dec 28 21:39:25 2011
@@ -18,7 +18,6 @@ package org.apache.openejb.config;
import org.apache.openejb.OpenEJBException;
import org.apache.openejb.config.sys.JaxbOpenejb;
-import org.apache.openejb.config.sys.Openejb;
import org.apache.openejb.config.sys.Resources;
import org.apache.openejb.core.webservices.WsdlResolver;
import org.apache.openejb.jee.ApplicationClient;
@@ -35,8 +34,11 @@ import org.apache.openejb.jee.WebApp;
import org.apache.openejb.jee.Webservices;
import org.apache.openejb.jee.bval.ValidationConfigType;
import org.apache.openejb.jee.jpa.EntityMappings;
+import org.apache.openejb.jee.jpa.fragment.PersistenceFragment;
+import org.apache.openejb.jee.jpa.fragment.PersistenceUnitFragment;
import org.apache.openejb.jee.jpa.unit.JaxbPersistenceFactory;
import org.apache.openejb.jee.jpa.unit.Persistence;
+import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
import org.apache.openejb.jee.oejb2.GeronimoEjbJarType;
import org.apache.openejb.jee.oejb2.JaxbOpenejbJar2;
import org.apache.openejb.jee.oejb2.OpenejbJarType;
@@ -131,7 +133,7 @@ public class ReadDescriptors implements
}
try {
- Persistence persistence = JaxbPersistenceFactory.getPersistence(persistenceUrl);
+ Persistence persistence = JaxbPersistenceFactory.getPersistence(Persistence.class, persistenceUrl);
PersistenceModule persistenceModule = new PersistenceModule(rootUrl, persistence);
persistenceModule.getWatchedResources().add(moduleName);
if ("file".equals(persistenceUrl.getProtocol())) {
@@ -144,6 +146,54 @@ public class ReadDescriptors implements
}
}
+ final List<URL> persistenceFragmentUrls = (List<URL>) appModule.getAltDDs().get("persistence-fragment.xml");
+ if (persistenceFragmentUrls != null) {
+ for (URL persistenceFragmentUrl : persistenceFragmentUrls) {
+ try {
+ final PersistenceFragment persistenceFragment = JaxbPersistenceFactory.getPersistence(PersistenceFragment.class, persistenceFragmentUrl);
+ // merging
+ for (PersistenceUnitFragment fragmentUnit : persistenceFragment.getPersistenceUnitFragment()) {
+ for (PersistenceModule persistenceModule : appModule.getPersistenceModules()) {
+ final Persistence persistence = persistenceModule.getPersistence();
+ for (PersistenceUnit unit : persistence.getPersistenceUnit()) {
+ if (!fragmentUnit.getName().equals(unit.getName())) {
+ continue;
+ }
+
+ if (!persistenceFragment.getVersion().equals(persistence.getVersion())) {
+ logger.error("persistence unit version and fragment version are different, fragment will be ignored");
+ continue;
+ }
+
+ if ("file".equals(persistenceFragmentUrl.getProtocol())) {
+ persistenceModule.getWatchedResources().add(URLs.toFile(persistenceFragmentUrl).getAbsolutePath());
+ }
+
+ for (String clazz : fragmentUnit.getClazz()) {
+ if (!unit.getClazz().contains(clazz)) {
+ logger.info("Adding class " + clazz + " to persistence unit " + fragmentUnit.getName());
+ unit.getClazz().add(clazz);
+ }
+ }
+ for (String mappingFile : fragmentUnit.getMappingFile()) {
+ if (!unit.getMappingFile().contains(mappingFile)) {
+ logger.info("Adding mapping file " + mappingFile + " to persistence unit " + fragmentUnit.getName());
+ unit.getMappingFile().add(mappingFile);
+ }
+ }
+ if (fragmentUnit.isExcludeUnlistedClasses()) {
+ unit.setExcludeUnlistedClasses(true);
+ logger.info("Excluding unlisted classes for persistence unit " + fragmentUnit.getName());
+ } // else let the main persistence unit decide
+ }
+ }
+ }
+ } catch (Exception e1) {
+ DeploymentLoader.logger.error("Unable to load Persistence Unit Fragment from EAR: " + appModule.getJarLocation() + ", fragment: " + persistenceFragmentUrl.toString() + ". Exception: " + e1.getMessage(), e1);
+ }
+ }
+ }
+
return appModule;
}
Added: openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/fragment/PersistenceFragment.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/fragment/PersistenceFragment.java?rev=1225350&view=auto
==============================================================================
--- openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/fragment/PersistenceFragment.java (added)
+++ openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/fragment/PersistenceFragment.java Wed Dec 28 21:39:25 2011
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.0.1-b01-fcs
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
+// Any modifications to this file will be lost upon recompilation of the source schema.
+// Generated on: 2006.08.11 at 06:51:30 PM PDT
+//
+
+
+package org.apache.openejb.jee.jpa.fragment;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+import java.util.ArrayList;
+import java.util.List;
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = {
+ "persistenceUnitFragment"
+})
+@XmlRootElement(name = "persistence-fragment")
+public class PersistenceFragment {
+
+ @XmlElement(name = "persistence-unit-fragment", required = true)
+ protected List<PersistenceUnitFragment> persistenceUnitFragment;
+
+ @XmlAttribute(required = true)
+ @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
+ protected String version = "1.0";
+
+ public PersistenceFragment() {
+ }
+
+ public PersistenceFragment(PersistenceUnitFragment... persistenceUnit) {
+ for (PersistenceUnitFragment unit : persistenceUnit) {
+ getPersistenceUnitFragment().add(unit);
+ }
+ }
+
+ /**
+ * Gets the value of the persistenceUnit property.
+ *
+ * <p>
+ * This accessor method returns a reference to the live list,
+ * not a snapshot. Therefore any modification you make to the
+ * returned list will be present inside the JAXB object.
+ * This is why there is not a <CODE>set</CODE> method for the persistenceUnit property.
+ *
+ * <p>
+ * For example, to add a new item, do as follows:
+ * <pre>
+ * getPersistenceUnit().add(newItem);
+ * </pre>
+ *
+ *
+ * <p>
+ * Objects of the following type(s) are allowed in the list
+ * {@link org.apache.openejb.jee.jpa.unit.PersistenceUnit }
+ *
+ *
+ */
+ public List<PersistenceUnitFragment> getPersistenceUnitFragment() {
+ if (persistenceUnitFragment == null) {
+ persistenceUnitFragment = new ArrayList<PersistenceUnitFragment>();
+ }
+ return persistenceUnitFragment;
+ }
+
+ public PersistenceUnitFragment addPersistenceUnitFragment(PersistenceUnitFragment unit) {
+ getPersistenceUnitFragment().add(unit);
+ return unit;
+ }
+
+ public PersistenceUnitFragment addPersistenceUnitFragment(String unitName) {
+ return addPersistenceUnitFragment(new PersistenceUnitFragment(unitName));
+ }
+
+ /**
+ * Gets the value of the version property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getVersion() {
+ if (version == null) {
+ return "1.0";
+ } else {
+ return version;
+ }
+ }
+
+ /**
+ * Sets the value of the version property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setVersion(String value) {
+ this.version = value;
+ }
+
+
+}
Added: openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/fragment/PersistenceUnitFragment.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/fragment/PersistenceUnitFragment.java?rev=1225350&view=auto
==============================================================================
--- openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/fragment/PersistenceUnitFragment.java (added)
+++ openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/fragment/PersistenceUnitFragment.java Wed Dec 28 21:39:25 2011
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.jee.jpa.fragment;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+import java.util.ArrayList;
+import java.util.List;
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = {
+ "description",
+ "mappingFile",
+ "jarFile",
+ "clazz",
+ "excludeUnlistedClasses"
+})
+public class PersistenceUnitFragment {
+
+ protected String description;
+ @XmlElement(name = "mapping-file", required = true)
+ protected List<String> mappingFile;
+ @XmlElement(name = "jar-file", required = true)
+ protected List<String> jarFile;
+ @XmlElement(name = "class", required = true)
+ protected List<String> clazz;
+ @XmlElement(name = "exclude-unlisted-classes", defaultValue = "false")
+ protected boolean excludeUnlistedClasses;
+ @XmlAttribute(required = true)
+ protected String name;
+
+ public PersistenceUnitFragment() {
+ // no-op
+ }
+
+ public PersistenceUnitFragment(String unitName) {
+ this.name = unitName;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String value) {
+ this.description = value;
+ }
+
+ public List<String> getMappingFile() {
+ if (mappingFile == null) {
+ mappingFile = new ArrayList<String>();
+ }
+ return this.mappingFile;
+ }
+
+ public List<String> getClazz() {
+ if (clazz == null) {
+ clazz = new ArrayList<String>();
+ }
+ return this.clazz;
+ }
+
+ public boolean addClass(String s) {
+ return getClazz().add(s);
+ }
+
+ public boolean addClass(Class<?> clazz) {
+ return addClass(clazz.getName());
+ }
+
+ public boolean isExcludeUnlistedClasses() {
+ return excludeUnlistedClasses;
+ }
+
+ public void setExcludeUnlistedClasses(boolean value) {
+ this.excludeUnlistedClasses = value;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String value) {
+ this.name = value;
+ }
+
+ public List<String> getJarFile() {
+ if (jarFile == null) {
+ jarFile = new ArrayList<String>();
+ }
+ return this.jarFile;
+ }
+}
Modified: openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/JaxbPersistenceFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/JaxbPersistenceFactory.java?rev=1225350&r1=1225349&r2=1225350&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/JaxbPersistenceFactory.java (original)
+++ openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/JaxbPersistenceFactory.java Wed Dec 28 21:39:25 2011
@@ -39,14 +39,15 @@ import java.net.URL;
*/
public class JaxbPersistenceFactory {
public static final String PERSISTENCE_SCHEMA = "http://java.sun.com/xml/ns/persistence";
- public static Persistence getPersistence(URL url) throws Exception {
+
+ public static <T> T getPersistence(Class<T> clazz, URL url) throws Exception {
InputStream persistenceDescriptor = null;
try {
persistenceDescriptor = url.openStream();
- JAXBContext jc = JAXBContextFactory.newInstance(Persistence.class);
+ JAXBContext jc = JAXBContextFactory.newInstance(clazz);
Unmarshaller u = jc.createUnmarshaller();
UnmarshallerHandler uh = u.getUnmarshallerHandler();
@@ -66,7 +67,7 @@ public class JaxbPersistenceFactory {
xmlFilter.setContentHandler(uh);
SAXSource source = new SAXSource(xmlFilter, new InputSource(persistenceDescriptor));
- return (Persistence) u.unmarshal(source);
+ return (T) u.unmarshal(source);
} finally {
if (persistenceDescriptor != null) persistenceDescriptor.close();
Added: openejb/trunk/openejb/examples/persistence-fragment/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/persistence-fragment/pom.xml?rev=1225350&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/persistence-fragment/pom.xml (added)
+++ openejb/trunk/openejb/examples/persistence-fragment/pom.xml Wed Dec 28 21:39:25 2011
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- $Rev: 1178411 $ $Date: 2011-10-03 15:35:26 +0200 (lun. 03 oct. 2011) $ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.superbiz</groupId>
+ <artifactId>persistence-fragment</artifactId>
+ <packaging>jar</packaging>
+ <version>1.1-SNAPSHOT</version>
+ <name>OpenEJB :: Examples :: Persistence Fragment</name>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <repositories>
+ <repository>
+ <id>apache-m2-snapshot</id>
+ <name>Apache Snapshot Repository</name>
+ <url>http://repository.apache.org/snapshots</url>
+ </repository>
+ </repositories>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>javaee-api</artifactId>
+ <version>6.0-3-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <!--
+ The <scope>test</scope> guarantees that non of your runtime
+ code is dependent on any OpenEJB classes.
+ -->
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>openejb-core</artifactId>
+ <version>4.0.0-beta-2-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <!--
+ This section allows you to configure where to publish libraries for sharing.
+ It is not required and may be deleted. For more information see:
+ http://maven.apache.org/plugins/maven-deploy-plugin/
+ -->
+ <distributionManagement>
+ <repository>
+ <id>localhost</id>
+ <url>file://${basedir}/target/repo/</url>
+ </repository>
+ <snapshotRepository>
+ <id>localhost</id>
+ <url>file://${basedir}/target/snapshot-repo/</url>
+ </snapshotRepository>
+ </distributionManagement>
+</project>
\ No newline at end of file
Added: openejb/trunk/openejb/examples/persistence-fragment/src/main/java/org/superbiz/injection/jpa/Movie.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/persistence-fragment/src/main/java/org/superbiz/injection/jpa/Movie.java?rev=1225350&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/persistence-fragment/src/main/java/org/superbiz/injection/jpa/Movie.java (added)
+++ openejb/trunk/openejb/examples/persistence-fragment/src/main/java/org/superbiz/injection/jpa/Movie.java Wed Dec 28 21:39:25 2011
@@ -0,0 +1,67 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.superbiz.injection.jpa;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+@Entity
+public class Movie {
+ @Id @GeneratedValue private long id;
+ private String director;
+ private String title;
+ private int year;
+
+ public Movie() {
+ // no-op
+ }
+
+ public Movie(String director, String title, int year) {
+ this.director = director;
+ this.title = title;
+ this.year = year;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public String getDirector() {
+ return director;
+ }
+
+ public void setDirector(String director) {
+ this.director = director;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public int getYear() {
+ return year;
+ }
+
+ public void setYear(int year) {
+ this.year = year;
+ }
+}
Added: openejb/trunk/openejb/examples/persistence-fragment/src/main/resources/META-INF/persistence-fragment.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/persistence-fragment/src/main/resources/META-INF/persistence-fragment.xml?rev=1225350&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/persistence-fragment/src/main/resources/META-INF/persistence-fragment.xml (added)
+++ openejb/trunk/openejb/examples/persistence-fragment/src/main/resources/META-INF/persistence-fragment.xml Wed Dec 28 21:39:25 2011
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<persistence-fragment version="2.0">
+ <persistence-unit-fragment name="movie-unit">
+ <class>org.superbiz.injection.jpa.Movie</class>
+ <exclude-unlisted-classes>true</exclude-unlisted-classes>
+ </persistence-unit-fragment>
+</persistence-fragment>
Added: openejb/trunk/openejb/examples/persistence-fragment/src/test/java/org/superbiz/injection/jpa/MoviesTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/persistence-fragment/src/test/java/org/superbiz/injection/jpa/MoviesTest.java?rev=1225350&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/persistence-fragment/src/test/java/org/superbiz/injection/jpa/MoviesTest.java (added)
+++ openejb/trunk/openejb/examples/persistence-fragment/src/test/java/org/superbiz/injection/jpa/MoviesTest.java Wed Dec 28 21:39:25 2011
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.superbiz.injection.jpa;
+
+import org.apache.openejb.assembler.classic.ReloadableEntityManagerFactory;
+import org.junit.Test;
+
+import javax.ejb.embeddable.EJBContainer;
+import javax.naming.Context;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceUnit;
+import java.util.Properties;
+
+import static org.junit.Assert.assertTrue;
+
+public class MoviesTest {
+ @PersistenceUnit
+ private EntityManagerFactory emf;
+
+ @Test
+ public void test() throws Exception {
+ final Properties p = new Properties();
+ p.put("movieDatabase", "new://Resource?type=DataSource");
+ p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
+ p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
+
+ final EJBContainer container = EJBContainer.createEJBContainer(p);
+ final Context context = container.getContext();
+ context.bind("inject", this);
+
+ assertTrue(((ReloadableEntityManagerFactory) emf).getManagedClasses().contains(Movie.class.getName()));
+
+ container.close();
+ }
+}
Added: openejb/trunk/openejb/examples/persistence-fragment/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/persistence-fragment/src/test/resources/META-INF/persistence.xml?rev=1225350&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/persistence-fragment/src/test/resources/META-INF/persistence.xml (added)
+++ openejb/trunk/openejb/examples/persistence-fragment/src/test/resources/META-INF/persistence.xml Wed Dec 28 21:39:25 2011
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<persistence version="2.0"
+ xmlns="http://java.sun.com/xml/ns/persistence"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
+ http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
+ <persistence-unit name="movie-unit">
+ <jta-data-source>movieDatabase</jta-data-source>
+ <non-jta-data-source>movieDatabaseUnmanaged</non-jta-data-source>
+ <properties>
+ <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
+ </properties>
+ </persistence-unit>
+</persistence>
Modified: openejb/trunk/openejb/examples/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/pom.xml?rev=1225350&r1=1225349&r2=1225350&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/pom.xml (original)
+++ openejb/trunk/openejb/examples/pom.xml Wed Dec 28 21:39:25 2011
@@ -65,6 +65,7 @@
<module>mbean-auto-registration</module>
<module>movies-complete-meta</module>
<module>movies-complete</module>
+ <module>persistence-fragment</module>
<module>quartz-app</module>
<module>reload-persistence-unit-properties</module>
<module>rest-on-ejb</module>