1 32 33 34 43 package stockonline.ejb.entity.cmp.stocktx; 44 45 import javax.naming.*; 46 import javax.rmi.*; 47 import javax.ejb.*; 48 import javax.sql.*; 49 50 import java.sql.*; 51 import java.util.*; 52 import java.rmi.*; 53 54 import stockonline.ejb.sql.SeqGenerator; 55 import stockonline.ejb.entity.interf.*; 56 57 61 public class StockTxBean implements EntityBean 62 { 63 final static boolean verbose = false; 64 final static String BEAN_NAME = "cmpStockTx"; 65 final static String RESOURCE_NAME = "java:comp/env/jdbc/StockDB"; 66 67 public int trans_id; public String trans_type; 70 public int sub_accno; 71 public int stock_id; 72 public int amount; 73 public float price; 74 public String trans_date; 75 76 protected EntityContext ctx; 77 private transient boolean isDirty; private java.text.SimpleDateFormat dateFormatter = new java.text.SimpleDateFormat ("dd/MM/yy"); 79 80 public StockTxBean() 81 { 82 if (verbose) System.out.println(BEAN_NAME + " instantiated"); 83 } 84 85 90 public int getTxID() 91 { 92 return trans_id; 93 } 94 95 99 104 108 public void setEntityContext(EntityContext ctx) 109 { 110 if (verbose) 111 System.out.println(BEAN_NAME + ".setEntityContext() called"); 112 113 this.ctx = ctx; 114 } 115 116 120 public void unsetEntityContext() 121 { 122 if (verbose) 123 System.out.println(BEAN_NAME + ".unsetEntityContext() called"); 124 125 this.ctx = null; 126 } 127 128 131 public void ejbActivate() 132 { 133 if (verbose) 134 System.out.println(BEAN_NAME + ".ejbActivate() called."); 135 136 setModified(true); 137 } 138 139 142 public void ejbPassivate() 143 { 144 if (verbose) 145 System.out.println(BEAN_NAME + ".ejbPassivate () called."); 146 } 147 148 154 public StockTxPK ejbCreate(String trans_type, int sub_accno, int stock_id, int amount, float price) 155 throws CreateException 156 { 157 if (verbose) 158 System.out.println(BEAN_NAME + ".ejbCreate() called."); 159 160 try 161 { 162 this.trans_id = SeqGenerator.getNextTxID(RESOURCE_NAME); 163 this.trans_type = trans_type; 164 this.sub_accno = sub_accno; 165 this.stock_id = stock_id; 166 this.amount = amount; 167 this.price = price; 168 this.trans_date = dateFormatter.format( new java.util.Date () ); 169 170 if(verbose) System.out.println("trans_date = " + trans_date); 171 172 return null; 173 } 174 catch(Exception ex) 175 { 176 String msg = BEAN_NAME + ".ejbCreate(): Failed to get a sequence number, due to: " + ex.toString(); 177 178 System.err.println(msg); 179 throw new CreateException(msg); 180 } 181 } 182 183 187 public void ejbPostCreate(String trans_type, int sub_accno, int stock_id, int amount, float price) 188 { 189 setModified(false); 190 } 191 192 198 public StockTxPK ejbCreate(int trans_id, String trans_type, int sub_accno, int stock_id, int amount, float price) 199 throws CreateException 200 { 201 if (verbose) 202 System.out.println(BEAN_NAME + ".ejbCreate() called."); 203 204 try 205 { 206 String currentDate = dateFormatter.format( new java.util.Date () ); 207 if(verbose) System.out.println(currentDate); 208 209 this.trans_id = trans_id; 210 this.trans_type = trans_type; 211 this.sub_accno = sub_accno; 212 this.stock_id = stock_id; 213 this.amount = amount; 214 this.price = price; 215 this.trans_date = currentDate; 216 217 return null; 218 } 219 catch(Exception ex) 220 { 221 String msg = BEAN_NAME + ".ejbCreate(): Failed to get a sequence number, due to: " + ex.toString(); 222 223 System.err.println(msg); 224 throw new CreateException(msg); 225 } 226 } 227 228 232 public void ejbPostCreate(int trans_id, String trans_type, int sub_accno, int stock_id, int amount, float price) 233 { 234 setModified(false); 235 } 236 237 241 public void ejbRemove() 242 { 243 if (verbose) 244 System.out.println(BEAN_NAME + ".ejbRemove() called."); 245 } 246 247 248 252 public void ejbLoad() throws RemoteException 253 { 254 if (verbose) 255 System.out.println(BEAN_NAME + ".ejbLoad() called."); 256 257 setModified(false); 258 } 259 260 264 public void ejbStore() throws RemoteException 265 { 266 if (verbose) 267 System.out.println(BEAN_NAME + ".ejbStore() called."); 268 269 } 271 272 277 public boolean isModified() 278 { 279 if (verbose) 280 System.out.println (BEAN_NAME + ".isModified(): isDirty = " + (isDirty ? "true" : "false")); 281 282 return isDirty; 283 } 284 285 290 public void setModified(boolean flag) 291 { 292 isDirty = flag; 293 } 294 } 295 | Popular Tags |