]> git.mxchange.org Git - pizzaservice.git/blob
dea48c2333abce036dfe1c3b6371dbbf10df5b30
[pizzaservice.git] /
1 /*
2  * Copyright (C) 2015 Roland Haeder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.pizzaapplication.beans.pizzaservice;
18
19 import java.io.IOException;
20 import java.lang.reflect.InvocationTargetException;
21 import java.sql.SQLException;
22 import java.util.Deque;
23 import javax.annotation.PostConstruct;
24 import javax.ejb.Stateless;
25 import javax.servlet.ServletException;
26 import org.mxchange.jshop.beans.BaseFrameworkBean;
27 import org.mxchange.jshop.beans.remote.shop.ShopSessionBeanRemote;
28 import org.mxchange.jshop.model.category.Category;
29 import org.mxchange.jshop.model.product.Product;
30 import org.mxchange.pizzaapplication.application.PizzaApplication;
31 import org.mxchange.pizzaapplication.application.PizzaServiceApplication;
32
33 /**
34  * The session bean
35  *
36  * @author Roland Haeder
37  */
38 @Stateless (name="shop", mappedName = "ejb/stateless-shop")
39 public class PizzaServiceSessionBean extends BaseFrameworkBean implements ShopSessionBeanRemote {
40
41         /**
42          * Serial number
43          */
44         private static final long serialVersionUID = 578314942948L;
45
46         /**
47          * Application instance
48          */
49         private final PizzaApplication app;
50
51         /**
52          * Initializer block
53          */
54         {
55                 // Get new application instance
56                 this.getLogger().debug("INITIALIZER!"); //NOI18N
57                 this.app = new PizzaServiceApplication();
58         }
59
60         /**
61          * Default constructor
62          */
63         public PizzaServiceSessionBean () {
64                 this.getLogger().trace("CALLED!"); //NOI18N
65         }
66
67         @PostConstruct
68         public void init () throws RuntimeException {
69                 // Trace message
70                 this.getLogger().trace("CALLED!"); //NOI18N
71
72                 try {
73                         // Call init method
74                         this.app.init();
75                 } catch (final SQLException | IOException ex) {
76                         // Continue to throw
77                         throw new RuntimeException(ex);
78                 }
79         }
80
81         @Override
82         public Deque<Product> getAvailableProducts () throws ServletException {
83                 try {
84                         return this.app.getAvailableProducts();
85                 } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
86                         // Continue to throw
87                         throw new ServletException(ex);
88                 }
89         }
90
91         @Override
92         public Deque<Product> getAllProducts () throws ServletException {
93                 try {
94                         return this.app.getAllProducts();
95                 } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
96                         // Continue to throw
97                         throw new ServletException(ex);
98                 }
99         }
100
101         @Override
102         public Deque<Category> getAllCategories () throws ServletException {
103                 try {
104                         return this.app.getAllCategories();
105                 } catch (final IOException | SQLException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
106                         // Continue to throw
107                         throw new ServletException(ex);
108                 }
109         }
110 }