Skip to content

Commit

Permalink
OWB-1446 fix reservation example
Browse files Browse the repository at this point in the history
  • Loading branch information
struberg committed Dec 11, 2024
1 parent e6422c5 commit 393784f
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 103 deletions.
7 changes: 3 additions & 4 deletions samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ under the License.
Start the samples with
$> mvn cargo:run
To debug an application please activate the 'cargoDebug' profile and attach to port 8000
To debug an application please activate the 'cargoDebug' profile and attach to port 8000:
$> mvn cargo:run -PcargoDebug
-->

Expand Down Expand Up @@ -141,8 +140,8 @@ under the License.
<module>guess</module>
<module>conversation-sample</module>
<module>jsf2sample</module>
<module>reservation</module>
<!--
<module>reservation</module>
<module>tomcat7-sample</module>
-->
</modules>
Expand All @@ -152,7 +151,7 @@ under the License.
<id>cargoDebug</id>
<properties>
<cargo.debug.args>
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 -Xnoagent
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -Xnoagent
</cargo.debug.args>
</properties>
</profile>
Expand Down
26 changes: 14 additions & 12 deletions samples/reservation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ under the License.

<properties>
<deploy.skip>true</deploy.skip>
<openjpa.version>2.4.2</openjpa.version>
<openjpa.version>4.0.1</openjpa.version>
<jakarta.persistence-api.version>3.0.0</jakarta.persistence-api.version>
</properties>

<!--
Expand Down Expand Up @@ -64,10 +65,10 @@ under the License.
</dependency>

<!-- CDI and atinject APIs -->
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
Expand Down Expand Up @@ -107,27 +108,28 @@ under the License.
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<!-- pseudo PersistenceContext injection -->

<!-- JSF Plugin -->
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-resource</artifactId>
<artifactId>openwebbeans-jsf</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>

<!-- JSF Plugin -->
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-jsf</artifactId>
<artifactId>openwebbeans-el22</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>


<!-- OpenJPA -->

<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jpa_2.0_spec</artifactId>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>${jakarta.persistence-api.version}</version>
</dependency>
<dependency>
<groupId>org.apache.openjpa</groupId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import jakarta.persistence.EntityManager;
import jakarta.persistence.Query;

import org.apache.commons.validator.GenericValidator;
import org.apache.webbeans.reservation.bindings.DatabaseLogin;
import org.apache.webbeans.reservation.bindings.EntityManagerQualifier;
import org.apache.webbeans.reservation.bindings.intercep.Transactional;
import org.apache.webbeans.reservation.controller.api.ILoginController;
import org.apache.webbeans.reservation.entity.User;
Expand All @@ -43,7 +42,7 @@ public class LoginController implements ILoginController
private Logger logger = Logger.getLogger(LoginController.class.getName());

/**Injection of the request scope entity manager*/
private @Inject @EntityManagerQualifier EntityManager entityManager;
private @Inject EntityManager entityManager;

/**
* Returns true if user exist else false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import javax.persistence.EntityManager;
import jakarta.persistence.EntityManager;

import org.apache.commons.logging.Log;
import org.apache.commons.validator.GenericValidator;
import org.apache.webbeans.reservation.bindings.ApplicationLog;
import org.apache.webbeans.reservation.bindings.EntityManagerQualifier;
import org.apache.webbeans.reservation.bindings.intercep.Transactional;
import org.apache.webbeans.reservation.controller.api.IRegisterController;
import org.apache.webbeans.reservation.entity.User;
Expand All @@ -39,7 +38,7 @@ public class RegisterController implements IRegisterController
{
private @Inject @ApplicationLog Log logger;

private @Inject @EntityManagerQualifier EntityManager entityManager;
private @Inject EntityManager entityManager;

/**
* Register the user.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import jakarta.persistence.EntityManager;
import jakarta.persistence.Query;

import org.apache.commons.logging.Log;
import org.apache.commons.validator.GenericValidator;
import org.apache.webbeans.reservation.bindings.ApplicationLog;
import org.apache.webbeans.reservation.bindings.EntityManagerQualifier;
import org.apache.webbeans.reservation.bindings.intercep.Transactional;
import org.apache.webbeans.reservation.entity.Hotel;
import org.apache.webbeans.reservation.entity.Reservation;
Expand All @@ -46,7 +45,7 @@ public class AdminController
{
private @Inject @ApplicationLog Log logger;

private @Inject @EntityManagerQualifier EntityManager entityManager;
private @Inject EntityManager entityManager;

@Transactional
public void createNewHotel(String name, int star, String city, String country)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@
import jakarta.enterprise.context.RequestScoped;
import jakarta.faces.model.SelectItem;
import jakarta.inject.Inject;
import javax.persistence.EntityManager;
import jakarta.persistence.EntityManager;

import org.apache.commons.logging.Log;
import org.apache.webbeans.reservation.bindings.ApplicationLog;
import org.apache.webbeans.reservation.bindings.EntityManagerQualifier;
import org.apache.webbeans.reservation.bindings.intercep.Transactional;
import org.apache.webbeans.reservation.entity.Hotel;
import org.apache.webbeans.reservation.entity.Reservation;
Expand All @@ -42,7 +41,7 @@
@RequestScoped
public class UserController
{
private @Inject @EntityManagerQualifier EntityManager entityManager;
private @Inject EntityManager entityManager;

private @Inject @ApplicationLog Log logger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
*/
package org.apache.webbeans.reservation.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Version;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Version;

@Entity
public class Hotel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import jakarta.persistence.Version;

@Entity
public class Reservation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import jakarta.persistence.Version;

@Entity
public class User
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.Interceptor;
import jakarta.interceptor.InvocationContext;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityTransaction;

import org.apache.commons.logging.Log;
import org.apache.webbeans.reservation.bindings.ApplicationLog;
import org.apache.webbeans.reservation.bindings.EntityManagerQualifier;
import org.apache.webbeans.reservation.bindings.intercep.Transactional;

@Interceptor
@Transactional
public class TransactionalInterceptor
{
private @Inject @EntityManagerQualifier EntityManager entityManager;
private @Inject EntityManager entityManager;

private @Inject @ApplicationLog Log logger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,33 @@
*/
package org.apache.webbeans.reservation.util;

import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.RequestScoped;
import jakarta.enterprise.inject.Disposes;
import jakarta.enterprise.inject.Produces;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;

@RequestScoped
public class EntityManagerUtil
{
private @PersistenceContext(unitName="reservation") EntityManager entityManager;

public EntityManagerUtil()
private EntityManagerFactory emf;

@PostConstruct
void init()
{

emf = Persistence.createEntityManagerFactory("reservation");
}

@Produces @RequestScoped @org.apache.webbeans.reservation.bindings.EntityManagerQualifier
@Produces
@RequestScoped
public EntityManager createEntityManager()
{
return entityManager;
return emf.createEntityManager();
}

public void dispose(@Disposes @org.apache.webbeans.reservation.bindings.EntityManagerQualifier EntityManager entityManager)
public void dispose(@Disposes EntityManager entityManager)
{
entityManager.close();
}
Expand Down

0 comments on commit 393784f

Please sign in to comment.