Skip to content

Commit a151ae1

Browse files
committed
Project remake for WildFly 9 on postgreSQL
Also versions have been updated.
1 parent 58744e5 commit a151ae1

File tree

11 files changed

+160
-127
lines changed

11 files changed

+160
-127
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.classpath
2+
.gitignore
3+
.project
4+
.settings
5+
6+
/target/
7+

README.md

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,47 @@
1-
cdi-resteasy-hibernate-angularjs-tomcat-sample
2-
==============================================
1+
cdi-resteasy-hibernate-angularjs-wildfly-postgresql-sample
2+
==========================================================
33

44
Sample application with full CRUD for Airport codes to showcase following technologies:
5-
- Java 7
6-
- CDI
5+
- Java 8
6+
- CDI
77
- RestEasy (JAX-RS)
88
- JPA / Hibernate
99
- AngularJS
1010
- Bootstrap
1111
- Maven (build)
1212

13-
Setup
14-
-----
13+
Setup WildFly 9.0 standalone.xml
14+
--------------------------------
15+
```xml
16+
<subsystem xmlns="urn:jboss:domain:datasources:3.0">
17+
<datasources>
18+
<datasource jta="true" jndi-name="java:/jdbc/test" pool-name="test" enabled="true" use-java-context="true">
19+
<connection-url>jdbc:postgresql://localhost:5432/test</connection-url>
20+
<driver-class>org.postgresql.Driver</driver-class>
21+
<driver>postgresql</driver>
22+
<pool>
23+
<min-pool-size>2</min-pool-size>
24+
<max-pool-size>20</max-pool-size>
25+
</pool>
26+
<security>
27+
<user-name>test</user-name>
28+
</security>
29+
</datasource>
30+
<drivers>
31+
<driver name="postgresql" module="org.postgresql">
32+
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
33+
</driver>
34+
</drivers>
35+
</datasources>
36+
</subsystem>
37+
```
38+
39+
Setup sample.war
40+
----------------
1541
- Use your favorite IDE to deploy and run the application.
16-
- Use maven command to deploy to Tomcat. NOTE: maven settings.xml need to be configured with your local server.
42+
- Use maven command to deploy to AS. NOTE: maven settings.xml need to be configured accordingly.
1743
```bash
18-
$ mvn tomcat7:deploy
44+
$ mvn clean deploy
1945
```
2046

2147
Access

pom.xml

Lines changed: 75 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,85 +4,116 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66

7-
<groupId>cdi-resteasy-hibernate-angularjs-tomcat-sample</groupId>
8-
<artifactId>cdi-resteasy-hibernate-angularjs-tomcat-sample</artifactId>
7+
<groupId>cdi-resteasy-hibernate-angularjs-sample</groupId>
8+
<artifactId>cdi-resteasy-hibernate-angularjs-sample</artifactId>
99
<version>1.0-SNAPSHOT</version>
1010
<packaging>war</packaging>
11-
<name>cdi-resteasy-hibernate-angularjs-tomcat-sample</name>
12-
<url>https://github.com/kumarvv</url>
11+
<name>cdi-resteasy-hibernate-angularjs-sample</name>
12+
<url>https://github.com/hibi</url>
1313

14-
<repositories>
15-
<repository>
16-
<id>JBoss repository</id>
17-
<url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
18-
</repository>
19-
</repositories>
14+
<properties>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
<dir.jboss>/opt/wildfly-9.0.0.Final</dir.jboss>
17+
<test.skip>true</test.skip>
18+
19+
<!-- JBoss dependency versions -->
20+
<version.jboss.bom>9.0.0.Beta2</version.jboss.bom>
21+
<version.jboss.spec.javaee.7.0>1.0.0.Final</version.jboss.spec.javaee.7.0>
22+
23+
<!-- plugin versions -->
24+
<version.compiler.plugin>3.1</version.compiler.plugin>
25+
<version.war.plugin>2.6</version.war.plugin>
26+
<version.surefire.plugin>2.16</version.surefire.plugin>
27+
28+
<!-- maven-compiler-plugin -->
29+
<maven.compiler.target>1.8</maven.compiler.target>
30+
<maven.compiler.source>1.8</maven.compiler.source>
31+
</properties>
32+
33+
<dependencyManagement>
34+
<dependencies>
35+
<dependency>
36+
<groupId>org.wildfly.bom</groupId>
37+
<artifactId>jboss-javaee-7.0-with-all</artifactId>
38+
<version>${version.jboss.bom}</version>
39+
<type>pom</type>
40+
<scope>import</scope>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>org.wildfly</groupId>
45+
<artifactId>wildfly-ejb-client-bom</artifactId>
46+
<version>${version.jboss.bom}</version>
47+
<type>pom</type>
48+
<scope>import</scope>
49+
</dependency>
50+
</dependencies>
51+
</dependencyManagement>
2052

