001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.geronimo.samples.daytrader; 018 019 import java.io.Serializable; 020 import java.math.BigDecimal; 021 022 import javax.persistence.Entity; 023 import javax.persistence.Id; 024 import javax.persistence.NamedQueries; 025 import javax.persistence.NamedQuery; 026 import javax.persistence.Version; 027 import javax.persistence.Table; 028 import javax.persistence.Column; 029 030 import org.apache.geronimo.samples.daytrader.util.Log; 031 032 @Entity(name = "quoteejb") 033 @Table(name = "quoteejb") 034 @NamedQueries({ 035 @NamedQuery(name = "allQuotes", 036 query = "SELECT q FROM quoteejb q"), 037 @NamedQuery(name = "quotesByChange", 038 query = "SELECT q FROM quoteejb q WHERE q.symbol LIKE 's:1__' ORDER BY q.change1 DESC") 039 }) 040 public class QuoteDataBean implements Serializable { 041 042 /* Accessor methods for persistent fields */ 043 044 @Id 045 @Column(length = 250) 046 private String symbol; /* symbol */ 047 @Column(length = 250) 048 private String companyName; /* companyName */ 049 private double volume; /* volume */ 050 private BigDecimal price; /* price */ 051 private BigDecimal open1; /* open1 price */ 052 private BigDecimal low; /* low price */ 053 private BigDecimal high; /* high price */ 054 private double change1; /* price change */ 055 // @Version 056 // private Integer optLock; 057 058 /* Accessor methods for relationship fields are not kept in the DataBean */ 059 public QuoteDataBean() { 060 } 061 062 public QuoteDataBean(String symbol, String companyName, double volume, 063 BigDecimal price, BigDecimal open, BigDecimal low, 064 BigDecimal high, double change) { 065 setSymbol(symbol); 066 setCompanyName(companyName); 067 setVolume(volume); 068 setPrice(price); 069 setOpen(open); 070 setLow(low); 071 setHigh(high); 072 setChange(change); 073 } 074 075 public static QuoteDataBean getRandomInstance() { 076 return new QuoteDataBean( 077 TradeConfig.rndSymbol(), //symbol 078 TradeConfig.rndSymbol() + " Incorporated", //Company Name 079 TradeConfig.rndFloat(100000), //volume 080 TradeConfig.rndBigDecimal(1000.0f), //price 081 TradeConfig.rndBigDecimal(1000.0f), //open1 082 TradeConfig.rndBigDecimal(1000.0f), //low 083 TradeConfig.rndBigDecimal(1000.0f), //high 084 TradeConfig.rndFloat(100000) //volume 085 ); 086 } 087 088 //Create a "zero" value quoteDataBean for the given symbol 089 public QuoteDataBean(String symbol) { 090 setSymbol(symbol); 091 } 092 093 094 public String toString() { 095 return "\n\tQuote Data for: " + getSymbol() 096 + "\n\t\t companyName: " + getCompanyName() 097 + "\n\t\t volume: " + getVolume() 098 + "\n\t\t price: " + getPrice() 099 + "\n\t\t open1: " + getOpen() 100 + "\n\t\t low: " + getLow() 101 + "\n\t\t high: " + getHigh() 102 + "\n\t\t change1: " + getChange() 103 ; 104 } 105 106 public String toHTML() { 107 return "<BR>Quote Data for: " + getSymbol() 108 + "<LI> companyName: " + getCompanyName() + "</LI>" 109 + "<LI> volume: " + getVolume() + "</LI>" 110 + "<LI> price: " + getPrice() + "</LI>" 111 + "<LI> open1: " + getOpen() + "</LI>" 112 + "<LI> low: " + getLow() + "</LI>" 113 + "<LI> high: " + getHigh() + "</LI>" 114 + "<LI> change1: " + getChange() + "</LI>" 115 ; 116 } 117 118 public void print() { 119 Log.log(this.toString()); 120 } 121 122 /** 123 * Gets the symbol 124 * 125 * @return Returns a String 126 */ 127 public String getSymbol() { 128 return symbol; 129 } 130 131 /** 132 * Sets the symbol 133 * 134 * @param symbol The symbol to set 135 */ 136 public void setSymbol(String symbol) { 137 this.symbol = symbol; 138 } 139 140 /** 141 * Gets the companyName 142 * 143 * @return Returns a String 144 */ 145 public String getCompanyName() { 146 return companyName; 147 } 148 149 /** 150 * Sets the companyName 151 * 152 * @param companyName The companyName to set 153 */ 154 public void setCompanyName(String companyName) { 155 this.companyName = companyName; 156 } 157 158 /** 159 * Gets the price 160 * 161 * @return Returns a BigDecimal 162 */ 163 public BigDecimal getPrice() { 164 return price; 165 } 166 167 /** 168 * Sets the price 169 * 170 * @param price The price to set 171 */ 172 public void setPrice(BigDecimal price) { 173 this.price = price; 174 } 175 176 /** 177 * Gets the open1 178 * 179 * @return Returns a BigDecimal 180 */ 181 public BigDecimal getOpen() { 182 return open1; 183 } 184 185 /** 186 * Sets the open1 187 * 188 * @param open The open1 to set 189 */ 190 public void setOpen(BigDecimal open) { 191 this.open1 = open; 192 } 193 194 /** 195 * Gets the low 196 * 197 * @return Returns a BigDecimal 198 */ 199 public BigDecimal getLow() { 200 return low; 201 } 202 203 /** 204 * Sets the low 205 * 206 * @param low The low to set 207 */ 208 public void setLow(BigDecimal low) { 209 this.low = low; 210 } 211 212 /** 213 * Gets the high 214 * 215 * @return Returns a BigDecimal 216 */ 217 public BigDecimal getHigh() { 218 return high; 219 } 220 221 /** 222 * Sets the high 223 * 224 * @param high The high to set 225 */ 226 public void setHigh(BigDecimal high) { 227 this.high = high; 228 } 229 230 /** 231 * Gets the change1 232 * 233 * @return Returns a double 234 */ 235 public double getChange() { 236 return change1; 237 } 238 239 /** 240 * Sets the change1 241 * 242 * @param change The change1 to set 243 */ 244 public void setChange(double change) { 245 this.change1 = change; 246 } 247 248 /** 249 * Gets the volume 250 * 251 * @return Returns a BigDecimal 252 */ 253 public double getVolume() { 254 return volume; 255 } 256 257 /** 258 * Sets the volume 259 * 260 * @param volume The volume to set 261 */ 262 public void setVolume(double volume) { 263 this.volume = volume; 264 } 265 266 }