Source code: com/globalretailtech/data/Currency.java
1 /*
2 * Copyright (C) 2001 Global Retail Technology, LLC
3 * <http://www.globalretailtech.com>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 package com.globalretailtech.data;
21
22 import java.sql.*;
23 import java.util.Vector;
24 import java.util.Locale;
25
26 import com.globalretailtech.util.Application;
27 import com.globalretailtech.util.Log;
28
29 /**
30 * Currency is used to manage all currencies (money). Includes conversion
31 * rates in reference to the local currency and flags to indicate whether
32 * it is the base currency and the local currency.
33 *
34 * @author Quentin Olson
35 */
36 public class Currency extends DBRecord
37 {
38
39 private static String table;
40 private static String [] columns;
41 private static int [] col_types;
42
43 static {
44
45 table = "currency";
46
47 columns = new String [11];
48
49 columns [0] = "currency_id";
50 columns [1] = "config_no";
51 columns [2] = "currency_code_id";
52 columns [3] = "conversion_rate";
53 columns [4] = "smallest_denom";
54 columns [5] = "decimal_digits";
55 columns [6] = "locale";
56 columns [7] = "is_base";
57 columns [8] = "is_local";
58 columns [9] = "last_update";
59 columns [10] = "currency_class";
60
61 col_types = new int [11];
62
63 col_types [0] = DBRecord.INT;
64 col_types [1] = DBRecord.INT;
65 col_types [2] = DBRecord.INT;
66 col_types [3] = DBRecord.DOUBLE;
67 col_types [4] = DBRecord.INT;
68 col_types [5] = DBRecord.INT;
69 col_types [6] = DBRecord.STRING;
70 col_types [7] = DBRecord.BOOLEAN;
71 col_types [8] = DBRecord.BOOLEAN;
72 col_types [9] = DBRecord.DATE;
73 col_types [10] = DBRecord.STRING;
74 }
75
76 private int currencyid;
77 private int configno;
78 private int currencycodeid;
79 private double conversionrate;
80 private int smallestdenom;
81 private int decimaldigits;
82 private String locale;
83 private boolean isbase;
84 private boolean islocal;
85 private Date lastupdate;
86 private String currencyclass;
87
88 public Currency ()
89 {}
90
91 public int currencyID ()
92 {
93 return currencyid;
94 }
95 public int configNo ()
96 {
97 return configno;
98 }
99 public int currencyCodeID ()
100 {
101 return currencycodeid;
102 }
103 public double conversionRate ()
104 {
105 return conversionrate;
106 }
107 public int smallestDenom ()
108 {
109 return smallestdenom;
110 }
111 public int decimalDigits ()
112 {
113 return decimaldigits;
114 }
115 public String locale ()
116 {
117 return locale;
118 }
119 public boolean isBase ()
120 {
121 return isbase;
122 }
123 public boolean isLocal ()
124 {
125 return islocal;
126 }
127 public Date lastUpdate ()
128 {
129 return lastupdate;
130 }
131 public String currencyClass ()
132 {
133 return currencyclass;
134 }
135
136 public void setCurrencyID (int value)
137 {
138 currencyid = value;
139 }
140 public void setConfigNo (int value)
141 {
142 configno = value;
143 }
144 public void setCurrencyCodeID (int value)
145 {
146 currencycodeid = value;
147 }
148 public void setConversionRate ( double value)
149 {
150 conversionrate = value;
151 }
152 public void setSmallestDenom (int value)
153 {
154 smallestdenom = value;
155 }
156 public void setDecimalDigits (int value)
157 {
158 decimaldigits = value;
159 }
160 public void setLocale (String value)
161 {
162 locale = value;
163 }
164 public void setIsBase (boolean value)
165 {
166 isbase = value;
167 }
168 public void setIsLocal (boolean value)
169 {
170 islocal = value;
171 }
172 public void setLastUpdate (Date value)
173 {
174 lastupdate = value;
175 }
176 public void setCurrencyClass (String value)
177 {
178 currencyclass = value;
179 }
180
181 public static String getByID (int id)
182 {
183
184 StringBuffer s = new StringBuffer ("select * from ");
185
186 s.append (table);
187 s.append (" where ");
188 s.append (columns [0]);
189 s.append (" = ");
190 s.append (Integer.toString (id));
191
192 return new String (s.toString ());
193 }
194
195 public static String getByLocale (String locale)
196 {
197
198 StringBuffer s = new StringBuffer ("select * from ");
199
200 s.append (table);
201 s.append (" where ");
202 s.append (columns [6]);
203 s.append (" = '");
204 s.append (locale);
205 s.append ("'");
206
207 return new String (s.toString ());
208 }
209
210 public DBRecord copy ()
211 {
212 Currency b = new Currency ();
213 return b;
214 }
215
216 public void populate (ResultSet rset)
217 {
218
219 try
220 {
221
222 setCurrencyID (rset.getInt ("currency_id"));
223 setConfigNo (rset.getInt ("config_no"));
224 setCurrencyCodeID (rset.getInt ("currency_code_id"));
225 setConversionRate (rset.getDouble ("conversion_rate"));
226 setSmallestDenom (rset.getInt ("smallest_denom"));
227 setDecimalDigits (rset.getInt ("decimal_digits"));
228 setLocale (rset.getString ("locale"));
229 setIsBase (rset.getInt ("is_base") > 0);
230 setIsLocal (rset.getInt ("is_local") > 0);
231 setLastUpdate (rset.getDate ("last_update"));
232 setCurrencyClass (rset.getString ("currency_class"));
233 }
234 catch (java.sql.SQLException e)
235 {
236 Application.dbConnection ().setException (e);
237 }
238 }
239
240 public boolean save ()
241 {
242 return true;
243 }
244 public boolean update ()
245 {
246 return true;
247 }
248 public String toXML ()
249 {
250 return super.toXML (table, columnObjects (), columns, col_types);
251 }
252
253 //
254 // Relations
255 //
256
257 private CurrencyCode currenycode;
258 public CurrencyCode currencyCode ()
259 {
260 return currenycode;
261 }
262 public void setCurrencyCode (CurrencyCode value)
263 {
264 currenycode = value;
265 }
266
267 public void relations ()
268 {
269
270 String fetchSpec = CurrencyCode.getByID (currencyCodeID ());
271 Vector v = Application.dbConnection ().fetch (new CurrencyCode (), fetchSpec);
272
273 if (v.size () > 0)
274 {
275 setCurrencyCode ((CurrencyCode) v.elementAt (0));
276 }
277 else
278 {
279 Log.warning ("Currency code not found for " + currencyID ());
280 }
281 }
282
283 public Vector columnObjects ()
284 {
285
286 Vector objs = new Vector ();
287
288 objs.addElement (new Integer (currencyID ()));
289 objs.addElement (new Integer (configNo ()));
290 objs.addElement (new Integer (currencyCodeID ()));
291 objs.addElement (new Double (conversionRate ()));
292 objs.addElement (new Integer (smallestDenom ()));
293 objs.addElement (new Integer (decimalDigits ()));
294 objs.addElement (new String (locale ()));
295 objs.addElement (new Boolean (isBase ()));
296 objs.addElement (new Boolean (isLocal ()));
297 objs.addElement (lastUpdate ());
298 objs.addElement (new String (currencyClass ()));
299
300 return objs;
301 }
302 }
303
304 /**
305 * $Log: Currency.java,v $
306 * Revision 1.1.1.1 2001/08/13 22:16:11 qolson
307 * Initial Checkin 0.2-2
308 *
309 *
310 */