2153
<dependencies>
22-
<!-- servlet -->
54+
<!-- Servlet -->
2355
<dependency>
24-
<groupId>org.jboss.spec.javax.servlet</groupId>
25-
<artifactId>jboss-servlet-api_3.0_spec</artifactId>
26-
<version>1.0.2.Final</version>
27-
<scope>provided</scope>
56+
<groupId>javax.servlet</groupId>
57+
<artifactId>javax.servlet-api</artifactId>
58+
<version>3.1.0</version>
2859
</dependency>
2960

3061
<!-- CDI / Weld -->
3162
<dependency>
32-
<groupId>org.jboss.weld</groupId>
33-
<artifactId>weld-core</artifactId>
34-
<version>2.2.4.Final</version>
35-
</dependency>
36-
<dependency>
37-
<groupId>org.jboss.weld</groupId>
38-
<artifactId>weld-core-impl</artifactId>
39-
<version>2.2.4.Final</version>
63+
<groupId>javax.enterprise</groupId>
64+
<artifactId>cdi-api</artifactId>
65+
<scope>provided</scope>
4066
</dependency>
67+
4168
<dependency>
42-
<groupId>org.jboss.weld.servlet</groupId>
43-
<artifactId>weld-servlet</artifactId>
44-
<version>2.2.4.Final</version>
69+
<groupId>org.jboss.spec.javax.ejb</groupId>
70+
<artifactId>jboss-ejb-api_3.2_spec</artifactId>
71+
<scope>provided</scope>
4572
</dependency>
4673

4774
<!-- JAX-RS / RestEasy -->
4875
<dependency>
4976
<groupId>org.jboss.resteasy</groupId>
5077
<artifactId>resteasy-jaxrs</artifactId>
51-
<version>3.0.8.Final</version>
78+
<scope>provided</scope>
5279
</dependency>
80+
5381
<dependency>
5482
<groupId>org.jboss.resteasy</groupId>
55-
<artifactId>resteasy-jackson2-provider</artifactId>
56-
<version>3.0.8.Final</version>
83+
<artifactId>resteasy-multipart-provider</artifactId>
84+
<scope>provided</scope>
5785
</dependency>
86+
87+
<!-- JPA / Hibernate -->
5888
<dependency>
59-
<groupId>org.jboss.resteasy</groupId>
60-
<artifactId>resteasy-cdi</artifactId>
61-
<version>3.0.8.Final</version>
89+
<groupId>org.hibernate.javax.persistence</groupId>
90+
<artifactId>hibernate-jpa-2.1-api</artifactId>
91+
<scope>provided</scope>
6292
</dependency>
6393

64-
<!-- JPA / Hibernate -->
6594
<dependency>
6695
<groupId>org.hibernate</groupId>
6796
<artifactId>hibernate-core</artifactId>
68-
<version>4.3.5.Final</version>
97+
<scope>provided</scope>
6998
</dependency>
99+
70100
<dependency>
71-
<groupId>org.hibernate</groupId>
72-
<artifactId>hibernate-entitymanager</artifactId>
73-
<version>4.3.6.Final</version>
101+
<groupId>org.jboss</groupId>
102+
<artifactId>jboss-ejb-client</artifactId>
103+
<scope>provided</scope>
74104
</dependency>
105+
75106
<dependency>
76-
<groupId>mysql</groupId>
77-
<artifactId>mysql-connector-java</artifactId>
78-
<version>5.1.32</version>
107+
<groupId>postgresql</groupId>
108+
<artifactId>postgresql</artifactId>
109+
<version>9.1-901.jdbc4</version>
79110
</dependency>
80111

81112
<!-- log4j -->
82113
<dependency>
83114
<groupId>log4j</groupId>
84115
<artifactId>log4j</artifactId>
85-
<version>1.2.17</version>
116+
<scope>provided</scope>
86117
</dependency>
87118
</dependencies>
88119

