[jboss-cvs] JBossAS SVN: r104524 - in projects/metadata/ejb/trunk/src: test/java/org/jboss/test/metadata/jpa/v2 and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu May 6 11:40:11 EDT 2010
Author: smarlow at redhat.com
Date: 2010-05-06 11:40:10 -0400 (Thu, 06 May 2010)
New Revision: 104524
Added:
projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/OwnerReferencePatchingList.java
Modified:
projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/PersistenceMetaData.java
projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/PersistenceUnitMetaData.java
projects/metadata/ejb/trunk/src/test/java/org/jboss/test/metadata/jpa/v2/PersistenceMDUnitTestCase.java
Log:
JBMETA-281 support for detecting version from persistence.xml files and passing it to the JPA 2 provider
Added: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/OwnerReferencePatchingList.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/OwnerReferencePatchingList.java (rev 0)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/OwnerReferencePatchingList.java 2010-05-06 15:40:10 UTC (rev 104524)
@@ -0,0 +1,193 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.metadata.jpa.spec;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
+/**
+ * List of elements, where the Object holding the list (or logically owning it), is
+ * passed to each List element (as they are added to the list).
+ *
+ * The owner of the list is specified via the OwnerReferencePatchingList.setOwner(Object).
+ *
+ * The owner of the list is passed to each element via reflection. OwnerReferencePatchingList.add(T t) will
+ * invoke the t.setOwner(Object) method (passing the owner). A IllegalArgumentException is thrown if that doesn't work.
+ *
+ * @author <a href="mailto:smarlow at redhat.com">Scott Marlow</a>
+ */
+public class OwnerReferencePatchingList<T> implements List<T>
+{
+ private List<T> list = new ArrayList();
+ private Object owner;
+
+ protected void setOwner(Object owner) {
+ if (owner == null)
+ throw new IllegalArgumentException("Null owner");
+ this.owner = owner;
+ }
+
+ public boolean add(T t)
+ {
+ Method setOwner = null;
+ try {
+ setOwner = t.getClass().getMethod("setOwner",Object.class);
+ } catch (NoSuchMethodException e) {
+ throw new IllegalArgumentException("cannot add type " + t.getClass().getName() + ", must have setOwner(Object) method", e);
+ }
+ try {
+ setOwner.invoke(t, owner );
+ } catch (IllegalAccessException e) {
+ throw new IllegalArgumentException("cannot add type " + t.getClass().getName() + ", couldn't call setOwner(Object) method", e);
+ } catch (InvocationTargetException e) {
+ throw new IllegalArgumentException("cannot add type " + t.getClass().getName() + ", could not call setOwner(Object) method", e);
+ }
+ return list.add(t);
+ }
+
+ public boolean addAll(Collection<? extends T> c)
+ {
+ //return list.addAll(c);
+ throw new UnsupportedOperationException("addAll(Collection) is not implemented");
+ }
+
+ public boolean addAll(int index, Collection<? extends T> c)
+ {
+ // return list.addAll(index, c);
+ throw new UnsupportedOperationException("addAll(int, Collection) is not implemented");
+ }
+
+ public int size()
+ {
+ return list.size();
+ }
+
+ public boolean isEmpty()
+ {
+ return list.isEmpty();
+ }
+
+ public boolean contains(Object o)
+ {
+ return list.contains(o);
+ }
+
+ public Iterator<T> iterator()
+ {
+ return list.iterator();
+ }
+
+ public Object[] toArray()
+ {
+ return list.toArray();
+ }
+
+ public <T> T[] toArray(T[] a)
+ {
+ return list.toArray(a);
+ }
+
+ public boolean remove(Object o)
+ {
+ return list.remove(o);
+ }
+
+ public boolean containsAll(Collection<?> c)
+ {
+ return list.containsAll(c);
+ }
+
+ public boolean removeAll(Collection<?> c)
+ {
+ return list.removeAll(c);
+ }
+
+ public boolean retainAll(Collection<?> c)
+ {
+ return list.retainAll(c);
+ }
+
+ public void clear()
+ {
+ list.clear();
+ }
+
+ public boolean equals(Object o)
+ {
+ return list.equals(o);
+ }
+
+ public int hashCode()
+ {
+ return list.hashCode();
+ }
+
+ public T get(int index)
+ {
+ return list.get(index);
+ }
+
+ public T set(int index, T element)
+ {
+ return list.set(index, element);
+ }
+
+ public void add(int index, T element)
+ {
+ list.add(index, element);
+ }
+
+ public T remove(int index)
+ {
+ return list.remove(index);
+ }
+
+ public int indexOf(Object o)
+ {
+ return list.indexOf(o);
+ }
+
+ public int lastIndexOf(Object o)
+ {
+ return list.lastIndexOf(o);
+ }
+
+ public ListIterator<T> listIterator()
+ {
+ return list.listIterator();
+ }
+
+ public ListIterator<T> listIterator(int index)
+ {
+ return list.listIterator(index);
+ }
+
+ public List<T> subList(int fromIndex, int toIndex)
+ {
+ return list.subList(fromIndex, toIndex);
+ }
+}
Modified: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/PersistenceMetaData.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/PersistenceMetaData.java 2010-05-06 15:38:56 UTC (rev 104523)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/PersistenceMetaData.java 2010-05-06 15:40:10 UTC (rev 104524)
@@ -22,8 +22,6 @@
package org.jboss.metadata.jpa.spec;
import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
@@ -50,7 +48,7 @@
public class PersistenceMetaData extends JBossObject implements Serializable
{
private String version;
- private List<PersistenceUnitMetaData> persistenceUnits;
+ private OwnerReferencePatchingList<PersistenceUnitMetaData> persistenceUnits;
public String getVersion()
{
@@ -63,15 +61,18 @@
this.version = version;
}
- public List<PersistenceUnitMetaData> getPersistenceUnits()
+ public OwnerReferencePatchingList<PersistenceUnitMetaData> getPersistenceUnits()
{
return persistenceUnits;
}
@XmlElement(name = "persistence-unit")
- public void setPersistenceUnits(List<PersistenceUnitMetaData> persistenceUnits)
+ public void setPersistenceUnits(OwnerReferencePatchingList<PersistenceUnitMetaData> persistenceUnits)
{
+ if( persistenceUnits == null)
+ throw new IllegalArgumentException("Null persistenceUnits");
this.persistenceUnits = persistenceUnits;
+ this.persistenceUnits.setOwner(this);
}
protected void toString(JBossStringBuilder builder)
@@ -84,12 +85,11 @@
public PersistenceMetaData clone()
{
PersistenceMetaData clone = (PersistenceMetaData)super.clone();
+ clone.setPersistenceUnits(new OwnerReferencePatchingList<PersistenceUnitMetaData>());
if (persistenceUnits != null)
{
- List<PersistenceUnitMetaData> units = new ArrayList<PersistenceUnitMetaData>();
for (PersistenceUnitMetaData unit : persistenceUnits)
- units.add(unit.clone());
- clone.setPersistenceUnits(units);
+ clone.getPersistenceUnits().add(unit.clone());
}
return clone;
}
Modified: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/PersistenceUnitMetaData.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/PersistenceUnitMetaData.java 2010-05-06 15:38:56 UTC (rev 104523)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/PersistenceUnitMetaData.java 2010-05-06 15:40:10 UTC (rev 104524)
@@ -61,6 +61,8 @@
private SharedCacheMode sharedCacheMode;
private ValidationMode validationMode;
+ private PersistenceMetaData persistenceMetaData;
+
@XmlElement
public SharedCacheMode getSharedCacheMode()
{
@@ -207,6 +209,20 @@
this.transactionType = transactionType;
}
+ public PersistenceMetaData getPersistenceMetaData()
+ {
+ return persistenceMetaData;
+ }
+
+ /**
+ * Do not call directly (should only be called by OwnerReferencePatchingList).
+ * @param owner is expected to be a PersistenceMetaData
+ */
+ public void setOwner(Object owner)
+ {
+ this.persistenceMetaData = (PersistenceMetaData) owner;
+ }
+
protected void toString(JBossStringBuilder builder)
{
builder.append("provider=").append(provider);
Modified: projects/metadata/ejb/trunk/src/test/java/org/jboss/test/metadata/jpa/v2/PersistenceMDUnitTestCase.java
===================================================================
--- projects/metadata/ejb/trunk/src/test/java/org/jboss/test/metadata/jpa/v2/PersistenceMDUnitTestCase.java 2010-05-06 15:38:56 UTC (rev 104523)
+++ projects/metadata/ejb/trunk/src/test/java/org/jboss/test/metadata/jpa/v2/PersistenceMDUnitTestCase.java 2010-05-06 15:40:10 UTC (rev 104524)
@@ -65,6 +65,13 @@
testPersistenceUnitMetaData(unit, "manager", "java:/DefaultDS", Collections.singleton("persistence.jar"), "hibernate", "create-drop");
unit = units.get(1);
testPersistenceUnitMetaData(unit, "dev", "java:/MySqlDS", new HashSet<String>(Arrays.asList("dev.jar", "foobar.jar")), "hibernate", "validate");
+ assertNotNull(unit.getPersistenceMetaData());
+ assertEquals("2.0", unit.getPersistenceMetaData().getVersion());
+
+ PersistenceMetaData pmdClone = unit.getPersistenceMetaData().clone();
+ assertNotNull(pmdClone);
+ unit = pmdClone.getPersistenceUnits().get(0);
+ assertEquals("2.0", unit.getPersistenceMetaData().getVersion());
}
public void testMultipleProperties() throws Exception
More information about the jboss-cvs-commits
mailing list