1 package org.apache.jetspeed.om.apps.coffees; 2 3 4 import java.math.BigDecimal ; 5 import java.sql.Connection ; 6 import java.util.ArrayList ; 7 import java.util.Collections ; 8 import java.util.Date ; 9 import java.util.List ; 10 11 import org.apache.commons.lang.ObjectUtils; 12 import org.apache.torque.TorqueException; 13 import org.apache.torque.om.BaseObject; 14 import org.apache.torque.om.ComboKey; 15 import org.apache.torque.om.DateKey; 16 import org.apache.torque.om.NumberKey; 17 import org.apache.torque.om.ObjectKey; 18 import org.apache.torque.om.SimpleKey; 19 import org.apache.torque.om.StringKey; 20 import org.apache.torque.om.Persistent; 21 import org.apache.torque.util.Criteria; 22 import org.apache.torque.util.Transaction; 23 24 25 33 public abstract class BaseCoffees extends BaseObject 34 { 35 36 private static final CoffeesPeer peer = 37 new CoffeesPeer(); 38 39 40 41 private int coffeeId; 42 43 44 private String coffeeName; 45 46 47 private int supplierId; 48 49 50 private double price; 51 52 53 private int sales; 54 55 56 private int total; 57 58 59 63 public int getCoffeeId() 64 { 65 return coffeeId; 66 } 67 68 69 72 public void setCoffeeId(int v ) 73 { 74 75 if (this.coffeeId != v) 76 { 77 this.coffeeId = v; 78 setModified(true); 79 } 80 81 82 } 83 84 85 89 public String getCoffeeName() 90 { 91 return coffeeName; 92 } 93 94 95 98 public void setCoffeeName(String v ) 99 { 100 101 if (!ObjectUtils.equals(this.coffeeName, v)) 102 { 103 this.coffeeName = v; 104 setModified(true); 105 } 106 107 108 } 109 110 111 115 public int getSupplierId() 116 { 117 return supplierId; 118 } 119 120 121 124 public void setSupplierId(int v ) 125 { 126 127 if (this.supplierId != v) 128 { 129 this.supplierId = v; 130 setModified(true); 131 } 132 133 134 } 135 136 137 141 public double getPrice() 142 { 143 return price; 144 } 145 146 147 150 public void setPrice(double v ) 151 { 152 153 if (this.price != v) 154 { 155 this.price = v; 156 setModified(true); 157 } 158 159 160 } 161 162 163 167 public int getSales() 168 { 169 return sales; 170 } 171 172 173 176 public void setSales(int v ) 177 { 178 179 if (this.sales != v) 180 { 181 this.sales = v; 182 setModified(true); 183 } 184 185 186 } 187 188 189 193 public int getTotal() 194 { 195 return total; 196 } 197 198 199 202 public void setTotal(int v ) 203 { 204 205 if (this.total != v) 206 { 207 this.total = v; 208 setModified(true); 209 } 210 211 212 } 213 214 215 216 217 private static List fieldNames = null; 218 219 222 public static synchronized List getFieldNames() 223 { 224 if (fieldNames == null) 225 { 226 fieldNames = new ArrayList (); 227 fieldNames.add("CoffeeId"); 228 fieldNames.add("CoffeeName"); 229 fieldNames.add("SupplierId"); 230 fieldNames.add("Price"); 231 fieldNames.add("Sales"); 232 fieldNames.add("Total"); 233 fieldNames = Collections.unmodifiableList(fieldNames); 234 } 235 return fieldNames; 236 } 237 238 242 public Object getByName(String name) 243 { 244 if (name.equals("CoffeeId")) 245 { 246 return new Integer (getCoffeeId()); 247 } 248 if (name.equals("CoffeeName")) 249 { 250 return getCoffeeName(); 251 } 252 if (name.equals("SupplierId")) 253 { 254 return new Integer (getSupplierId()); 255 } 256 if (name.equals("Price")) 257 { 258 return new Double (getPrice()); 259 } 260 if (name.equals("Sales")) 261 { 262 return new Integer (getSales()); 263 } 264 if (name.equals("Total")) 265 { 266 return new Integer (getTotal()); 267 } 268 return null; 269 } 270 271 276 public Object getByPeerName(String name) 277 { 278 if (name.equals(CoffeesPeer.COFFEE_ID )) 279 { 280 return new Integer (getCoffeeId()); 281 } 282 if (name.equals(CoffeesPeer.COFFEE_NAME )) 283 { 284 return getCoffeeName(); 285 } 286 if (name.equals(CoffeesPeer.SUPPLIER_ID )) 287 { 288 return new Integer (getSupplierId()); 289 } 290 if (name.equals(CoffeesPeer.PRICE )) 291 { 292 return new Double (getPrice()); 293 } 294 if (name.equals(CoffeesPeer.SALES )) 295 { 296 return new Integer (getSales()); 297 } 298 if (name.equals(CoffeesPeer.TOTAL )) 299 { 300 return new Integer (getTotal()); 301 } 302 return null; 303 } 304 305 309 public Object getByPosition(int pos) 310 { 311 if ( pos == 0 ) 312 { 313 return new Integer (getCoffeeId()); 314 } 315 if ( pos == 1 ) 316 { 317 return getCoffeeName(); 318 } 319 if ( pos == 2 ) 320 { 321 return new Integer (getSupplierId()); 322 } 323 if ( pos == 3 ) 324 { 325 return new Double (getPrice()); 326 } 327 if ( pos == 4 ) 328 { 329 return new Integer (getSales()); 330 } 331 if ( pos == 5 ) 332 { 333 return new Integer (getTotal()); 334 } 335 return null; 336 } 337 338 342 public void save() throws Exception 343 { 344 save(CoffeesPeer.getMapBuilder() 345 .getDatabaseMap().getName()); 346 } 347 348 355 public void save(String dbName) throws TorqueException 356 { 357 Connection con = null; 358 try 359 { 360 con = Transaction.begin(dbName); 361 save(con); 362 Transaction.commit(con); 363 } 364 catch(TorqueException e) 365 { 366 Transaction.safeRollback(con); 367 throw e; 368 } 369 } 370 371 373 private boolean alreadyInSave = false; 374 381 public void save(Connection con) throws TorqueException 382 { 383 if (!alreadyInSave) 384 { 385 alreadyInSave = true; 386 387 388 389 if (isModified()) 391 { 392 if (isNew()) 393 { 394 CoffeesPeer.doInsert((Coffees)this, con); 395 setNew(false); 396 } 397 else 398 { 399 CoffeesPeer.doUpdate((Coffees)this, con); 400 } 401 402 if (isCacheOnSave()) 403 { 404 CoffeesManager.putInstance(this); 405 } 406 } 407 408 alreadyInSave = false; 409 } 410 } 411 412 416 protected boolean isCacheOnSave() 417 { 418 return true; 419 } 420 421 422 427 public void setPrimaryKey(ObjectKey coffeeId) 428 { 429 setCoffeeId(((NumberKey)coffeeId).intValue()); 430 } 431 432 435 public void setPrimaryKey(String key) 436 { 437 setCoffeeId(Integer.parseInt(key)); 438 } 439 440 441 445 public ObjectKey getPrimaryKey() 446 { 447 return SimpleKey.keyFor(getCoffeeId()); 448 } 449 450 451 456 public Coffees copy() throws TorqueException 457 { 458 Coffees copyObj = new Coffees(); 459 copyObj.setCoffeeId(coffeeId); 460 copyObj.setCoffeeName(coffeeName); 461 copyObj.setSupplierId(supplierId); 462 copyObj.setPrice(price); 463 copyObj.setSales(sales); 464 copyObj.setTotal(total); 465 466 copyObj.setCoffeeId(0); 467 468 return copyObj; 469 } 470 471 477 public CoffeesPeer getPeer() 478 { 479 return peer; 480 } 481 } 482 | Popular Tags |