diff --git a/samples/pom.xml b/samples/pom.xml index ee0e991a2..333df3f51 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -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 --> @@ -141,8 +140,8 @@ under the License. guess conversation-sample jsf2sample + reservation @@ -152,7 +151,7 @@ under the License. cargoDebug - -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 -Xnoagent + -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -Xnoagent diff --git a/samples/reservation/pom.xml b/samples/reservation/pom.xml index 100c4fb1e..e8c73b3d4 100644 --- a/samples/reservation/pom.xml +++ b/samples/reservation/pom.xml @@ -34,7 +34,8 @@ under the License. true - 2.4.2 + 4.0.1 + 3.0.0 - - jakarta.enterprise - jakarta.enterprise.cdi-api - + + jakarta.enterprise + jakarta.enterprise.cdi-api + jakarta.inject jakarta.inject-api @@ -107,27 +108,28 @@ under the License. ${project.version} runtime - + + org.apache.openwebbeans - openwebbeans-resource + openwebbeans-jsf ${project.version} runtime - org.apache.openwebbeans - openwebbeans-jsf + openwebbeans-el22 ${project.version} - runtime + - org.apache.geronimo.specs - geronimo-jpa_2.0_spec + jakarta.persistence + jakarta.persistence-api + ${jakarta.persistence-api.version} org.apache.openjpa diff --git a/samples/reservation/src/main/java/org/apache/webbeans/reservation/bindings/EntityManagerQualifier.java b/samples/reservation/src/main/java/org/apache/webbeans/reservation/bindings/EntityManagerQualifier.java deleted file mode 100644 index 35217efa0..000000000 --- a/samples/reservation/src/main/java/org/apache/webbeans/reservation/bindings/EntityManagerQualifier.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.webbeans.reservation.bindings; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.ElementType.PARAMETER; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import jakarta.inject.Qualifier; - - -@Qualifier -@Retention(RetentionPolicy.RUNTIME) -@Target( {FIELD, METHOD, TYPE,PARAMETER}) -public @interface EntityManagerQualifier -{ - -} diff --git a/samples/reservation/src/main/java/org/apache/webbeans/reservation/controller/LoginController.java b/samples/reservation/src/main/java/org/apache/webbeans/reservation/controller/LoginController.java index d8a5df387..f20c722c7 100644 --- a/samples/reservation/src/main/java/org/apache/webbeans/reservation/controller/LoginController.java +++ b/samples/reservation/src/main/java/org/apache/webbeans/reservation/controller/LoginController.java @@ -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; @@ -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 diff --git a/samples/reservation/src/main/java/org/apache/webbeans/reservation/controller/RegisterController.java b/samples/reservation/src/main/java/org/apache/webbeans/reservation/controller/RegisterController.java index 01bf38811..2d35bd631 100644 --- a/samples/reservation/src/main/java/org/apache/webbeans/reservation/controller/RegisterController.java +++ b/samples/reservation/src/main/java/org/apache/webbeans/reservation/controller/RegisterController.java @@ -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; @@ -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. diff --git a/samples/reservation/src/main/java/org/apache/webbeans/reservation/controller/admin/AdminController.java b/samples/reservation/src/main/java/org/apache/webbeans/reservation/controller/admin/AdminController.java index 0b4fe13e2..f2382c225 100644 --- a/samples/reservation/src/main/java/org/apache/webbeans/reservation/controller/admin/AdminController.java +++ b/samples/reservation/src/main/java/org/apache/webbeans/reservation/controller/admin/AdminController.java @@ -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; @@ -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) diff --git a/samples/reservation/src/main/java/org/apache/webbeans/reservation/controller/user/UserController.java b/samples/reservation/src/main/java/org/apache/webbeans/reservation/controller/user/UserController.java index 752ccd699..4bac79261 100644 --- a/samples/reservation/src/main/java/org/apache/webbeans/reservation/controller/user/UserController.java +++ b/samples/reservation/src/main/java/org/apache/webbeans/reservation/controller/user/UserController.java @@ -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; @@ -42,7 +41,7 @@ @RequestScoped public class UserController { - private @Inject @EntityManagerQualifier EntityManager entityManager; + private @Inject EntityManager entityManager; private @Inject @ApplicationLog Log logger; diff --git a/samples/reservation/src/main/java/org/apache/webbeans/reservation/entity/Hotel.java b/samples/reservation/src/main/java/org/apache/webbeans/reservation/entity/Hotel.java index 0398bb1ea..c58074c62 100644 --- a/samples/reservation/src/main/java/org/apache/webbeans/reservation/entity/Hotel.java +++ b/samples/reservation/src/main/java/org/apache/webbeans/reservation/entity/Hotel.java @@ -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 diff --git a/samples/reservation/src/main/java/org/apache/webbeans/reservation/entity/Reservation.java b/samples/reservation/src/main/java/org/apache/webbeans/reservation/entity/Reservation.java index 79baa4675..a7d536ace 100644 --- a/samples/reservation/src/main/java/org/apache/webbeans/reservation/entity/Reservation.java +++ b/samples/reservation/src/main/java/org/apache/webbeans/reservation/entity/Reservation.java @@ -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 diff --git a/samples/reservation/src/main/java/org/apache/webbeans/reservation/entity/User.java b/samples/reservation/src/main/java/org/apache/webbeans/reservation/entity/User.java index f6897326c..6269d6a35 100644 --- a/samples/reservation/src/main/java/org/apache/webbeans/reservation/entity/User.java +++ b/samples/reservation/src/main/java/org/apache/webbeans/reservation/entity/User.java @@ -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 diff --git a/samples/reservation/src/main/java/org/apache/webbeans/reservation/intercept/TransactionalInterceptor.java b/samples/reservation/src/main/java/org/apache/webbeans/reservation/intercept/TransactionalInterceptor.java index b156f54b2..0c3ef79fd 100644 --- a/samples/reservation/src/main/java/org/apache/webbeans/reservation/intercept/TransactionalInterceptor.java +++ b/samples/reservation/src/main/java/org/apache/webbeans/reservation/intercept/TransactionalInterceptor.java @@ -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; diff --git a/samples/reservation/src/main/java/org/apache/webbeans/reservation/util/EntityManagerUtil.java b/samples/reservation/src/main/java/org/apache/webbeans/reservation/util/EntityManagerUtil.java index 0977163ed..872390779 100644 --- a/samples/reservation/src/main/java/org/apache/webbeans/reservation/util/EntityManagerUtil.java +++ b/samples/reservation/src/main/java/org/apache/webbeans/reservation/util/EntityManagerUtil.java @@ -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(); }