@@ -94,28 +125,18 @@
94125
<artifactId>maven-compiler-plugin</artifactId>
95126
<version>3.1</version>
96127
<configuration>
97-
<source>1.7</source>
98-
<target>1.7</target>
128+
<source>${maven.compiler.source}</source>
129+
<target>${maven.compiler.target}</target>
99130
</configuration>
100131
</plugin>
101132
<plugin>
102133
<groupId>org.apache.maven.plugins</groupId>
103134
<artifactId>maven-war-plugin</artifactId>
104-
<version>2.4</version>
135+
<version>${version.war.plugin}</version>
105136
<configuration>
106137
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
107138
</configuration>
108139
</plugin>
109-
<plugin>
110-
<groupId>org.apache.tomcat.maven</groupId>
111-
<artifactId>tomcat7-maven-plugin</artifactId>
112-
<version>2.2</version>
113-
<configuration>
114-
<url>http://localhost:8080/manager/text</url>
115-
<server>local-tomcat-7</server>
116-
<path>/sample</path>
117-
</configuration>
118-
</plugin>
119140
</plugins>
120141
</build>
121142

src/airport.csv

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/main/java/com/kumarvv/sample/cdi/CdiResources.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,12 @@
44

55
import javax.enterprise.inject.Produces;
66
import javax.enterprise.inject.spi.InjectionPoint;
7-
import javax.persistence.EntityManager;
8-
import javax.persistence.EntityManagerFactory;
9-
import javax.persistence.Persistence;
10-
import javax.persistence.PersistenceContext;
117

128
/**
139
* CDI resources
1410
*/
1511
public class CdiResources {
1612

17-
@PersistenceContext
18-
EntityManager em;
19-
20-
@Produces
21-
public EntityManager createEm() {
22-
if (em == null) {
23-
EntityManagerFactory emf = Persistence.createEntityManagerFactory("TestPU");
24-
em = emf.createEntityManager();
25-
}
26-
return em;
27-
}
28-
2913
@Produces
3014
public Logger getLogger(InjectionPoint injectionPoint) {
3115
return Logger.getLogger(injectionPoint.getMember().getDeclaringClass());

src/main/java/com/kumarvv/sample/model/Airport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class Airport {
1414
private String country;
1515

1616
@Id
17-
@GeneratedValue(strategy = GenerationType.IDENTITY)
17+
@GeneratedValue(strategy=GenerationType.AUTO, generator="generator.main_id_seq")
1818
public Long getId() {
1919
return id;
2020
}
@@ -23,7 +23,7 @@ public void setId(Long id) {
2323
this.id = id;
2424
}
2525

26-
@Column(unique = true, nullable = false, length = 5)
26+
@Column(nullable = false, length = 5)
2727
public String getCode() {
2828
return code;
2929
}

src/main/java/com/kumarvv/sample/model/AirportDAO.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,24 @@
22

33
import org.apache.log4j.Logger;
44

5+
import java.util.List;
6+
7+
import javax.ejb.Stateless;
8+
import javax.ejb.TransactionManagement;
9+
import javax.ejb.TransactionManagementType;
510
import javax.inject.Inject;
611
import javax.persistence.EntityManager;
712
import javax.persistence.NoResultException;
8-
import java.util.List;
13+
import javax.persistence.PersistenceContext;
914

1015
/**
1116
* Sample AirportDAO
1217
*/
18+
@Stateless
19+
@TransactionManagement(TransactionManagementType.CONTAINER)
1320
public class AirportDAO {
1421

15-
@Inject
22+
@PersistenceContext
1623
EntityManager em;
1724

1825
@Inject
@@ -50,24 +57,18 @@ public Airport getOne(String code) {
5057

5158
public Airport insert(Airport airport) {
5259
try {
53-
em.getTransaction().begin();
5460
em.persist(airport);
55-
em.getTransaction().commit();
5661
} catch (Exception e) {
5762
log.error(e);
58-
em.getTransaction().rollback();
5963
}
6064
return airport;
6165
}
6266

6367
public Airport update(Airport airport) {
6468
try {
65-
em.getTransaction().begin();
6669
em.merge(airport);
67-
em.getTransaction().commit();
6870
} catch (Exception e) {
6971
log.error(e);
70-
em.getTransaction().rollback();
7172
}
7273
return airport;
7374
}
@@ -76,13 +77,10 @@ public void remove(Long id) {
7677
Airport airport = em.find(Airport.class, id);
7778
try {
7879
if (airport != null) {
79-
em.getTransaction().begin();
8080
em.remove(airport);
81-
em.getTransaction().commit();
8281
}
8382
} catch (Exception e) {
8483
log.error(e);
85-
em.getTransaction().rollback();
8684
}
8785
}
8886

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
5+
http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
6+
version="2.0">
7+
<sequence-generator name="generator.main_id_seq" allocation-size="1" sequence-name="airport_id_seq"/>
8+
</entity-mappings>

0 commit comments

Comments
 (0)