[jboss-cvs] JBossAS SVN: r58825 - in branches/Branch_4_0/ejb3: . src/resources/test/clusteredentity/embeddedid/META-INF src/test/org/jboss/ejb3/test/clusteredentity/embeddedid
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Dec 4 01:50:15 EST 2006
Author: bstansberry at jboss.com
Date: 2006-12-04 01:50:13 -0500 (Mon, 04 Dec 2006)
New Revision: 58825
Added:
branches/Branch_4_0/ejb3/src/resources/test/clusteredentity/embeddedid/META-INF/application.xml
branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/embeddedid/EmbeddedIdTest.java
branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/embeddedid/EmbeddedIdTestBean.java
branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/embeddedid/Musician.java
branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/embeddedid/MusicianPK.java
Modified:
branches/Branch_4_0/ejb3/build-test.xml
Log:
Add a test with @EmbeddedId
Modified: branches/Branch_4_0/ejb3/build-test.xml
===================================================================
--- branches/Branch_4_0/ejb3/build-test.xml 2006-12-04 06:50:10 UTC (rev 58824)
+++ branches/Branch_4_0/ejb3/build-test.xml 2006-12-04 06:50:13 UTC (rev 58825)
@@ -2596,7 +2596,29 @@
<include name="clusteredentity-ds.xml"/>
</fileset>
</jar>
-
+
+ <jar jarfile="${build.lib}/clusteredentity-embeddedid-test.jar">
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/ejb3/test/clusteredentity/embeddedid/*.class"/>
+ </fileset>
+ <fileset dir="${resources}/test/clusteredentity/classloader">
+ <include name="META-INF/persistence.xml"/>
+ <!--include name="META-INF/jboss.xml"/-->
+ </fileset>
+ </jar>
+
+ <jar jarfile="${build.lib}/clusteredentity-embeddedid-test.ear">
+ <fileset dir="${build.lib}">
+ <include name="clusteredentity-embeddedid-test.jar"/>
+ </fileset>
+ <fileset dir="${resources}/test/clusteredentity/classloader">
+ <include name="META-INF/jboss-app.xml"/>
+ <include name="clusteredentity-ds.xml"/>
+ </fileset>
+ <fileset dir="${resources}/test/clusteredentity/embeddedid">
+ <include name="META-INF/application.xml"/>
+ </fileset>
+ </jar>
</target>
Added: branches/Branch_4_0/ejb3/src/resources/test/clusteredentity/embeddedid/META-INF/application.xml
===================================================================
--- branches/Branch_4_0/ejb3/src/resources/test/clusteredentity/embeddedid/META-INF/application.xml 2006-12-04 06:50:10 UTC (rev 58824)
+++ branches/Branch_4_0/ejb3/src/resources/test/clusteredentity/embeddedid/META-INF/application.xml 2006-12-04 06:50:13 UTC (rev 58825)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<application>
+ <display-name>Second clustered entity with scoped classloader test ear</display-name>
+ <module>
+ <ejb>clusteredentity-embeddedid-test.jar</ejb>
+ </module>
+</application>
\ No newline at end of file
Added: branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/embeddedid/EmbeddedIdTest.java
===================================================================
--- branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/embeddedid/EmbeddedIdTest.java 2006-12-04 06:50:10 UTC (rev 58824)
+++ branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/embeddedid/EmbeddedIdTest.java 2006-12-04 06:50:13 UTC (rev 58825)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.ejb3.test.clusteredentity.embeddedid;
+
+import java.util.List;
+
+
+/**
+ * SFSB interface for {@link EmbeddedIdTestBean}.
+ *
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+public interface EmbeddedIdTest
+{
+ static final MusicianPK DEFAULT_PK = new MusicianPK("Brian", "Stansberry", "None of your business");
+
+ void createMusician(MusicianPK pk, String instrument);
+
+ List<MusicianPK> getMusiciansForInstrument(String instrument, boolean useNamedRegion);
+
+ void cleanup();
+
+ void remove();
+}
Added: branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/embeddedid/EmbeddedIdTestBean.java
===================================================================
--- branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/embeddedid/EmbeddedIdTestBean.java 2006-12-04 06:50:10 UTC (rev 58824)
+++ branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/embeddedid/EmbeddedIdTestBean.java 2006-12-04 06:50:13 UTC (rev 58825)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.ejb3.test.clusteredentity.embeddedid;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.ejb.Remote;
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+
+import org.jboss.logging.Logger;
+
+/**
+ * SFSB used for testing replicated query caching with an @EmbeddedId.
+ *
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+ at Stateful
+ at Remote(EmbeddedIdTest.class)
+public class EmbeddedIdTestBean implements EmbeddedIdTest
+{
+ private static final Logger log = Logger.getLogger(EmbeddedIdTestBean.class);
+
+ @PersistenceContext
+ private EntityManager manager;
+
+ public void createMusician(MusicianPK pk, String instrument)
+ {
+ Musician musician = new Musician();
+ musician.setId(pk);
+ musician.setInstrument(instrument);
+ manager.persist(musician);
+ }
+
+ public List<MusicianPK> getMusiciansForInstrument(String instrument, boolean useNamedRegion)
+ {
+ String queryName = useNamedRegion ? "musician.byinstrument.namedregion"
+ : "musician.byinstrument.default";
+ Query query = manager.createNamedQuery(queryName);
+ query.setParameter(1, instrument);
+ List<MusicianPK> result = new ArrayList<MusicianPK>();
+ List users = query.getResultList();
+ if (users != null)
+ {
+ for (Iterator it = users.iterator(); it.hasNext();)
+ {
+ result.add(((Musician) it.next()).getId());
+ }
+ }
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.test.clusteredentity.classloader.UserTest#cleanup()
+ */
+ public void cleanup()
+ {
+ Query query = manager.createQuery("select musician from Musician as musician");
+ List accts = query.getResultList();
+ if (accts != null)
+ {
+ for (Iterator it = accts.iterator(); it.hasNext();)
+ {
+ try
+ {
+ Musician musician = (Musician) it.next();
+ log.info("Removing " + musician);
+ manager.remove(musician);
+ }
+ catch (Exception ignored) {}
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.test.clusteredentity.classloader.UserTest#remove()
+ */
+ @Remove
+ public void remove()
+ {
+ cleanup();
+ }
+
+}
Added: branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/embeddedid/Musician.java
===================================================================
--- branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/embeddedid/Musician.java 2006-12-04 06:50:10 UTC (rev 58824)
+++ branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/embeddedid/Musician.java 2006-12-04 06:50:13 UTC (rev 58825)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.ejb3.test.clusteredentity.embeddedid;
+
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.QueryHint;
+
+import org.hibernate.annotations.Cache;
+import org.hibernate.annotations.CacheConcurrencyStrategy;
+
+/**
+ * Entity used for testing replicated query caching with an @EmbeddedId.
+ *
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+ at Entity
+ at Cache (usage=CacheConcurrencyStrategy.TRANSACTIONAL)
+ at NamedQueries({
+ @NamedQuery(name="musician.byinstrument.default",query="select musician from Musician as musician where musician.instrument = ?1",
+ hints={@QueryHint(name="org.hibernate.cacheable",value="true")}),
+ @NamedQuery(name="musician.byinstrument.namedregion",query="select musician from Musician as musician where musician.instrument = ?1",
+ hints={@QueryHint(name="org.hibernate.cacheable",value="true"),
+ @QueryHint(name="org.hibernate.cacheable",value="true")
+ })
+})
+public class Musician
+{
+ private MusicianPK id;
+ private String instrument;
+
+ @EmbeddedId
+ public MusicianPK getId()
+ {
+ return id;
+ }
+ public void setId(MusicianPK id)
+ {
+ this.id = id;
+ }
+
+ public String getInstrument()
+ {
+ return instrument;
+ }
+ public void setInstrument(String instrument)
+ {
+ this.instrument = instrument;
+ }
+
+}
Added: branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/embeddedid/MusicianPK.java
===================================================================
--- branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/embeddedid/MusicianPK.java 2006-12-04 06:50:10 UTC (rev 58824)
+++ branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/embeddedid/MusicianPK.java 2006-12-04 06:50:13 UTC (rev 58825)
@@ -0,0 +1,127 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.ejb3.test.clusteredentity.embeddedid;
+
+import java.io.Serializable;
+
+import javax.persistence.Embeddable;
+
+/**
+ * Primary key for the {@link Musician} entity.
+ *
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+ at Embeddable
+public class MusicianPK implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ private String firstName;
+ private String lastName;
+ private String ssn;
+
+ /**
+ * Default constructor
+ */
+ public MusicianPK() {}
+
+ public MusicianPK(String firstName, String lastName, String ssn)
+ {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ this.ssn = ssn;
+ }
+
+ public String getFirstName()
+ {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName)
+ {
+ this.firstName = firstName;
+ }
+
+ public String getLastName()
+ {
+ return lastName;
+ }
+
+ public void setLastName(String lastName)
+ {
+ this.lastName = lastName;
+ }
+
+ public String getSsn()
+ {
+ return ssn;
+ }
+
+ public void setSsn(String ssn)
+ {
+ this.ssn = ssn;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ boolean equal = (this == obj);
+
+ if (!equal && obj instanceof MusicianPK)
+ {
+ MusicianPK other = (MusicianPK) obj;
+
+ equal = firstName.equals(other.firstName)
+ && lastName.equals(other.lastName)
+ && ssn.equals(other.ssn);
+ }
+ return equal;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = 19;
+ result = result * 29 + firstName.hashCode();
+ result = result * 29 + lastName.hashCode();
+ result = result * 29 + ssn.hashCode();
+ return result;
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer(getClass().getName());
+ sb.append("[firstName=");
+ sb.append(firstName);
+ sb.append(",lastName=");
+ sb.append(lastName);
+ sb.append(",ssn=");
+ sb.append(ssn);
+ sb.append("]");
+ return sb.toString();
+ }
+
+
+
+}
More information about the jboss-cvs-commits
mailing list