]> git.mxchange.org Git - pizzaservice-ejb.git/blob - src/java/org/mxchange/pizzaapplication/model/customer/PizzaAdminCustomerSessionBean.java
Continued a bit:
[pizzaservice-ejb.git] / src / java / org / mxchange / pizzaapplication / model / customer / PizzaAdminCustomerSessionBean.java
1 /*
2  * Copyright (C) 2016 Roland Haeder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License as
6  * published by the Free Software Foundation, either version 3 of the
7  * License, or (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 Affero General Public License for more details.
13  *
14  * You should have received a copy of the GNU Affero General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.pizzaapplication.model.customer;
18
19 import java.text.MessageFormat;
20 import java.util.List;
21 import javax.ejb.Stateless;
22 import javax.persistence.Query;
23 import org.mxchange.jcustomercore.model.customer.Customer;
24 import org.mxchange.jcustomercore.utils.CustomerUtils;
25 import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean;
26
27 /**
28  * A stateless administrative customer session bean (EJB)
29  * <p>
30  * @author Roland Haeder<roland@mxchange.org>
31  */
32 @Stateless (name = "admincustomer", description = "Administrative bean handling customer data")
33 public class PizzaAdminCustomerSessionBean extends BasePizzaDatabaseBean implements PizzaAdminCustomerSessionBeanRemote {
34
35         /**
36          * Serial number
37          */
38         private static final long serialVersionUID = 19_845_893_648_175_427L;
39
40         @Override
41         @SuppressWarnings ("unchecked")
42         public List<Customer> allCustomers () {
43                 // Trace message
44                 this.getLoggerBeanLocal().logTrace("allCustomers: CALLED!"); //NOI18N
45
46                 // Get named query
47                 Query query = this.getEntityManager().createNamedQuery("AllCustomers", List.class); //NOI18N
48
49                 // Get result
50                 List<Customer> customers = query.getResultList();
51
52                 // Trace message
53                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("allCustomers: customers.size()={0} - EXIT!", customers.size())); //NOI18N
54
55                 // Return full list
56                 return customers;
57         }
58
59         @Override
60         public String createCustomerNumber () {
61                 // Init named query
62                 Query query = this.getEntityManager().createNamedQuery("SearchCustomerByNumber", RateCalcCustomer.class);
63
64                 // Default is not found
65                 String customerNumber = null;
66
67                 // Search until a free number was found
68                 while (null == customerNumber) {
69                         // Create new number
70                         String cn = CustomerUtils.generateCustomerNumber(RateCalcAdminCustomerSessionBeanRemote.CUSTOMER_NUMBER_LENGTH);
71                 }
72         }
73
74 }