Skip to content

Commit faa7c48

Browse files
authored
Merge branch 'master' into PAYARA-1941-Create-a-bean-validation-2-sample
2 parents 87668f7 + 42ffb72 commit faa7c48

File tree

11 files changed

+199
-6
lines changed

11 files changed

+199
-6
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ jdk:
55
env:
66
- TESTFOLDER=cdi
77
- TESTFOLDER=servlet
8+
- TESTFOLDER=jpa
89
- TESTFOLDER=jsf
910
- TESTFOLDER=jsonb
1011

LICENSE

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Except where otherwise indicated, everything in this repository is licensed under the MIT license:
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

jpa/pom.xml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion>
3+
4+
<parent>
5+
<groupId>org.javaee8</groupId>
6+
<artifactId>samples-parent</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
</parent>
9+
10+
<artifactId>jpa</artifactId>
11+
<packaging>pom</packaging>
12+
<name>Java EE 8 Samples: JPA</name>
13+
14+
<modules>
15+
<module>stream</module>
16+
</modules>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.javaee8</groupId>
21+
<artifactId>test-utils</artifactId>
22+
<version>${project.version}</version>
23+
</dependency>
24+
</dependencies>
25+
</project>

jpa/stream/pom.xml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion>
3+
4+
<parent>
5+
<groupId>org.javaee8</groupId>
6+
<artifactId>jpa</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
</parent>
9+
10+
<artifactId>stream</artifactId>
11+
<packaging>war</packaging>
12+
<name>Java EE 8 Samples: JPA - Stream</name>
13+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package org.javaee8.jpa.stream.domain;
2+
3+
import java.io.Serializable;
4+
import javax.persistence.Basic;
5+
import javax.persistence.Entity;
6+
import javax.persistence.GeneratedValue;
7+
import javax.persistence.GenerationType;
8+
import javax.persistence.Id;
9+
10+
/**
11+
*
12+
* @author Gaurav Gupta
13+
*
14+
*/
15+
@Entity
16+
public class Person implements Serializable {
17+
18+
@Id
19+
@GeneratedValue(strategy = GenerationType.AUTO)
20+
private Long id;
21+
22+
@Basic
23+
private String name;
24+
25+
@Basic
26+
private String address;
27+
28+
public Long getId() {
29+
return this.id;
30+
}
31+
32+
public void setId(Long id) {
33+
this.id = id;
34+
}
35+
36+
public String getName() {
37+
return this.name;
38+
}
39+
40+
public void setName(String name) {
41+
this.name = name;
42+
}
43+
44+
public String getAddress() {
45+
return this.address;
46+
}
47+
48+
public void setAddress(String address) {
49+
this.address = address;
50+
}
51+
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.javaee8.jpa.stream.repository;
2+
3+
import java.util.stream.Stream;
4+
import javax.persistence.EntityManager;
5+
import javax.persistence.PersistenceContext;
6+
import javax.persistence.criteria.CriteriaQuery;
7+
import org.javaee8.jpa.stream.domain.Person;
8+
9+
/**
10+
*
11+
* @author Gaurav Gupta
12+
*
13+
*/
14+
public class PersonRepository {
15+
16+
@PersistenceContext(unitName = "DEFAULT_PU")
17+
private EntityManager em;
18+
19+
public Stream<Person> findAll() {
20+
CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
21+
cq.select(cq.from(Person.class));
22+
return em.createQuery(cq).getResultStream();
23+
}
24+
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.javaee8.jpa.stream.controller;
2+
3+
import java.util.stream.Stream;
4+
import org.javaee8.jpa.stream.repository.PersonRepository;
5+
import org.javaee8.jpa.stream.domain.Person;
6+
import javax.inject.Inject;
7+
import org.jboss.arquillian.container.test.api.Deployment;
8+
import org.jboss.arquillian.junit.Arquillian;
9+
import org.jboss.shrinkwrap.api.ShrinkWrap;
10+
import org.junit.Test;
11+
import org.jboss.shrinkwrap.api.spec.WebArchive;
12+
import static org.junit.Assert.assertEquals;
13+
import org.junit.runner.RunWith;
14+
15+
/**
16+
*
17+
* @author Gaurav Gupta
18+
*
19+
*/
20+
@RunWith(Arquillian.class)
21+
public class PersonControllerTest {
22+
23+
@Deployment
24+
public static WebArchive createDeployment() {
25+
return ShrinkWrap.create(WebArchive.class)
26+
.addAsWebInfResource("beans.xml")
27+
.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
28+
.addAsResource("META-INF/sql/insert.sql")
29+
.addClass(Person.class)
30+
.addClass(PersonRepository.class);
31+
}
32+
33+
@Inject
34+
private PersonRepository personRepository;
35+
36+
@Test
37+
public void testStream() throws Exception {
38+
Stream<Person> personStream = personRepository.findAll();
39+
long personCount = personStream.count();
40+
assertEquals(2, personCount);
41+
}
42+
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
INSERT INTO person (id, name, address) VALUES (1002, 'Arjan', 'abc')
2+
INSERT INTO person (id, name, address) VALUES (1001, 'Gaurav', 'xyz')
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
5+
bean-discovery-mode="all">
6+
</beans>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
3+
<persistence-unit name="DEFAULT_PU" transaction-type="JTA">
4+
<jta-data-source>java:comp/DefaultDataSource</jta-data-source>
5+
<exclude-unlisted-classes>false</exclude-unlisted-classes>
6+
<properties>
7+
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
8+
<property name="javax.persistence.sql-load-script-source" value="META-INF/sql/insert.sql"/>
9+
</properties>
10+
</persistence-unit>
11+
</persistence>

pom.xml

+14-6
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,13 @@
6767
Each spec is represented by one module. "test-utils" is a helper module.
6868
-->
6969
<modules>
70-
<module>test-utils</module>
71-
<module>servlet</module>
72-
<module>jsf</module>
73-
<module>cdi</module>
74-
<module>jsonb</module>
75-
<module>validation</module>
70+
<module>test-utils</module>
71+
<module>servlet</module>
72+
<module>jsf</module>
73+
<module>cdi</module>
74+
<module>jpa</module>
75+
<module>jsonb</module>
76+
<module>validation</module>
7677
</modules>
7778

7879
<dependencyManagement>
@@ -124,6 +125,13 @@
124125
<scope>provided</scope>
125126
</dependency>
126127

128+
<dependency>
129+
<groupId>org.eclipse.persistence</groupId>
130+
<artifactId>javax.persistence</artifactId>
131+
<version>2.2.0-RC1</version>
132+
<scope>provided</scope>
133+
</dependency>
134+
127135
<dependency>
128136
<groupId>javax.ws.rs</groupId>
129137
<artifactId>javax.ws.rs-api</artifactId>

0 commit comments

Comments
 (0)