getAllEntities() {
+ return entityManager.createQuery("SELECT _testEntity FROM TestEntity _testEntity", TestEntity.class)
+ .getResultList();
+ }
+
+
+
+}
diff --git a/jpa/datasourcedefinition-annotation-pu/src/main/resources/META-INF/persistence.xml b/jpa/datasourcedefinition-annotation-pu/src/main/resources/META-INF/persistence.xml
new file mode 100644
index 000000000..f93200d69
--- /dev/null
+++ b/jpa/datasourcedefinition-annotation-pu/src/main/resources/META-INF/persistence.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+ java:app/MyApp/MyDS
+
+
+
+
+
+
+
diff --git a/jpa/datasourcedefinition-annotation-pu/src/test/java/org/javaee7/jpa/datasourcedefinition_annotation_pu/DataSourceDefinitionAnnotationPuTest.java b/jpa/datasourcedefinition-annotation-pu/src/test/java/org/javaee7/jpa/datasourcedefinition_annotation_pu/DataSourceDefinitionAnnotationPuTest.java
new file mode 100644
index 000000000..572471714
--- /dev/null
+++ b/jpa/datasourcedefinition-annotation-pu/src/test/java/org/javaee7/jpa/datasourcedefinition_annotation_pu/DataSourceDefinitionAnnotationPuTest.java
@@ -0,0 +1,58 @@
+package org.javaee7.jpa.datasourcedefinition_annotation_pu;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.javaee7.jpa.datasourcedefinition_annotation_pu.config.DataSourceDefinitionConfig;
+import org.javaee7.jpa.datasourcedefinition_annotation_pu.entity.TestEntity;
+import org.javaee7.jpa.datasourcedefinition_annotation_pu.service.TestService;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.resolver.api.maven.Maven;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * This tests that a data source defined via an annotation in {@link DataSourceDefinitionConfig} can be used by JPA.
+ *
+ * The actual JPA code being run is not specifically relevant; any kind of JPA operation that
+ * uses the data source is okay here.
+ *
+ * @author Arjan Tijms
+ */
+@RunWith(Arquillian.class)
+public class DataSourceDefinitionAnnotationPuTest {
+
+ @Inject
+ private TestService testService;
+
+ @Deployment
+ public static Archive> deploy() {
+ return ShrinkWrap.create(WebArchive.class)
+ .addPackages(true, DataSourceDefinitionAnnotationPuTest.class.getPackage())
+ .addAsResource("META-INF/persistence.xml")
+ .addAsLibraries(Maven.resolver()
+ .loadPomFromFile("pom.xml")
+ .resolve("com.h2database:h2")
+ .withoutTransitivity()
+ .asSingleFile())
+ ;
+ }
+
+ @Test
+ public void insertAndQueryEntity() throws Exception {
+
+ testService.saveNewEntity();
+
+ List testEntities = testService.getAllEntities();
+
+ assertTrue(testEntities.size() == 1);
+ assertTrue(testEntities.get(0).getValue().equals("mytest"));
+ }
+}
diff --git a/jpa/datasourcedefinition-webxml-pu/pom.xml b/jpa/datasourcedefinition-webxml-pu/pom.xml
new file mode 100644
index 000000000..66e77a31d
--- /dev/null
+++ b/jpa/datasourcedefinition-webxml-pu/pom.xml
@@ -0,0 +1,23 @@
+
+
+ 4.0.0
+
+
+ org.javaee7.jpa
+ jpa-samples
+ 1.0-SNAPSHOT
+
+
+ datasourcedefinition-webxml-pu
+ war
+
+
+
+ com.h2database
+ h2
+ 1.3.173
+
+
+
+
diff --git a/jpa/datasourcedefinition-webxml-pu/src/main/java/org/javaee7/jpa/datasourcedefinition_webxml_pu/entity/TestEntity.java b/jpa/datasourcedefinition-webxml-pu/src/main/java/org/javaee7/jpa/datasourcedefinition_webxml_pu/entity/TestEntity.java
new file mode 100644
index 000000000..c1c10a627
--- /dev/null
+++ b/jpa/datasourcedefinition-webxml-pu/src/main/java/org/javaee7/jpa/datasourcedefinition_webxml_pu/entity/TestEntity.java
@@ -0,0 +1,39 @@
+package org.javaee7.jpa.datasourcedefinition_webxml_pu.entity;
+
+import static javax.persistence.GenerationType.IDENTITY;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+/**
+ * A very simple JPA entity that will be used for testing
+ *
+ * @author Arjan Tijms
+ *
+ */
+@Entity
+public class TestEntity {
+
+ @Id
+ @GeneratedValue(strategy = IDENTITY)
+ private Long id;
+ private String value;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+}
diff --git a/jpa/datasourcedefinition-webxml-pu/src/main/java/org/javaee7/jpa/datasourcedefinition_webxml_pu/service/TestService.java b/jpa/datasourcedefinition-webxml-pu/src/main/java/org/javaee7/jpa/datasourcedefinition_webxml_pu/service/TestService.java
new file mode 100644
index 000000000..676cc67b3
--- /dev/null
+++ b/jpa/datasourcedefinition-webxml-pu/src/main/java/org/javaee7/jpa/datasourcedefinition_webxml_pu/service/TestService.java
@@ -0,0 +1,40 @@
+package org.javaee7.jpa.datasourcedefinition_webxml_pu.service;
+
+import java.util.List;
+
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.javaee7.jpa.datasourcedefinition_webxml_pu.entity.TestEntity;
+
+/**
+ * This service does some JPA operations. The purpose of this entire test
+ * is just to see whether the data source can be used so the actual operations
+ * don't matter much.
+ *
+ * @author Arjan Tijms
+ *
+ */
+@Stateless
+public class TestService {
+
+ @PersistenceContext
+ private EntityManager entityManager;
+
+ public void saveNewEntity() {
+
+ TestEntity testEntity = new TestEntity();
+ testEntity.setValue("mytest");
+
+ entityManager.persist(testEntity);
+ }
+
+ public List getAllEntities() {
+ return entityManager.createQuery("SELECT _testEntity FROM TestEntity _testEntity", TestEntity.class)
+ .getResultList();
+ }
+
+
+
+}
diff --git a/jpa/datasourcedefinition-webxml-pu/src/main/resources/META-INF/persistence.xml b/jpa/datasourcedefinition-webxml-pu/src/main/resources/META-INF/persistence.xml
new file mode 100644
index 000000000..5f4e9ffba
--- /dev/null
+++ b/jpa/datasourcedefinition-webxml-pu/src/main/resources/META-INF/persistence.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+ java:app/MyApp/MyDS
+
+
+
+
+
+
+
diff --git a/jpa/datasourcedefinition-webxml-pu/src/main/webapp/WEB-INF/web.xml b/jpa/datasourcedefinition-webxml-pu/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 000000000..5078e198e
--- /dev/null
+++ b/jpa/datasourcedefinition-webxml-pu/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+ java:app/MyApp/MyDS
+ org.h2.jdbcx.JdbcDataSource
+ jdbc:h2:mem:test
+
+
+
+
diff --git a/jpa/datasourcedefinition-webxml-pu/src/test/java/org/javaee7/jpa/datasourcedefinition_webxml_pu/DataSourceDefinitionWebxmlPuTest.java b/jpa/datasourcedefinition-webxml-pu/src/test/java/org/javaee7/jpa/datasourcedefinition_webxml_pu/DataSourceDefinitionWebxmlPuTest.java
new file mode 100644
index 000000000..a3b0e608f
--- /dev/null
+++ b/jpa/datasourcedefinition-webxml-pu/src/test/java/org/javaee7/jpa/datasourcedefinition_webxml_pu/DataSourceDefinitionWebxmlPuTest.java
@@ -0,0 +1,65 @@
+package org.javaee7.jpa.datasourcedefinition_webxml_pu;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.javaee7.jpa.datasourcedefinition_webxml_pu.entity.TestEntity;
+import org.javaee7.jpa.datasourcedefinition_webxml_pu.service.TestService;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.resolver.api.maven.Maven;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * This tests that a data source defined in web.xml can be used by JPA.
+ *
+ * The actual JPA code being run is not specifically relevant; any kind of JPA operation that
+ * uses the data source is okay here.
+ *
+ * @author Arjan Tijms
+ */
+@RunWith(Arquillian.class)
+public class DataSourceDefinitionWebxmlPuTest {
+
+ private static final String WEBAPP_SRC = "src/main/webapp";
+
+ @Inject
+ private TestService testService;
+
+ @Deployment
+ public static Archive> deploy() {
+ return ShrinkWrap.create(WebArchive.class)
+ .addPackages(true, DataSourceDefinitionWebxmlPuTest.class.getPackage())
+ .addAsResource("META-INF/persistence.xml")
+ .addAsWebInfResource(resource("web.xml"))
+ .addAsLibraries(Maven.resolver()
+ .loadPomFromFile("pom.xml")
+ .resolve("com.h2database:h2")
+ .withoutTransitivity()
+ .asSingleFile())
+ ;
+ }
+
+ @Test
+ public void insertAndQueryEntity() throws Exception {
+
+ testService.saveNewEntity();
+
+ List testEntities = testService.getAllEntities();
+
+ assertTrue(testEntities.size() == 1);
+ assertTrue(testEntities.get(0).getValue().equals("mytest"));
+ }
+
+ private static File resource(String name) {
+ return new File(WEBAPP_SRC + "/WEB-INF", name);
+ }
+}
diff --git a/jpa/pom.xml b/jpa/pom.xml
index b5d0d5f9d..2b3b9a765 100644
--- a/jpa/pom.xml
+++ b/jpa/pom.xml
@@ -16,6 +16,9 @@
criteria
+ datasourcedefinition
+ datasourcedefinition-webxml-pu
+ datasourcedefinition-annotation-pu
dynamic-named-query
entitygraph
listeners
@@ -35,7 +38,6 @@
unsynchronized-pc
extended-pc
jpa-converter
- datasourcedefinition