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 import java.util.Date; 022 023 import javax.persistence.Entity; 024 import javax.persistence.GeneratedValue; 025 import javax.persistence.Id; 026 import javax.persistence.NamedQueries; 027 import javax.persistence.NamedQuery; 028 import javax.persistence.OneToOne; 029 import javax.persistence.Version; 030 import javax.persistence.Table; 031 import javax.persistence.Column; 032 import javax.persistence.Transient; 033 034 import org.apache.geronimo.samples.daytrader.util.Log; 035 036 @Entity(name = "holdingejb") 037 @Table(name = "holdingejb") 038 @NamedQueries({ 039 @NamedQuery(name = "holdingsByUserID", 040 query = "SELECT h FROM holdingejb h where h.account.profile.userID = :userID") 041 }) 042 public class HoldingDataBean 043 implements Serializable { 044 045 /* persistent/relationship fields */ 046 047 @Id 048 @GeneratedValue 049 private Integer holdingID; /* holdingID */ 050 private double quantity; /* quantity */ 051 private BigDecimal purchasePrice; /* purchasePrice */ 052 private Date purchaseDate; /* purchaseDate */ 053 // @Column(length = 250) 054 @Transient 055 private String quoteID; /* Holding(*) ---> Quote(1) */ 056 @OneToOne 057 private AccountDataBean account; 058 @OneToOne 059 private QuoteDataBean quote; 060 061 // @Version 062 // private Integer optLock; 063 064 public HoldingDataBean() { 065 } 066 067 public HoldingDataBean(Integer holdingID, 068 double quantity, 069 BigDecimal purchasePrice, 070 Date purchaseDate, 071 String quoteID) { 072 setHoldingID(holdingID); 073 setQuantity(quantity); 074 setPurchasePrice(purchasePrice); 075 setPurchaseDate(purchaseDate); 076 setQuoteID(quoteID); 077 } 078 079 public HoldingDataBean(double quantity, 080 BigDecimal purchasePrice, 081 Date purchaseDate, 082 AccountDataBean account, 083 QuoteDataBean quote) { 084 setQuantity(quantity); 085 setPurchasePrice(purchasePrice); 086 setPurchaseDate(purchaseDate); 087 setAccount(account); 088 setQuote(quote); 089 } 090 091 public static HoldingDataBean getRandomInstance() { 092 return new HoldingDataBean( 093 new Integer(TradeConfig.rndInt(100000)), //holdingID 094 TradeConfig.rndQuantity(), //quantity 095 TradeConfig.rndBigDecimal(1000.0f), //purchasePrice 096 new java.util.Date(TradeConfig.rndInt(Integer.MAX_VALUE)), //purchaseDate 097 TradeConfig.rndSymbol() // symbol 098 ); 099 } 100 101 public String toString() { 102 return "\n\tHolding Data for holding: " + getHoldingID() 103 + "\n\t\t quantity:" + getQuantity() 104 + "\n\t\t purchasePrice:" + getPurchasePrice() 105 + "\n\t\t purchaseDate:" + getPurchaseDate() 106 + "\n\t\t quoteID:" + getQuoteID() 107 ; 108 } 109 110 public String toHTML() { 111 return "<BR>Holding Data for holding: " + getHoldingID() + "</B>" 112 + "<LI> quantity:" + getQuantity() + "</LI>" 113 + "<LI> purchasePrice:" + getPurchasePrice() + "</LI>" 114 + "<LI> purchaseDate:" + getPurchaseDate() + "</LI>" 115 + "<LI> quoteID:" + getQuoteID() + "</LI>" 116 ; 117 } 118 119 public void print() { 120 Log.log(this.toString()); 121 } 122 123 /** 124 * Gets the holdingID 125 * 126 * @return Returns a Integer 127 */ 128 public Integer getHoldingID() { 129 return holdingID; 130 } 131 132 /** 133 * Sets the holdingID 134 * 135 * @param holdingID The holdingID to set 136 */ 137 public void setHoldingID(Integer holdingID) { 138 this.holdingID = holdingID; 139 } 140 141 /** 142 * Gets the quantity 143 * 144 * @return Returns a BigDecimal 145 */ 146 public double getQuantity() { 147 return quantity; 148 } 149 150 /** 151 * Sets the quantity 152 * 153 * @param quantity The quantity to set 154 */ 155 public void setQuantity(double quantity) { 156 this.quantity = quantity; 157 } 158 159 /** 160 * Gets the purchasePrice 161 * 162 * @return Returns a BigDecimal 163 */ 164 public BigDecimal getPurchasePrice() { 165 return purchasePrice; 166 } 167 168 /** 169 * Sets the purchasePrice 170 * 171 * @param purchasePrice The purchasePrice to set 172 */ 173 public void setPurchasePrice(BigDecimal purchasePrice) { 174 this.purchasePrice = purchasePrice; 175 } 176 177 /** 178 * Gets the purchaseDate 179 * 180 * @return Returns a Date 181 */ 182 public Date getPurchaseDate() { 183 return purchaseDate; 184 } 185 186 /** 187 * Sets the purchaseDate 188 * 189 * @param purchaseDate The purchaseDate to set 190 */ 191 public void setPurchaseDate(Date purchaseDate) { 192 this.purchaseDate = purchaseDate; 193 } 194 195 /** 196 * Gets the quoteID 197 * 198 * @return Returns symbol for associated quote 199 */ 200 public String getQuoteID() { 201 if (quote != null) { 202 return quote.getSymbol(); 203 } 204 return quoteID; 205 } 206 207 /** 208 * Sets the quoteID 209 * 210 * @param quoteID The quoteID to set 211 */ 212 public void setQuoteID(String quoteID) { 213 this.quoteID = quoteID; 214 } 215 216 public AccountDataBean getAccount() { 217 return account; 218 } 219 220 public void setAccount(AccountDataBean account) { 221 this.account = account; 222 } 223 224 /** 225 * Gets the quoteID 226 * 227 * @return Returns a Integer 228 */ 229 /* Disabled for D185273 230 public String getSymbol() { 231 return getQuoteID(); 232 } 233 */ 234 public QuoteDataBean getQuote() { 235 return quote; 236 } 237 238 public void setQuote(QuoteDataBean quote) { 239 this.quote = quote; 240 } 241 }