]> git.mxchange.org Git - jcustomer-core.git/blob - src/org/mxchange/jshopcore/model/basket/BaseBasket.java
Continued:
[jcustomer-core.git] / src / org / mxchange / jshopcore / model / basket / BaseBasket.java
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.jshopcore.model.basket;
18
19 import java.io.IOException;
20 import java.lang.reflect.InvocationTargetException;
21 import java.sql.SQLException;
22 import java.text.MessageFormat;
23 import java.util.Map;
24 import org.mxchange.jcoreee.BaseEeSystem;
25
26 /**
27  * A general basket class
28  *
29  * @author Roland Haeder
30  * @param <T> Any instance that implements AddableBasketItem
31  */
32 public abstract class BaseBasket<T extends AddableBasketItem> extends BaseEeSystem implements Basket<T> {
33         /**
34          * Serial number
35          */
36         private static final long serialVersionUID = 782_396_762_230_845_717L;
37
38         /**
39          * Protected constructor with session instance
40          *
41          * @throws java.sql.SQLException If an SQL error occurs
42          */
43         protected BaseBasket () throws SQLException {
44                 // Trace message
45                 this.getLogger().logTrace("CALLED!"); //NOI18N
46         }
47
48         @Override
49         public void init () throws SQLException {
50                 // Trace message
51                 this.getLogger().logTrace("CALLED!"); //NOI18N
52         }
53
54         @Override
55         @SuppressWarnings ("unchecked")
56         public void addItem (final T item) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
57                 // Trace call
58                 this.getLogger().logTrace(MessageFormat.format("item={0} - CALLED!", item)); //NOI18N
59
60                 // item must not be null
61                 if (null == item) {
62                         // Then abort here
63                         throw new NullPointerException("item is null"); //NOI18N
64                 } else if (this.isAdded(item)) {
65                         // Already been added
66                         throw new IllegalArgumentException("item has already been added. Did you miss to call isAdded()?"); //NOI18N
67                 }
68
69                 // Add item to database
70                 // TODO: ((BasketFrontend) this.getFrontend()).addItem(item, this.getSessionId());
71
72                 // Trace call
73                 this.getLogger().logTrace("EXIT!"); //NOI18N
74         }
75
76         @Override
77         public boolean isEmpty () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
78                 // Deligate call to frontend
79                 // TODO: return ((BasketFrontend) this.getFrontend()).isEmpty();
80                 throw new UnsupportedOperationException("Not yet implmeneted.");
81         }
82
83         @Override
84         @SuppressWarnings("unchecked")
85         public Map<Long, T> getAll () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
86                 // Trace message
87                 this.getLogger().logTrace("CALLED!"); //NOI18N
88
89                 // Init map
90                 // TODO: Map<Long, T> map = ((BasketFrontend) this.getFrontend()).getAll();
91                 Map<Long, T> map = null;
92
93                 // Trace message
94                 this.getLogger().logTrace("map=" + map); //NOI18N
95
96                 // Return it
97                 return map;
98         }
99
100         @Override
101         public AddableBasketItem getLast () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
102                 // Deligate to frontend
103                 // TODO: return ((BasketFrontend) this.getFrontend()).getLast();
104                 throw new UnsupportedOperationException("Not yet implmeneted.");
105         }
106
107         @Override
108         public int getLastNumRows () {
109                 // Deligate to frontend
110                 // TODO: return this.getFrontend().getLastNumRows();
111                 throw new UnsupportedOperationException("Not yet implmeneted.");
112         }
113
114         @Override
115         public boolean isAdded (final T item) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
116                 // Trace call
117                 this.getLogger().logTrace(MessageFormat.format("item={0} - CALLED!", item)); //NOI18N
118
119                 // item must not be null
120                 if (null == item) {
121                         // Then abort here
122                         throw new NullPointerException("item is null"); //NOI18N
123                 }
124
125                 // Call map's method
126                 // TODO: boolean isAdded = ((BasketFrontend) this.getFrontend()).isAdded(item, this.getSessionId());
127                 boolean isAdded = true;
128
129                 // Trace message
130                 this.getLogger().logTrace(MessageFormat.format("isAdded={0} - EXIT!", isAdded)); //NOI18N
131
132                 // Return it
133                 return isAdded;
134         }
135 }