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.ejb; 018 019 import javax.ejb.*; 020 import java.math.BigDecimal; 021 import java.sql.Timestamp; 022 import org.apache.geronimo.samples.daytrader.*; 023 024 public abstract class HoldingBean 025 implements EntityBean { 026 027 private EntityContext context; 028 029 /* Accessor methods for persistent fields */ 030 031 public abstract Integer getHoldingID(); /* holdingID */ 032 public abstract void setHoldingID(Integer holdingID); 033 public abstract double getQuantity(); /* quantity */ 034 public abstract void setQuantity(double quantity); 035 public abstract BigDecimal getPurchasePrice(); /* purchasePrice */ 036 public abstract void setPurchasePrice(BigDecimal purchasePrice); 037 public abstract Timestamp getPurchaseDate(); /* purchaseDate */ 038 public abstract void setPurchaseDate(Timestamp purchaseDate); 039 040 /* Accessor methods for relationship fields */ 041 public abstract LocalAccount getAccount(); /* Account(1) <---> Holding(*) */ 042 public abstract void setAccount(LocalAccount account); 043 public abstract LocalQuote getQuote(); /* Holding(*) ---> Quote(1) */ 044 public abstract void setQuote(LocalQuote quote); 045 046 /* Select methods */ 047 048 public abstract LocalQuote ejbSelectQuoteFromSymbol(String symbol) 049 throws FinderException; 050 051 052 private LocalQuote getQuoteFromSymbol(String symbol) throws FinderException 053 { 054 LocalHolding holding = (LocalHolding) context.getEJBLocalObject(); 055 return ejbSelectQuoteFromSymbol(symbol); 056 } 057 058 /* Business methods */ 059 060 public HoldingDataBean getDataBean() 061 { 062 return new HoldingDataBean(getHoldingID(), 063 getQuantity(), 064 getPurchasePrice(), 065 getPurchaseDate(), 066 (String)getQuote().getPrimaryKey()); 067 } 068 069 public String toString() 070 { 071 return getDataBean().toString(); 072 } 073 074 075 /* Required javax.ejb.EntityBean interface methods */ 076 public Integer ejbCreate (int holdingID, LocalAccount account, LocalQuote quote, double quantity, BigDecimal purchasePrice) 077 throws CreateException { 078 return this.ejbCreate(new Integer(holdingID), account, quote, quantity, purchasePrice); 079 } 080 081 public Integer ejbCreate (Integer holdingID, LocalAccount account, LocalQuote quote, double quantity, BigDecimal purchasePrice) 082 throws CreateException { 083 084 setHoldingID(holdingID); 085 setQuantity(quantity); 086 setPurchasePrice(purchasePrice); 087 setPurchaseDate(new Timestamp(System.currentTimeMillis())); 088 089 return null; 090 } 091 092 public void ejbPostCreate (Integer holdingID, LocalAccount account, LocalQuote quote, double quantity, BigDecimal purchasePrice) 093 throws CreateException { 094 095 //Establish relationship with Quote for this holding 096 setAccount(account); 097 setQuote(quote); 098 } 099 100 public void ejbPostCreate (int holdingID, LocalAccount account, LocalQuote quote, double quantity, BigDecimal purchasePrice) 101 throws CreateException { 102 this.ejbPostCreate(new Integer(holdingID), account, quote, quantity, purchasePrice); 103 } 104 105 public void setEntityContext(EntityContext ctx) { 106 context = ctx; 107 } 108 109 public void unsetEntityContext() { 110 context = null; 111 } 112 113 public void ejbRemove() { 114 } 115 116 public void ejbLoad() { 117 } 118 119 public void ejbStore() { 120 } 121 122 public void ejbPassivate() { 123 } 124 125 public void ejbActivate() { 126 } 127 }